]> git.ipfire.org Git - thirdparty/grsecurity-scrape.git/blame - test/grsecurity-3.0-3.12.8-201401251521.patch
Auto commit, 1 new patch{es}.
[thirdparty/grsecurity-scrape.git] / test / grsecurity-3.0-3.12.8-201401251521.patch
CommitLineData
f3f21576
PK
1diff --git a/Documentation/dontdiff b/Documentation/dontdiff
2index b89a739..9dc5aff 100644
3--- a/Documentation/dontdiff
4+++ b/Documentation/dontdiff
5@@ -2,9 +2,11 @@
6 *.aux
7 *.bin
8 *.bz2
9+*.c.[012]*.*
10 *.cis
11 *.cpio
12 *.csp
13+*.dbg
14 *.dsp
15 *.dvi
16 *.elf
17@@ -14,6 +16,7 @@
18 *.gcov
19 *.gen.S
20 *.gif
21+*.gmo
22 *.grep
23 *.grp
24 *.gz
25@@ -48,14 +51,17 @@
26 *.tab.h
27 *.tex
28 *.ver
29+*.vim
30 *.xml
31 *.xz
32 *_MODULES
33+*_reg_safe.h
34 *_vga16.c
35 *~
36 \#*#
37 *.9
38-.*
39+.[^g]*
40+.gen*
41 .*.d
42 .mm
43 53c700_d.h
44@@ -69,9 +75,11 @@ Image
45 Module.markers
46 Module.symvers
47 PENDING
48+PERF*
49 SCCS
50 System.map*
51 TAGS
52+TRACEEVENT-CFLAGS
53 aconf
54 af_names.h
55 aic7*reg.h*
56@@ -80,6 +88,7 @@ aic7*seq.h*
57 aicasm
58 aicdb.h*
59 altivec*.c
60+ashldi3.S
61 asm-offsets.h
62 asm_offsets.h
63 autoconf.h*
64@@ -92,32 +101,40 @@ bounds.h
65 bsetup
66 btfixupprep
67 build
68+builtin-policy.h
69 bvmlinux
70 bzImage*
71 capability_names.h
72 capflags.c
73 classlist.h*
74+clut_vga16.c
75+common-cmds.h
76 comp*.log
77 compile.h*
78 conf
79 config
80 config-*
81 config_data.h*
82+config.c
83 config.mak
84 config.mak.autogen
85+config.tmp
86 conmakehash
87 consolemap_deftbl.c*
88 cpustr.h
89 crc32table.h*
90 cscope.*
91 defkeymap.c
92+devicetable-offsets.h
93 devlist.h*
94 dnotify_test
95 docproc
96 dslm
97+dtc-lexer.lex.c
98 elf2ecoff
99 elfconfig.h*
100 evergreen_reg_safe.h
101+exception_policy.conf
102 fixdep
103 flask.h
104 fore200e_mkfirm
105@@ -125,12 +142,15 @@ fore200e_pca_fw.c*
106 gconf
107 gconf.glade.h
108 gen-devlist
109+gen-kdb_cmds.c
110 gen_crc32table
111 gen_init_cpio
112 generated
113 genheaders
114 genksyms
115 *_gray256.c
116+hash
117+hid-example
118 hpet_example
119 hugepage-mmap
120 hugepage-shm
121@@ -145,14 +165,14 @@ int32.c
122 int4.c
123 int8.c
124 kallsyms
125-kconfig
126+kern_constants.h
127 keywords.c
128 ksym.c*
129 ksym.h*
130 kxgettext
131 lex.c
132 lex.*.c
133-linux
134+lib1funcs.S
135 logo_*.c
136 logo_*_clut224.c
137 logo_*_mono.c
138@@ -162,14 +182,15 @@ mach-types.h
139 machtypes.h
140 map
141 map_hugetlb
142-media
143 mconf
144+mdp
145 miboot*
146 mk_elfconfig
147 mkboot
148 mkbugboot
149 mkcpustr
150 mkdep
151+mkpiggy
152 mkprep
153 mkregtable
154 mktables
155@@ -185,6 +206,8 @@ oui.c*
156 page-types
157 parse.c
158 parse.h
159+parse-events*
160+pasyms.h
161 patches*
162 pca200e.bin
163 pca200e_ecd.bin2
164@@ -194,6 +217,7 @@ perf-archive
165 piggyback
166 piggy.gzip
167 piggy.S
168+pmu-*
169 pnmtologo
170 ppc_defs.h*
171 pss_boot.h
172@@ -203,7 +227,11 @@ r200_reg_safe.h
173 r300_reg_safe.h
174 r420_reg_safe.h
175 r600_reg_safe.h
176+randstruct.seed
177+realmode.lds
178+realmode.relocs
179 recordmcount
180+regdb.c
181 relocs
182 rlim_names.h
183 rn50_reg_safe.h
184@@ -213,8 +241,12 @@ series
185 setup
186 setup.bin
187 setup.elf
188+signing_key*
189+size_overflow_hash.h
190 sImage
191+slabinfo
192 sm_tbl*
193+sortextable
194 split-include
195 syscalltab.h
196 tables.c
197@@ -224,6 +256,7 @@ tftpboot.img
198 timeconst.h
199 times.h*
200 trix_boot.h
201+user_constants.h
202 utsrelease.h*
203 vdso-syms.lds
204 vdso.lds
205@@ -235,13 +268,17 @@ vdso32.lds
206 vdso32.so.dbg
207 vdso64.lds
208 vdso64.so.dbg
209+vdsox32.lds
210+vdsox32-syms.lds
211 version.h*
212 vmImage
213 vmlinux
214 vmlinux-*
215 vmlinux.aout
216 vmlinux.bin.all
217+vmlinux.bin.bz2
218 vmlinux.lds
219+vmlinux.relocs
220 vmlinuz
221 voffset.h
222 vsyscall.lds
223@@ -249,9 +286,12 @@ vsyscall_32.lds
224 wanxlfw.inc
225 uImage
226 unifdef
227+utsrelease.h
228 wakeup.bin
229 wakeup.elf
230 wakeup.lds
231+x509*
232 zImage*
233 zconf.hash.c
234+zconf.lex.c
235 zoffset.h
236diff --git a/Documentation/kernel-parameters.txt b/Documentation/kernel-parameters.txt
237index 4f7c57c..a2dc685 100644
238--- a/Documentation/kernel-parameters.txt
239+++ b/Documentation/kernel-parameters.txt
240@@ -1031,6 +1031,10 @@ bytes respectively. Such letter suffixes can also be entirely omitted.
241 Format: <unsigned int> such that (rxsize & ~0x1fffc0) == 0.
242 Default: 1024
243
244+ grsec_proc_gid= [GRKERNSEC_PROC_USERGROUP] Chooses GID to
245+ ignore grsecurity's /proc restrictions
246+
247+
248 hashdist= [KNL,NUMA] Large hashes allocated during boot
249 are distributed across NUMA nodes. Defaults on
250 for 64-bit NUMA, off otherwise.
251@@ -2001,6 +2005,10 @@ bytes respectively. Such letter suffixes can also be entirely omitted.
252 noexec=on: enable non-executable mappings (default)
253 noexec=off: disable non-executable mappings
254
255+ nopcid [X86-64]
256+ Disable PCID (Process-Context IDentifier) even if it
257+ is supported by the processor.
258+
259 nosmap [X86]
260 Disable SMAP (Supervisor Mode Access Prevention)
261 even if it is supported by processor.
262@@ -2268,6 +2276,25 @@ bytes respectively. Such letter suffixes can also be entirely omitted.
263 the specified number of seconds. This is to be used if
264 your oopses keep scrolling off the screen.
265
266+ pax_nouderef [X86] disables UDEREF. Most likely needed under certain
267+ virtualization environments that don't cope well with the
268+ expand down segment used by UDEREF on X86-32 or the frequent
269+ page table updates on X86-64.
270+
271+ pax_sanitize_slab=
272+ 0/1 to disable/enable slab object sanitization (enabled by
273+ default).
274+
275+ pax_softmode= 0/1 to disable/enable PaX softmode on boot already.
276+
277+ pax_extra_latent_entropy
278+ Enable a very simple form of latent entropy extraction
279+ from the first 4GB of memory as the bootmem allocator
280+ passes the memory pages to the buddy allocator.
281+
282+ pax_weakuderef [X86-64] enables the weaker but faster form of UDEREF
283+ when the processor supports PCID.
284+
285 pcbit= [HW,ISDN]
286
287 pcd. [PARIDE]
288diff --git a/Makefile b/Makefile
289index 5d0ec13..c74651e 100644
290--- a/Makefile
291+++ b/Makefile
292@@ -241,8 +241,9 @@ CONFIG_SHELL := $(shell if [ -x "$$BASH" ]; then echo $$BASH; \
293
294 HOSTCC = gcc
295 HOSTCXX = g++
296-HOSTCFLAGS = -Wall -Wmissing-prototypes -Wstrict-prototypes -O2 -fomit-frame-pointer
297-HOSTCXXFLAGS = -O2
298+HOSTCFLAGS = -Wall -W -Wmissing-prototypes -Wstrict-prototypes -Wno-unused-parameter -Wno-missing-field-initializers -O2 -fomit-frame-pointer -fno-delete-null-pointer-checks
299+HOSTCFLAGS += $(call cc-option, -Wno-empty-body)
300+HOSTCXXFLAGS = -O2 -Wall -W -fno-delete-null-pointer-checks
301
302 # Decide whether to build built-in, modular, or both.
303 # Normally, just do built-in.
304@@ -414,8 +415,8 @@ export RCS_TAR_IGNORE := --exclude SCCS --exclude BitKeeper --exclude .svn \
305 # Rules shared between *config targets and build targets
306
307 # Basic helpers built in scripts/
308-PHONY += scripts_basic
309-scripts_basic:
310+PHONY += scripts_basic gcc-plugins
311+scripts_basic: gcc-plugins
312 $(Q)$(MAKE) $(build)=scripts/basic
313 $(Q)rm -f .tmp_quiet_recordmcount
314
315@@ -576,6 +577,74 @@ else
316 KBUILD_CFLAGS += -O2
317 endif
318
319+ifndef DISABLE_PAX_PLUGINS
320+ifeq ($(call cc-ifversion, -ge, 0408, y), y)
321+PLUGINCC := $(shell $(CONFIG_SHELL) $(srctree)/scripts/gcc-plugin.sh "$(HOSTCXX)" "$(HOSTCXX)" "$(CC)")
322+else
323+PLUGINCC := $(shell $(CONFIG_SHELL) $(srctree)/scripts/gcc-plugin.sh "$(HOSTCC)" "$(HOSTCXX)" "$(CC)")
324+endif
325+ifneq ($(PLUGINCC),)
326+ifdef CONFIG_PAX_CONSTIFY_PLUGIN
327+CONSTIFY_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/constify_plugin.so -DCONSTIFY_PLUGIN
328+endif
329+ifdef CONFIG_PAX_MEMORY_STACKLEAK
330+STACKLEAK_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/stackleak_plugin.so -DSTACKLEAK_PLUGIN
331+STACKLEAK_PLUGIN_CFLAGS += -fplugin-arg-stackleak_plugin-track-lowest-sp=100
332+endif
333+ifdef CONFIG_KALLOCSTAT_PLUGIN
334+KALLOCSTAT_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/kallocstat_plugin.so
335+endif
336+ifdef CONFIG_PAX_KERNEXEC_PLUGIN
337+KERNEXEC_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/kernexec_plugin.so
338+KERNEXEC_PLUGIN_CFLAGS += -fplugin-arg-kernexec_plugin-method=$(CONFIG_PAX_KERNEXEC_PLUGIN_METHOD) -DKERNEXEC_PLUGIN
339+KERNEXEC_PLUGIN_AFLAGS := -DKERNEXEC_PLUGIN
340+endif
341+ifdef CONFIG_GRKERNSEC_RANDSTRUCT
342+GRKERNSEC_RANDSTRUCT_SEED := $(shell $(CONFIG_SHELL) $(srctree)/scripts/gen-random-seed.sh)
343+RANDSTRUCT_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/randomize_layout_plugin.so -DRANDSTRUCT_PLUGIN
344+RANDSTRUCT_PLUGIN_CFLAGS += -fplugin-arg-randomize_layout_plugin-seed=$(GRKERNSEC_RANDSTRUCT_SEED)
345+ifdef CONFIG_GRKERNSEC_RANDSTRUCT
346+RANDSTRUCT_PLUGIN_CFLAGS += -fplugin-arg-randomize_layout_plugin-performance-mode
347+endif
348+endif
349+ifdef CONFIG_CHECKER_PLUGIN
350+ifeq ($(call cc-ifversion, -ge, 0406, y), y)
351+CHECKER_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/checker_plugin.so -DCHECKER_PLUGIN
352+endif
353+endif
354+COLORIZE_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/colorize_plugin.so
355+ifdef CONFIG_PAX_SIZE_OVERFLOW
356+SIZE_OVERFLOW_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/size_overflow_plugin.so -DSIZE_OVERFLOW_PLUGIN
357+endif
358+ifdef CONFIG_PAX_LATENT_ENTROPY
359+LATENT_ENTROPY_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/latent_entropy_plugin.so -DLATENT_ENTROPY_PLUGIN
360+endif
361+ifdef CONFIG_PAX_MEMORY_STRUCTLEAK
362+STRUCTLEAK_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/structleak_plugin.so -DSTRUCTLEAK_PLUGIN
363+endif
364+GCC_PLUGINS_CFLAGS := $(CONSTIFY_PLUGIN_CFLAGS) $(STACKLEAK_PLUGIN_CFLAGS) $(KALLOCSTAT_PLUGIN_CFLAGS)
365+GCC_PLUGINS_CFLAGS += $(KERNEXEC_PLUGIN_CFLAGS) $(CHECKER_PLUGIN_CFLAGS) $(COLORIZE_PLUGIN_CFLAGS)
366+GCC_PLUGINS_CFLAGS += $(SIZE_OVERFLOW_PLUGIN_CFLAGS) $(LATENT_ENTROPY_PLUGIN_CFLAGS) $(STRUCTLEAK_PLUGIN_CFLAGS)
367+GCC_PLUGINS_CFLAGS += $(RANDSTRUCT_PLUGIN_CFLAGS)
368+GCC_PLUGINS_AFLAGS := $(KERNEXEC_PLUGIN_AFLAGS)
369+export PLUGINCC GCC_PLUGINS_CFLAGS GCC_PLUGINS_AFLAGS CONSTIFY_PLUGIN
370+ifeq ($(KBUILD_EXTMOD),)
371+gcc-plugins:
372+ $(Q)$(MAKE) $(build)=tools/gcc
373+else
374+gcc-plugins: ;
375+endif
376+else
377+gcc-plugins:
378+ifeq ($(call cc-ifversion, -ge, 0405, y), y)
379+ $(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.))
380+else
381+ $(Q)echo "warning, your gcc version does not support plugins, you should upgrade it to gcc 4.5 at least"
382+endif
383+ $(Q)echo "PAX_MEMORY_STACKLEAK, constification, PAX_LATENT_ENTROPY and other features will be less secure. PAX_SIZE_OVERFLOW will not be active."
384+endif
385+endif
386+
387 include $(srctree)/arch/$(SRCARCH)/Makefile
388
389 ifdef CONFIG_READABLE_ASM
390@@ -733,7 +802,7 @@ export mod_sign_cmd
391
392
393 ifeq ($(KBUILD_EXTMOD),)
394-core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/
395+core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/ grsecurity/
396
397 vmlinux-dirs := $(patsubst %/,%,$(filter %/, $(init-y) $(init-m) \
398 $(core-y) $(core-m) $(drivers-y) $(drivers-m) \
399@@ -782,6 +851,8 @@ endif
400
401 # The actual objects are generated when descending,
402 # make sure no implicit rule kicks in
403+$(filter-out $(init-y),$(vmlinux-deps)): KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
404+$(filter-out $(init-y),$(vmlinux-deps)): KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
405 $(sort $(vmlinux-deps)): $(vmlinux-dirs) ;
406
407 # Handle descending into subdirectories listed in $(vmlinux-dirs)
408@@ -791,7 +862,7 @@ $(sort $(vmlinux-deps)): $(vmlinux-dirs) ;
409 # Error messages still appears in the original language
410
411 PHONY += $(vmlinux-dirs)
412-$(vmlinux-dirs): prepare scripts
413+$(vmlinux-dirs): gcc-plugins prepare scripts
414 $(Q)$(MAKE) $(build)=$@
415
416 define filechk_kernel.release
417@@ -834,10 +905,13 @@ prepare1: prepare2 $(version_h) include/generated/utsrelease.h \
418
419 archprepare: archheaders archscripts prepare1 scripts_basic
420
421+prepare0: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
422+prepare0: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
423 prepare0: archprepare FORCE
424 $(Q)$(MAKE) $(build)=.
425
426 # All the preparing..
427+prepare: KBUILD_CFLAGS := $(filter-out $(GCC_PLUGINS_CFLAGS),$(KBUILD_CFLAGS))
428 prepare: prepare0
429
430 # Generate some files
431@@ -945,6 +1019,8 @@ all: modules
432 # using awk while concatenating to the final file.
433
434 PHONY += modules
435+modules: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
436+modules: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
437 modules: $(vmlinux-dirs) $(if $(KBUILD_BUILTIN),vmlinux) modules.builtin
438 $(Q)$(AWK) '!x[$$0]++' $(vmlinux-dirs:%=$(objtree)/%/modules.order) > $(objtree)/modules.order
439 @$(kecho) ' Building modules, stage 2.';
440@@ -960,7 +1036,7 @@ modules.builtin: $(vmlinux-dirs:%=%/modules.builtin)
441
442 # Target to prepare building external modules
443 PHONY += modules_prepare
444-modules_prepare: prepare scripts
445+modules_prepare: gcc-plugins prepare scripts
446
447 # Target to install modules
448 PHONY += modules_install
449@@ -1026,7 +1102,8 @@ MRPROPER_FILES += .config .config.old .version .old_version $(version_h) \
450 Module.symvers tags TAGS cscope* GPATH GTAGS GRTAGS GSYMS \
451 signing_key.priv signing_key.x509 x509.genkey \
452 extra_certificates signing_key.x509.keyid \
453- signing_key.x509.signer
454+ signing_key.x509.signer tools/gcc/size_overflow_hash.h \
455+ tools/gcc/randstruct.seed
456
457 # clean - Delete most, but leave enough to build external modules
458 #
459@@ -1066,6 +1143,7 @@ distclean: mrproper
460 \( -name '*.orig' -o -name '*.rej' -o -name '*~' \
461 -o -name '*.bak' -o -name '#*#' -o -name '.*.orig' \
462 -o -name '.*.rej' \
463+ -o -name '.*.rej' -o -name '*.so' \
464 -o -name '*%' -o -name '.*.cmd' -o -name 'core' \) \
465 -type f -print | xargs rm -f
466
467@@ -1227,6 +1305,8 @@ PHONY += $(module-dirs) modules
468 $(module-dirs): crmodverdir $(objtree)/Module.symvers
469 $(Q)$(MAKE) $(build)=$(patsubst _module_%,%,$@)
470
471+modules: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
472+modules: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
473 modules: $(module-dirs)
474 @$(kecho) ' Building modules, stage 2.';
475 $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modpost
476@@ -1366,17 +1446,21 @@ else
477 target-dir = $(if $(KBUILD_EXTMOD),$(dir $<),$(dir $@))
478 endif
479
480-%.s: %.c prepare scripts FORCE
481+%.s: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
482+%.s: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
483+%.s: %.c gcc-plugins prepare scripts FORCE
484 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
485 %.i: %.c prepare scripts FORCE
486 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
487-%.o: %.c prepare scripts FORCE
488+%.o: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
489+%.o: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
490+%.o: %.c gcc-plugins prepare scripts FORCE
491 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
492 %.lst: %.c prepare scripts FORCE
493 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
494-%.s: %.S prepare scripts FORCE
495+%.s: %.S gcc-plugins prepare scripts FORCE
496 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
497-%.o: %.S prepare scripts FORCE
498+%.o: %.S gcc-plugins prepare scripts FORCE
499 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
500 %.symtypes: %.c prepare scripts FORCE
501 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
502@@ -1386,11 +1470,15 @@ endif
503 $(cmd_crmodverdir)
504 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
505 $(build)=$(build-dir)
506-%/: prepare scripts FORCE
507+%/: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
508+%/: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
509+%/: gcc-plugins prepare scripts FORCE
510 $(cmd_crmodverdir)
511 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
512 $(build)=$(build-dir)
513-%.ko: prepare scripts FORCE
514+%.ko: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
515+%.ko: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
516+%.ko: gcc-plugins prepare scripts FORCE
517 $(cmd_crmodverdir)
518 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
519 $(build)=$(build-dir) $(@:.ko=.o)
520diff --git a/arch/alpha/include/asm/atomic.h b/arch/alpha/include/asm/atomic.h
521index 78b03ef..da28a51 100644
522--- a/arch/alpha/include/asm/atomic.h
523+++ b/arch/alpha/include/asm/atomic.h
524@@ -292,6 +292,16 @@ static inline long atomic64_dec_if_positive(atomic64_t *v)
525 #define atomic_dec(v) atomic_sub(1,(v))
526 #define atomic64_dec(v) atomic64_sub(1,(v))
527
528+#define atomic64_read_unchecked(v) atomic64_read(v)
529+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
530+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
531+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
532+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
533+#define atomic64_inc_unchecked(v) atomic64_inc(v)
534+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
535+#define atomic64_dec_unchecked(v) atomic64_dec(v)
536+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
537+
538 #define smp_mb__before_atomic_dec() smp_mb()
539 #define smp_mb__after_atomic_dec() smp_mb()
540 #define smp_mb__before_atomic_inc() smp_mb()
541diff --git a/arch/alpha/include/asm/cache.h b/arch/alpha/include/asm/cache.h
542index ad368a9..fbe0f25 100644
543--- a/arch/alpha/include/asm/cache.h
544+++ b/arch/alpha/include/asm/cache.h
545@@ -4,19 +4,19 @@
546 #ifndef __ARCH_ALPHA_CACHE_H
547 #define __ARCH_ALPHA_CACHE_H
548
549+#include <linux/const.h>
550
551 /* Bytes per L1 (data) cache line. */
552 #if defined(CONFIG_ALPHA_GENERIC) || defined(CONFIG_ALPHA_EV6)
553-# define L1_CACHE_BYTES 64
554 # define L1_CACHE_SHIFT 6
555 #else
556 /* Both EV4 and EV5 are write-through, read-allocate,
557 direct-mapped, physical.
558 */
559-# define L1_CACHE_BYTES 32
560 # define L1_CACHE_SHIFT 5
561 #endif
562
563+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
564 #define SMP_CACHE_BYTES L1_CACHE_BYTES
565
566 #endif
567diff --git a/arch/alpha/include/asm/elf.h b/arch/alpha/include/asm/elf.h
568index 968d999..d36b2df 100644
569--- a/arch/alpha/include/asm/elf.h
570+++ b/arch/alpha/include/asm/elf.h
571@@ -91,6 +91,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
572
573 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x1000000)
574
575+#ifdef CONFIG_PAX_ASLR
576+#define PAX_ELF_ET_DYN_BASE (current->personality & ADDR_LIMIT_32BIT ? 0x10000 : 0x120000000UL)
577+
578+#define PAX_DELTA_MMAP_LEN (current->personality & ADDR_LIMIT_32BIT ? 14 : 28)
579+#define PAX_DELTA_STACK_LEN (current->personality & ADDR_LIMIT_32BIT ? 14 : 19)
580+#endif
581+
582 /* $0 is set by ld.so to a pointer to a function which might be
583 registered using atexit. This provides a mean for the dynamic
584 linker to call DT_FINI functions for shared libraries that have
585diff --git a/arch/alpha/include/asm/pgalloc.h b/arch/alpha/include/asm/pgalloc.h
586index bc2a0da..8ad11ee 100644
587--- a/arch/alpha/include/asm/pgalloc.h
588+++ b/arch/alpha/include/asm/pgalloc.h
589@@ -29,6 +29,12 @@ pgd_populate(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
590 pgd_set(pgd, pmd);
591 }
592
593+static inline void
594+pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
595+{
596+ pgd_populate(mm, pgd, pmd);
597+}
598+
599 extern pgd_t *pgd_alloc(struct mm_struct *mm);
600
601 static inline void
602diff --git a/arch/alpha/include/asm/pgtable.h b/arch/alpha/include/asm/pgtable.h
603index d8f9b7e..f6222fa 100644
604--- a/arch/alpha/include/asm/pgtable.h
605+++ b/arch/alpha/include/asm/pgtable.h
606@@ -102,6 +102,17 @@ struct vm_area_struct;
607 #define PAGE_SHARED __pgprot(_PAGE_VALID | __ACCESS_BITS)
608 #define PAGE_COPY __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW)
609 #define PAGE_READONLY __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW)
610+
611+#ifdef CONFIG_PAX_PAGEEXEC
612+# define PAGE_SHARED_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOE)
613+# define PAGE_COPY_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW | _PAGE_FOE)
614+# define PAGE_READONLY_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW | _PAGE_FOE)
615+#else
616+# define PAGE_SHARED_NOEXEC PAGE_SHARED
617+# define PAGE_COPY_NOEXEC PAGE_COPY
618+# define PAGE_READONLY_NOEXEC PAGE_READONLY
619+#endif
620+
621 #define PAGE_KERNEL __pgprot(_PAGE_VALID | _PAGE_ASM | _PAGE_KRE | _PAGE_KWE)
622
623 #define _PAGE_NORMAL(x) __pgprot(_PAGE_VALID | __ACCESS_BITS | (x))
624diff --git a/arch/alpha/kernel/module.c b/arch/alpha/kernel/module.c
625index 2fd00b7..cfd5069 100644
626--- a/arch/alpha/kernel/module.c
627+++ b/arch/alpha/kernel/module.c
628@@ -160,7 +160,7 @@ apply_relocate_add(Elf64_Shdr *sechdrs, const char *strtab,
629
630 /* The small sections were sorted to the end of the segment.
631 The following should definitely cover them. */
632- gp = (u64)me->module_core + me->core_size - 0x8000;
633+ gp = (u64)me->module_core_rw + me->core_size_rw - 0x8000;
634 got = sechdrs[me->arch.gotsecindex].sh_addr;
635
636 for (i = 0; i < n; i++) {
637diff --git a/arch/alpha/kernel/osf_sys.c b/arch/alpha/kernel/osf_sys.c
638index 1402fcc..0b1abd2 100644
639--- a/arch/alpha/kernel/osf_sys.c
640+++ b/arch/alpha/kernel/osf_sys.c
641@@ -1298,10 +1298,11 @@ SYSCALL_DEFINE1(old_adjtimex, struct timex32 __user *, txc_p)
642 generic version except that we know how to honor ADDR_LIMIT_32BIT. */
643
644 static unsigned long
645-arch_get_unmapped_area_1(unsigned long addr, unsigned long len,
646- unsigned long limit)
647+arch_get_unmapped_area_1(struct file *filp, unsigned long addr, unsigned long len,
648+ unsigned long limit, unsigned long flags)
649 {
650 struct vm_unmapped_area_info info;
651+ unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
652
653 info.flags = 0;
654 info.length = len;
655@@ -1309,6 +1310,7 @@ arch_get_unmapped_area_1(unsigned long addr, unsigned long len,
656 info.high_limit = limit;
657 info.align_mask = 0;
658 info.align_offset = 0;
659+ info.threadstack_offset = offset;
660 return vm_unmapped_area(&info);
661 }
662
663@@ -1341,20 +1343,24 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
664 merely specific addresses, but regions of memory -- perhaps
665 this feature should be incorporated into all ports? */
666
667+#ifdef CONFIG_PAX_RANDMMAP
668+ if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
669+#endif
670+
671 if (addr) {
672- addr = arch_get_unmapped_area_1 (PAGE_ALIGN(addr), len, limit);
673+ addr = arch_get_unmapped_area_1 (filp, PAGE_ALIGN(addr), len, limit, flags);
674 if (addr != (unsigned long) -ENOMEM)
675 return addr;
676 }
677
678 /* Next, try allocating at TASK_UNMAPPED_BASE. */
679- addr = arch_get_unmapped_area_1 (PAGE_ALIGN(TASK_UNMAPPED_BASE),
680- len, limit);
681+ addr = arch_get_unmapped_area_1 (filp, PAGE_ALIGN(current->mm->mmap_base), len, limit, flags);
682+
683 if (addr != (unsigned long) -ENOMEM)
684 return addr;
685
686 /* Finally, try allocating in low memory. */
687- addr = arch_get_unmapped_area_1 (PAGE_SIZE, len, limit);
688+ addr = arch_get_unmapped_area_1 (filp, PAGE_SIZE, len, limit, flags);
689
690 return addr;
691 }
692diff --git a/arch/alpha/mm/fault.c b/arch/alpha/mm/fault.c
693index 98838a0..b304fb4 100644
694--- a/arch/alpha/mm/fault.c
695+++ b/arch/alpha/mm/fault.c
696@@ -53,6 +53,124 @@ __load_new_mm_context(struct mm_struct *next_mm)
697 __reload_thread(pcb);
698 }
699
700+#ifdef CONFIG_PAX_PAGEEXEC
701+/*
702+ * PaX: decide what to do with offenders (regs->pc = fault address)
703+ *
704+ * returns 1 when task should be killed
705+ * 2 when patched PLT trampoline was detected
706+ * 3 when unpatched PLT trampoline was detected
707+ */
708+static int pax_handle_fetch_fault(struct pt_regs *regs)
709+{
710+
711+#ifdef CONFIG_PAX_EMUPLT
712+ int err;
713+
714+ do { /* PaX: patched PLT emulation #1 */
715+ unsigned int ldah, ldq, jmp;
716+
717+ err = get_user(ldah, (unsigned int *)regs->pc);
718+ err |= get_user(ldq, (unsigned int *)(regs->pc+4));
719+ err |= get_user(jmp, (unsigned int *)(regs->pc+8));
720+
721+ if (err)
722+ break;
723+
724+ if ((ldah & 0xFFFF0000U) == 0x277B0000U &&
725+ (ldq & 0xFFFF0000U) == 0xA77B0000U &&
726+ jmp == 0x6BFB0000U)
727+ {
728+ unsigned long r27, addr;
729+ unsigned long addrh = (ldah | 0xFFFFFFFFFFFF0000UL) << 16;
730+ unsigned long addrl = ldq | 0xFFFFFFFFFFFF0000UL;
731+
732+ addr = regs->r27 + ((addrh ^ 0x80000000UL) + 0x80000000UL) + ((addrl ^ 0x8000UL) + 0x8000UL);
733+ err = get_user(r27, (unsigned long *)addr);
734+ if (err)
735+ break;
736+
737+ regs->r27 = r27;
738+ regs->pc = r27;
739+ return 2;
740+ }
741+ } while (0);
742+
743+ do { /* PaX: patched PLT emulation #2 */
744+ unsigned int ldah, lda, br;
745+
746+ err = get_user(ldah, (unsigned int *)regs->pc);
747+ err |= get_user(lda, (unsigned int *)(regs->pc+4));
748+ err |= get_user(br, (unsigned int *)(regs->pc+8));
749+
750+ if (err)
751+ break;
752+
753+ if ((ldah & 0xFFFF0000U) == 0x277B0000U &&
754+ (lda & 0xFFFF0000U) == 0xA77B0000U &&
755+ (br & 0xFFE00000U) == 0xC3E00000U)
756+ {
757+ unsigned long addr = br | 0xFFFFFFFFFFE00000UL;
758+ unsigned long addrh = (ldah | 0xFFFFFFFFFFFF0000UL) << 16;
759+ unsigned long addrl = lda | 0xFFFFFFFFFFFF0000UL;
760+
761+ regs->r27 += ((addrh ^ 0x80000000UL) + 0x80000000UL) + ((addrl ^ 0x8000UL) + 0x8000UL);
762+ regs->pc += 12 + (((addr ^ 0x00100000UL) + 0x00100000UL) << 2);
763+ return 2;
764+ }
765+ } while (0);
766+
767+ do { /* PaX: unpatched PLT emulation */
768+ unsigned int br;
769+
770+ err = get_user(br, (unsigned int *)regs->pc);
771+
772+ if (!err && (br & 0xFFE00000U) == 0xC3800000U) {
773+ unsigned int br2, ldq, nop, jmp;
774+ unsigned long addr = br | 0xFFFFFFFFFFE00000UL, resolver;
775+
776+ addr = regs->pc + 4 + (((addr ^ 0x00100000UL) + 0x00100000UL) << 2);
777+ err = get_user(br2, (unsigned int *)addr);
778+ err |= get_user(ldq, (unsigned int *)(addr+4));
779+ err |= get_user(nop, (unsigned int *)(addr+8));
780+ err |= get_user(jmp, (unsigned int *)(addr+12));
781+ err |= get_user(resolver, (unsigned long *)(addr+16));
782+
783+ if (err)
784+ break;
785+
786+ if (br2 == 0xC3600000U &&
787+ ldq == 0xA77B000CU &&
788+ nop == 0x47FF041FU &&
789+ jmp == 0x6B7B0000U)
790+ {
791+ regs->r28 = regs->pc+4;
792+ regs->r27 = addr+16;
793+ regs->pc = resolver;
794+ return 3;
795+ }
796+ }
797+ } while (0);
798+#endif
799+
800+ return 1;
801+}
802+
803+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
804+{
805+ unsigned long i;
806+
807+ printk(KERN_ERR "PAX: bytes at PC: ");
808+ for (i = 0; i < 5; i++) {
809+ unsigned int c;
810+ if (get_user(c, (unsigned int *)pc+i))
811+ printk(KERN_CONT "???????? ");
812+ else
813+ printk(KERN_CONT "%08x ", c);
814+ }
815+ printk("\n");
816+}
817+#endif
818
819 /*
820 * This routine handles page faults. It determines the address,
821@@ -133,8 +251,29 @@ retry:
822 good_area:
823 si_code = SEGV_ACCERR;
824 if (cause < 0) {
825- if (!(vma->vm_flags & VM_EXEC))
826+ if (!(vma->vm_flags & VM_EXEC)) {
827+
828+#ifdef CONFIG_PAX_PAGEEXEC
829+ if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->pc)
830+ goto bad_area;
831+
832+ up_read(&mm->mmap_sem);
833+ switch (pax_handle_fetch_fault(regs)) {
834+
835+#ifdef CONFIG_PAX_EMUPLT
836+ case 2:
837+ case 3:
838+ return;
839+#endif
840+
841+ }
842+ pax_report_fault(regs, (void *)regs->pc, (void *)rdusp());
843+ do_group_exit(SIGKILL);
844+#else
845 goto bad_area;
846+#endif
847+
848+ }
849 } else if (!cause) {
850 /* Allow reads even for write-only mappings */
851 if (!(vma->vm_flags & (VM_READ | VM_WRITE)))
852diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig
853index 1ad6fb6..9406b3d 100644
854--- a/arch/arm/Kconfig
855+++ b/arch/arm/Kconfig
856@@ -1832,7 +1832,7 @@ config ALIGNMENT_TRAP
857
858 config UACCESS_WITH_MEMCPY
859 bool "Use kernel mem{cpy,set}() for {copy_to,clear}_user()"
860- depends on MMU
861+ depends on MMU && !PAX_MEMORY_UDEREF
862 default y if CPU_FEROCEON
863 help
864 Implement faster copy_to_user and clear_user methods for CPU
865@@ -2097,6 +2097,7 @@ config XIP_PHYS_ADDR
866 config KEXEC
867 bool "Kexec system call (EXPERIMENTAL)"
868 depends on (!SMP || PM_SLEEP_SMP)
869+ depends on !GRKERNSEC_KMEM
870 help
871 kexec is a system call that implements the ability to shutdown your
872 current kernel, and to start another kernel. It is like a reboot
873diff --git a/arch/arm/include/asm/atomic.h b/arch/arm/include/asm/atomic.h
874index da1c77d..2ee6056 100644
875--- a/arch/arm/include/asm/atomic.h
876+++ b/arch/arm/include/asm/atomic.h
877@@ -17,17 +17,35 @@
878 #include <asm/barrier.h>
879 #include <asm/cmpxchg.h>
880
881+#ifdef CONFIG_GENERIC_ATOMIC64
882+#include <asm-generic/atomic64.h>
883+#endif
884+
885 #define ATOMIC_INIT(i) { (i) }
886
887 #ifdef __KERNEL__
888
889+#define _ASM_EXTABLE(from, to) \
890+" .pushsection __ex_table,\"a\"\n"\
891+" .align 3\n" \
892+" .long " #from ", " #to"\n" \
893+" .popsection"
894+
895 /*
896 * On ARM, ordinary assignment (str instruction) doesn't clear the local
897 * strex/ldrex monitor on some implementations. The reason we can use it for
898 * atomic_set() is the clrex or dummy strex done on every exception return.
899 */
900 #define atomic_read(v) (*(volatile int *)&(v)->counter)
901+static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
902+{
903+ return v->counter;
904+}
905 #define atomic_set(v,i) (((v)->counter) = (i))
906+static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
907+{
908+ v->counter = i;
909+}
910
911 #if __LINUX_ARM_ARCH__ >= 6
912
913@@ -42,6 +60,35 @@ static inline void atomic_add(int i, atomic_t *v)
914 int result;
915
916 __asm__ __volatile__("@ atomic_add\n"
917+"1: ldrex %1, [%3]\n"
918+" adds %0, %1, %4\n"
919+
920+#ifdef CONFIG_PAX_REFCOUNT
921+" bvc 3f\n"
922+"2: bkpt 0xf103\n"
923+"3:\n"
924+#endif
925+
926+" strex %1, %0, [%3]\n"
927+" teq %1, #0\n"
928+" bne 1b"
929+
930+#ifdef CONFIG_PAX_REFCOUNT
931+"\n4:\n"
932+ _ASM_EXTABLE(2b, 4b)
933+#endif
934+
935+ : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
936+ : "r" (&v->counter), "Ir" (i)
937+ : "cc");
938+}
939+
940+static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
941+{
942+ unsigned long tmp;
943+ int result;
944+
945+ __asm__ __volatile__("@ atomic_add_unchecked\n"
946 "1: ldrex %0, [%3]\n"
947 " add %0, %0, %4\n"
948 " strex %1, %0, [%3]\n"
949@@ -60,6 +107,42 @@ static inline int atomic_add_return(int i, atomic_t *v)
950 smp_mb();
951
952 __asm__ __volatile__("@ atomic_add_return\n"
953+"1: ldrex %1, [%3]\n"
954+" adds %0, %1, %4\n"
955+
956+#ifdef CONFIG_PAX_REFCOUNT
957+" bvc 3f\n"
958+" mov %0, %1\n"
959+"2: bkpt 0xf103\n"
960+"3:\n"
961+#endif
962+
963+" strex %1, %0, [%3]\n"
964+" teq %1, #0\n"
965+" bne 1b"
966+
967+#ifdef CONFIG_PAX_REFCOUNT
968+"\n4:\n"
969+ _ASM_EXTABLE(2b, 4b)
970+#endif
971+
972+ : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
973+ : "r" (&v->counter), "Ir" (i)
974+ : "cc");
975+
976+ smp_mb();
977+
978+ return result;
979+}
980+
981+static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
982+{
983+ unsigned long tmp;
984+ int result;
985+
986+ smp_mb();
987+
988+ __asm__ __volatile__("@ atomic_add_return_unchecked\n"
989 "1: ldrex %0, [%3]\n"
990 " add %0, %0, %4\n"
991 " strex %1, %0, [%3]\n"
992@@ -80,6 +163,35 @@ static inline void atomic_sub(int i, atomic_t *v)
993 int result;
994
995 __asm__ __volatile__("@ atomic_sub\n"
996+"1: ldrex %1, [%3]\n"
997+" subs %0, %1, %4\n"
998+
999+#ifdef CONFIG_PAX_REFCOUNT
1000+" bvc 3f\n"
1001+"2: bkpt 0xf103\n"
1002+"3:\n"
1003+#endif
1004+
1005+" strex %1, %0, [%3]\n"
1006+" teq %1, #0\n"
1007+" bne 1b"
1008+
1009+#ifdef CONFIG_PAX_REFCOUNT
1010+"\n4:\n"
1011+ _ASM_EXTABLE(2b, 4b)
1012+#endif
1013+
1014+ : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1015+ : "r" (&v->counter), "Ir" (i)
1016+ : "cc");
1017+}
1018+
1019+static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
1020+{
1021+ unsigned long tmp;
1022+ int result;
1023+
1024+ __asm__ __volatile__("@ atomic_sub_unchecked\n"
1025 "1: ldrex %0, [%3]\n"
1026 " sub %0, %0, %4\n"
1027 " strex %1, %0, [%3]\n"
1028@@ -98,11 +210,25 @@ static inline int atomic_sub_return(int i, atomic_t *v)
1029 smp_mb();
1030
1031 __asm__ __volatile__("@ atomic_sub_return\n"
1032-"1: ldrex %0, [%3]\n"
1033-" sub %0, %0, %4\n"
1034+"1: ldrex %1, [%3]\n"
1035+" subs %0, %1, %4\n"
1036+
1037+#ifdef CONFIG_PAX_REFCOUNT
1038+" bvc 3f\n"
1039+" mov %0, %1\n"
1040+"2: bkpt 0xf103\n"
1041+"3:\n"
1042+#endif
1043+
1044 " strex %1, %0, [%3]\n"
1045 " teq %1, #0\n"
1046 " bne 1b"
1047+
1048+#ifdef CONFIG_PAX_REFCOUNT
1049+"\n4:\n"
1050+ _ASM_EXTABLE(2b, 4b)
1051+#endif
1052+
1053 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1054 : "r" (&v->counter), "Ir" (i)
1055 : "cc");
1056@@ -134,6 +260,28 @@ static inline int atomic_cmpxchg(atomic_t *ptr, int old, int new)
1057 return oldval;
1058 }
1059
1060+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *ptr, int old, int new)
1061+{
1062+ unsigned long oldval, res;
1063+
1064+ smp_mb();
1065+
1066+ do {
1067+ __asm__ __volatile__("@ atomic_cmpxchg_unchecked\n"
1068+ "ldrex %1, [%3]\n"
1069+ "mov %0, #0\n"
1070+ "teq %1, %4\n"
1071+ "strexeq %0, %5, [%3]\n"
1072+ : "=&r" (res), "=&r" (oldval), "+Qo" (ptr->counter)
1073+ : "r" (&ptr->counter), "Ir" (old), "r" (new)
1074+ : "cc");
1075+ } while (res);
1076+
1077+ smp_mb();
1078+
1079+ return oldval;
1080+}
1081+
1082 static inline void atomic_clear_mask(unsigned long mask, unsigned long *addr)
1083 {
1084 unsigned long tmp, tmp2;
1085@@ -167,7 +315,17 @@ static inline int atomic_add_return(int i, atomic_t *v)
1086
1087 return val;
1088 }
1089+
1090+static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
1091+{
1092+ return atomic_add_return(i, v);
1093+}
1094+
1095 #define atomic_add(i, v) (void) atomic_add_return(i, v)
1096+static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
1097+{
1098+ (void) atomic_add_return(i, v);
1099+}
1100
1101 static inline int atomic_sub_return(int i, atomic_t *v)
1102 {
1103@@ -182,6 +340,10 @@ static inline int atomic_sub_return(int i, atomic_t *v)
1104 return val;
1105 }
1106 #define atomic_sub(i, v) (void) atomic_sub_return(i, v)
1107+static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
1108+{
1109+ (void) atomic_sub_return(i, v);
1110+}
1111
1112 static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
1113 {
1114@@ -197,6 +359,11 @@ static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
1115 return ret;
1116 }
1117
1118+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
1119+{
1120+ return atomic_cmpxchg(v, old, new);
1121+}
1122+
1123 static inline void atomic_clear_mask(unsigned long mask, unsigned long *addr)
1124 {
1125 unsigned long flags;
1126@@ -209,6 +376,10 @@ static inline void atomic_clear_mask(unsigned long mask, unsigned long *addr)
1127 #endif /* __LINUX_ARM_ARCH__ */
1128
1129 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
1130+static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
1131+{
1132+ return xchg(&v->counter, new);
1133+}
1134
1135 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
1136 {
1137@@ -221,11 +392,27 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
1138 }
1139
1140 #define atomic_inc(v) atomic_add(1, v)
1141+static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
1142+{
1143+ atomic_add_unchecked(1, v);
1144+}
1145 #define atomic_dec(v) atomic_sub(1, v)
1146+static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
1147+{
1148+ atomic_sub_unchecked(1, v);
1149+}
1150
1151 #define atomic_inc_and_test(v) (atomic_add_return(1, v) == 0)
1152+static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
1153+{
1154+ return atomic_add_return_unchecked(1, v) == 0;
1155+}
1156 #define atomic_dec_and_test(v) (atomic_sub_return(1, v) == 0)
1157 #define atomic_inc_return(v) (atomic_add_return(1, v))
1158+static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
1159+{
1160+ return atomic_add_return_unchecked(1, v);
1161+}
1162 #define atomic_dec_return(v) (atomic_sub_return(1, v))
1163 #define atomic_sub_and_test(i, v) (atomic_sub_return(i, v) == 0)
1164
1165@@ -241,6 +428,14 @@ typedef struct {
1166 u64 __aligned(8) counter;
1167 } atomic64_t;
1168
1169+#ifdef CONFIG_PAX_REFCOUNT
1170+typedef struct {
1171+ u64 __aligned(8) counter;
1172+} atomic64_unchecked_t;
1173+#else
1174+typedef atomic64_t atomic64_unchecked_t;
1175+#endif
1176+
1177 #define ATOMIC64_INIT(i) { (i) }
1178
1179 #ifdef CONFIG_ARM_LPAE
1180@@ -257,6 +452,19 @@ static inline u64 atomic64_read(const atomic64_t *v)
1181 return result;
1182 }
1183
1184+static inline u64 atomic64_read_unchecked(const atomic64_unchecked_t *v)
1185+{
1186+ u64 result;
1187+
1188+ __asm__ __volatile__("@ atomic64_read_unchecked\n"
1189+" ldrd %0, %H0, [%1]"
1190+ : "=&r" (result)
1191+ : "r" (&v->counter), "Qo" (v->counter)
1192+ );
1193+
1194+ return result;
1195+}
1196+
1197 static inline void atomic64_set(atomic64_t *v, u64 i)
1198 {
1199 __asm__ __volatile__("@ atomic64_set\n"
1200@@ -265,6 +473,15 @@ static inline void atomic64_set(atomic64_t *v, u64 i)
1201 : "r" (&v->counter), "r" (i)
1202 );
1203 }
1204+
1205+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, u64 i)
1206+{
1207+ __asm__ __volatile__("@ atomic64_set_unchecked\n"
1208+" strd %2, %H2, [%1]"
1209+ : "=Qo" (v->counter)
1210+ : "r" (&v->counter), "r" (i)
1211+ );
1212+}
1213 #else
1214 static inline u64 atomic64_read(const atomic64_t *v)
1215 {
1216@@ -279,6 +496,19 @@ static inline u64 atomic64_read(const atomic64_t *v)
1217 return result;
1218 }
1219
1220+static inline u64 atomic64_read_unchecked(atomic64_unchecked_t *v)
1221+{
1222+ u64 result;
1223+
1224+ __asm__ __volatile__("@ atomic64_read_unchecked\n"
1225+" ldrexd %0, %H0, [%1]"
1226+ : "=&r" (result)
1227+ : "r" (&v->counter), "Qo" (v->counter)
1228+ );
1229+
1230+ return result;
1231+}
1232+
1233 static inline void atomic64_set(atomic64_t *v, u64 i)
1234 {
1235 u64 tmp;
1236@@ -292,6 +522,21 @@ static inline void atomic64_set(atomic64_t *v, u64 i)
1237 : "r" (&v->counter), "r" (i)
1238 : "cc");
1239 }
1240+
1241+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, u64 i)
1242+{
1243+ u64 tmp;
1244+
1245+ __asm__ __volatile__("@ atomic64_set_unchecked\n"
1246+"1: ldrexd %0, %H0, [%2]\n"
1247+" strexd %0, %3, %H3, [%2]\n"
1248+" teq %0, #0\n"
1249+" bne 1b"
1250+ : "=&r" (tmp), "=Qo" (v->counter)
1251+ : "r" (&v->counter), "r" (i)
1252+ : "cc");
1253+}
1254+
1255 #endif
1256
1257 static inline void atomic64_add(u64 i, atomic64_t *v)
1258@@ -302,6 +547,36 @@ static inline void atomic64_add(u64 i, atomic64_t *v)
1259 __asm__ __volatile__("@ atomic64_add\n"
1260 "1: ldrexd %0, %H0, [%3]\n"
1261 " adds %0, %0, %4\n"
1262+" adcs %H0, %H0, %H4\n"
1263+
1264+#ifdef CONFIG_PAX_REFCOUNT
1265+" bvc 3f\n"
1266+"2: bkpt 0xf103\n"
1267+"3:\n"
1268+#endif
1269+
1270+" strexd %1, %0, %H0, [%3]\n"
1271+" teq %1, #0\n"
1272+" bne 1b"
1273+
1274+#ifdef CONFIG_PAX_REFCOUNT
1275+"\n4:\n"
1276+ _ASM_EXTABLE(2b, 4b)
1277+#endif
1278+
1279+ : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1280+ : "r" (&v->counter), "r" (i)
1281+ : "cc");
1282+}
1283+
1284+static inline void atomic64_add_unchecked(u64 i, atomic64_unchecked_t *v)
1285+{
1286+ u64 result;
1287+ unsigned long tmp;
1288+
1289+ __asm__ __volatile__("@ atomic64_add_unchecked\n"
1290+"1: ldrexd %0, %H0, [%3]\n"
1291+" adds %0, %0, %4\n"
1292 " adc %H0, %H0, %H4\n"
1293 " strexd %1, %0, %H0, [%3]\n"
1294 " teq %1, #0\n"
1295@@ -313,12 +588,49 @@ static inline void atomic64_add(u64 i, atomic64_t *v)
1296
1297 static inline u64 atomic64_add_return(u64 i, atomic64_t *v)
1298 {
1299- u64 result;
1300- unsigned long tmp;
1301+ u64 result, tmp;
1302
1303 smp_mb();
1304
1305 __asm__ __volatile__("@ atomic64_add_return\n"
1306+"1: ldrexd %1, %H1, [%3]\n"
1307+" adds %0, %1, %4\n"
1308+" adcs %H0, %H1, %H4\n"
1309+
1310+#ifdef CONFIG_PAX_REFCOUNT
1311+" bvc 3f\n"
1312+" mov %0, %1\n"
1313+" mov %H0, %H1\n"
1314+"2: bkpt 0xf103\n"
1315+"3:\n"
1316+#endif
1317+
1318+" strexd %1, %0, %H0, [%3]\n"
1319+" teq %1, #0\n"
1320+" bne 1b"
1321+
1322+#ifdef CONFIG_PAX_REFCOUNT
1323+"\n4:\n"
1324+ _ASM_EXTABLE(2b, 4b)
1325+#endif
1326+
1327+ : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1328+ : "r" (&v->counter), "r" (i)
1329+ : "cc");
1330+
1331+ smp_mb();
1332+
1333+ return result;
1334+}
1335+
1336+static inline u64 atomic64_add_return_unchecked(u64 i, atomic64_unchecked_t *v)
1337+{
1338+ u64 result;
1339+ unsigned long tmp;
1340+
1341+ smp_mb();
1342+
1343+ __asm__ __volatile__("@ atomic64_add_return_unchecked\n"
1344 "1: ldrexd %0, %H0, [%3]\n"
1345 " adds %0, %0, %4\n"
1346 " adc %H0, %H0, %H4\n"
1347@@ -342,6 +654,36 @@ static inline void atomic64_sub(u64 i, atomic64_t *v)
1348 __asm__ __volatile__("@ atomic64_sub\n"
1349 "1: ldrexd %0, %H0, [%3]\n"
1350 " subs %0, %0, %4\n"
1351+" sbcs %H0, %H0, %H4\n"
1352+
1353+#ifdef CONFIG_PAX_REFCOUNT
1354+" bvc 3f\n"
1355+"2: bkpt 0xf103\n"
1356+"3:\n"
1357+#endif
1358+
1359+" strexd %1, %0, %H0, [%3]\n"
1360+" teq %1, #0\n"
1361+" bne 1b"
1362+
1363+#ifdef CONFIG_PAX_REFCOUNT
1364+"\n4:\n"
1365+ _ASM_EXTABLE(2b, 4b)
1366+#endif
1367+
1368+ : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1369+ : "r" (&v->counter), "r" (i)
1370+ : "cc");
1371+}
1372+
1373+static inline void atomic64_sub_unchecked(u64 i, atomic64_unchecked_t *v)
1374+{
1375+ u64 result;
1376+ unsigned long tmp;
1377+
1378+ __asm__ __volatile__("@ atomic64_sub_unchecked\n"
1379+"1: ldrexd %0, %H0, [%3]\n"
1380+" subs %0, %0, %4\n"
1381 " sbc %H0, %H0, %H4\n"
1382 " strexd %1, %0, %H0, [%3]\n"
1383 " teq %1, #0\n"
1384@@ -353,18 +695,32 @@ static inline void atomic64_sub(u64 i, atomic64_t *v)
1385
1386 static inline u64 atomic64_sub_return(u64 i, atomic64_t *v)
1387 {
1388- u64 result;
1389- unsigned long tmp;
1390+ u64 result, tmp;
1391
1392 smp_mb();
1393
1394 __asm__ __volatile__("@ atomic64_sub_return\n"
1395-"1: ldrexd %0, %H0, [%3]\n"
1396-" subs %0, %0, %4\n"
1397-" sbc %H0, %H0, %H4\n"
1398+"1: ldrexd %1, %H1, [%3]\n"
1399+" subs %0, %1, %4\n"
1400+" sbcs %H0, %H1, %H4\n"
1401+
1402+#ifdef CONFIG_PAX_REFCOUNT
1403+" bvc 3f\n"
1404+" mov %0, %1\n"
1405+" mov %H0, %H1\n"
1406+"2: bkpt 0xf103\n"
1407+"3:\n"
1408+#endif
1409+
1410 " strexd %1, %0, %H0, [%3]\n"
1411 " teq %1, #0\n"
1412 " bne 1b"
1413+
1414+#ifdef CONFIG_PAX_REFCOUNT
1415+"\n4:\n"
1416+ _ASM_EXTABLE(2b, 4b)
1417+#endif
1418+
1419 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1420 : "r" (&v->counter), "r" (i)
1421 : "cc");
1422@@ -398,6 +754,30 @@ static inline u64 atomic64_cmpxchg(atomic64_t *ptr, u64 old, u64 new)
1423 return oldval;
1424 }
1425
1426+static inline u64 atomic64_cmpxchg_unchecked(atomic64_unchecked_t *ptr, u64 old, u64 new)
1427+{
1428+ u64 oldval;
1429+ unsigned long res;
1430+
1431+ smp_mb();
1432+
1433+ do {
1434+ __asm__ __volatile__("@ atomic64_cmpxchg_unchecked\n"
1435+ "ldrexd %1, %H1, [%3]\n"
1436+ "mov %0, #0\n"
1437+ "teq %1, %4\n"
1438+ "teqeq %H1, %H4\n"
1439+ "strexdeq %0, %5, %H5, [%3]"
1440+ : "=&r" (res), "=&r" (oldval), "+Qo" (ptr->counter)
1441+ : "r" (&ptr->counter), "r" (old), "r" (new)
1442+ : "cc");
1443+ } while (res);
1444+
1445+ smp_mb();
1446+
1447+ return oldval;
1448+}
1449+
1450 static inline u64 atomic64_xchg(atomic64_t *ptr, u64 new)
1451 {
1452 u64 result;
1453@@ -421,21 +801,34 @@ static inline u64 atomic64_xchg(atomic64_t *ptr, u64 new)
1454
1455 static inline u64 atomic64_dec_if_positive(atomic64_t *v)
1456 {
1457- u64 result;
1458- unsigned long tmp;
1459+ u64 result, tmp;
1460
1461 smp_mb();
1462
1463 __asm__ __volatile__("@ atomic64_dec_if_positive\n"
1464-"1: ldrexd %0, %H0, [%3]\n"
1465-" subs %0, %0, #1\n"
1466-" sbc %H0, %H0, #0\n"
1467+"1: ldrexd %1, %H1, [%3]\n"
1468+" subs %0, %1, #1\n"
1469+" sbcs %H0, %H1, #0\n"
1470+
1471+#ifdef CONFIG_PAX_REFCOUNT
1472+" bvc 3f\n"
1473+" mov %0, %1\n"
1474+" mov %H0, %H1\n"
1475+"2: bkpt 0xf103\n"
1476+"3:\n"
1477+#endif
1478+
1479 " teq %H0, #0\n"
1480-" bmi 2f\n"
1481+" bmi 4f\n"
1482 " strexd %1, %0, %H0, [%3]\n"
1483 " teq %1, #0\n"
1484 " bne 1b\n"
1485-"2:"
1486+"4:\n"
1487+
1488+#ifdef CONFIG_PAX_REFCOUNT
1489+ _ASM_EXTABLE(2b, 4b)
1490+#endif
1491+
1492 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1493 : "r" (&v->counter)
1494 : "cc");
1495@@ -458,13 +851,25 @@ static inline int atomic64_add_unless(atomic64_t *v, u64 a, u64 u)
1496 " teq %0, %5\n"
1497 " teqeq %H0, %H5\n"
1498 " moveq %1, #0\n"
1499-" beq 2f\n"
1500+" beq 4f\n"
1501 " adds %0, %0, %6\n"
1502-" adc %H0, %H0, %H6\n"
1503+" adcs %H0, %H0, %H6\n"
1504+
1505+#ifdef CONFIG_PAX_REFCOUNT
1506+" bvc 3f\n"
1507+"2: bkpt 0xf103\n"
1508+"3:\n"
1509+#endif
1510+
1511 " strexd %2, %0, %H0, [%4]\n"
1512 " teq %2, #0\n"
1513 " bne 1b\n"
1514-"2:"
1515+"4:\n"
1516+
1517+#ifdef CONFIG_PAX_REFCOUNT
1518+ _ASM_EXTABLE(2b, 4b)
1519+#endif
1520+
1521 : "=&r" (val), "+r" (ret), "=&r" (tmp), "+Qo" (v->counter)
1522 : "r" (&v->counter), "r" (u), "r" (a)
1523 : "cc");
1524@@ -477,10 +882,13 @@ static inline int atomic64_add_unless(atomic64_t *v, u64 a, u64 u)
1525
1526 #define atomic64_add_negative(a, v) (atomic64_add_return((a), (v)) < 0)
1527 #define atomic64_inc(v) atomic64_add(1LL, (v))
1528+#define atomic64_inc_unchecked(v) atomic64_add_unchecked(1LL, (v))
1529 #define atomic64_inc_return(v) atomic64_add_return(1LL, (v))
1530+#define atomic64_inc_return_unchecked(v) atomic64_add_return_unchecked(1LL, (v))
1531 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
1532 #define atomic64_sub_and_test(a, v) (atomic64_sub_return((a), (v)) == 0)
1533 #define atomic64_dec(v) atomic64_sub(1LL, (v))
1534+#define atomic64_dec_unchecked(v) atomic64_sub_unchecked(1LL, (v))
1535 #define atomic64_dec_return(v) atomic64_sub_return(1LL, (v))
1536 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
1537 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
1538diff --git a/arch/arm/include/asm/cache.h b/arch/arm/include/asm/cache.h
1539index 75fe66b..ba3dee4 100644
1540--- a/arch/arm/include/asm/cache.h
1541+++ b/arch/arm/include/asm/cache.h
1542@@ -4,8 +4,10 @@
1543 #ifndef __ASMARM_CACHE_H
1544 #define __ASMARM_CACHE_H
1545
1546+#include <linux/const.h>
1547+
1548 #define L1_CACHE_SHIFT CONFIG_ARM_L1_CACHE_SHIFT
1549-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
1550+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
1551
1552 /*
1553 * Memory returned by kmalloc() may be used for DMA, so we must make
1554@@ -24,5 +26,6 @@
1555 #endif
1556
1557 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
1558+#define __read_only __attribute__ ((__section__(".data..read_only")))
1559
1560 #endif
1561diff --git a/arch/arm/include/asm/cacheflush.h b/arch/arm/include/asm/cacheflush.h
1562index 15f2d5b..43ffa53 100644
1563--- a/arch/arm/include/asm/cacheflush.h
1564+++ b/arch/arm/include/asm/cacheflush.h
1565@@ -116,7 +116,7 @@ struct cpu_cache_fns {
1566 void (*dma_unmap_area)(const void *, size_t, int);
1567
1568 void (*dma_flush_range)(const void *, const void *);
1569-};
1570+} __no_const;
1571
1572 /*
1573 * Select the calling method
1574diff --git a/arch/arm/include/asm/checksum.h b/arch/arm/include/asm/checksum.h
1575index 6dcc164..b14d917 100644
1576--- a/arch/arm/include/asm/checksum.h
1577+++ b/arch/arm/include/asm/checksum.h
1578@@ -37,7 +37,19 @@ __wsum
1579 csum_partial_copy_nocheck(const void *src, void *dst, int len, __wsum sum);
1580
1581 __wsum
1582-csum_partial_copy_from_user(const void __user *src, void *dst, int len, __wsum sum, int *err_ptr);
1583+__csum_partial_copy_from_user(const void __user *src, void *dst, int len, __wsum sum, int *err_ptr);
1584+
1585+static inline __wsum
1586+csum_partial_copy_from_user(const void __user *src, void *dst, int len, __wsum sum, int *err_ptr)
1587+{
1588+ __wsum ret;
1589+ pax_open_userland();
1590+ ret = __csum_partial_copy_from_user(src, dst, len, sum, err_ptr);
1591+ pax_close_userland();
1592+ return ret;
1593+}
1594+
1595+
1596
1597 /*
1598 * Fold a partial checksum without adding pseudo headers
1599diff --git a/arch/arm/include/asm/cmpxchg.h b/arch/arm/include/asm/cmpxchg.h
1600index 4f009c1..466c59b 100644
1601--- a/arch/arm/include/asm/cmpxchg.h
1602+++ b/arch/arm/include/asm/cmpxchg.h
1603@@ -102,6 +102,8 @@ static inline unsigned long __xchg(unsigned long x, volatile void *ptr, int size
1604
1605 #define xchg(ptr,x) \
1606 ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
1607+#define xchg_unchecked(ptr,x) \
1608+ ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
1609
1610 #include <asm-generic/cmpxchg-local.h>
1611
1612diff --git a/arch/arm/include/asm/domain.h b/arch/arm/include/asm/domain.h
1613index 6ddbe44..b5e38b1 100644
1614--- a/arch/arm/include/asm/domain.h
1615+++ b/arch/arm/include/asm/domain.h
1616@@ -48,18 +48,37 @@
1617 * Domain types
1618 */
1619 #define DOMAIN_NOACCESS 0
1620-#define DOMAIN_CLIENT 1
1621 #ifdef CONFIG_CPU_USE_DOMAINS
1622+#define DOMAIN_USERCLIENT 1
1623+#define DOMAIN_KERNELCLIENT 1
1624 #define DOMAIN_MANAGER 3
1625+#define DOMAIN_VECTORS DOMAIN_USER
1626 #else
1627+
1628+#ifdef CONFIG_PAX_KERNEXEC
1629 #define DOMAIN_MANAGER 1
1630+#define DOMAIN_KERNEXEC 3
1631+#else
1632+#define DOMAIN_MANAGER 1
1633+#endif
1634+
1635+#ifdef CONFIG_PAX_MEMORY_UDEREF
1636+#define DOMAIN_USERCLIENT 0
1637+#define DOMAIN_UDEREF 1
1638+#define DOMAIN_VECTORS DOMAIN_KERNEL
1639+#else
1640+#define DOMAIN_USERCLIENT 1
1641+#define DOMAIN_VECTORS DOMAIN_USER
1642+#endif
1643+#define DOMAIN_KERNELCLIENT 1
1644+
1645 #endif
1646
1647 #define domain_val(dom,type) ((type) << (2*(dom)))
1648
1649 #ifndef __ASSEMBLY__
1650
1651-#ifdef CONFIG_CPU_USE_DOMAINS
1652+#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
1653 static inline void set_domain(unsigned val)
1654 {
1655 asm volatile(
1656@@ -68,15 +87,7 @@ static inline void set_domain(unsigned val)
1657 isb();
1658 }
1659
1660-#define modify_domain(dom,type) \
1661- do { \
1662- struct thread_info *thread = current_thread_info(); \
1663- unsigned int domain = thread->cpu_domain; \
1664- domain &= ~domain_val(dom, DOMAIN_MANAGER); \
1665- thread->cpu_domain = domain | domain_val(dom, type); \
1666- set_domain(thread->cpu_domain); \
1667- } while (0)
1668-
1669+extern void modify_domain(unsigned int dom, unsigned int type);
1670 #else
1671 static inline void set_domain(unsigned val) { }
1672 static inline void modify_domain(unsigned dom, unsigned type) { }
1673diff --git a/arch/arm/include/asm/elf.h b/arch/arm/include/asm/elf.h
1674index f4b46d3..abc9b2b 100644
1675--- a/arch/arm/include/asm/elf.h
1676+++ b/arch/arm/include/asm/elf.h
1677@@ -114,7 +114,14 @@ int dump_task_regs(struct task_struct *t, elf_gregset_t *elfregs);
1678 the loader. We need to make sure that it is out of the way of the program
1679 that it will "exec", and that there is sufficient room for the brk. */
1680
1681-#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
1682+#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
1683+
1684+#ifdef CONFIG_PAX_ASLR
1685+#define PAX_ELF_ET_DYN_BASE 0x00008000UL
1686+
1687+#define PAX_DELTA_MMAP_LEN ((current->personality == PER_LINUX_32BIT) ? 16 : 10)
1688+#define PAX_DELTA_STACK_LEN ((current->personality == PER_LINUX_32BIT) ? 16 : 10)
1689+#endif
1690
1691 /* When the program starts, a1 contains a pointer to a function to be
1692 registered with atexit, as per the SVR4 ABI. A value of 0 means we
1693@@ -124,10 +131,6 @@ int dump_task_regs(struct task_struct *t, elf_gregset_t *elfregs);
1694 extern void elf_set_personality(const struct elf32_hdr *);
1695 #define SET_PERSONALITY(ex) elf_set_personality(&(ex))
1696
1697-struct mm_struct;
1698-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
1699-#define arch_randomize_brk arch_randomize_brk
1700-
1701 #ifdef CONFIG_MMU
1702 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
1703 struct linux_binprm;
1704diff --git a/arch/arm/include/asm/fncpy.h b/arch/arm/include/asm/fncpy.h
1705index de53547..52b9a28 100644
1706--- a/arch/arm/include/asm/fncpy.h
1707+++ b/arch/arm/include/asm/fncpy.h
1708@@ -81,7 +81,9 @@
1709 BUG_ON((uintptr_t)(dest_buf) & (FNCPY_ALIGN - 1) || \
1710 (__funcp_address & ~(uintptr_t)1 & (FNCPY_ALIGN - 1))); \
1711 \
1712+ pax_open_kernel(); \
1713 memcpy(dest_buf, (void const *)(__funcp_address & ~1), size); \
1714+ pax_close_kernel(); \
1715 flush_icache_range((unsigned long)(dest_buf), \
1716 (unsigned long)(dest_buf) + (size)); \
1717 \
1718diff --git a/arch/arm/include/asm/futex.h b/arch/arm/include/asm/futex.h
1719index e42cf59..7b94b8f 100644
1720--- a/arch/arm/include/asm/futex.h
1721+++ b/arch/arm/include/asm/futex.h
1722@@ -50,6 +50,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
1723 if (!access_ok(VERIFY_WRITE, uaddr, sizeof(u32)))
1724 return -EFAULT;
1725
1726+ pax_open_userland();
1727+
1728 smp_mb();
1729 __asm__ __volatile__("@futex_atomic_cmpxchg_inatomic\n"
1730 "1: ldrex %1, [%4]\n"
1731@@ -65,6 +67,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
1732 : "cc", "memory");
1733 smp_mb();
1734
1735+ pax_close_userland();
1736+
1737 *uval = val;
1738 return ret;
1739 }
1740@@ -95,6 +99,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
1741 if (!access_ok(VERIFY_WRITE, uaddr, sizeof(u32)))
1742 return -EFAULT;
1743
1744+ pax_open_userland();
1745+
1746 __asm__ __volatile__("@futex_atomic_cmpxchg_inatomic\n"
1747 "1: " TUSER(ldr) " %1, [%4]\n"
1748 " teq %1, %2\n"
1749@@ -105,6 +111,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
1750 : "r" (oldval), "r" (newval), "r" (uaddr), "Ir" (-EFAULT)
1751 : "cc", "memory");
1752
1753+ pax_close_userland();
1754+
1755 *uval = val;
1756 return ret;
1757 }
1758@@ -127,6 +135,7 @@ futex_atomic_op_inuser (int encoded_op, u32 __user *uaddr)
1759 return -EFAULT;
1760
1761 pagefault_disable(); /* implies preempt_disable() */
1762+ pax_open_userland();
1763
1764 switch (op) {
1765 case FUTEX_OP_SET:
1766@@ -148,6 +157,7 @@ futex_atomic_op_inuser (int encoded_op, u32 __user *uaddr)
1767 ret = -ENOSYS;
1768 }
1769
1770+ pax_close_userland();
1771 pagefault_enable(); /* subsumes preempt_enable() */
1772
1773 if (!ret) {
1774diff --git a/arch/arm/include/asm/kmap_types.h b/arch/arm/include/asm/kmap_types.h
1775index 83eb2f7..ed77159 100644
1776--- a/arch/arm/include/asm/kmap_types.h
1777+++ b/arch/arm/include/asm/kmap_types.h
1778@@ -4,6 +4,6 @@
1779 /*
1780 * This is the "bare minimum". AIO seems to require this.
1781 */
1782-#define KM_TYPE_NR 16
1783+#define KM_TYPE_NR 17
1784
1785 #endif
1786diff --git a/arch/arm/include/asm/mach/dma.h b/arch/arm/include/asm/mach/dma.h
1787index 9e614a1..3302cca 100644
1788--- a/arch/arm/include/asm/mach/dma.h
1789+++ b/arch/arm/include/asm/mach/dma.h
1790@@ -22,7 +22,7 @@ struct dma_ops {
1791 int (*residue)(unsigned int, dma_t *); /* optional */
1792 int (*setspeed)(unsigned int, dma_t *, int); /* optional */
1793 const char *type;
1794-};
1795+} __do_const;
1796
1797 struct dma_struct {
1798 void *addr; /* single DMA address */
1799diff --git a/arch/arm/include/asm/mach/map.h b/arch/arm/include/asm/mach/map.h
1800index 2fe141f..192dc01 100644
1801--- a/arch/arm/include/asm/mach/map.h
1802+++ b/arch/arm/include/asm/mach/map.h
1803@@ -27,13 +27,16 @@ struct map_desc {
1804 #define MT_MINICLEAN 6
1805 #define MT_LOW_VECTORS 7
1806 #define MT_HIGH_VECTORS 8
1807-#define MT_MEMORY 9
1808+#define MT_MEMORY_RWX 9
1809 #define MT_ROM 10
1810-#define MT_MEMORY_NONCACHED 11
1811+#define MT_MEMORY_NONCACHED_RX 11
1812 #define MT_MEMORY_DTCM 12
1813 #define MT_MEMORY_ITCM 13
1814 #define MT_MEMORY_SO 14
1815 #define MT_MEMORY_DMA_READY 15
1816+#define MT_MEMORY_RW 16
1817+#define MT_MEMORY_RX 17
1818+#define MT_MEMORY_NONCACHED_RW 18
1819
1820 #ifdef CONFIG_MMU
1821 extern void iotable_init(struct map_desc *, int);
1822diff --git a/arch/arm/include/asm/outercache.h b/arch/arm/include/asm/outercache.h
1823index f94784f..9a09a4a 100644
1824--- a/arch/arm/include/asm/outercache.h
1825+++ b/arch/arm/include/asm/outercache.h
1826@@ -35,7 +35,7 @@ struct outer_cache_fns {
1827 #endif
1828 void (*set_debug)(unsigned long);
1829 void (*resume)(void);
1830-};
1831+} __no_const;
1832
1833 extern struct outer_cache_fns outer_cache;
1834
1835diff --git a/arch/arm/include/asm/page.h b/arch/arm/include/asm/page.h
1836index 4355f0e..c229913 100644
1837--- a/arch/arm/include/asm/page.h
1838+++ b/arch/arm/include/asm/page.h
1839@@ -114,7 +114,7 @@ struct cpu_user_fns {
1840 void (*cpu_clear_user_highpage)(struct page *page, unsigned long vaddr);
1841 void (*cpu_copy_user_highpage)(struct page *to, struct page *from,
1842 unsigned long vaddr, struct vm_area_struct *vma);
1843-};
1844+} __no_const;
1845
1846 #ifdef MULTI_USER
1847 extern struct cpu_user_fns cpu_user;
1848diff --git a/arch/arm/include/asm/pgalloc.h b/arch/arm/include/asm/pgalloc.h
1849index 943504f..c37a730 100644
1850--- a/arch/arm/include/asm/pgalloc.h
1851+++ b/arch/arm/include/asm/pgalloc.h
1852@@ -17,6 +17,7 @@
1853 #include <asm/processor.h>
1854 #include <asm/cacheflush.h>
1855 #include <asm/tlbflush.h>
1856+#include <asm/system_info.h>
1857
1858 #define check_pgt_cache() do { } while (0)
1859
1860@@ -43,6 +44,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1861 set_pud(pud, __pud(__pa(pmd) | PMD_TYPE_TABLE));
1862 }
1863
1864+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1865+{
1866+ pud_populate(mm, pud, pmd);
1867+}
1868+
1869 #else /* !CONFIG_ARM_LPAE */
1870
1871 /*
1872@@ -51,6 +57,7 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1873 #define pmd_alloc_one(mm,addr) ({ BUG(); ((pmd_t *)2); })
1874 #define pmd_free(mm, pmd) do { } while (0)
1875 #define pud_populate(mm,pmd,pte) BUG()
1876+#define pud_populate_kernel(mm,pmd,pte) BUG()
1877
1878 #endif /* CONFIG_ARM_LPAE */
1879
1880@@ -126,6 +133,19 @@ static inline void pte_free(struct mm_struct *mm, pgtable_t pte)
1881 __free_page(pte);
1882 }
1883
1884+static inline void __section_update(pmd_t *pmdp, unsigned long addr, pmdval_t prot)
1885+{
1886+#ifdef CONFIG_ARM_LPAE
1887+ pmdp[0] = __pmd(pmd_val(pmdp[0]) | prot);
1888+#else
1889+ if (addr & SECTION_SIZE)
1890+ pmdp[1] = __pmd(pmd_val(pmdp[1]) | prot);
1891+ else
1892+ pmdp[0] = __pmd(pmd_val(pmdp[0]) | prot);
1893+#endif
1894+ flush_pmd_entry(pmdp);
1895+}
1896+
1897 static inline void __pmd_populate(pmd_t *pmdp, phys_addr_t pte,
1898 pmdval_t prot)
1899 {
1900@@ -155,7 +175,7 @@ pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmdp, pte_t *ptep)
1901 static inline void
1902 pmd_populate(struct mm_struct *mm, pmd_t *pmdp, pgtable_t ptep)
1903 {
1904- __pmd_populate(pmdp, page_to_phys(ptep), _PAGE_USER_TABLE);
1905+ __pmd_populate(pmdp, page_to_phys(ptep), _PAGE_USER_TABLE | __supported_pmd_mask);
1906 }
1907 #define pmd_pgtable(pmd) pmd_page(pmd)
1908
1909diff --git a/arch/arm/include/asm/pgtable-2level-hwdef.h b/arch/arm/include/asm/pgtable-2level-hwdef.h
1910index 5cfba15..f415e1a 100644
1911--- a/arch/arm/include/asm/pgtable-2level-hwdef.h
1912+++ b/arch/arm/include/asm/pgtable-2level-hwdef.h
1913@@ -20,12 +20,15 @@
1914 #define PMD_TYPE_FAULT (_AT(pmdval_t, 0) << 0)
1915 #define PMD_TYPE_TABLE (_AT(pmdval_t, 1) << 0)
1916 #define PMD_TYPE_SECT (_AT(pmdval_t, 2) << 0)
1917+#define PMD_PXNTABLE (_AT(pmdval_t, 1) << 2) /* v7 */
1918 #define PMD_BIT4 (_AT(pmdval_t, 1) << 4)
1919 #define PMD_DOMAIN(x) (_AT(pmdval_t, (x)) << 5)
1920 #define PMD_PROTECTION (_AT(pmdval_t, 1) << 9) /* v5 */
1921+
1922 /*
1923 * - section
1924 */
1925+#define PMD_SECT_PXN (_AT(pmdval_t, 1) << 0) /* v7 */
1926 #define PMD_SECT_BUFFERABLE (_AT(pmdval_t, 1) << 2)
1927 #define PMD_SECT_CACHEABLE (_AT(pmdval_t, 1) << 3)
1928 #define PMD_SECT_XN (_AT(pmdval_t, 1) << 4) /* v6 */
1929@@ -37,6 +40,7 @@
1930 #define PMD_SECT_nG (_AT(pmdval_t, 1) << 17) /* v6 */
1931 #define PMD_SECT_SUPER (_AT(pmdval_t, 1) << 18) /* v6 */
1932 #define PMD_SECT_AF (_AT(pmdval_t, 0))
1933+#define PMD_SECT_RDONLY (_AT(pmdval_t, 0))
1934
1935 #define PMD_SECT_UNCACHED (_AT(pmdval_t, 0))
1936 #define PMD_SECT_BUFFERED (PMD_SECT_BUFFERABLE)
1937@@ -66,6 +70,7 @@
1938 * - extended small page/tiny page
1939 */
1940 #define PTE_EXT_XN (_AT(pteval_t, 1) << 0) /* v6 */
1941+#define PTE_EXT_PXN (_AT(pteval_t, 1) << 2) /* v7 */
1942 #define PTE_EXT_AP_MASK (_AT(pteval_t, 3) << 4)
1943 #define PTE_EXT_AP0 (_AT(pteval_t, 1) << 4)
1944 #define PTE_EXT_AP1 (_AT(pteval_t, 2) << 4)
1945diff --git a/arch/arm/include/asm/pgtable-2level.h b/arch/arm/include/asm/pgtable-2level.h
1946index f97ee02..cc9fe9e 100644
1947--- a/arch/arm/include/asm/pgtable-2level.h
1948+++ b/arch/arm/include/asm/pgtable-2level.h
1949@@ -126,6 +126,9 @@
1950 #define L_PTE_SHARED (_AT(pteval_t, 1) << 10) /* shared(v6), coherent(xsc3) */
1951 #define L_PTE_NONE (_AT(pteval_t, 1) << 11)
1952
1953+/* Two-level page tables only have PXN in the PGD, not in the PTE. */
1954+#define L_PTE_PXN (_AT(pteval_t, 0))
1955+
1956 /*
1957 * These are the memory types, defined to be compatible with
1958 * pre-ARMv6 CPUs cacheable and bufferable bits: XXCB
1959diff --git a/arch/arm/include/asm/pgtable-3level-hwdef.h b/arch/arm/include/asm/pgtable-3level-hwdef.h
1960index 626989f..9d67a33 100644
1961--- a/arch/arm/include/asm/pgtable-3level-hwdef.h
1962+++ b/arch/arm/include/asm/pgtable-3level-hwdef.h
1963@@ -75,6 +75,7 @@
1964 #define PTE_EXT_SHARED (_AT(pteval_t, 3) << 8) /* SH[1:0], inner shareable */
1965 #define PTE_EXT_AF (_AT(pteval_t, 1) << 10) /* Access Flag */
1966 #define PTE_EXT_NG (_AT(pteval_t, 1) << 11) /* nG */
1967+#define PTE_EXT_PXN (_AT(pteval_t, 1) << 53) /* PXN */
1968 #define PTE_EXT_XN (_AT(pteval_t, 1) << 54) /* XN */
1969
1970 /*
1971diff --git a/arch/arm/include/asm/pgtable-3level.h b/arch/arm/include/asm/pgtable-3level.h
1972index 5689c18..eea12f9 100644
1973--- a/arch/arm/include/asm/pgtable-3level.h
1974+++ b/arch/arm/include/asm/pgtable-3level.h
1975@@ -82,6 +82,7 @@
1976 #define L_PTE_RDONLY (_AT(pteval_t, 1) << 7) /* AP[2] */
1977 #define L_PTE_SHARED (_AT(pteval_t, 3) << 8) /* SH[1:0], inner shareable */
1978 #define L_PTE_YOUNG (_AT(pteval_t, 1) << 10) /* AF */
1979+#define L_PTE_PXN (_AT(pteval_t, 1) << 53) /* PXN */
1980 #define L_PTE_XN (_AT(pteval_t, 1) << 54) /* XN */
1981 #define L_PTE_DIRTY (_AT(pteval_t, 1) << 55) /* unused */
1982 #define L_PTE_SPECIAL (_AT(pteval_t, 1) << 56) /* unused */
1983@@ -95,6 +96,7 @@
1984 /*
1985 * To be used in assembly code with the upper page attributes.
1986 */
1987+#define L_PTE_PXN_HIGH (1 << (53 - 32))
1988 #define L_PTE_XN_HIGH (1 << (54 - 32))
1989 #define L_PTE_DIRTY_HIGH (1 << (55 - 32))
1990
1991diff --git a/arch/arm/include/asm/pgtable.h b/arch/arm/include/asm/pgtable.h
1992index 1571d12..b8a9b43 100644
1993--- a/arch/arm/include/asm/pgtable.h
1994+++ b/arch/arm/include/asm/pgtable.h
1995@@ -33,6 +33,9 @@
1996 #include <asm/pgtable-2level.h>
1997 #endif
1998
1999+#define ktla_ktva(addr) (addr)
2000+#define ktva_ktla(addr) (addr)
2001+
2002 /*
2003 * Just any arbitrary offset to the start of the vmalloc VM area: the
2004 * current 8MB value just means that there will be a 8MB "hole" after the
2005@@ -48,6 +51,9 @@
2006 #define LIBRARY_TEXT_START 0x0c000000
2007
2008 #ifndef __ASSEMBLY__
2009+extern pteval_t __supported_pte_mask;
2010+extern pmdval_t __supported_pmd_mask;
2011+
2012 extern void __pte_error(const char *file, int line, pte_t);
2013 extern void __pmd_error(const char *file, int line, pmd_t);
2014 extern void __pgd_error(const char *file, int line, pgd_t);
2015@@ -56,6 +62,48 @@ extern void __pgd_error(const char *file, int line, pgd_t);
2016 #define pmd_ERROR(pmd) __pmd_error(__FILE__, __LINE__, pmd)
2017 #define pgd_ERROR(pgd) __pgd_error(__FILE__, __LINE__, pgd)
2018
2019+#define __HAVE_ARCH_PAX_OPEN_KERNEL
2020+#define __HAVE_ARCH_PAX_CLOSE_KERNEL
2021+
2022+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2023+#include <asm/domain.h>
2024+#include <linux/thread_info.h>
2025+#include <linux/preempt.h>
2026+
2027+static inline int test_domain(int domain, int domaintype)
2028+{
2029+ return ((current_thread_info()->cpu_domain) & domain_val(domain, 3)) == domain_val(domain, domaintype);
2030+}
2031+#endif
2032+
2033+#ifdef CONFIG_PAX_KERNEXEC
2034+static inline unsigned long pax_open_kernel(void) {
2035+#ifdef CONFIG_ARM_LPAE
2036+ /* TODO */
2037+#else
2038+ preempt_disable();
2039+ BUG_ON(test_domain(DOMAIN_KERNEL, DOMAIN_KERNEXEC));
2040+ modify_domain(DOMAIN_KERNEL, DOMAIN_KERNEXEC);
2041+#endif
2042+ return 0;
2043+}
2044+
2045+static inline unsigned long pax_close_kernel(void) {
2046+#ifdef CONFIG_ARM_LPAE
2047+ /* TODO */
2048+#else
2049+ BUG_ON(test_domain(DOMAIN_KERNEL, DOMAIN_MANAGER));
2050+ /* DOMAIN_MANAGER = "client" under KERNEXEC */
2051+ modify_domain(DOMAIN_KERNEL, DOMAIN_MANAGER);
2052+ preempt_enable_no_resched();
2053+#endif
2054+ return 0;
2055+}
2056+#else
2057+static inline unsigned long pax_open_kernel(void) { return 0; }
2058+static inline unsigned long pax_close_kernel(void) { return 0; }
2059+#endif
2060+
2061 /*
2062 * This is the lowest virtual address we can permit any user space
2063 * mapping to be mapped at. This is particularly important for
2064@@ -75,8 +123,8 @@ extern void __pgd_error(const char *file, int line, pgd_t);
2065 /*
2066 * The pgprot_* and protection_map entries will be fixed up in runtime
2067 * to include the cachable and bufferable bits based on memory policy,
2068- * as well as any architecture dependent bits like global/ASID and SMP
2069- * shared mapping bits.
2070+ * as well as any architecture dependent bits like global/ASID, PXN,
2071+ * and SMP shared mapping bits.
2072 */
2073 #define _L_PTE_DEFAULT L_PTE_PRESENT | L_PTE_YOUNG
2074
2075@@ -260,7 +308,7 @@ static inline pte_t pte_mkspecial(pte_t pte) { return pte; }
2076 static inline pte_t pte_modify(pte_t pte, pgprot_t newprot)
2077 {
2078 const pteval_t mask = L_PTE_XN | L_PTE_RDONLY | L_PTE_USER |
2079- L_PTE_NONE | L_PTE_VALID;
2080+ L_PTE_NONE | L_PTE_VALID | __supported_pte_mask;
2081 pte_val(pte) = (pte_val(pte) & ~mask) | (pgprot_val(newprot) & mask);
2082 return pte;
2083 }
2084diff --git a/arch/arm/include/asm/proc-fns.h b/arch/arm/include/asm/proc-fns.h
2085index 5324c11..bcae5f0 100644
2086--- a/arch/arm/include/asm/proc-fns.h
2087+++ b/arch/arm/include/asm/proc-fns.h
2088@@ -75,7 +75,7 @@ extern struct processor {
2089 unsigned int suspend_size;
2090 void (*do_suspend)(void *);
2091 void (*do_resume)(void *);
2092-} processor;
2093+} __do_const processor;
2094
2095 #ifndef MULTI_CPU
2096 extern void cpu_proc_init(void);
2097diff --git a/arch/arm/include/asm/psci.h b/arch/arm/include/asm/psci.h
2098index c4ae171..ea0c0c2 100644
2099--- a/arch/arm/include/asm/psci.h
2100+++ b/arch/arm/include/asm/psci.h
2101@@ -29,7 +29,7 @@ struct psci_operations {
2102 int (*cpu_off)(struct psci_power_state state);
2103 int (*cpu_on)(unsigned long cpuid, unsigned long entry_point);
2104 int (*migrate)(unsigned long cpuid);
2105-};
2106+} __no_const;
2107
2108 extern struct psci_operations psci_ops;
2109 extern struct smp_operations psci_smp_ops;
2110diff --git a/arch/arm/include/asm/smp.h b/arch/arm/include/asm/smp.h
2111index a8cae71c..65dd797 100644
2112--- a/arch/arm/include/asm/smp.h
2113+++ b/arch/arm/include/asm/smp.h
2114@@ -110,7 +110,7 @@ struct smp_operations {
2115 int (*cpu_disable)(unsigned int cpu);
2116 #endif
2117 #endif
2118-};
2119+} __no_const;
2120
2121 /*
2122 * set platform specific SMP operations
2123diff --git a/arch/arm/include/asm/thread_info.h b/arch/arm/include/asm/thread_info.h
2124index df5e13d..97efb82 100644
2125--- a/arch/arm/include/asm/thread_info.h
2126+++ b/arch/arm/include/asm/thread_info.h
2127@@ -88,9 +88,9 @@ struct thread_info {
2128 .flags = 0, \
2129 .preempt_count = INIT_PREEMPT_COUNT, \
2130 .addr_limit = KERNEL_DS, \
2131- .cpu_domain = domain_val(DOMAIN_USER, DOMAIN_MANAGER) | \
2132- domain_val(DOMAIN_KERNEL, DOMAIN_MANAGER) | \
2133- domain_val(DOMAIN_IO, DOMAIN_CLIENT), \
2134+ .cpu_domain = domain_val(DOMAIN_USER, DOMAIN_USERCLIENT) | \
2135+ domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT) | \
2136+ domain_val(DOMAIN_IO, DOMAIN_KERNELCLIENT), \
2137 .restart_block = { \
2138 .fn = do_no_restart_syscall, \
2139 }, \
2140@@ -163,7 +163,11 @@ extern int vfp_restore_user_hwstate(struct user_vfp __user *,
2141 #define TIF_SYSCALL_AUDIT 9
2142 #define TIF_SYSCALL_TRACEPOINT 10
2143 #define TIF_SECCOMP 11 /* seccomp syscall filtering active */
2144-#define TIF_NOHZ 12 /* in adaptive nohz mode */
2145+/* within 8 bits of TIF_SYSCALL_TRACE
2146+ * to meet flexible second operand requirements
2147+ */
2148+#define TIF_GRSEC_SETXID 12
2149+#define TIF_NOHZ 13 /* in adaptive nohz mode */
2150 #define TIF_USING_IWMMXT 17
2151 #define TIF_MEMDIE 18 /* is terminating due to OOM killer */
2152 #define TIF_RESTORE_SIGMASK 20
2153@@ -176,10 +180,11 @@ extern int vfp_restore_user_hwstate(struct user_vfp __user *,
2154 #define _TIF_SYSCALL_TRACEPOINT (1 << TIF_SYSCALL_TRACEPOINT)
2155 #define _TIF_SECCOMP (1 << TIF_SECCOMP)
2156 #define _TIF_USING_IWMMXT (1 << TIF_USING_IWMMXT)
2157+#define _TIF_GRSEC_SETXID (1 << TIF_GRSEC_SETXID)
2158
2159 /* Checks for any syscall work in entry-common.S */
2160 #define _TIF_SYSCALL_WORK (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \
2161- _TIF_SYSCALL_TRACEPOINT | _TIF_SECCOMP)
2162+ _TIF_SYSCALL_TRACEPOINT | _TIF_SECCOMP | _TIF_GRSEC_SETXID)
2163
2164 /*
2165 * Change these and you break ASM code in entry-common.S
2166diff --git a/arch/arm/include/asm/uaccess.h b/arch/arm/include/asm/uaccess.h
2167index 72abdc5..9eba222 100644
2168--- a/arch/arm/include/asm/uaccess.h
2169+++ b/arch/arm/include/asm/uaccess.h
2170@@ -18,6 +18,7 @@
2171 #include <asm/domain.h>
2172 #include <asm/unified.h>
2173 #include <asm/compiler.h>
2174+#include <asm/pgtable.h>
2175
2176 #if __LINUX_ARM_ARCH__ < 6
2177 #include <asm-generic/uaccess-unaligned.h>
2178@@ -70,11 +71,38 @@ extern int __put_user_bad(void);
2179 static inline void set_fs(mm_segment_t fs)
2180 {
2181 current_thread_info()->addr_limit = fs;
2182- modify_domain(DOMAIN_KERNEL, fs ? DOMAIN_CLIENT : DOMAIN_MANAGER);
2183+ modify_domain(DOMAIN_KERNEL, fs ? DOMAIN_KERNELCLIENT : DOMAIN_MANAGER);
2184 }
2185
2186 #define segment_eq(a,b) ((a) == (b))
2187
2188+#define __HAVE_ARCH_PAX_OPEN_USERLAND
2189+#define __HAVE_ARCH_PAX_CLOSE_USERLAND
2190+
2191+static inline void pax_open_userland(void)
2192+{
2193+
2194+#ifdef CONFIG_PAX_MEMORY_UDEREF
2195+ if (segment_eq(get_fs(), USER_DS)) {
2196+ BUG_ON(test_domain(DOMAIN_USER, DOMAIN_UDEREF));
2197+ modify_domain(DOMAIN_USER, DOMAIN_UDEREF);
2198+ }
2199+#endif
2200+
2201+}
2202+
2203+static inline void pax_close_userland(void)
2204+{
2205+
2206+#ifdef CONFIG_PAX_MEMORY_UDEREF
2207+ if (segment_eq(get_fs(), USER_DS)) {
2208+ BUG_ON(test_domain(DOMAIN_USER, DOMAIN_NOACCESS));
2209+ modify_domain(DOMAIN_USER, DOMAIN_NOACCESS);
2210+ }
2211+#endif
2212+
2213+}
2214+
2215 #define __addr_ok(addr) ({ \
2216 unsigned long flag; \
2217 __asm__("cmp %2, %0; movlo %0, #0" \
2218@@ -150,8 +178,12 @@ extern int __get_user_4(void *);
2219
2220 #define get_user(x,p) \
2221 ({ \
2222+ int __e; \
2223 might_fault(); \
2224- __get_user_check(x,p); \
2225+ pax_open_userland(); \
2226+ __e = __get_user_check(x,p); \
2227+ pax_close_userland(); \
2228+ __e; \
2229 })
2230
2231 extern int __put_user_1(void *, unsigned int);
2232@@ -195,8 +227,12 @@ extern int __put_user_8(void *, unsigned long long);
2233
2234 #define put_user(x,p) \
2235 ({ \
2236+ int __e; \
2237 might_fault(); \
2238- __put_user_check(x,p); \
2239+ pax_open_userland(); \
2240+ __e = __put_user_check(x,p); \
2241+ pax_close_userland(); \
2242+ __e; \
2243 })
2244
2245 #else /* CONFIG_MMU */
2246@@ -237,13 +273,17 @@ static inline void set_fs(mm_segment_t fs)
2247 #define __get_user(x,ptr) \
2248 ({ \
2249 long __gu_err = 0; \
2250+ pax_open_userland(); \
2251 __get_user_err((x),(ptr),__gu_err); \
2252+ pax_close_userland(); \
2253 __gu_err; \
2254 })
2255
2256 #define __get_user_error(x,ptr,err) \
2257 ({ \
2258+ pax_open_userland(); \
2259 __get_user_err((x),(ptr),err); \
2260+ pax_close_userland(); \
2261 (void) 0; \
2262 })
2263
2264@@ -319,13 +359,17 @@ do { \
2265 #define __put_user(x,ptr) \
2266 ({ \
2267 long __pu_err = 0; \
2268+ pax_open_userland(); \
2269 __put_user_err((x),(ptr),__pu_err); \
2270+ pax_close_userland(); \
2271 __pu_err; \
2272 })
2273
2274 #define __put_user_error(x,ptr,err) \
2275 ({ \
2276+ pax_open_userland(); \
2277 __put_user_err((x),(ptr),err); \
2278+ pax_close_userland(); \
2279 (void) 0; \
2280 })
2281
2282@@ -425,11 +469,44 @@ do { \
2283
2284
2285 #ifdef CONFIG_MMU
2286-extern unsigned long __must_check __copy_from_user(void *to, const void __user *from, unsigned long n);
2287-extern unsigned long __must_check __copy_to_user(void __user *to, const void *from, unsigned long n);
2288+extern unsigned long __must_check ___copy_from_user(void *to, const void __user *from, unsigned long n);
2289+extern unsigned long __must_check ___copy_to_user(void __user *to, const void *from, unsigned long n);
2290+
2291+static inline unsigned long __must_check __copy_from_user(void *to, const void __user *from, unsigned long n)
2292+{
2293+ unsigned long ret;
2294+
2295+ check_object_size(to, n, false);
2296+ pax_open_userland();
2297+ ret = ___copy_from_user(to, from, n);
2298+ pax_close_userland();
2299+ return ret;
2300+}
2301+
2302+static inline unsigned long __must_check __copy_to_user(void __user *to, const void *from, unsigned long n)
2303+{
2304+ unsigned long ret;
2305+
2306+ check_object_size(from, n, true);
2307+ pax_open_userland();
2308+ ret = ___copy_to_user(to, from, n);
2309+ pax_close_userland();
2310+ return ret;
2311+}
2312+
2313 extern unsigned long __must_check __copy_to_user_std(void __user *to, const void *from, unsigned long n);
2314-extern unsigned long __must_check __clear_user(void __user *addr, unsigned long n);
2315+extern unsigned long __must_check ___clear_user(void __user *addr, unsigned long n);
2316 extern unsigned long __must_check __clear_user_std(void __user *addr, unsigned long n);
2317+
2318+static inline unsigned long __must_check __clear_user(void __user *addr, unsigned long n)
2319+{
2320+ unsigned long ret;
2321+ pax_open_userland();
2322+ ret = ___clear_user(addr, n);
2323+ pax_close_userland();
2324+ return ret;
2325+}
2326+
2327 #else
2328 #define __copy_from_user(to,from,n) (memcpy(to, (void __force *)from, n), 0)
2329 #define __copy_to_user(to,from,n) (memcpy((void __force *)to, from, n), 0)
2330@@ -438,6 +515,9 @@ extern unsigned long __must_check __clear_user_std(void __user *addr, unsigned l
2331
2332 static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
2333 {
2334+ if ((long)n < 0)
2335+ return n;
2336+
2337 if (access_ok(VERIFY_READ, from, n))
2338 n = __copy_from_user(to, from, n);
2339 else /* security hole - plug it */
2340@@ -447,6 +527,9 @@ static inline unsigned long __must_check copy_from_user(void *to, const void __u
2341
2342 static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
2343 {
2344+ if ((long)n < 0)
2345+ return n;
2346+
2347 if (access_ok(VERIFY_WRITE, to, n))
2348 n = __copy_to_user(to, from, n);
2349 return n;
2350diff --git a/arch/arm/include/uapi/asm/ptrace.h b/arch/arm/include/uapi/asm/ptrace.h
2351index 5af0ed1..cea83883 100644
2352--- a/arch/arm/include/uapi/asm/ptrace.h
2353+++ b/arch/arm/include/uapi/asm/ptrace.h
2354@@ -92,7 +92,7 @@
2355 * ARMv7 groups of PSR bits
2356 */
2357 #define APSR_MASK 0xf80f0000 /* N, Z, C, V, Q and GE flags */
2358-#define PSR_ISET_MASK 0x01000010 /* ISA state (J, T) mask */
2359+#define PSR_ISET_MASK 0x01000020 /* ISA state (J, T) mask */
2360 #define PSR_IT_MASK 0x0600fc00 /* If-Then execution state mask */
2361 #define PSR_ENDIAN_MASK 0x00000200 /* Endianness state mask */
2362
2363diff --git a/arch/arm/kernel/armksyms.c b/arch/arm/kernel/armksyms.c
2364index 60d3b73..e5a0f22 100644
2365--- a/arch/arm/kernel/armksyms.c
2366+++ b/arch/arm/kernel/armksyms.c
2367@@ -53,7 +53,7 @@ EXPORT_SYMBOL(arm_delay_ops);
2368
2369 /* networking */
2370 EXPORT_SYMBOL(csum_partial);
2371-EXPORT_SYMBOL(csum_partial_copy_from_user);
2372+EXPORT_SYMBOL(__csum_partial_copy_from_user);
2373 EXPORT_SYMBOL(csum_partial_copy_nocheck);
2374 EXPORT_SYMBOL(__csum_ipv6_magic);
2375
2376@@ -89,9 +89,9 @@ EXPORT_SYMBOL(__memzero);
2377 #ifdef CONFIG_MMU
2378 EXPORT_SYMBOL(copy_page);
2379
2380-EXPORT_SYMBOL(__copy_from_user);
2381-EXPORT_SYMBOL(__copy_to_user);
2382-EXPORT_SYMBOL(__clear_user);
2383+EXPORT_SYMBOL(___copy_from_user);
2384+EXPORT_SYMBOL(___copy_to_user);
2385+EXPORT_SYMBOL(___clear_user);
2386
2387 EXPORT_SYMBOL(__get_user_1);
2388 EXPORT_SYMBOL(__get_user_2);
2389diff --git a/arch/arm/kernel/entry-armv.S b/arch/arm/kernel/entry-armv.S
2390index ec3e5cf..b450ee3 100644
2391--- a/arch/arm/kernel/entry-armv.S
2392+++ b/arch/arm/kernel/entry-armv.S
2393@@ -47,6 +47,87 @@
2394 9997:
2395 .endm
2396
2397+ .macro pax_enter_kernel
2398+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2399+ @ make aligned space for saved DACR
2400+ sub sp, sp, #8
2401+ @ save regs
2402+ stmdb sp!, {r1, r2}
2403+ @ read DACR from cpu_domain into r1
2404+ mov r2, sp
2405+ @ assume 8K pages, since we have to split the immediate in two
2406+ bic r2, r2, #(0x1fc0)
2407+ bic r2, r2, #(0x3f)
2408+ ldr r1, [r2, #TI_CPU_DOMAIN]
2409+ @ store old DACR on stack
2410+ str r1, [sp, #8]
2411+#ifdef CONFIG_PAX_KERNEXEC
2412+ @ set type of DOMAIN_KERNEL to DOMAIN_KERNELCLIENT
2413+ bic r1, r1, #(domain_val(DOMAIN_KERNEL, 3))
2414+ orr r1, r1, #(domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT))
2415+#endif
2416+#ifdef CONFIG_PAX_MEMORY_UDEREF
2417+ @ set current DOMAIN_USER to DOMAIN_NOACCESS
2418+ bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2419+#endif
2420+ @ write r1 to current_thread_info()->cpu_domain
2421+ str r1, [r2, #TI_CPU_DOMAIN]
2422+ @ write r1 to DACR
2423+ mcr p15, 0, r1, c3, c0, 0
2424+ @ instruction sync
2425+ instr_sync
2426+ @ restore regs
2427+ ldmia sp!, {r1, r2}
2428+#endif
2429+ .endm
2430+
2431+ .macro pax_open_userland
2432+#ifdef CONFIG_PAX_MEMORY_UDEREF
2433+ @ save regs
2434+ stmdb sp!, {r0, r1}
2435+ @ read DACR from cpu_domain into r1
2436+ mov r0, sp
2437+ @ assume 8K pages, since we have to split the immediate in two
2438+ bic r0, r0, #(0x1fc0)
2439+ bic r0, r0, #(0x3f)
2440+ ldr r1, [r0, #TI_CPU_DOMAIN]
2441+ @ set current DOMAIN_USER to DOMAIN_CLIENT
2442+ bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2443+ orr r1, r1, #(domain_val(DOMAIN_USER, DOMAIN_UDEREF))
2444+ @ write r1 to current_thread_info()->cpu_domain
2445+ str r1, [r0, #TI_CPU_DOMAIN]
2446+ @ write r1 to DACR
2447+ mcr p15, 0, r1, c3, c0, 0
2448+ @ instruction sync
2449+ instr_sync
2450+ @ restore regs
2451+ ldmia sp!, {r0, r1}
2452+#endif
2453+ .endm
2454+
2455+ .macro pax_close_userland
2456+#ifdef CONFIG_PAX_MEMORY_UDEREF
2457+ @ save regs
2458+ stmdb sp!, {r0, r1}
2459+ @ read DACR from cpu_domain into r1
2460+ mov r0, sp
2461+ @ assume 8K pages, since we have to split the immediate in two
2462+ bic r0, r0, #(0x1fc0)
2463+ bic r0, r0, #(0x3f)
2464+ ldr r1, [r0, #TI_CPU_DOMAIN]
2465+ @ set current DOMAIN_USER to DOMAIN_NOACCESS
2466+ bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2467+ @ write r1 to current_thread_info()->cpu_domain
2468+ str r1, [r0, #TI_CPU_DOMAIN]
2469+ @ write r1 to DACR
2470+ mcr p15, 0, r1, c3, c0, 0
2471+ @ instruction sync
2472+ instr_sync
2473+ @ restore regs
2474+ ldmia sp!, {r0, r1}
2475+#endif
2476+ .endm
2477+
2478 .macro pabt_helper
2479 @ PABORT handler takes pt_regs in r2, fault address in r4 and psr in r5
2480 #ifdef MULTI_PABORT
2481@@ -89,11 +170,15 @@
2482 * Invalid mode handlers
2483 */
2484 .macro inv_entry, reason
2485+
2486+ pax_enter_kernel
2487+
2488 sub sp, sp, #S_FRAME_SIZE
2489 ARM( stmib sp, {r1 - lr} )
2490 THUMB( stmia sp, {r0 - r12} )
2491 THUMB( str sp, [sp, #S_SP] )
2492 THUMB( str lr, [sp, #S_LR] )
2493+
2494 mov r1, #\reason
2495 .endm
2496
2497@@ -149,7 +234,11 @@ ENDPROC(__und_invalid)
2498 .macro svc_entry, stack_hole=0
2499 UNWIND(.fnstart )
2500 UNWIND(.save {r0 - pc} )
2501+
2502+ pax_enter_kernel
2503+
2504 sub sp, sp, #(S_FRAME_SIZE + \stack_hole - 4)
2505+
2506 #ifdef CONFIG_THUMB2_KERNEL
2507 SPFIX( str r0, [sp] ) @ temporarily saved
2508 SPFIX( mov r0, sp )
2509@@ -164,7 +253,12 @@ ENDPROC(__und_invalid)
2510 ldmia r0, {r3 - r5}
2511 add r7, sp, #S_SP - 4 @ here for interlock avoidance
2512 mov r6, #-1 @ "" "" "" ""
2513+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2514+ @ offset sp by 8 as done in pax_enter_kernel
2515+ add r2, sp, #(S_FRAME_SIZE + \stack_hole + 4)
2516+#else
2517 add r2, sp, #(S_FRAME_SIZE + \stack_hole - 4)
2518+#endif
2519 SPFIX( addeq r2, r2, #4 )
2520 str r3, [sp, #-4]! @ save the "real" r0 copied
2521 @ from the exception stack
2522@@ -317,6 +411,9 @@ ENDPROC(__pabt_svc)
2523 .macro usr_entry
2524 UNWIND(.fnstart )
2525 UNWIND(.cantunwind ) @ don't unwind the user space
2526+
2527+ pax_enter_kernel_user
2528+
2529 sub sp, sp, #S_FRAME_SIZE
2530 ARM( stmib sp, {r1 - r12} )
2531 THUMB( stmia sp, {r0 - r12} )
2532@@ -416,7 +513,9 @@ __und_usr:
2533 tst r3, #PSR_T_BIT @ Thumb mode?
2534 bne __und_usr_thumb
2535 sub r4, r2, #4 @ ARM instr at LR - 4
2536+ pax_open_userland
2537 1: ldrt r0, [r4]
2538+ pax_close_userland
2539 #ifdef CONFIG_CPU_ENDIAN_BE8
2540 rev r0, r0 @ little endian instruction
2541 #endif
2542@@ -451,10 +550,14 @@ __und_usr_thumb:
2543 */
2544 .arch armv6t2
2545 #endif
2546+ pax_open_userland
2547 2: ldrht r5, [r4]
2548+ pax_close_userland
2549 cmp r5, #0xe800 @ 32bit instruction if xx != 0
2550 blo __und_usr_fault_16 @ 16bit undefined instruction
2551+ pax_open_userland
2552 3: ldrht r0, [r2]
2553+ pax_close_userland
2554 add r2, r2, #2 @ r2 is PC + 2, make it PC + 4
2555 str r2, [sp, #S_PC] @ it's a 2x16bit instr, update
2556 orr r0, r0, r5, lsl #16
2557@@ -483,7 +586,8 @@ ENDPROC(__und_usr)
2558 */
2559 .pushsection .fixup, "ax"
2560 .align 2
2561-4: mov pc, r9
2562+4: pax_close_userland
2563+ mov pc, r9
2564 .popsection
2565 .pushsection __ex_table,"a"
2566 .long 1b, 4b
2567@@ -693,7 +797,7 @@ ENTRY(__switch_to)
2568 THUMB( str lr, [ip], #4 )
2569 ldr r4, [r2, #TI_TP_VALUE]
2570 ldr r5, [r2, #TI_TP_VALUE + 4]
2571-#ifdef CONFIG_CPU_USE_DOMAINS
2572+#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2573 ldr r6, [r2, #TI_CPU_DOMAIN]
2574 #endif
2575 switch_tls r1, r4, r5, r3, r7
2576@@ -702,7 +806,7 @@ ENTRY(__switch_to)
2577 ldr r8, =__stack_chk_guard
2578 ldr r7, [r7, #TSK_STACK_CANARY]
2579 #endif
2580-#ifdef CONFIG_CPU_USE_DOMAINS
2581+#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2582 mcr p15, 0, r6, c3, c0, 0 @ Set domain register
2583 #endif
2584 mov r5, r0
2585diff --git a/arch/arm/kernel/entry-common.S b/arch/arm/kernel/entry-common.S
2586index bc6bd96..bd026cb 100644
2587--- a/arch/arm/kernel/entry-common.S
2588+++ b/arch/arm/kernel/entry-common.S
2589@@ -10,18 +10,46 @@
2590
2591 #include <asm/unistd.h>
2592 #include <asm/ftrace.h>
2593+#include <asm/domain.h>
2594 #include <asm/unwind.h>
2595
2596+#include "entry-header.S"
2597+
2598 #ifdef CONFIG_NEED_RET_TO_USER
2599 #include <mach/entry-macro.S>
2600 #else
2601 .macro arch_ret_to_user, tmp1, tmp2
2602+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2603+ @ save regs
2604+ stmdb sp!, {r1, r2}
2605+ @ read DACR from cpu_domain into r1
2606+ mov r2, sp
2607+ @ assume 8K pages, since we have to split the immediate in two
2608+ bic r2, r2, #(0x1fc0)
2609+ bic r2, r2, #(0x3f)
2610+ ldr r1, [r2, #TI_CPU_DOMAIN]
2611+#ifdef CONFIG_PAX_KERNEXEC
2612+ @ set type of DOMAIN_KERNEL to DOMAIN_KERNELCLIENT
2613+ bic r1, r1, #(domain_val(DOMAIN_KERNEL, 3))
2614+ orr r1, r1, #(domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT))
2615+#endif
2616+#ifdef CONFIG_PAX_MEMORY_UDEREF
2617+ @ set current DOMAIN_USER to DOMAIN_UDEREF
2618+ bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2619+ orr r1, r1, #(domain_val(DOMAIN_USER, DOMAIN_UDEREF))
2620+#endif
2621+ @ write r1 to current_thread_info()->cpu_domain
2622+ str r1, [r2, #TI_CPU_DOMAIN]
2623+ @ write r1 to DACR
2624+ mcr p15, 0, r1, c3, c0, 0
2625+ @ instruction sync
2626+ instr_sync
2627+ @ restore regs
2628+ ldmia sp!, {r1, r2}
2629+#endif
2630 .endm
2631 #endif
2632
2633-#include "entry-header.S"
2634-
2635-
2636 .align 5
2637 /*
2638 * This is the fast syscall return path. We do as little as
2639@@ -413,6 +441,12 @@ ENTRY(vector_swi)
2640 USER( ldr scno, [lr, #-4] ) @ get SWI instruction
2641 #endif
2642
2643+ /*
2644+ * do this here to avoid a performance hit of wrapping the code above
2645+ * that directly dereferences userland to parse the SWI instruction
2646+ */
2647+ pax_enter_kernel_user
2648+
2649 adr tbl, sys_call_table @ load syscall table pointer
2650
2651 #if defined(CONFIG_OABI_COMPAT)
2652diff --git a/arch/arm/kernel/entry-header.S b/arch/arm/kernel/entry-header.S
2653index 39f89fb..d612bd9 100644
2654--- a/arch/arm/kernel/entry-header.S
2655+++ b/arch/arm/kernel/entry-header.S
2656@@ -184,6 +184,60 @@
2657 msr cpsr_c, \rtemp @ switch back to the SVC mode
2658 .endm
2659
2660+ .macro pax_enter_kernel_user
2661+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2662+ @ save regs
2663+ stmdb sp!, {r0, r1}
2664+ @ read DACR from cpu_domain into r1
2665+ mov r0, sp
2666+ @ assume 8K pages, since we have to split the immediate in two
2667+ bic r0, r0, #(0x1fc0)
2668+ bic r0, r0, #(0x3f)
2669+ ldr r1, [r0, #TI_CPU_DOMAIN]
2670+#ifdef CONFIG_PAX_MEMORY_UDEREF
2671+ @ set current DOMAIN_USER to DOMAIN_NOACCESS
2672+ bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2673+#endif
2674+#ifdef CONFIG_PAX_KERNEXEC
2675+ @ set current DOMAIN_KERNEL to DOMAIN_KERNELCLIENT
2676+ bic r1, r1, #(domain_val(DOMAIN_KERNEL, 3))
2677+ orr r1, r1, #(domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT))
2678+#endif
2679+ @ write r1 to current_thread_info()->cpu_domain
2680+ str r1, [r0, #TI_CPU_DOMAIN]
2681+ @ write r1 to DACR
2682+ mcr p15, 0, r1, c3, c0, 0
2683+ @ instruction sync
2684+ instr_sync
2685+ @ restore regs
2686+ ldmia sp!, {r0, r1}
2687+#endif
2688+ .endm
2689+
2690+ .macro pax_exit_kernel
2691+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2692+ @ save regs
2693+ stmdb sp!, {r0, r1}
2694+ @ read old DACR from stack into r1
2695+ ldr r1, [sp, #(8 + S_SP)]
2696+ sub r1, r1, #8
2697+ ldr r1, [r1]
2698+
2699+ @ write r1 to current_thread_info()->cpu_domain
2700+ mov r0, sp
2701+ @ assume 8K pages, since we have to split the immediate in two
2702+ bic r0, r0, #(0x1fc0)
2703+ bic r0, r0, #(0x3f)
2704+ str r1, [r0, #TI_CPU_DOMAIN]
2705+ @ write r1 to DACR
2706+ mcr p15, 0, r1, c3, c0, 0
2707+ @ instruction sync
2708+ instr_sync
2709+ @ restore regs
2710+ ldmia sp!, {r0, r1}
2711+#endif
2712+ .endm
2713+
2714 #ifndef CONFIG_THUMB2_KERNEL
2715 .macro svc_exit, rpsr, irq = 0
2716 .if \irq != 0
2717@@ -203,6 +257,9 @@
2718 blne trace_hardirqs_off
2719 #endif
2720 .endif
2721+
2722+ pax_exit_kernel
2723+
2724 msr spsr_cxsf, \rpsr
2725 #if defined(CONFIG_CPU_V6)
2726 ldr r0, [sp]
2727@@ -266,6 +323,9 @@
2728 blne trace_hardirqs_off
2729 #endif
2730 .endif
2731+
2732+ pax_exit_kernel
2733+
2734 ldr lr, [sp, #S_SP] @ top of the stack
2735 ldrd r0, r1, [sp, #S_LR] @ calling lr and pc
2736 clrex @ clear the exclusive monitor
2737diff --git a/arch/arm/kernel/fiq.c b/arch/arm/kernel/fiq.c
2738index 918875d..cd5fa27 100644
2739--- a/arch/arm/kernel/fiq.c
2740+++ b/arch/arm/kernel/fiq.c
2741@@ -87,7 +87,10 @@ void set_fiq_handler(void *start, unsigned int length)
2742 void *base = vectors_page;
2743 unsigned offset = FIQ_OFFSET;
2744
2745+ pax_open_kernel();
2746 memcpy(base + offset, start, length);
2747+ pax_close_kernel();
2748+
2749 if (!cache_is_vipt_nonaliasing())
2750 flush_icache_range((unsigned long)base + offset, offset +
2751 length);
2752diff --git a/arch/arm/kernel/head.S b/arch/arm/kernel/head.S
2753index 476de57..4857a76 100644
2754--- a/arch/arm/kernel/head.S
2755+++ b/arch/arm/kernel/head.S
2756@@ -52,7 +52,9 @@
2757 .equ swapper_pg_dir, KERNEL_RAM_VADDR - PG_DIR_SIZE
2758
2759 .macro pgtbl, rd, phys
2760- add \rd, \phys, #TEXT_OFFSET - PG_DIR_SIZE
2761+ mov \rd, #TEXT_OFFSET
2762+ sub \rd, #PG_DIR_SIZE
2763+ add \rd, \rd, \phys
2764 .endm
2765
2766 /*
2767@@ -432,7 +434,7 @@ __enable_mmu:
2768 mov r5, #(domain_val(DOMAIN_USER, DOMAIN_MANAGER) | \
2769 domain_val(DOMAIN_KERNEL, DOMAIN_MANAGER) | \
2770 domain_val(DOMAIN_TABLE, DOMAIN_MANAGER) | \
2771- domain_val(DOMAIN_IO, DOMAIN_CLIENT))
2772+ domain_val(DOMAIN_IO, DOMAIN_KERNELCLIENT))
2773 mcr p15, 0, r5, c3, c0, 0 @ load domain access register
2774 mcr p15, 0, r4, c2, c0, 0 @ load page table pointer
2775 #endif
2776diff --git a/arch/arm/kernel/module.c b/arch/arm/kernel/module.c
2777index 084dc88..fce4e68 100644
2778--- a/arch/arm/kernel/module.c
2779+++ b/arch/arm/kernel/module.c
2780@@ -37,12 +37,39 @@
2781 #endif
2782
2783 #ifdef CONFIG_MMU
2784-void *module_alloc(unsigned long size)
2785+static inline void *__module_alloc(unsigned long size, pgprot_t prot)
2786 {
2787+ if (!size || PAGE_ALIGN(size) > MODULES_END - MODULES_VADDR)
2788+ return NULL;
2789 return __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END,
2790- GFP_KERNEL, PAGE_KERNEL_EXEC, -1,
2791+ GFP_KERNEL, prot, -1,
2792 __builtin_return_address(0));
2793 }
2794+
2795+void *module_alloc(unsigned long size)
2796+{
2797+
2798+#ifdef CONFIG_PAX_KERNEXEC
2799+ return __module_alloc(size, PAGE_KERNEL);
2800+#else
2801+ return __module_alloc(size, PAGE_KERNEL_EXEC);
2802+#endif
2803+
2804+}
2805+
2806+#ifdef CONFIG_PAX_KERNEXEC
2807+void module_free_exec(struct module *mod, void *module_region)
2808+{
2809+ module_free(mod, module_region);
2810+}
2811+EXPORT_SYMBOL(module_free_exec);
2812+
2813+void *module_alloc_exec(unsigned long size)
2814+{
2815+ return __module_alloc(size, PAGE_KERNEL_EXEC);
2816+}
2817+EXPORT_SYMBOL(module_alloc_exec);
2818+#endif
2819 #endif
2820
2821 int
2822diff --git a/arch/arm/kernel/patch.c b/arch/arm/kernel/patch.c
2823index 07314af..c46655c 100644
2824--- a/arch/arm/kernel/patch.c
2825+++ b/arch/arm/kernel/patch.c
2826@@ -18,6 +18,7 @@ void __kprobes __patch_text(void *addr, unsigned int insn)
2827 bool thumb2 = IS_ENABLED(CONFIG_THUMB2_KERNEL);
2828 int size;
2829
2830+ pax_open_kernel();
2831 if (thumb2 && __opcode_is_thumb16(insn)) {
2832 *(u16 *)addr = __opcode_to_mem_thumb16(insn);
2833 size = sizeof(u16);
2834@@ -39,6 +40,7 @@ void __kprobes __patch_text(void *addr, unsigned int insn)
2835 *(u32 *)addr = insn;
2836 size = sizeof(u32);
2837 }
2838+ pax_close_kernel();
2839
2840 flush_icache_range((uintptr_t)(addr),
2841 (uintptr_t)(addr) + size);
2842diff --git a/arch/arm/kernel/process.c b/arch/arm/kernel/process.c
2843index 92f7b15..7048500 100644
2844--- a/arch/arm/kernel/process.c
2845+++ b/arch/arm/kernel/process.c
2846@@ -217,6 +217,7 @@ void machine_power_off(void)
2847
2848 if (pm_power_off)
2849 pm_power_off();
2850+ BUG();
2851 }
2852
2853 /*
2854@@ -230,7 +231,7 @@ void machine_power_off(void)
2855 * executing pre-reset code, and using RAM that the primary CPU's code wishes
2856 * to use. Implementing such co-ordination would be essentially impossible.
2857 */
2858-void machine_restart(char *cmd)
2859+__noreturn void machine_restart(char *cmd)
2860 {
2861 local_irq_disable();
2862 smp_send_stop();
2863@@ -253,8 +254,8 @@ void __show_regs(struct pt_regs *regs)
2864
2865 show_regs_print_info(KERN_DEFAULT);
2866
2867- print_symbol("PC is at %s\n", instruction_pointer(regs));
2868- print_symbol("LR is at %s\n", regs->ARM_lr);
2869+ printk("PC is at %pA\n", (void *)instruction_pointer(regs));
2870+ printk("LR is at %pA\n", (void *)regs->ARM_lr);
2871 printk("pc : [<%08lx>] lr : [<%08lx>] psr: %08lx\n"
2872 "sp : %08lx ip : %08lx fp : %08lx\n",
2873 regs->ARM_pc, regs->ARM_lr, regs->ARM_cpsr,
2874@@ -425,12 +426,6 @@ unsigned long get_wchan(struct task_struct *p)
2875 return 0;
2876 }
2877
2878-unsigned long arch_randomize_brk(struct mm_struct *mm)
2879-{
2880- unsigned long range_end = mm->brk + 0x02000000;
2881- return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
2882-}
2883-
2884 #ifdef CONFIG_MMU
2885 #ifdef CONFIG_KUSER_HELPERS
2886 /*
2887@@ -446,7 +441,7 @@ static struct vm_area_struct gate_vma = {
2888
2889 static int __init gate_vma_init(void)
2890 {
2891- gate_vma.vm_page_prot = PAGE_READONLY_EXEC;
2892+ gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
2893 return 0;
2894 }
2895 arch_initcall(gate_vma_init);
2896@@ -472,41 +467,16 @@ int in_gate_area_no_mm(unsigned long addr)
2897
2898 const char *arch_vma_name(struct vm_area_struct *vma)
2899 {
2900- return is_gate_vma(vma) ? "[vectors]" :
2901- (vma->vm_mm && vma->vm_start == vma->vm_mm->context.sigpage) ?
2902- "[sigpage]" : NULL;
2903+ return is_gate_vma(vma) ? "[vectors]" : NULL;
2904 }
2905
2906-static struct page *signal_page;
2907-extern struct page *get_signal_page(void);
2908-
2909 int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
2910 {
2911 struct mm_struct *mm = current->mm;
2912- unsigned long addr;
2913- int ret;
2914-
2915- if (!signal_page)
2916- signal_page = get_signal_page();
2917- if (!signal_page)
2918- return -ENOMEM;
2919
2920 down_write(&mm->mmap_sem);
2921- addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, 0);
2922- if (IS_ERR_VALUE(addr)) {
2923- ret = addr;
2924- goto up_fail;
2925- }
2926-
2927- ret = install_special_mapping(mm, addr, PAGE_SIZE,
2928- VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC,
2929- &signal_page);
2930-
2931- if (ret == 0)
2932- mm->context.sigpage = addr;
2933-
2934- up_fail:
2935+ mm->context.sigpage = (PAGE_OFFSET + (get_random_int() % 0x3FFEFFE0)) & 0xFFFFFFFC;
2936 up_write(&mm->mmap_sem);
2937- return ret;
2938+ return 0;
2939 }
2940 #endif
2941diff --git a/arch/arm/kernel/psci.c b/arch/arm/kernel/psci.c
2942index 4693188..4596c5e 100644
2943--- a/arch/arm/kernel/psci.c
2944+++ b/arch/arm/kernel/psci.c
2945@@ -24,7 +24,7 @@
2946 #include <asm/opcodes-virt.h>
2947 #include <asm/psci.h>
2948
2949-struct psci_operations psci_ops;
2950+struct psci_operations psci_ops __read_only;
2951
2952 static int (*invoke_psci_fn)(u32, u32, u32, u32);
2953
2954diff --git a/arch/arm/kernel/ptrace.c b/arch/arm/kernel/ptrace.c
2955index 0dd3b79..e018f64 100644
2956--- a/arch/arm/kernel/ptrace.c
2957+++ b/arch/arm/kernel/ptrace.c
2958@@ -929,10 +929,19 @@ static int tracehook_report_syscall(struct pt_regs *regs,
2959 return current_thread_info()->syscall;
2960 }
2961
2962+#ifdef CONFIG_GRKERNSEC_SETXID
2963+extern void gr_delayed_cred_worker(void);
2964+#endif
2965+
2966 asmlinkage int syscall_trace_enter(struct pt_regs *regs, int scno)
2967 {
2968 current_thread_info()->syscall = scno;
2969
2970+#ifdef CONFIG_GRKERNSEC_SETXID
2971+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
2972+ gr_delayed_cred_worker();
2973+#endif
2974+
2975 /* Do the secure computing check first; failures should be fast. */
2976 if (secure_computing(scno) == -1)
2977 return -1;
2978diff --git a/arch/arm/kernel/setup.c b/arch/arm/kernel/setup.c
2979index 0e1e2b3..c0e821d 100644
2980--- a/arch/arm/kernel/setup.c
2981+++ b/arch/arm/kernel/setup.c
2982@@ -98,21 +98,23 @@ EXPORT_SYMBOL(system_serial_high);
2983 unsigned int elf_hwcap __read_mostly;
2984 EXPORT_SYMBOL(elf_hwcap);
2985
2986+pteval_t __supported_pte_mask __read_only;
2987+pmdval_t __supported_pmd_mask __read_only;
2988
2989 #ifdef MULTI_CPU
2990-struct processor processor __read_mostly;
2991+struct processor processor;
2992 #endif
2993 #ifdef MULTI_TLB
2994-struct cpu_tlb_fns cpu_tlb __read_mostly;
2995+struct cpu_tlb_fns cpu_tlb __read_only;
2996 #endif
2997 #ifdef MULTI_USER
2998-struct cpu_user_fns cpu_user __read_mostly;
2999+struct cpu_user_fns cpu_user __read_only;
3000 #endif
3001 #ifdef MULTI_CACHE
3002-struct cpu_cache_fns cpu_cache __read_mostly;
3003+struct cpu_cache_fns cpu_cache __read_only;
3004 #endif
3005 #ifdef CONFIG_OUTER_CACHE
3006-struct outer_cache_fns outer_cache __read_mostly;
3007+struct outer_cache_fns outer_cache __read_only;
3008 EXPORT_SYMBOL(outer_cache);
3009 #endif
3010
3011@@ -245,9 +247,13 @@ static int __get_cpu_architecture(void)
3012 asm("mrc p15, 0, %0, c0, c1, 4"
3013 : "=r" (mmfr0));
3014 if ((mmfr0 & 0x0000000f) >= 0x00000003 ||
3015- (mmfr0 & 0x000000f0) >= 0x00000030)
3016+ (mmfr0 & 0x000000f0) >= 0x00000030) {
3017 cpu_arch = CPU_ARCH_ARMv7;
3018- else if ((mmfr0 & 0x0000000f) == 0x00000002 ||
3019+ if ((mmfr0 & 0x0000000f) == 0x00000005 || (mmfr0 & 0x0000000f) == 0x00000004) {
3020+ __supported_pte_mask |= L_PTE_PXN;
3021+ __supported_pmd_mask |= PMD_PXNTABLE;
3022+ }
3023+ } else if ((mmfr0 & 0x0000000f) == 0x00000002 ||
3024 (mmfr0 & 0x000000f0) == 0x00000020)
3025 cpu_arch = CPU_ARCH_ARMv6;
3026 else
3027@@ -571,7 +577,7 @@ static void __init setup_processor(void)
3028 __cpu_architecture = __get_cpu_architecture();
3029
3030 #ifdef MULTI_CPU
3031- processor = *list->proc;
3032+ memcpy((void *)&processor, list->proc, sizeof processor);
3033 #endif
3034 #ifdef MULTI_TLB
3035 cpu_tlb = *list->tlb;
3036diff --git a/arch/arm/kernel/signal.c b/arch/arm/kernel/signal.c
3037index ab33042..11248a8 100644
3038--- a/arch/arm/kernel/signal.c
3039+++ b/arch/arm/kernel/signal.c
3040@@ -45,8 +45,6 @@ static const unsigned long sigreturn_codes[7] = {
3041 MOV_R7_NR_RT_SIGRETURN, SWI_SYS_RT_SIGRETURN, SWI_THUMB_RT_SIGRETURN,
3042 };
3043
3044-static unsigned long signal_return_offset;
3045-
3046 #ifdef CONFIG_CRUNCH
3047 static int preserve_crunch_context(struct crunch_sigframe __user *frame)
3048 {
3049@@ -411,8 +409,7 @@ setup_return(struct pt_regs *regs, struct ksignal *ksig,
3050 * except when the MPU has protected the vectors
3051 * page from PL0
3052 */
3053- retcode = mm->context.sigpage + signal_return_offset +
3054- (idx << 2) + thumb;
3055+ retcode = mm->context.sigpage + (idx << 2) + thumb;
3056 } else
3057 #endif
3058 {
3059@@ -616,33 +613,3 @@ do_work_pending(struct pt_regs *regs, unsigned int thread_flags, int syscall)
3060 } while (thread_flags & _TIF_WORK_MASK);
3061 return 0;
3062 }
3063-
3064-struct page *get_signal_page(void)
3065-{
3066- unsigned long ptr;
3067- unsigned offset;
3068- struct page *page;
3069- void *addr;
3070-
3071- page = alloc_pages(GFP_KERNEL, 0);
3072-
3073- if (!page)
3074- return NULL;
3075-
3076- addr = page_address(page);
3077-
3078- /* Give the signal return code some randomness */
3079- offset = 0x200 + (get_random_int() & 0x7fc);
3080- signal_return_offset = offset;
3081-
3082- /*
3083- * Copy signal return handlers into the vector page, and
3084- * set sigreturn to be a pointer to these.
3085- */
3086- memcpy(addr + offset, sigreturn_codes, sizeof(sigreturn_codes));
3087-
3088- ptr = (unsigned long)addr + offset;
3089- flush_icache_range(ptr, ptr + sizeof(sigreturn_codes));
3090-
3091- return page;
3092-}
3093diff --git a/arch/arm/kernel/smp.c b/arch/arm/kernel/smp.c
3094index 72024ea..ae302dd 100644
3095--- a/arch/arm/kernel/smp.c
3096+++ b/arch/arm/kernel/smp.c
3097@@ -70,7 +70,7 @@ enum ipi_msg_type {
3098
3099 static DECLARE_COMPLETION(cpu_running);
3100
3101-static struct smp_operations smp_ops;
3102+static struct smp_operations smp_ops __read_only;
3103
3104 void __init smp_set_ops(struct smp_operations *ops)
3105 {
3106diff --git a/arch/arm/kernel/traps.c b/arch/arm/kernel/traps.c
3107index 1f735aa..08af6f7 100644
3108--- a/arch/arm/kernel/traps.c
3109+++ b/arch/arm/kernel/traps.c
3110@@ -61,7 +61,7 @@ static void dump_mem(const char *, const char *, unsigned long, unsigned long);
3111 void dump_backtrace_entry(unsigned long where, unsigned long from, unsigned long frame)
3112 {
3113 #ifdef CONFIG_KALLSYMS
3114- printk("[<%08lx>] (%pS) from [<%08lx>] (%pS)\n", where, (void *)where, from, (void *)from);
3115+ printk("[<%08lx>] (%pA) from [<%08lx>] (%pA)\n", where, (void *)where, from, (void *)from);
3116 #else
3117 printk("Function entered at [<%08lx>] from [<%08lx>]\n", where, from);
3118 #endif
3119@@ -263,6 +263,8 @@ static arch_spinlock_t die_lock = __ARCH_SPIN_LOCK_UNLOCKED;
3120 static int die_owner = -1;
3121 static unsigned int die_nest_count;
3122
3123+extern void gr_handle_kernel_exploit(void);
3124+
3125 static unsigned long oops_begin(void)
3126 {
3127 int cpu;
3128@@ -305,6 +307,9 @@ static void oops_end(unsigned long flags, struct pt_regs *regs, int signr)
3129 panic("Fatal exception in interrupt");
3130 if (panic_on_oops)
3131 panic("Fatal exception");
3132+
3133+ gr_handle_kernel_exploit();
3134+
3135 if (signr)
3136 do_exit(signr);
3137 }
3138@@ -635,7 +640,9 @@ asmlinkage int arm_syscall(int no, struct pt_regs *regs)
3139 * The user helper at 0xffff0fe0 must be used instead.
3140 * (see entry-armv.S for details)
3141 */
3142+ pax_open_kernel();
3143 *((unsigned int *)0xffff0ff0) = regs->ARM_r0;
3144+ pax_close_kernel();
3145 }
3146 return 0;
3147
3148@@ -892,7 +899,11 @@ void __init early_trap_init(void *vectors_base)
3149 kuser_init(vectors_base);
3150
3151 flush_icache_range(vectors, vectors + PAGE_SIZE * 2);
3152- modify_domain(DOMAIN_USER, DOMAIN_CLIENT);
3153+
3154+#ifndef CONFIG_PAX_MEMORY_UDEREF
3155+ modify_domain(DOMAIN_USER, DOMAIN_USERCLIENT);
3156+#endif
3157+
3158 #else /* ifndef CONFIG_CPU_V7M */
3159 /*
3160 * on V7-M there is no need to copy the vector table to a dedicated
3161diff --git a/arch/arm/kernel/vmlinux.lds.S b/arch/arm/kernel/vmlinux.lds.S
3162index 7bcee5c..e2f3249 100644
3163--- a/arch/arm/kernel/vmlinux.lds.S
3164+++ b/arch/arm/kernel/vmlinux.lds.S
3165@@ -8,7 +8,11 @@
3166 #include <asm/thread_info.h>
3167 #include <asm/memory.h>
3168 #include <asm/page.h>
3169-
3170+
3171+#ifdef CONFIG_PAX_KERNEXEC
3172+#include <asm/pgtable.h>
3173+#endif
3174+
3175 #define PROC_INFO \
3176 . = ALIGN(4); \
3177 VMLINUX_SYMBOL(__proc_info_begin) = .; \
3178@@ -34,7 +38,7 @@
3179 #endif
3180
3181 #if (defined(CONFIG_SMP_ON_UP) && !defined(CONFIG_DEBUG_SPINLOCK)) || \
3182- defined(CONFIG_GENERIC_BUG)
3183+ defined(CONFIG_GENERIC_BUG) || defined(CONFIG_PAX_REFCOUNT)
3184 #define ARM_EXIT_KEEP(x) x
3185 #define ARM_EXIT_DISCARD(x)
3186 #else
3187@@ -90,6 +94,11 @@ SECTIONS
3188 _text = .;
3189 HEAD_TEXT
3190 }
3191+
3192+#ifdef CONFIG_PAX_KERNEXEC
3193+ . = ALIGN(1<<SECTION_SHIFT);
3194+#endif
3195+
3196 .text : { /* Real text segment */
3197 _stext = .; /* Text and read-only data */
3198 __exception_text_start = .;
3199@@ -112,6 +121,8 @@ SECTIONS
3200 ARM_CPU_KEEP(PROC_INFO)
3201 }
3202
3203+ _etext = .; /* End of text section */
3204+
3205 RO_DATA(PAGE_SIZE)
3206
3207 . = ALIGN(4);
3208@@ -142,7 +153,9 @@ SECTIONS
3209
3210 NOTES
3211
3212- _etext = .; /* End of text and rodata section */
3213+#ifdef CONFIG_PAX_KERNEXEC
3214+ . = ALIGN(1<<SECTION_SHIFT);
3215+#endif
3216
3217 #ifndef CONFIG_XIP_KERNEL
3218 . = ALIGN(PAGE_SIZE);
3219@@ -220,6 +233,11 @@ SECTIONS
3220 . = PAGE_OFFSET + TEXT_OFFSET;
3221 #else
3222 __init_end = .;
3223+
3224+#ifdef CONFIG_PAX_KERNEXEC
3225+ . = ALIGN(1<<SECTION_SHIFT);
3226+#endif
3227+
3228 . = ALIGN(THREAD_SIZE);
3229 __data_loc = .;
3230 #endif
3231diff --git a/arch/arm/kvm/arm.c b/arch/arm/kvm/arm.c
3232index 9c697db..115237f 100644
3233--- a/arch/arm/kvm/arm.c
3234+++ b/arch/arm/kvm/arm.c
3235@@ -56,7 +56,7 @@ static unsigned long hyp_default_vectors;
3236 static DEFINE_PER_CPU(struct kvm_vcpu *, kvm_arm_running_vcpu);
3237
3238 /* The VMID used in the VTTBR */
3239-static atomic64_t kvm_vmid_gen = ATOMIC64_INIT(1);
3240+static atomic64_unchecked_t kvm_vmid_gen = ATOMIC64_INIT(1);
3241 static u8 kvm_next_vmid;
3242 static DEFINE_SPINLOCK(kvm_vmid_lock);
3243
3244@@ -396,7 +396,7 @@ void force_vm_exit(const cpumask_t *mask)
3245 */
3246 static bool need_new_vmid_gen(struct kvm *kvm)
3247 {
3248- return unlikely(kvm->arch.vmid_gen != atomic64_read(&kvm_vmid_gen));
3249+ return unlikely(kvm->arch.vmid_gen != atomic64_read_unchecked(&kvm_vmid_gen));
3250 }
3251
3252 /**
3253@@ -429,7 +429,7 @@ static void update_vttbr(struct kvm *kvm)
3254
3255 /* First user of a new VMID generation? */
3256 if (unlikely(kvm_next_vmid == 0)) {
3257- atomic64_inc(&kvm_vmid_gen);
3258+ atomic64_inc_unchecked(&kvm_vmid_gen);
3259 kvm_next_vmid = 1;
3260
3261 /*
3262@@ -446,7 +446,7 @@ static void update_vttbr(struct kvm *kvm)
3263 kvm_call_hyp(__kvm_flush_vm_context);
3264 }
3265
3266- kvm->arch.vmid_gen = atomic64_read(&kvm_vmid_gen);
3267+ kvm->arch.vmid_gen = atomic64_read_unchecked(&kvm_vmid_gen);
3268 kvm->arch.vmid = kvm_next_vmid;
3269 kvm_next_vmid++;
3270
3271diff --git a/arch/arm/lib/clear_user.S b/arch/arm/lib/clear_user.S
3272index 14a0d98..7771a7d 100644
3273--- a/arch/arm/lib/clear_user.S
3274+++ b/arch/arm/lib/clear_user.S
3275@@ -12,14 +12,14 @@
3276
3277 .text
3278
3279-/* Prototype: int __clear_user(void *addr, size_t sz)
3280+/* Prototype: int ___clear_user(void *addr, size_t sz)
3281 * Purpose : clear some user memory
3282 * Params : addr - user memory address to clear
3283 * : sz - number of bytes to clear
3284 * Returns : number of bytes NOT cleared
3285 */
3286 ENTRY(__clear_user_std)
3287-WEAK(__clear_user)
3288+WEAK(___clear_user)
3289 stmfd sp!, {r1, lr}
3290 mov r2, #0
3291 cmp r1, #4
3292@@ -44,7 +44,7 @@ WEAK(__clear_user)
3293 USER( strnebt r2, [r0])
3294 mov r0, #0
3295 ldmfd sp!, {r1, pc}
3296-ENDPROC(__clear_user)
3297+ENDPROC(___clear_user)
3298 ENDPROC(__clear_user_std)
3299
3300 .pushsection .fixup,"ax"
3301diff --git a/arch/arm/lib/copy_from_user.S b/arch/arm/lib/copy_from_user.S
3302index 66a477a..bee61d3 100644
3303--- a/arch/arm/lib/copy_from_user.S
3304+++ b/arch/arm/lib/copy_from_user.S
3305@@ -16,7 +16,7 @@
3306 /*
3307 * Prototype:
3308 *
3309- * size_t __copy_from_user(void *to, const void *from, size_t n)
3310+ * size_t ___copy_from_user(void *to, const void *from, size_t n)
3311 *
3312 * Purpose:
3313 *
3314@@ -84,11 +84,11 @@
3315
3316 .text
3317
3318-ENTRY(__copy_from_user)
3319+ENTRY(___copy_from_user)
3320
3321 #include "copy_template.S"
3322
3323-ENDPROC(__copy_from_user)
3324+ENDPROC(___copy_from_user)
3325
3326 .pushsection .fixup,"ax"
3327 .align 0
3328diff --git a/arch/arm/lib/copy_page.S b/arch/arm/lib/copy_page.S
3329index 6ee2f67..d1cce76 100644
3330--- a/arch/arm/lib/copy_page.S
3331+++ b/arch/arm/lib/copy_page.S
3332@@ -10,6 +10,7 @@
3333 * ASM optimised string functions
3334 */
3335 #include <linux/linkage.h>
3336+#include <linux/const.h>
3337 #include <asm/assembler.h>
3338 #include <asm/asm-offsets.h>
3339 #include <asm/cache.h>
3340diff --git a/arch/arm/lib/copy_to_user.S b/arch/arm/lib/copy_to_user.S
3341index d066df6..df28194 100644
3342--- a/arch/arm/lib/copy_to_user.S
3343+++ b/arch/arm/lib/copy_to_user.S
3344@@ -16,7 +16,7 @@
3345 /*
3346 * Prototype:
3347 *
3348- * size_t __copy_to_user(void *to, const void *from, size_t n)
3349+ * size_t ___copy_to_user(void *to, const void *from, size_t n)
3350 *
3351 * Purpose:
3352 *
3353@@ -88,11 +88,11 @@
3354 .text
3355
3356 ENTRY(__copy_to_user_std)
3357-WEAK(__copy_to_user)
3358+WEAK(___copy_to_user)
3359
3360 #include "copy_template.S"
3361
3362-ENDPROC(__copy_to_user)
3363+ENDPROC(___copy_to_user)
3364 ENDPROC(__copy_to_user_std)
3365
3366 .pushsection .fixup,"ax"
3367diff --git a/arch/arm/lib/csumpartialcopyuser.S b/arch/arm/lib/csumpartialcopyuser.S
3368index 7d08b43..f7ca7ea 100644
3369--- a/arch/arm/lib/csumpartialcopyuser.S
3370+++ b/arch/arm/lib/csumpartialcopyuser.S
3371@@ -57,8 +57,8 @@
3372 * Returns : r0 = checksum, [[sp, #0], #0] = 0 or -EFAULT
3373 */
3374
3375-#define FN_ENTRY ENTRY(csum_partial_copy_from_user)
3376-#define FN_EXIT ENDPROC(csum_partial_copy_from_user)
3377+#define FN_ENTRY ENTRY(__csum_partial_copy_from_user)
3378+#define FN_EXIT ENDPROC(__csum_partial_copy_from_user)
3379
3380 #include "csumpartialcopygeneric.S"
3381
3382diff --git a/arch/arm/lib/delay.c b/arch/arm/lib/delay.c
3383index 5306de3..aed6d03 100644
3384--- a/arch/arm/lib/delay.c
3385+++ b/arch/arm/lib/delay.c
3386@@ -28,7 +28,7 @@
3387 /*
3388 * Default to the loop-based delay implementation.
3389 */
3390-struct arm_delay_ops arm_delay_ops = {
3391+struct arm_delay_ops arm_delay_ops __read_only = {
3392 .delay = __loop_delay,
3393 .const_udelay = __loop_const_udelay,
3394 .udelay = __loop_udelay,
3395diff --git a/arch/arm/lib/uaccess_with_memcpy.c b/arch/arm/lib/uaccess_with_memcpy.c
3396index 025f742..a9e5b3b 100644
3397--- a/arch/arm/lib/uaccess_with_memcpy.c
3398+++ b/arch/arm/lib/uaccess_with_memcpy.c
3399@@ -104,7 +104,7 @@ out:
3400 }
3401
3402 unsigned long
3403-__copy_to_user(void __user *to, const void *from, unsigned long n)
3404+___copy_to_user(void __user *to, const void *from, unsigned long n)
3405 {
3406 /*
3407 * This test is stubbed out of the main function above to keep
3408@@ -155,7 +155,7 @@ out:
3409 return n;
3410 }
3411
3412-unsigned long __clear_user(void __user *addr, unsigned long n)
3413+unsigned long ___clear_user(void __user *addr, unsigned long n)
3414 {
3415 /* See rational for this in __copy_to_user() above. */
3416 if (n < 64)
3417diff --git a/arch/arm/mach-kirkwood/common.c b/arch/arm/mach-kirkwood/common.c
3418index 1767611..d2e7e24 100644
3419--- a/arch/arm/mach-kirkwood/common.c
3420+++ b/arch/arm/mach-kirkwood/common.c
3421@@ -156,7 +156,16 @@ static void clk_gate_fn_disable(struct clk_hw *hw)
3422 clk_gate_ops.disable(hw);
3423 }
3424
3425-static struct clk_ops clk_gate_fn_ops;
3426+static int clk_gate_fn_is_enabled(struct clk_hw *hw)
3427+{
3428+ return clk_gate_ops.is_enabled(hw);
3429+}
3430+
3431+static struct clk_ops clk_gate_fn_ops = {
3432+ .enable = clk_gate_fn_enable,
3433+ .disable = clk_gate_fn_disable,
3434+ .is_enabled = clk_gate_fn_is_enabled,
3435+};
3436
3437 static struct clk __init *clk_register_gate_fn(struct device *dev,
3438 const char *name,
3439@@ -190,14 +199,6 @@ static struct clk __init *clk_register_gate_fn(struct device *dev,
3440 gate_fn->fn_en = fn_en;
3441 gate_fn->fn_dis = fn_dis;
3442
3443- /* ops is the gate ops, but with our enable/disable functions */
3444- if (clk_gate_fn_ops.enable != clk_gate_fn_enable ||
3445- clk_gate_fn_ops.disable != clk_gate_fn_disable) {
3446- clk_gate_fn_ops = clk_gate_ops;
3447- clk_gate_fn_ops.enable = clk_gate_fn_enable;
3448- clk_gate_fn_ops.disable = clk_gate_fn_disable;
3449- }
3450-
3451 clk = clk_register(dev, &gate_fn->gate.hw);
3452
3453 if (IS_ERR(clk))
3454diff --git a/arch/arm/mach-omap2/board-n8x0.c b/arch/arm/mach-omap2/board-n8x0.c
3455index 827d1500..2885dc6 100644
3456--- a/arch/arm/mach-omap2/board-n8x0.c
3457+++ b/arch/arm/mach-omap2/board-n8x0.c
3458@@ -627,7 +627,7 @@ static int n8x0_menelaus_late_init(struct device *dev)
3459 }
3460 #endif
3461
3462-static struct menelaus_platform_data n8x0_menelaus_platform_data __initdata = {
3463+static struct menelaus_platform_data n8x0_menelaus_platform_data __initconst = {
3464 .late_init = n8x0_menelaus_late_init,
3465 };
3466
3467diff --git a/arch/arm/mach-omap2/gpmc.c b/arch/arm/mach-omap2/gpmc.c
3468index 579697a..1d5a3b2 100644
3469--- a/arch/arm/mach-omap2/gpmc.c
3470+++ b/arch/arm/mach-omap2/gpmc.c
3471@@ -148,7 +148,6 @@ struct omap3_gpmc_regs {
3472 };
3473
3474 static struct gpmc_client_irq gpmc_client_irq[GPMC_NR_IRQ];
3475-static struct irq_chip gpmc_irq_chip;
3476 static int gpmc_irq_start;
3477
3478 static struct resource gpmc_mem_root;
3479@@ -716,6 +715,18 @@ static void gpmc_irq_noop(struct irq_data *data) { }
3480
3481 static unsigned int gpmc_irq_noop_ret(struct irq_data *data) { return 0; }
3482
3483+static struct irq_chip gpmc_irq_chip = {
3484+ .name = "gpmc",
3485+ .irq_startup = gpmc_irq_noop_ret,
3486+ .irq_enable = gpmc_irq_enable,
3487+ .irq_disable = gpmc_irq_disable,
3488+ .irq_shutdown = gpmc_irq_noop,
3489+ .irq_ack = gpmc_irq_noop,
3490+ .irq_mask = gpmc_irq_noop,
3491+ .irq_unmask = gpmc_irq_noop,
3492+
3493+};
3494+
3495 static int gpmc_setup_irq(void)
3496 {
3497 int i;
3498@@ -730,15 +741,6 @@ static int gpmc_setup_irq(void)
3499 return gpmc_irq_start;
3500 }
3501
3502- gpmc_irq_chip.name = "gpmc";
3503- gpmc_irq_chip.irq_startup = gpmc_irq_noop_ret;
3504- gpmc_irq_chip.irq_enable = gpmc_irq_enable;
3505- gpmc_irq_chip.irq_disable = gpmc_irq_disable;
3506- gpmc_irq_chip.irq_shutdown = gpmc_irq_noop;
3507- gpmc_irq_chip.irq_ack = gpmc_irq_noop;
3508- gpmc_irq_chip.irq_mask = gpmc_irq_noop;
3509- gpmc_irq_chip.irq_unmask = gpmc_irq_noop;
3510-
3511 gpmc_client_irq[0].bitmask = GPMC_IRQ_FIFOEVENTENABLE;
3512 gpmc_client_irq[1].bitmask = GPMC_IRQ_COUNT_EVENT;
3513
3514diff --git a/arch/arm/mach-omap2/omap-mpuss-lowpower.c b/arch/arm/mach-omap2/omap-mpuss-lowpower.c
3515index f991016..145ebeb 100644
3516--- a/arch/arm/mach-omap2/omap-mpuss-lowpower.c
3517+++ b/arch/arm/mach-omap2/omap-mpuss-lowpower.c
3518@@ -84,7 +84,7 @@ struct cpu_pm_ops {
3519 int (*finish_suspend)(unsigned long cpu_state);
3520 void (*resume)(void);
3521 void (*scu_prepare)(unsigned int cpu_id, unsigned int cpu_state);
3522-};
3523+} __no_const;
3524
3525 static DEFINE_PER_CPU(struct omap4_cpu_pm_info, omap4_pm_info);
3526 static struct powerdomain *mpuss_pd;
3527@@ -102,7 +102,7 @@ static void dummy_cpu_resume(void)
3528 static void dummy_scu_prepare(unsigned int cpu_id, unsigned int cpu_state)
3529 {}
3530
3531-struct cpu_pm_ops omap_pm_ops = {
3532+static struct cpu_pm_ops omap_pm_ops __read_only = {
3533 .finish_suspend = default_finish_suspend,
3534 .resume = dummy_cpu_resume,
3535 .scu_prepare = dummy_scu_prepare,
3536diff --git a/arch/arm/mach-omap2/omap-wakeupgen.c b/arch/arm/mach-omap2/omap-wakeupgen.c
3537index 813c615..ce467c6 100644
3538--- a/arch/arm/mach-omap2/omap-wakeupgen.c
3539+++ b/arch/arm/mach-omap2/omap-wakeupgen.c
3540@@ -339,7 +339,7 @@ static int irq_cpu_hotplug_notify(struct notifier_block *self,
3541 return NOTIFY_OK;
3542 }
3543
3544-static struct notifier_block __refdata irq_hotplug_notifier = {
3545+static struct notifier_block irq_hotplug_notifier = {
3546 .notifier_call = irq_cpu_hotplug_notify,
3547 };
3548
3549diff --git a/arch/arm/mach-omap2/omap_device.c b/arch/arm/mach-omap2/omap_device.c
3550index 53f0735..5b54eb6 100644
3551--- a/arch/arm/mach-omap2/omap_device.c
3552+++ b/arch/arm/mach-omap2/omap_device.c
3553@@ -504,7 +504,7 @@ void omap_device_delete(struct omap_device *od)
3554 struct platform_device __init *omap_device_build(const char *pdev_name,
3555 int pdev_id,
3556 struct omap_hwmod *oh,
3557- void *pdata, int pdata_len)
3558+ const void *pdata, int pdata_len)
3559 {
3560 struct omap_hwmod *ohs[] = { oh };
3561
3562@@ -532,7 +532,7 @@ struct platform_device __init *omap_device_build(const char *pdev_name,
3563 struct platform_device __init *omap_device_build_ss(const char *pdev_name,
3564 int pdev_id,
3565 struct omap_hwmod **ohs,
3566- int oh_cnt, void *pdata,
3567+ int oh_cnt, const void *pdata,
3568 int pdata_len)
3569 {
3570 int ret = -ENOMEM;
3571diff --git a/arch/arm/mach-omap2/omap_device.h b/arch/arm/mach-omap2/omap_device.h
3572index 17ca1ae..beba869 100644
3573--- a/arch/arm/mach-omap2/omap_device.h
3574+++ b/arch/arm/mach-omap2/omap_device.h
3575@@ -71,12 +71,12 @@ int omap_device_idle(struct platform_device *pdev);
3576 /* Core code interface */
3577
3578 struct platform_device *omap_device_build(const char *pdev_name, int pdev_id,
3579- struct omap_hwmod *oh, void *pdata,
3580+ struct omap_hwmod *oh, const void *pdata,
3581 int pdata_len);
3582
3583 struct platform_device *omap_device_build_ss(const char *pdev_name, int pdev_id,
3584 struct omap_hwmod **oh, int oh_cnt,
3585- void *pdata, int pdata_len);
3586+ const void *pdata, int pdata_len);
3587
3588 struct omap_device *omap_device_alloc(struct platform_device *pdev,
3589 struct omap_hwmod **ohs, int oh_cnt);
3590diff --git a/arch/arm/mach-omap2/omap_hwmod.c b/arch/arm/mach-omap2/omap_hwmod.c
3591index 832adb1..49b62c4 100644
3592--- a/arch/arm/mach-omap2/omap_hwmod.c
3593+++ b/arch/arm/mach-omap2/omap_hwmod.c
3594@@ -194,10 +194,10 @@ struct omap_hwmod_soc_ops {
3595 int (*init_clkdm)(struct omap_hwmod *oh);
3596 void (*update_context_lost)(struct omap_hwmod *oh);
3597 int (*get_context_lost)(struct omap_hwmod *oh);
3598-};
3599+} __no_const;
3600
3601 /* soc_ops: adapts the omap_hwmod code to the currently-booted SoC */
3602-static struct omap_hwmod_soc_ops soc_ops;
3603+static struct omap_hwmod_soc_ops soc_ops __read_only;
3604
3605 /* omap_hwmod_list contains all registered struct omap_hwmods */
3606 static LIST_HEAD(omap_hwmod_list);
3607diff --git a/arch/arm/mach-omap2/wd_timer.c b/arch/arm/mach-omap2/wd_timer.c
3608index d15c7bb..b2d1f0c 100644
3609--- a/arch/arm/mach-omap2/wd_timer.c
3610+++ b/arch/arm/mach-omap2/wd_timer.c
3611@@ -110,7 +110,9 @@ static int __init omap_init_wdt(void)
3612 struct omap_hwmod *oh;
3613 char *oh_name = "wd_timer2";
3614 char *dev_name = "omap_wdt";
3615- struct omap_wd_timer_platform_data pdata;
3616+ static struct omap_wd_timer_platform_data pdata = {
3617+ .read_reset_sources = prm_read_reset_sources
3618+ };
3619
3620 if (!cpu_class_is_omap2() || of_have_populated_dt())
3621 return 0;
3622@@ -121,8 +123,6 @@ static int __init omap_init_wdt(void)
3623 return -EINVAL;
3624 }
3625
3626- pdata.read_reset_sources = prm_read_reset_sources;
3627-
3628 pdev = omap_device_build(dev_name, id, oh, &pdata,
3629 sizeof(struct omap_wd_timer_platform_data));
3630 WARN(IS_ERR(pdev), "Can't build omap_device for %s:%s.\n",
3631diff --git a/arch/arm/mach-tegra/cpuidle-tegra20.c b/arch/arm/mach-tegra/cpuidle-tegra20.c
3632index b82dcae..44ee5b6 100644
3633--- a/arch/arm/mach-tegra/cpuidle-tegra20.c
3634+++ b/arch/arm/mach-tegra/cpuidle-tegra20.c
3635@@ -180,7 +180,7 @@ static int tegra20_idle_lp2_coupled(struct cpuidle_device *dev,
3636 bool entered_lp2 = false;
3637
3638 if (tegra_pending_sgi())
3639- ACCESS_ONCE(abort_flag) = true;
3640+ ACCESS_ONCE_RW(abort_flag) = true;
3641
3642 cpuidle_coupled_parallel_barrier(dev, &abort_barrier);
3643
3644diff --git a/arch/arm/mach-ux500/setup.h b/arch/arm/mach-ux500/setup.h
3645index 656324a..0beba28 100644
3646--- a/arch/arm/mach-ux500/setup.h
3647+++ b/arch/arm/mach-ux500/setup.h
3648@@ -40,13 +40,6 @@ extern void ux500_timer_init(void);
3649 .type = MT_DEVICE, \
3650 }
3651
3652-#define __MEM_DEV_DESC(x, sz) { \
3653- .virtual = IO_ADDRESS(x), \
3654- .pfn = __phys_to_pfn(x), \
3655- .length = sz, \
3656- .type = MT_MEMORY, \
3657-}
3658-
3659 extern struct smp_operations ux500_smp_ops;
3660 extern void ux500_cpu_die(unsigned int cpu);
3661
3662diff --git a/arch/arm/mm/Kconfig b/arch/arm/mm/Kconfig
3663index cd2c88e..4dd9b67 100644
3664--- a/arch/arm/mm/Kconfig
3665+++ b/arch/arm/mm/Kconfig
3666@@ -446,7 +446,7 @@ config CPU_32v5
3667
3668 config CPU_32v6
3669 bool
3670- select CPU_USE_DOMAINS if CPU_V6 && MMU
3671+ select CPU_USE_DOMAINS if CPU_V6 && MMU && !PAX_KERNEXEC && !PAX_MEMORY_UDEREF
3672 select TLS_REG_EMUL if !CPU_32v6K && !MMU
3673
3674 config CPU_32v6K
3675@@ -601,6 +601,7 @@ config CPU_CP15_MPU
3676
3677 config CPU_USE_DOMAINS
3678 bool
3679+ depends on !ARM_LPAE && !PAX_KERNEXEC && !PAX_MEMORY_UDEREF
3680 help
3681 This option enables or disables the use of domain switching
3682 via the set_fs() function.
3683@@ -800,6 +801,7 @@ config NEED_KUSER_HELPERS
3684 config KUSER_HELPERS
3685 bool "Enable kuser helpers in vector page" if !NEED_KUSER_HELPERS
3686 default y
3687+ depends on !(CPU_V6 || CPU_V6K || CPU_V7) || GRKERNSEC_OLD_ARM_USERLAND
3688 help
3689 Warning: disabling this option may break user programs.
3690
3691@@ -812,7 +814,7 @@ config KUSER_HELPERS
3692 See Documentation/arm/kernel_user_helpers.txt for details.
3693
3694 However, the fixed address nature of these helpers can be used
3695- by ROP (return orientated programming) authors when creating
3696+ by ROP (Return Oriented Programming) authors when creating
3697 exploits.
3698
3699 If all of the binaries and libraries which run on your platform
3700diff --git a/arch/arm/mm/alignment.c b/arch/arm/mm/alignment.c
3701index 6f4585b..7b6f52b 100644
3702--- a/arch/arm/mm/alignment.c
3703+++ b/arch/arm/mm/alignment.c
3704@@ -211,10 +211,12 @@ union offset_union {
3705 #define __get16_unaligned_check(ins,val,addr) \
3706 do { \
3707 unsigned int err = 0, v, a = addr; \
3708+ pax_open_userland(); \
3709 __get8_unaligned_check(ins,v,a,err); \
3710 val = v << ((BE) ? 8 : 0); \
3711 __get8_unaligned_check(ins,v,a,err); \
3712 val |= v << ((BE) ? 0 : 8); \
3713+ pax_close_userland(); \
3714 if (err) \
3715 goto fault; \
3716 } while (0)
3717@@ -228,6 +230,7 @@ union offset_union {
3718 #define __get32_unaligned_check(ins,val,addr) \
3719 do { \
3720 unsigned int err = 0, v, a = addr; \
3721+ pax_open_userland(); \
3722 __get8_unaligned_check(ins,v,a,err); \
3723 val = v << ((BE) ? 24 : 0); \
3724 __get8_unaligned_check(ins,v,a,err); \
3725@@ -236,6 +239,7 @@ union offset_union {
3726 val |= v << ((BE) ? 8 : 16); \
3727 __get8_unaligned_check(ins,v,a,err); \
3728 val |= v << ((BE) ? 0 : 24); \
3729+ pax_close_userland(); \
3730 if (err) \
3731 goto fault; \
3732 } while (0)
3733@@ -249,6 +253,7 @@ union offset_union {
3734 #define __put16_unaligned_check(ins,val,addr) \
3735 do { \
3736 unsigned int err = 0, v = val, a = addr; \
3737+ pax_open_userland(); \
3738 __asm__( FIRST_BYTE_16 \
3739 ARM( "1: "ins" %1, [%2], #1\n" ) \
3740 THUMB( "1: "ins" %1, [%2]\n" ) \
3741@@ -268,6 +273,7 @@ union offset_union {
3742 " .popsection\n" \
3743 : "=r" (err), "=&r" (v), "=&r" (a) \
3744 : "0" (err), "1" (v), "2" (a)); \
3745+ pax_close_userland(); \
3746 if (err) \
3747 goto fault; \
3748 } while (0)
3749@@ -281,6 +287,7 @@ union offset_union {
3750 #define __put32_unaligned_check(ins,val,addr) \
3751 do { \
3752 unsigned int err = 0, v = val, a = addr; \
3753+ pax_open_userland(); \
3754 __asm__( FIRST_BYTE_32 \
3755 ARM( "1: "ins" %1, [%2], #1\n" ) \
3756 THUMB( "1: "ins" %1, [%2]\n" ) \
3757@@ -310,6 +317,7 @@ union offset_union {
3758 " .popsection\n" \
3759 : "=r" (err), "=&r" (v), "=&r" (a) \
3760 : "0" (err), "1" (v), "2" (a)); \
3761+ pax_close_userland(); \
3762 if (err) \
3763 goto fault; \
3764 } while (0)
3765diff --git a/arch/arm/mm/cache-l2x0.c b/arch/arm/mm/cache-l2x0.c
3766index 447da6f..77a5057 100644
3767--- a/arch/arm/mm/cache-l2x0.c
3768+++ b/arch/arm/mm/cache-l2x0.c
3769@@ -45,7 +45,7 @@ struct l2x0_of_data {
3770 void (*setup)(const struct device_node *, u32 *, u32 *);
3771 void (*save)(void);
3772 struct outer_cache_fns outer_cache;
3773-};
3774+} __do_const;
3775
3776 static bool of_init = false;
3777
3778diff --git a/arch/arm/mm/context.c b/arch/arm/mm/context.c
3779index 84e6f77..0b52f31 100644
3780--- a/arch/arm/mm/context.c
3781+++ b/arch/arm/mm/context.c
3782@@ -43,7 +43,7 @@
3783 #define NUM_USER_ASIDS ASID_FIRST_VERSION
3784
3785 static DEFINE_RAW_SPINLOCK(cpu_asid_lock);
3786-static atomic64_t asid_generation = ATOMIC64_INIT(ASID_FIRST_VERSION);
3787+static atomic64_unchecked_t asid_generation = ATOMIC64_INIT(ASID_FIRST_VERSION);
3788 static DECLARE_BITMAP(asid_map, NUM_USER_ASIDS);
3789
3790 static DEFINE_PER_CPU(atomic64_t, active_asids);
3791@@ -180,7 +180,7 @@ static int is_reserved_asid(u64 asid)
3792 static u64 new_context(struct mm_struct *mm, unsigned int cpu)
3793 {
3794 u64 asid = atomic64_read(&mm->context.id);
3795- u64 generation = atomic64_read(&asid_generation);
3796+ u64 generation = atomic64_read_unchecked(&asid_generation);
3797
3798 if (asid != 0 && is_reserved_asid(asid)) {
3799 /*
3800@@ -198,7 +198,7 @@ static u64 new_context(struct mm_struct *mm, unsigned int cpu)
3801 */
3802 asid = find_next_zero_bit(asid_map, NUM_USER_ASIDS, 1);
3803 if (asid == NUM_USER_ASIDS) {
3804- generation = atomic64_add_return(ASID_FIRST_VERSION,
3805+ generation = atomic64_add_return_unchecked(ASID_FIRST_VERSION,
3806 &asid_generation);
3807 flush_context(cpu);
3808 asid = find_next_zero_bit(asid_map, NUM_USER_ASIDS, 1);
3809@@ -227,14 +227,14 @@ void check_and_switch_context(struct mm_struct *mm, struct task_struct *tsk)
3810 cpu_set_reserved_ttbr0();
3811
3812 asid = atomic64_read(&mm->context.id);
3813- if (!((asid ^ atomic64_read(&asid_generation)) >> ASID_BITS)
3814+ if (!((asid ^ atomic64_read_unchecked(&asid_generation)) >> ASID_BITS)
3815 && atomic64_xchg(&per_cpu(active_asids, cpu), asid))
3816 goto switch_mm_fastpath;
3817
3818 raw_spin_lock_irqsave(&cpu_asid_lock, flags);
3819 /* Check that our ASID belongs to the current generation. */
3820 asid = atomic64_read(&mm->context.id);
3821- if ((asid ^ atomic64_read(&asid_generation)) >> ASID_BITS) {
3822+ if ((asid ^ atomic64_read_unchecked(&asid_generation)) >> ASID_BITS) {
3823 asid = new_context(mm, cpu);
3824 atomic64_set(&mm->context.id, asid);
3825 }
3826diff --git a/arch/arm/mm/fault.c b/arch/arm/mm/fault.c
3827index eb8830a..5360ce7 100644
3828--- a/arch/arm/mm/fault.c
3829+++ b/arch/arm/mm/fault.c
3830@@ -25,6 +25,7 @@
3831 #include <asm/system_misc.h>
3832 #include <asm/system_info.h>
3833 #include <asm/tlbflush.h>
3834+#include <asm/sections.h>
3835
3836 #include "fault.h"
3837
3838@@ -138,6 +139,31 @@ __do_kernel_fault(struct mm_struct *mm, unsigned long addr, unsigned int fsr,
3839 if (fixup_exception(regs))
3840 return;
3841
3842+#ifdef CONFIG_PAX_MEMORY_UDEREF
3843+ if (addr < TASK_SIZE) {
3844+ if (current->signal->curr_ip)
3845+ printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to access userland memory at %08lx\n", &current->signal->curr_ip, current->comm, task_pid_nr(current),
3846+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()), addr);
3847+ else
3848+ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to access userland memory at %08lx\n", current->comm, task_pid_nr(current),
3849+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()), addr);
3850+ }
3851+#endif
3852+
3853+#ifdef CONFIG_PAX_KERNEXEC
3854+ if ((fsr & FSR_WRITE) &&
3855+ (((unsigned long)_stext <= addr && addr < init_mm.end_code) ||
3856+ (MODULES_VADDR <= addr && addr < MODULES_END)))
3857+ {
3858+ if (current->signal->curr_ip)
3859+ printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n", &current->signal->curr_ip, current->comm, task_pid_nr(current),
3860+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
3861+ else
3862+ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n", current->comm, task_pid_nr(current),
3863+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
3864+ }
3865+#endif
3866+
3867 /*
3868 * No handler, we'll have to terminate things with extreme prejudice.
3869 */
3870@@ -174,6 +200,13 @@ __do_user_fault(struct task_struct *tsk, unsigned long addr,
3871 }
3872 #endif
3873
3874+#ifdef CONFIG_PAX_PAGEEXEC
3875+ if (fsr & FSR_LNX_PF) {
3876+ pax_report_fault(regs, (void *)regs->ARM_pc, (void *)regs->ARM_sp);
3877+ do_group_exit(SIGKILL);
3878+ }
3879+#endif
3880+
3881 tsk->thread.address = addr;
3882 tsk->thread.error_code = fsr;
3883 tsk->thread.trap_no = 14;
3884@@ -401,6 +434,33 @@ do_page_fault(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
3885 }
3886 #endif /* CONFIG_MMU */
3887
3888+#ifdef CONFIG_PAX_PAGEEXEC
3889+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
3890+{
3891+ long i;
3892+
3893+ printk(KERN_ERR "PAX: bytes at PC: ");
3894+ for (i = 0; i < 20; i++) {
3895+ unsigned char c;
3896+ if (get_user(c, (__force unsigned char __user *)pc+i))
3897+ printk(KERN_CONT "?? ");
3898+ else
3899+ printk(KERN_CONT "%02x ", c);
3900+ }
3901+ printk("\n");
3902+
3903+ printk(KERN_ERR "PAX: bytes at SP-4: ");
3904+ for (i = -1; i < 20; i++) {
3905+ unsigned long c;
3906+ if (get_user(c, (__force unsigned long __user *)sp+i))
3907+ printk(KERN_CONT "???????? ");
3908+ else
3909+ printk(KERN_CONT "%08lx ", c);
3910+ }
3911+ printk("\n");
3912+}
3913+#endif
3914+
3915 /*
3916 * First Level Translation Fault Handler
3917 *
3918@@ -548,9 +608,22 @@ do_DataAbort(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
3919 const struct fsr_info *inf = fsr_info + fsr_fs(fsr);
3920 struct siginfo info;
3921
3922+#ifdef CONFIG_PAX_MEMORY_UDEREF
3923+ if (addr < TASK_SIZE && is_domain_fault(fsr)) {
3924+ if (current->signal->curr_ip)
3925+ printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to access userland memory at %08lx\n", &current->signal->curr_ip, current->comm, task_pid_nr(current),
3926+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()), addr);
3927+ else
3928+ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to access userland memory at %08lx\n", current->comm, task_pid_nr(current),
3929+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()), addr);
3930+ goto die;
3931+ }
3932+#endif
3933+
3934 if (!inf->fn(addr, fsr & ~FSR_LNX_PF, regs))
3935 return;
3936
3937+die:
3938 printk(KERN_ALERT "Unhandled fault: %s (0x%03x) at 0x%08lx\n",
3939 inf->name, fsr, addr);
3940
3941@@ -574,15 +647,98 @@ hook_ifault_code(int nr, int (*fn)(unsigned long, unsigned int, struct pt_regs *
3942 ifsr_info[nr].name = name;
3943 }
3944
3945+asmlinkage int sys_sigreturn(struct pt_regs *regs);
3946+asmlinkage int sys_rt_sigreturn(struct pt_regs *regs);
3947+
3948 asmlinkage void __exception
3949 do_PrefetchAbort(unsigned long addr, unsigned int ifsr, struct pt_regs *regs)
3950 {
3951 const struct fsr_info *inf = ifsr_info + fsr_fs(ifsr);
3952 struct siginfo info;
3953+ unsigned long pc = instruction_pointer(regs);
3954+
3955+ if (user_mode(regs)) {
3956+ unsigned long sigpage = current->mm->context.sigpage;
3957+
3958+ if (sigpage <= pc && pc < sigpage + 7*4) {
3959+ if (pc < sigpage + 3*4)
3960+ sys_sigreturn(regs);
3961+ else
3962+ sys_rt_sigreturn(regs);
3963+ return;
3964+ }
3965+ if (pc == 0xffff0f60UL) {
3966+ /*
3967+ * PaX: __kuser_cmpxchg64 emulation
3968+ */
3969+ // TODO
3970+ //regs->ARM_pc = regs->ARM_lr;
3971+ //return;
3972+ }
3973+ if (pc == 0xffff0fa0UL) {
3974+ /*
3975+ * PaX: __kuser_memory_barrier emulation
3976+ */
3977+ // dmb(); implied by the exception
3978+ regs->ARM_pc = regs->ARM_lr;
3979+ return;
3980+ }
3981+ if (pc == 0xffff0fc0UL) {
3982+ /*
3983+ * PaX: __kuser_cmpxchg emulation
3984+ */
3985+ // TODO
3986+ //long new;
3987+ //int op;
3988+
3989+ //op = FUTEX_OP_SET << 28;
3990+ //new = futex_atomic_op_inuser(op, regs->ARM_r2);
3991+ //regs->ARM_r0 = old != new;
3992+ //regs->ARM_pc = regs->ARM_lr;
3993+ //return;
3994+ }
3995+ if (pc == 0xffff0fe0UL) {
3996+ /*
3997+ * PaX: __kuser_get_tls emulation
3998+ */
3999+ regs->ARM_r0 = current_thread_info()->tp_value[0];
4000+ regs->ARM_pc = regs->ARM_lr;
4001+ return;
4002+ }
4003+ }
4004+
4005+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
4006+ else if (is_domain_fault(ifsr) || is_xn_fault(ifsr)) {
4007+ if (current->signal->curr_ip)
4008+ printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to execute %s memory at %08lx\n", &current->signal->curr_ip, current->comm, task_pid_nr(current),
4009+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()),
4010+ pc >= TASK_SIZE ? "non-executable kernel" : "userland", pc);
4011+ else
4012+ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to execute %s memory at %08lx\n", current->comm, task_pid_nr(current),
4013+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()),
4014+ pc >= TASK_SIZE ? "non-executable kernel" : "userland", pc);
4015+ goto die;
4016+ }
4017+#endif
4018+
4019+#ifdef CONFIG_PAX_REFCOUNT
4020+ if (fsr_fs(ifsr) == FAULT_CODE_DEBUG) {
4021+ unsigned int bkpt;
4022+
4023+ if (!probe_kernel_address(pc, bkpt) && cpu_to_le32(bkpt) == 0xe12f1073) {
4024+ current->thread.error_code = ifsr;
4025+ current->thread.trap_no = 0;
4026+ pax_report_refcount_overflow(regs);
4027+ fixup_exception(regs);
4028+ return;
4029+ }
4030+ }
4031+#endif
4032
4033 if (!inf->fn(addr, ifsr | FSR_LNX_PF, regs))
4034 return;
4035
4036+die:
4037 printk(KERN_ALERT "Unhandled prefetch abort: %s (0x%03x) at 0x%08lx\n",
4038 inf->name, ifsr, addr);
4039
4040diff --git a/arch/arm/mm/fault.h b/arch/arm/mm/fault.h
4041index cf08bdf..772656c 100644
4042--- a/arch/arm/mm/fault.h
4043+++ b/arch/arm/mm/fault.h
4044@@ -3,6 +3,7 @@
4045
4046 /*
4047 * Fault status register encodings. We steal bit 31 for our own purposes.
4048+ * Set when the FSR value is from an instruction fault.
4049 */
4050 #define FSR_LNX_PF (1 << 31)
4051 #define FSR_WRITE (1 << 11)
4052@@ -22,6 +23,17 @@ static inline int fsr_fs(unsigned int fsr)
4053 }
4054 #endif
4055
4056+/* valid for LPAE and !LPAE */
4057+static inline int is_xn_fault(unsigned int fsr)
4058+{
4059+ return ((fsr_fs(fsr) & 0x3c) == 0xc);
4060+}
4061+
4062+static inline int is_domain_fault(unsigned int fsr)
4063+{
4064+ return ((fsr_fs(fsr) & 0xD) == 0x9);
4065+}
4066+
4067 void do_bad_area(unsigned long addr, unsigned int fsr, struct pt_regs *regs);
4068 unsigned long search_exception_table(unsigned long addr);
4069
4070diff --git a/arch/arm/mm/init.c b/arch/arm/mm/init.c
4071index 18ec4c5..479bb6a 100644
4072--- a/arch/arm/mm/init.c
4073+++ b/arch/arm/mm/init.c
4074@@ -30,6 +30,8 @@
4075 #include <asm/setup.h>
4076 #include <asm/tlb.h>
4077 #include <asm/fixmap.h>
4078+#include <asm/system_info.h>
4079+#include <asm/cp15.h>
4080
4081 #include <asm/mach/arch.h>
4082 #include <asm/mach/map.h>
4083@@ -684,7 +686,46 @@ void free_initmem(void)
4084 {
4085 #ifdef CONFIG_HAVE_TCM
4086 extern char __tcm_start, __tcm_end;
4087+#endif
4088
4089+#ifdef CONFIG_PAX_KERNEXEC
4090+ unsigned long addr;
4091+ pgd_t *pgd;
4092+ pud_t *pud;
4093+ pmd_t *pmd;
4094+ int cpu_arch = cpu_architecture();
4095+ unsigned int cr = get_cr();
4096+
4097+ if (cpu_arch >= CPU_ARCH_ARMv6 && (cr & CR_XP)) {
4098+ /* make pages tables, etc before .text NX */
4099+ for (addr = PAGE_OFFSET; addr < (unsigned long)_stext; addr += SECTION_SIZE) {
4100+ pgd = pgd_offset_k(addr);
4101+ pud = pud_offset(pgd, addr);
4102+ pmd = pmd_offset(pud, addr);
4103+ __section_update(pmd, addr, PMD_SECT_XN);
4104+ }
4105+ /* make init NX */
4106+ for (addr = (unsigned long)__init_begin; addr < (unsigned long)_sdata; addr += SECTION_SIZE) {
4107+ pgd = pgd_offset_k(addr);
4108+ pud = pud_offset(pgd, addr);
4109+ pmd = pmd_offset(pud, addr);
4110+ __section_update(pmd, addr, PMD_SECT_XN);
4111+ }
4112+ /* make kernel code/rodata RX */
4113+ for (addr = (unsigned long)_stext; addr < (unsigned long)__init_begin; addr += SECTION_SIZE) {
4114+ pgd = pgd_offset_k(addr);
4115+ pud = pud_offset(pgd, addr);
4116+ pmd = pmd_offset(pud, addr);
4117+#ifdef CONFIG_ARM_LPAE
4118+ __section_update(pmd, addr, PMD_SECT_RDONLY);
4119+#else
4120+ __section_update(pmd, addr, PMD_SECT_APX|PMD_SECT_AP_WRITE);
4121+#endif
4122+ }
4123+ }
4124+#endif
4125+
4126+#ifdef CONFIG_HAVE_TCM
4127 poison_init_mem(&__tcm_start, &__tcm_end - &__tcm_start);
4128 free_reserved_area(&__tcm_start, &__tcm_end, -1, "TCM link");
4129 #endif
4130diff --git a/arch/arm/mm/ioremap.c b/arch/arm/mm/ioremap.c
4131index f123d6e..04bf569 100644
4132--- a/arch/arm/mm/ioremap.c
4133+++ b/arch/arm/mm/ioremap.c
4134@@ -392,9 +392,9 @@ __arm_ioremap_exec(phys_addr_t phys_addr, size_t size, bool cached)
4135 unsigned int mtype;
4136
4137 if (cached)
4138- mtype = MT_MEMORY;
4139+ mtype = MT_MEMORY_RX;
4140 else
4141- mtype = MT_MEMORY_NONCACHED;
4142+ mtype = MT_MEMORY_NONCACHED_RX;
4143
4144 return __arm_ioremap_caller(phys_addr, size, mtype,
4145 __builtin_return_address(0));
4146diff --git a/arch/arm/mm/mmap.c b/arch/arm/mm/mmap.c
4147index 304661d..53a6b19 100644
4148--- a/arch/arm/mm/mmap.c
4149+++ b/arch/arm/mm/mmap.c
4150@@ -59,6 +59,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
4151 struct vm_area_struct *vma;
4152 int do_align = 0;
4153 int aliasing = cache_is_vipt_aliasing();
4154+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
4155 struct vm_unmapped_area_info info;
4156
4157 /*
4158@@ -81,6 +82,10 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
4159 if (len > TASK_SIZE)
4160 return -ENOMEM;
4161
4162+#ifdef CONFIG_PAX_RANDMMAP
4163+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
4164+#endif
4165+
4166 if (addr) {
4167 if (do_align)
4168 addr = COLOUR_ALIGN(addr, pgoff);
4169@@ -88,8 +93,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
4170 addr = PAGE_ALIGN(addr);
4171
4172 vma = find_vma(mm, addr);
4173- if (TASK_SIZE - len >= addr &&
4174- (!vma || addr + len <= vma->vm_start))
4175+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
4176 return addr;
4177 }
4178
4179@@ -99,6 +103,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
4180 info.high_limit = TASK_SIZE;
4181 info.align_mask = do_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
4182 info.align_offset = pgoff << PAGE_SHIFT;
4183+ info.threadstack_offset = offset;
4184 return vm_unmapped_area(&info);
4185 }
4186
4187@@ -112,6 +117,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4188 unsigned long addr = addr0;
4189 int do_align = 0;
4190 int aliasing = cache_is_vipt_aliasing();
4191+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
4192 struct vm_unmapped_area_info info;
4193
4194 /*
4195@@ -132,6 +138,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4196 return addr;
4197 }
4198
4199+#ifdef CONFIG_PAX_RANDMMAP
4200+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
4201+#endif
4202+
4203 /* requesting a specific address */
4204 if (addr) {
4205 if (do_align)
4206@@ -139,8 +149,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4207 else
4208 addr = PAGE_ALIGN(addr);
4209 vma = find_vma(mm, addr);
4210- if (TASK_SIZE - len >= addr &&
4211- (!vma || addr + len <= vma->vm_start))
4212+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
4213 return addr;
4214 }
4215
4216@@ -150,6 +159,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4217 info.high_limit = mm->mmap_base;
4218 info.align_mask = do_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
4219 info.align_offset = pgoff << PAGE_SHIFT;
4220+ info.threadstack_offset = offset;
4221 addr = vm_unmapped_area(&info);
4222
4223 /*
4224@@ -173,6 +183,10 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
4225 {
4226 unsigned long random_factor = 0UL;
4227
4228+#ifdef CONFIG_PAX_RANDMMAP
4229+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
4230+#endif
4231+
4232 /* 8 bits of randomness in 20 address space bits */
4233 if ((current->flags & PF_RANDOMIZE) &&
4234 !(current->personality & ADDR_NO_RANDOMIZE))
4235@@ -180,9 +194,21 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
4236
4237 if (mmap_is_legacy()) {
4238 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
4239+
4240+#ifdef CONFIG_PAX_RANDMMAP
4241+ if (mm->pax_flags & MF_PAX_RANDMMAP)
4242+ mm->mmap_base += mm->delta_mmap;
4243+#endif
4244+
4245 mm->get_unmapped_area = arch_get_unmapped_area;
4246 } else {
4247 mm->mmap_base = mmap_base(random_factor);
4248+
4249+#ifdef CONFIG_PAX_RANDMMAP
4250+ if (mm->pax_flags & MF_PAX_RANDMMAP)
4251+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
4252+#endif
4253+
4254 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
4255 }
4256 }
4257diff --git a/arch/arm/mm/mmu.c b/arch/arm/mm/mmu.c
4258index b1d17ee..7a6f4d3 100644
4259--- a/arch/arm/mm/mmu.c
4260+++ b/arch/arm/mm/mmu.c
4261@@ -36,6 +36,22 @@
4262 #include "mm.h"
4263 #include "tcm.h"
4264
4265+#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
4266+void modify_domain(unsigned int dom, unsigned int type)
4267+{
4268+ struct thread_info *thread = current_thread_info();
4269+ unsigned int domain = thread->cpu_domain;
4270+ /*
4271+ * DOMAIN_MANAGER might be defined to some other value,
4272+ * use the arch-defined constant
4273+ */
4274+ domain &= ~domain_val(dom, 3);
4275+ thread->cpu_domain = domain | domain_val(dom, type);
4276+ set_domain(thread->cpu_domain);
4277+}
4278+EXPORT_SYMBOL(modify_domain);
4279+#endif
4280+
4281 /*
4282 * empty_zero_page is a special page that is used for
4283 * zero-initialized data and COW.
4284@@ -228,10 +244,18 @@ __setup("noalign", noalign_setup);
4285
4286 #endif /* ifdef CONFIG_CPU_CP15 / else */
4287
4288-#define PROT_PTE_DEVICE L_PTE_PRESENT|L_PTE_YOUNG|L_PTE_DIRTY|L_PTE_XN
4289+#define PROT_PTE_DEVICE L_PTE_PRESENT|L_PTE_YOUNG|L_PTE_DIRTY
4290 #define PROT_SECT_DEVICE PMD_TYPE_SECT|PMD_SECT_AP_WRITE
4291
4292-static struct mem_type mem_types[] = {
4293+#ifdef CONFIG_PAX_KERNEXEC
4294+#define L_PTE_KERNEXEC L_PTE_RDONLY
4295+#define PMD_SECT_KERNEXEC PMD_SECT_RDONLY
4296+#else
4297+#define L_PTE_KERNEXEC L_PTE_DIRTY
4298+#define PMD_SECT_KERNEXEC PMD_SECT_AP_WRITE
4299+#endif
4300+
4301+static struct mem_type mem_types[] __read_only = {
4302 [MT_DEVICE] = { /* Strongly ordered / ARMv6 shared device */
4303 .prot_pte = PROT_PTE_DEVICE | L_PTE_MT_DEV_SHARED |
4304 L_PTE_SHARED,
4305@@ -260,16 +284,16 @@ static struct mem_type mem_types[] = {
4306 [MT_UNCACHED] = {
4307 .prot_pte = PROT_PTE_DEVICE,
4308 .prot_l1 = PMD_TYPE_TABLE,
4309- .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
4310+ .prot_sect = PROT_SECT_DEVICE,
4311 .domain = DOMAIN_IO,
4312 },
4313 [MT_CACHECLEAN] = {
4314- .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
4315+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_RDONLY,
4316 .domain = DOMAIN_KERNEL,
4317 },
4318 #ifndef CONFIG_ARM_LPAE
4319 [MT_MINICLEAN] = {
4320- .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN | PMD_SECT_MINICACHE,
4321+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_MINICACHE | PMD_SECT_RDONLY,
4322 .domain = DOMAIN_KERNEL,
4323 },
4324 #endif
4325@@ -277,36 +301,54 @@ static struct mem_type mem_types[] = {
4326 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4327 L_PTE_RDONLY,
4328 .prot_l1 = PMD_TYPE_TABLE,
4329- .domain = DOMAIN_USER,
4330+ .domain = DOMAIN_VECTORS,
4331 },
4332 [MT_HIGH_VECTORS] = {
4333 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4334 L_PTE_USER | L_PTE_RDONLY,
4335 .prot_l1 = PMD_TYPE_TABLE,
4336- .domain = DOMAIN_USER,
4337+ .domain = DOMAIN_VECTORS,
4338 },
4339- [MT_MEMORY] = {
4340+ [MT_MEMORY_RWX] = {
4341 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY,
4342 .prot_l1 = PMD_TYPE_TABLE,
4343 .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE,
4344 .domain = DOMAIN_KERNEL,
4345 },
4346+ [MT_MEMORY_RW] = {
4347+ .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY,
4348+ .prot_l1 = PMD_TYPE_TABLE,
4349+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE,
4350+ .domain = DOMAIN_KERNEL,
4351+ },
4352+ [MT_MEMORY_RX] = {
4353+ .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_KERNEXEC,
4354+ .prot_l1 = PMD_TYPE_TABLE,
4355+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_KERNEXEC,
4356+ .domain = DOMAIN_KERNEL,
4357+ },
4358 [MT_ROM] = {
4359- .prot_sect = PMD_TYPE_SECT,
4360+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_RDONLY,
4361 .domain = DOMAIN_KERNEL,
4362 },
4363- [MT_MEMORY_NONCACHED] = {
4364+ [MT_MEMORY_NONCACHED_RW] = {
4365 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4366 L_PTE_MT_BUFFERABLE,
4367 .prot_l1 = PMD_TYPE_TABLE,
4368 .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE,
4369 .domain = DOMAIN_KERNEL,
4370 },
4371+ [MT_MEMORY_NONCACHED_RX] = {
4372+ .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_KERNEXEC |
4373+ L_PTE_MT_BUFFERABLE,
4374+ .prot_l1 = PMD_TYPE_TABLE,
4375+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_KERNEXEC,
4376+ .domain = DOMAIN_KERNEL,
4377+ },
4378 [MT_MEMORY_DTCM] = {
4379- .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4380- L_PTE_XN,
4381+ .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY,
4382 .prot_l1 = PMD_TYPE_TABLE,
4383- .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
4384+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_RDONLY,
4385 .domain = DOMAIN_KERNEL,
4386 },
4387 [MT_MEMORY_ITCM] = {
4388@@ -316,10 +358,10 @@ static struct mem_type mem_types[] = {
4389 },
4390 [MT_MEMORY_SO] = {
4391 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4392- L_PTE_MT_UNCACHED | L_PTE_XN,
4393+ L_PTE_MT_UNCACHED,
4394 .prot_l1 = PMD_TYPE_TABLE,
4395 .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE | PMD_SECT_S |
4396- PMD_SECT_UNCACHED | PMD_SECT_XN,
4397+ PMD_SECT_UNCACHED,
4398 .domain = DOMAIN_KERNEL,
4399 },
4400 [MT_MEMORY_DMA_READY] = {
4401@@ -405,9 +447,35 @@ static void __init build_mem_type_table(void)
4402 * to prevent speculative instruction fetches.
4403 */
4404 mem_types[MT_DEVICE].prot_sect |= PMD_SECT_XN;
4405+ mem_types[MT_DEVICE].prot_pte |= L_PTE_XN;
4406 mem_types[MT_DEVICE_NONSHARED].prot_sect |= PMD_SECT_XN;
4407+ mem_types[MT_DEVICE_NONSHARED].prot_pte |= L_PTE_XN;
4408 mem_types[MT_DEVICE_CACHED].prot_sect |= PMD_SECT_XN;
4409+ mem_types[MT_DEVICE_CACHED].prot_pte |= L_PTE_XN;
4410 mem_types[MT_DEVICE_WC].prot_sect |= PMD_SECT_XN;
4411+ mem_types[MT_DEVICE_WC].prot_pte |= L_PTE_XN;
4412+
4413+ /* Mark other regions on ARMv6+ as execute-never */
4414+
4415+#ifdef CONFIG_PAX_KERNEXEC
4416+ mem_types[MT_UNCACHED].prot_sect |= PMD_SECT_XN;
4417+ mem_types[MT_UNCACHED].prot_pte |= L_PTE_XN;
4418+ mem_types[MT_CACHECLEAN].prot_sect |= PMD_SECT_XN;
4419+ mem_types[MT_CACHECLEAN].prot_pte |= L_PTE_XN;
4420+#ifndef CONFIG_ARM_LPAE
4421+ mem_types[MT_MINICLEAN].prot_sect |= PMD_SECT_XN;
4422+ mem_types[MT_MINICLEAN].prot_pte |= L_PTE_XN;
4423+#endif
4424+ mem_types[MT_MEMORY_RW].prot_sect |= PMD_SECT_XN;
4425+ mem_types[MT_MEMORY_RW].prot_pte |= L_PTE_XN;
4426+ mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |= PMD_SECT_XN;
4427+ mem_types[MT_MEMORY_NONCACHED_RW].prot_pte |= PMD_SECT_XN;
4428+ mem_types[MT_MEMORY_DTCM].prot_sect |= PMD_SECT_XN;
4429+ mem_types[MT_MEMORY_DTCM].prot_pte |= L_PTE_XN;
4430+#endif
4431+
4432+ mem_types[MT_MEMORY_SO].prot_sect |= PMD_SECT_XN;
4433+ mem_types[MT_MEMORY_SO].prot_pte |= L_PTE_XN;
4434 }
4435 if (cpu_arch >= CPU_ARCH_ARMv7 && (cr & CR_TRE)) {
4436 /*
4437@@ -468,6 +536,9 @@ static void __init build_mem_type_table(void)
4438 * from SVC mode and no access from userspace.
4439 */
4440 mem_types[MT_ROM].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4441+#ifdef CONFIG_PAX_KERNEXEC
4442+ mem_types[MT_MEMORY_RX].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4443+#endif
4444 mem_types[MT_MINICLEAN].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4445 mem_types[MT_CACHECLEAN].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4446 #endif
4447@@ -485,11 +556,17 @@ static void __init build_mem_type_table(void)
4448 mem_types[MT_DEVICE_WC].prot_pte |= L_PTE_SHARED;
4449 mem_types[MT_DEVICE_CACHED].prot_sect |= PMD_SECT_S;
4450 mem_types[MT_DEVICE_CACHED].prot_pte |= L_PTE_SHARED;
4451- mem_types[MT_MEMORY].prot_sect |= PMD_SECT_S;
4452- mem_types[MT_MEMORY].prot_pte |= L_PTE_SHARED;
4453+ mem_types[MT_MEMORY_RWX].prot_sect |= PMD_SECT_S;
4454+ mem_types[MT_MEMORY_RWX].prot_pte |= L_PTE_SHARED;
4455+ mem_types[MT_MEMORY_RW].prot_sect |= PMD_SECT_S;
4456+ mem_types[MT_MEMORY_RW].prot_pte |= L_PTE_SHARED;
4457+ mem_types[MT_MEMORY_RX].prot_sect |= PMD_SECT_S;
4458+ mem_types[MT_MEMORY_RX].prot_pte |= L_PTE_SHARED;
4459 mem_types[MT_MEMORY_DMA_READY].prot_pte |= L_PTE_SHARED;
4460- mem_types[MT_MEMORY_NONCACHED].prot_sect |= PMD_SECT_S;
4461- mem_types[MT_MEMORY_NONCACHED].prot_pte |= L_PTE_SHARED;
4462+ mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |= PMD_SECT_S;
4463+ mem_types[MT_MEMORY_NONCACHED_RW].prot_pte |= L_PTE_SHARED;
4464+ mem_types[MT_MEMORY_NONCACHED_RX].prot_sect |= PMD_SECT_S;
4465+ mem_types[MT_MEMORY_NONCACHED_RX].prot_pte |= L_PTE_SHARED;
4466 }
4467 }
4468
4469@@ -500,15 +577,20 @@ static void __init build_mem_type_table(void)
4470 if (cpu_arch >= CPU_ARCH_ARMv6) {
4471 if (cpu_arch >= CPU_ARCH_ARMv7 && (cr & CR_TRE)) {
4472 /* Non-cacheable Normal is XCB = 001 */
4473- mem_types[MT_MEMORY_NONCACHED].prot_sect |=
4474+ mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |=
4475+ PMD_SECT_BUFFERED;
4476+ mem_types[MT_MEMORY_NONCACHED_RX].prot_sect |=
4477 PMD_SECT_BUFFERED;
4478 } else {
4479 /* For both ARMv6 and non-TEX-remapping ARMv7 */
4480- mem_types[MT_MEMORY_NONCACHED].prot_sect |=
4481+ mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |=
4482+ PMD_SECT_TEX(1);
4483+ mem_types[MT_MEMORY_NONCACHED_RX].prot_sect |=
4484 PMD_SECT_TEX(1);
4485 }
4486 } else {
4487- mem_types[MT_MEMORY_NONCACHED].prot_sect |= PMD_SECT_BUFFERABLE;
4488+ mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |= PMD_SECT_BUFFERABLE;
4489+ mem_types[MT_MEMORY_NONCACHED_RX].prot_sect |= PMD_SECT_BUFFERABLE;
4490 }
4491
4492 #ifdef CONFIG_ARM_LPAE
4493@@ -524,6 +606,8 @@ static void __init build_mem_type_table(void)
4494 vecs_pgprot |= PTE_EXT_AF;
4495 #endif
4496
4497+ user_pgprot |= __supported_pte_mask;
4498+
4499 for (i = 0; i < 16; i++) {
4500 pteval_t v = pgprot_val(protection_map[i]);
4501 protection_map[i] = __pgprot(v | user_pgprot);
4502@@ -541,10 +625,15 @@ static void __init build_mem_type_table(void)
4503
4504 mem_types[MT_LOW_VECTORS].prot_l1 |= ecc_mask;
4505 mem_types[MT_HIGH_VECTORS].prot_l1 |= ecc_mask;
4506- mem_types[MT_MEMORY].prot_sect |= ecc_mask | cp->pmd;
4507- mem_types[MT_MEMORY].prot_pte |= kern_pgprot;
4508+ mem_types[MT_MEMORY_RWX].prot_sect |= ecc_mask | cp->pmd;
4509+ mem_types[MT_MEMORY_RWX].prot_pte |= kern_pgprot;
4510+ mem_types[MT_MEMORY_RW].prot_sect |= ecc_mask | cp->pmd;
4511+ mem_types[MT_MEMORY_RW].prot_pte |= kern_pgprot;
4512+ mem_types[MT_MEMORY_RX].prot_sect |= ecc_mask | cp->pmd;
4513+ mem_types[MT_MEMORY_RX].prot_pte |= kern_pgprot;
4514 mem_types[MT_MEMORY_DMA_READY].prot_pte |= kern_pgprot;
4515- mem_types[MT_MEMORY_NONCACHED].prot_sect |= ecc_mask;
4516+ mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |= ecc_mask;
4517+ mem_types[MT_MEMORY_NONCACHED_RX].prot_sect |= ecc_mask;
4518 mem_types[MT_ROM].prot_sect |= cp->pmd;
4519
4520 switch (cp->pmd) {
4521@@ -1186,18 +1275,15 @@ void __init arm_mm_memblock_reserve(void)
4522 * called function. This means you can't use any function or debugging
4523 * method which may touch any device, otherwise the kernel _will_ crash.
4524 */
4525+
4526+static char vectors[PAGE_SIZE * 2] __read_only __aligned(PAGE_SIZE);
4527+
4528 static void __init devicemaps_init(const struct machine_desc *mdesc)
4529 {
4530 struct map_desc map;
4531 unsigned long addr;
4532- void *vectors;
4533
4534- /*
4535- * Allocate the vector page early.
4536- */
4537- vectors = early_alloc(PAGE_SIZE * 2);
4538-
4539- early_trap_init(vectors);
4540+ early_trap_init(&vectors);
4541
4542 for (addr = VMALLOC_START; addr; addr += PMD_SIZE)
4543 pmd_clear(pmd_off_k(addr));
4544@@ -1237,7 +1323,7 @@ static void __init devicemaps_init(const struct machine_desc *mdesc)
4545 * location (0xffff0000). If we aren't using high-vectors, also
4546 * create a mapping at the low-vectors virtual address.
4547 */
4548- map.pfn = __phys_to_pfn(virt_to_phys(vectors));
4549+ map.pfn = __phys_to_pfn(virt_to_phys(&vectors));
4550 map.virtual = 0xffff0000;
4551 map.length = PAGE_SIZE;
4552 #ifdef CONFIG_KUSER_HELPERS
4553@@ -1309,8 +1395,39 @@ static void __init map_lowmem(void)
4554 map.pfn = __phys_to_pfn(start);
4555 map.virtual = __phys_to_virt(start);
4556 map.length = end - start;
4557- map.type = MT_MEMORY;
4558
4559+#ifdef CONFIG_PAX_KERNEXEC
4560+ if (map.virtual <= (unsigned long)_stext && ((unsigned long)_end < (map.virtual + map.length))) {
4561+ struct map_desc kernel;
4562+ struct map_desc initmap;
4563+
4564+ /* when freeing initmem we will make this RW */
4565+ initmap.pfn = __phys_to_pfn(__pa(__init_begin));
4566+ initmap.virtual = (unsigned long)__init_begin;
4567+ initmap.length = _sdata - __init_begin;
4568+ initmap.type = MT_MEMORY_RWX;
4569+ create_mapping(&initmap);
4570+
4571+ /* when freeing initmem we will make this RX */
4572+ kernel.pfn = __phys_to_pfn(__pa(_stext));
4573+ kernel.virtual = (unsigned long)_stext;
4574+ kernel.length = __init_begin - _stext;
4575+ kernel.type = MT_MEMORY_RWX;
4576+ create_mapping(&kernel);
4577+
4578+ if (map.virtual < (unsigned long)_stext) {
4579+ map.length = (unsigned long)_stext - map.virtual;
4580+ map.type = MT_MEMORY_RWX;
4581+ create_mapping(&map);
4582+ }
4583+
4584+ map.pfn = __phys_to_pfn(__pa(_sdata));
4585+ map.virtual = (unsigned long)_sdata;
4586+ map.length = end - __pa(_sdata);
4587+ }
4588+#endif
4589+
4590+ map.type = MT_MEMORY_RW;
4591 create_mapping(&map);
4592 }
4593 }
4594diff --git a/arch/arm/net/bpf_jit_32.c b/arch/arm/net/bpf_jit_32.c
4595index 99b44e0..8c9106f 100644
4596--- a/arch/arm/net/bpf_jit_32.c
4597+++ b/arch/arm/net/bpf_jit_32.c
4598@@ -637,10 +637,10 @@ load_ind:
4599 emit(ARM_MUL(r_A, r_A, r_X), ctx);
4600 break;
4601 case BPF_S_ALU_DIV_K:
4602- /* current k == reciprocal_value(userspace k) */
4603+ if (k == 1)
4604+ break;
4605 emit_mov_i(r_scratch, k, ctx);
4606- /* A = top 32 bits of the product */
4607- emit(ARM_UMULL(r_scratch, r_A, r_A, r_scratch), ctx);
4608+ emit_udiv(r_A, r_A, r_scratch, ctx);
4609 break;
4610 case BPF_S_ALU_DIV_X:
4611 update_on_xread(ctx);
4612diff --git a/arch/arm/plat-omap/sram.c b/arch/arm/plat-omap/sram.c
4613index a5bc92d..0bb4730 100644
4614--- a/arch/arm/plat-omap/sram.c
4615+++ b/arch/arm/plat-omap/sram.c
4616@@ -93,6 +93,8 @@ void __init omap_map_sram(unsigned long start, unsigned long size,
4617 * Looks like we need to preserve some bootloader code at the
4618 * beginning of SRAM for jumping to flash for reboot to work...
4619 */
4620+ pax_open_kernel();
4621 memset_io(omap_sram_base + omap_sram_skip, 0,
4622 omap_sram_size - omap_sram_skip);
4623+ pax_close_kernel();
4624 }
4625diff --git a/arch/arm/plat-samsung/include/plat/dma-ops.h b/arch/arm/plat-samsung/include/plat/dma-ops.h
4626index ce6d763..cfea917 100644
4627--- a/arch/arm/plat-samsung/include/plat/dma-ops.h
4628+++ b/arch/arm/plat-samsung/include/plat/dma-ops.h
4629@@ -47,7 +47,7 @@ struct samsung_dma_ops {
4630 int (*started)(unsigned ch);
4631 int (*flush)(unsigned ch);
4632 int (*stop)(unsigned ch);
4633-};
4634+} __no_const;
4635
4636 extern void *samsung_dmadev_get_ops(void);
4637 extern void *s3c_dma_get_ops(void);
4638diff --git a/arch/avr32/include/asm/cache.h b/arch/avr32/include/asm/cache.h
4639index c3a58a1..78fbf54 100644
4640--- a/arch/avr32/include/asm/cache.h
4641+++ b/arch/avr32/include/asm/cache.h
4642@@ -1,8 +1,10 @@
4643 #ifndef __ASM_AVR32_CACHE_H
4644 #define __ASM_AVR32_CACHE_H
4645
4646+#include <linux/const.h>
4647+
4648 #define L1_CACHE_SHIFT 5
4649-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4650+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4651
4652 /*
4653 * Memory returned by kmalloc() may be used for DMA, so we must make
4654diff --git a/arch/avr32/include/asm/elf.h b/arch/avr32/include/asm/elf.h
4655index d232888..87c8df1 100644
4656--- a/arch/avr32/include/asm/elf.h
4657+++ b/arch/avr32/include/asm/elf.h
4658@@ -84,8 +84,14 @@ typedef struct user_fpu_struct elf_fpregset_t;
4659 the loader. We need to make sure that it is out of the way of the program
4660 that it will "exec", and that there is sufficient room for the brk. */
4661
4662-#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
4663+#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
4664
4665+#ifdef CONFIG_PAX_ASLR
4666+#define PAX_ELF_ET_DYN_BASE 0x00001000UL
4667+
4668+#define PAX_DELTA_MMAP_LEN 15
4669+#define PAX_DELTA_STACK_LEN 15
4670+#endif
4671
4672 /* This yields a mask that user programs can use to figure out what
4673 instruction set this CPU supports. This could be done in user space,
4674diff --git a/arch/avr32/include/asm/kmap_types.h b/arch/avr32/include/asm/kmap_types.h
4675index 479330b..53717a8 100644
4676--- a/arch/avr32/include/asm/kmap_types.h
4677+++ b/arch/avr32/include/asm/kmap_types.h
4678@@ -2,9 +2,9 @@
4679 #define __ASM_AVR32_KMAP_TYPES_H
4680
4681 #ifdef CONFIG_DEBUG_HIGHMEM
4682-# define KM_TYPE_NR 29
4683+# define KM_TYPE_NR 30
4684 #else
4685-# define KM_TYPE_NR 14
4686+# define KM_TYPE_NR 15
4687 #endif
4688
4689 #endif /* __ASM_AVR32_KMAP_TYPES_H */
4690diff --git a/arch/avr32/mm/fault.c b/arch/avr32/mm/fault.c
4691index 0eca933..eb78c7b 100644
4692--- a/arch/avr32/mm/fault.c
4693+++ b/arch/avr32/mm/fault.c
4694@@ -41,6 +41,23 @@ static inline int notify_page_fault(struct pt_regs *regs, int trap)
4695
4696 int exception_trace = 1;
4697
4698+#ifdef CONFIG_PAX_PAGEEXEC
4699+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
4700+{
4701+ unsigned long i;
4702+
4703+ printk(KERN_ERR "PAX: bytes at PC: ");
4704+ for (i = 0; i < 20; i++) {
4705+ unsigned char c;
4706+ if (get_user(c, (unsigned char *)pc+i))
4707+ printk(KERN_CONT "???????? ");
4708+ else
4709+ printk(KERN_CONT "%02x ", c);
4710+ }
4711+ printk("\n");
4712+}
4713+#endif
4714+
4715 /*
4716 * This routine handles page faults. It determines the address and the
4717 * problem, and then passes it off to one of the appropriate routines.
4718@@ -176,6 +193,16 @@ bad_area:
4719 up_read(&mm->mmap_sem);
4720
4721 if (user_mode(regs)) {
4722+
4723+#ifdef CONFIG_PAX_PAGEEXEC
4724+ if (mm->pax_flags & MF_PAX_PAGEEXEC) {
4725+ if (ecr == ECR_PROTECTION_X || ecr == ECR_TLB_MISS_X) {
4726+ pax_report_fault(regs, (void *)regs->pc, (void *)regs->sp);
4727+ do_group_exit(SIGKILL);
4728+ }
4729+ }
4730+#endif
4731+
4732 if (exception_trace && printk_ratelimit())
4733 printk("%s%s[%d]: segfault at %08lx pc %08lx "
4734 "sp %08lx ecr %lu\n",
4735diff --git a/arch/blackfin/include/asm/cache.h b/arch/blackfin/include/asm/cache.h
4736index 568885a..f8008df 100644
4737--- a/arch/blackfin/include/asm/cache.h
4738+++ b/arch/blackfin/include/asm/cache.h
4739@@ -7,6 +7,7 @@
4740 #ifndef __ARCH_BLACKFIN_CACHE_H
4741 #define __ARCH_BLACKFIN_CACHE_H
4742
4743+#include <linux/const.h>
4744 #include <linux/linkage.h> /* for asmlinkage */
4745
4746 /*
4747@@ -14,7 +15,7 @@
4748 * Blackfin loads 32 bytes for cache
4749 */
4750 #define L1_CACHE_SHIFT 5
4751-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4752+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4753 #define SMP_CACHE_BYTES L1_CACHE_BYTES
4754
4755 #define ARCH_DMA_MINALIGN L1_CACHE_BYTES
4756diff --git a/arch/cris/include/arch-v10/arch/cache.h b/arch/cris/include/arch-v10/arch/cache.h
4757index aea2718..3639a60 100644
4758--- a/arch/cris/include/arch-v10/arch/cache.h
4759+++ b/arch/cris/include/arch-v10/arch/cache.h
4760@@ -1,8 +1,9 @@
4761 #ifndef _ASM_ARCH_CACHE_H
4762 #define _ASM_ARCH_CACHE_H
4763
4764+#include <linux/const.h>
4765 /* Etrax 100LX have 32-byte cache-lines. */
4766-#define L1_CACHE_BYTES 32
4767 #define L1_CACHE_SHIFT 5
4768+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4769
4770 #endif /* _ASM_ARCH_CACHE_H */
4771diff --git a/arch/cris/include/arch-v32/arch/cache.h b/arch/cris/include/arch-v32/arch/cache.h
4772index 7caf25d..ee65ac5 100644
4773--- a/arch/cris/include/arch-v32/arch/cache.h
4774+++ b/arch/cris/include/arch-v32/arch/cache.h
4775@@ -1,11 +1,12 @@
4776 #ifndef _ASM_CRIS_ARCH_CACHE_H
4777 #define _ASM_CRIS_ARCH_CACHE_H
4778
4779+#include <linux/const.h>
4780 #include <arch/hwregs/dma.h>
4781
4782 /* A cache-line is 32 bytes. */
4783-#define L1_CACHE_BYTES 32
4784 #define L1_CACHE_SHIFT 5
4785+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4786
4787 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
4788
4789diff --git a/arch/frv/include/asm/atomic.h b/arch/frv/include/asm/atomic.h
4790index b86329d..6709906 100644
4791--- a/arch/frv/include/asm/atomic.h
4792+++ b/arch/frv/include/asm/atomic.h
4793@@ -186,6 +186,16 @@ static inline void atomic64_dec(atomic64_t *v)
4794 #define atomic64_cmpxchg(v, old, new) (__cmpxchg_64(old, new, &(v)->counter))
4795 #define atomic64_xchg(v, new) (__xchg_64(new, &(v)->counter))
4796
4797+#define atomic64_read_unchecked(v) atomic64_read(v)
4798+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
4799+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
4800+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
4801+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
4802+#define atomic64_inc_unchecked(v) atomic64_inc(v)
4803+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
4804+#define atomic64_dec_unchecked(v) atomic64_dec(v)
4805+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
4806+
4807 static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
4808 {
4809 int c, old;
4810diff --git a/arch/frv/include/asm/cache.h b/arch/frv/include/asm/cache.h
4811index 2797163..c2a401d 100644
4812--- a/arch/frv/include/asm/cache.h
4813+++ b/arch/frv/include/asm/cache.h
4814@@ -12,10 +12,11 @@
4815 #ifndef __ASM_CACHE_H
4816 #define __ASM_CACHE_H
4817
4818+#include <linux/const.h>
4819
4820 /* bytes per L1 cache line */
4821 #define L1_CACHE_SHIFT (CONFIG_FRV_L1_CACHE_SHIFT)
4822-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4823+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4824
4825 #define __cacheline_aligned __attribute__((aligned(L1_CACHE_BYTES)))
4826 #define ____cacheline_aligned __attribute__((aligned(L1_CACHE_BYTES)))
4827diff --git a/arch/frv/include/asm/kmap_types.h b/arch/frv/include/asm/kmap_types.h
4828index 43901f2..0d8b865 100644
4829--- a/arch/frv/include/asm/kmap_types.h
4830+++ b/arch/frv/include/asm/kmap_types.h
4831@@ -2,6 +2,6 @@
4832 #ifndef _ASM_KMAP_TYPES_H
4833 #define _ASM_KMAP_TYPES_H
4834
4835-#define KM_TYPE_NR 17
4836+#define KM_TYPE_NR 18
4837
4838 #endif
4839diff --git a/arch/frv/mm/elf-fdpic.c b/arch/frv/mm/elf-fdpic.c
4840index 836f147..4cf23f5 100644
4841--- a/arch/frv/mm/elf-fdpic.c
4842+++ b/arch/frv/mm/elf-fdpic.c
4843@@ -61,6 +61,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
4844 {
4845 struct vm_area_struct *vma;
4846 struct vm_unmapped_area_info info;
4847+ unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
4848
4849 if (len > TASK_SIZE)
4850 return -ENOMEM;
4851@@ -73,8 +74,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
4852 if (addr) {
4853 addr = PAGE_ALIGN(addr);
4854 vma = find_vma(current->mm, addr);
4855- if (TASK_SIZE - len >= addr &&
4856- (!vma || addr + len <= vma->vm_start))
4857+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
4858 goto success;
4859 }
4860
4861@@ -85,6 +85,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
4862 info.high_limit = (current->mm->start_stack - 0x00200000);
4863 info.align_mask = 0;
4864 info.align_offset = 0;
4865+ info.threadstack_offset = offset;
4866 addr = vm_unmapped_area(&info);
4867 if (!(addr & ~PAGE_MASK))
4868 goto success;
4869diff --git a/arch/hexagon/include/asm/cache.h b/arch/hexagon/include/asm/cache.h
4870index f4ca594..adc72fd6 100644
4871--- a/arch/hexagon/include/asm/cache.h
4872+++ b/arch/hexagon/include/asm/cache.h
4873@@ -21,9 +21,11 @@
4874 #ifndef __ASM_CACHE_H
4875 #define __ASM_CACHE_H
4876
4877+#include <linux/const.h>
4878+
4879 /* Bytes per L1 cache line */
4880-#define L1_CACHE_SHIFT (5)
4881-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4882+#define L1_CACHE_SHIFT 5
4883+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4884
4885 #define __cacheline_aligned __aligned(L1_CACHE_BYTES)
4886 #define ____cacheline_aligned __aligned(L1_CACHE_BYTES)
4887diff --git a/arch/ia64/Kconfig b/arch/ia64/Kconfig
4888index 7740ab1..17fa8c5 100644
4889--- a/arch/ia64/Kconfig
4890+++ b/arch/ia64/Kconfig
4891@@ -554,6 +554,7 @@ source "drivers/sn/Kconfig"
4892 config KEXEC
4893 bool "kexec system call"
4894 depends on !IA64_HP_SIM && (!SMP || HOTPLUG_CPU)
4895+ depends on !GRKERNSEC_KMEM
4896 help
4897 kexec is a system call that implements the ability to shutdown your
4898 current kernel, and to start another kernel. It is like a reboot
4899diff --git a/arch/ia64/include/asm/atomic.h b/arch/ia64/include/asm/atomic.h
4900index 6e6fe18..a6ae668 100644
4901--- a/arch/ia64/include/asm/atomic.h
4902+++ b/arch/ia64/include/asm/atomic.h
4903@@ -208,6 +208,16 @@ atomic64_add_negative (__s64 i, atomic64_t *v)
4904 #define atomic64_inc(v) atomic64_add(1, (v))
4905 #define atomic64_dec(v) atomic64_sub(1, (v))
4906
4907+#define atomic64_read_unchecked(v) atomic64_read(v)
4908+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
4909+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
4910+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
4911+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
4912+#define atomic64_inc_unchecked(v) atomic64_inc(v)
4913+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
4914+#define atomic64_dec_unchecked(v) atomic64_dec(v)
4915+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
4916+
4917 /* Atomic operations are already serializing */
4918 #define smp_mb__before_atomic_dec() barrier()
4919 #define smp_mb__after_atomic_dec() barrier()
4920diff --git a/arch/ia64/include/asm/cache.h b/arch/ia64/include/asm/cache.h
4921index 988254a..e1ee885 100644
4922--- a/arch/ia64/include/asm/cache.h
4923+++ b/arch/ia64/include/asm/cache.h
4924@@ -1,6 +1,7 @@
4925 #ifndef _ASM_IA64_CACHE_H
4926 #define _ASM_IA64_CACHE_H
4927
4928+#include <linux/const.h>
4929
4930 /*
4931 * Copyright (C) 1998-2000 Hewlett-Packard Co
4932@@ -9,7 +10,7 @@
4933
4934 /* Bytes per L1 (data) cache line. */
4935 #define L1_CACHE_SHIFT CONFIG_IA64_L1_CACHE_SHIFT
4936-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4937+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4938
4939 #ifdef CONFIG_SMP
4940 # define SMP_CACHE_SHIFT L1_CACHE_SHIFT
4941diff --git a/arch/ia64/include/asm/elf.h b/arch/ia64/include/asm/elf.h
4942index 5a83c5c..4d7f553 100644
4943--- a/arch/ia64/include/asm/elf.h
4944+++ b/arch/ia64/include/asm/elf.h
4945@@ -42,6 +42,13 @@
4946 */
4947 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x800000000UL)
4948
4949+#ifdef CONFIG_PAX_ASLR
4950+#define PAX_ELF_ET_DYN_BASE (current->personality == PER_LINUX32 ? 0x08048000UL : 0x4000000000000000UL)
4951+
4952+#define PAX_DELTA_MMAP_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
4953+#define PAX_DELTA_STACK_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
4954+#endif
4955+
4956 #define PT_IA_64_UNWIND 0x70000001
4957
4958 /* IA-64 relocations: */
4959diff --git a/arch/ia64/include/asm/pgalloc.h b/arch/ia64/include/asm/pgalloc.h
4960index 96a8d92..617a1cf 100644
4961--- a/arch/ia64/include/asm/pgalloc.h
4962+++ b/arch/ia64/include/asm/pgalloc.h
4963@@ -39,6 +39,12 @@ pgd_populate(struct mm_struct *mm, pgd_t * pgd_entry, pud_t * pud)
4964 pgd_val(*pgd_entry) = __pa(pud);
4965 }
4966
4967+static inline void
4968+pgd_populate_kernel(struct mm_struct *mm, pgd_t * pgd_entry, pud_t * pud)
4969+{
4970+ pgd_populate(mm, pgd_entry, pud);
4971+}
4972+
4973 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
4974 {
4975 return quicklist_alloc(0, GFP_KERNEL, NULL);
4976@@ -57,6 +63,12 @@ pud_populate(struct mm_struct *mm, pud_t * pud_entry, pmd_t * pmd)
4977 pud_val(*pud_entry) = __pa(pmd);
4978 }
4979
4980+static inline void
4981+pud_populate_kernel(struct mm_struct *mm, pud_t * pud_entry, pmd_t * pmd)
4982+{
4983+ pud_populate(mm, pud_entry, pmd);
4984+}
4985+
4986 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
4987 {
4988 return quicklist_alloc(0, GFP_KERNEL, NULL);
4989diff --git a/arch/ia64/include/asm/pgtable.h b/arch/ia64/include/asm/pgtable.h
4990index 7935115..c0eca6a 100644
4991--- a/arch/ia64/include/asm/pgtable.h
4992+++ b/arch/ia64/include/asm/pgtable.h
4993@@ -12,7 +12,7 @@
4994 * David Mosberger-Tang <davidm@hpl.hp.com>
4995 */
4996
4997-
4998+#include <linux/const.h>
4999 #include <asm/mman.h>
5000 #include <asm/page.h>
5001 #include <asm/processor.h>
5002@@ -142,6 +142,17 @@
5003 #define PAGE_READONLY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
5004 #define PAGE_COPY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
5005 #define PAGE_COPY_EXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RX)
5006+
5007+#ifdef CONFIG_PAX_PAGEEXEC
5008+# define PAGE_SHARED_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RW)
5009+# define PAGE_READONLY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
5010+# define PAGE_COPY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
5011+#else
5012+# define PAGE_SHARED_NOEXEC PAGE_SHARED
5013+# define PAGE_READONLY_NOEXEC PAGE_READONLY
5014+# define PAGE_COPY_NOEXEC PAGE_COPY
5015+#endif
5016+
5017 #define PAGE_GATE __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_X_RX)
5018 #define PAGE_KERNEL __pgprot(__DIRTY_BITS | _PAGE_PL_0 | _PAGE_AR_RWX)
5019 #define PAGE_KERNELRX __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_RX)
5020diff --git a/arch/ia64/include/asm/spinlock.h b/arch/ia64/include/asm/spinlock.h
5021index 45698cd..e8e2dbc 100644
5022--- a/arch/ia64/include/asm/spinlock.h
5023+++ b/arch/ia64/include/asm/spinlock.h
5024@@ -71,7 +71,7 @@ static __always_inline void __ticket_spin_unlock(arch_spinlock_t *lock)
5025 unsigned short *p = (unsigned short *)&lock->lock + 1, tmp;
5026
5027 asm volatile ("ld2.bias %0=[%1]" : "=r"(tmp) : "r"(p));
5028- ACCESS_ONCE(*p) = (tmp + 2) & ~1;
5029+ ACCESS_ONCE_RW(*p) = (tmp + 2) & ~1;
5030 }
5031
5032 static __always_inline void __ticket_spin_unlock_wait(arch_spinlock_t *lock)
5033diff --git a/arch/ia64/include/asm/uaccess.h b/arch/ia64/include/asm/uaccess.h
5034index 449c8c0..18965fb 100644
5035--- a/arch/ia64/include/asm/uaccess.h
5036+++ b/arch/ia64/include/asm/uaccess.h
5037@@ -240,12 +240,24 @@ extern unsigned long __must_check __copy_user (void __user *to, const void __use
5038 static inline unsigned long
5039 __copy_to_user (void __user *to, const void *from, unsigned long count)
5040 {
5041+ if (count > INT_MAX)
5042+ return count;
5043+
5044+ if (!__builtin_constant_p(count))
5045+ check_object_size(from, count, true);
5046+
5047 return __copy_user(to, (__force void __user *) from, count);
5048 }
5049
5050 static inline unsigned long
5051 __copy_from_user (void *to, const void __user *from, unsigned long count)
5052 {
5053+ if (count > INT_MAX)
5054+ return count;
5055+
5056+ if (!__builtin_constant_p(count))
5057+ check_object_size(to, count, false);
5058+
5059 return __copy_user((__force void __user *) to, from, count);
5060 }
5061
5062@@ -255,10 +267,13 @@ __copy_from_user (void *to, const void __user *from, unsigned long count)
5063 ({ \
5064 void __user *__cu_to = (to); \
5065 const void *__cu_from = (from); \
5066- long __cu_len = (n); \
5067+ unsigned long __cu_len = (n); \
5068 \
5069- if (__access_ok(__cu_to, __cu_len, get_fs())) \
5070+ if (__cu_len <= INT_MAX && __access_ok(__cu_to, __cu_len, get_fs())) { \
5071+ if (!__builtin_constant_p(n)) \
5072+ check_object_size(__cu_from, __cu_len, true); \
5073 __cu_len = __copy_user(__cu_to, (__force void __user *) __cu_from, __cu_len); \
5074+ } \
5075 __cu_len; \
5076 })
5077
5078@@ -266,11 +281,14 @@ __copy_from_user (void *to, const void __user *from, unsigned long count)
5079 ({ \
5080 void *__cu_to = (to); \
5081 const void __user *__cu_from = (from); \
5082- long __cu_len = (n); \
5083+ unsigned long __cu_len = (n); \
5084 \
5085 __chk_user_ptr(__cu_from); \
5086- if (__access_ok(__cu_from, __cu_len, get_fs())) \
5087+ if (__cu_len <= INT_MAX && __access_ok(__cu_from, __cu_len, get_fs())) { \
5088+ if (!__builtin_constant_p(n)) \
5089+ check_object_size(__cu_to, __cu_len, false); \
5090 __cu_len = __copy_user((__force void __user *) __cu_to, __cu_from, __cu_len); \
5091+ } \
5092 __cu_len; \
5093 })
5094
5095diff --git a/arch/ia64/kernel/module.c b/arch/ia64/kernel/module.c
5096index 24603be..948052d 100644
5097--- a/arch/ia64/kernel/module.c
5098+++ b/arch/ia64/kernel/module.c
5099@@ -307,8 +307,7 @@ plt_target (struct plt_entry *plt)
5100 void
5101 module_free (struct module *mod, void *module_region)
5102 {
5103- if (mod && mod->arch.init_unw_table &&
5104- module_region == mod->module_init) {
5105+ if (mod && mod->arch.init_unw_table && module_region == mod->module_init_rx) {
5106 unw_remove_unwind_table(mod->arch.init_unw_table);
5107 mod->arch.init_unw_table = NULL;
5108 }
5109@@ -494,15 +493,39 @@ module_frob_arch_sections (Elf_Ehdr *ehdr, Elf_Shdr *sechdrs, char *secstrings,
5110 }
5111
5112 static inline int
5113+in_init_rx (const struct module *mod, uint64_t addr)
5114+{
5115+ return addr - (uint64_t) mod->module_init_rx < mod->init_size_rx;
5116+}
5117+
5118+static inline int
5119+in_init_rw (const struct module *mod, uint64_t addr)
5120+{
5121+ return addr - (uint64_t) mod->module_init_rw < mod->init_size_rw;
5122+}
5123+
5124+static inline int
5125 in_init (const struct module *mod, uint64_t addr)
5126 {
5127- return addr - (uint64_t) mod->module_init < mod->init_size;
5128+ return in_init_rx(mod, addr) || in_init_rw(mod, addr);
5129+}
5130+
5131+static inline int
5132+in_core_rx (const struct module *mod, uint64_t addr)
5133+{
5134+ return addr - (uint64_t) mod->module_core_rx < mod->core_size_rx;
5135+}
5136+
5137+static inline int
5138+in_core_rw (const struct module *mod, uint64_t addr)
5139+{
5140+ return addr - (uint64_t) mod->module_core_rw < mod->core_size_rw;
5141 }
5142
5143 static inline int
5144 in_core (const struct module *mod, uint64_t addr)
5145 {
5146- return addr - (uint64_t) mod->module_core < mod->core_size;
5147+ return in_core_rx(mod, addr) || in_core_rw(mod, addr);
5148 }
5149
5150 static inline int
5151@@ -685,7 +708,14 @@ do_reloc (struct module *mod, uint8_t r_type, Elf64_Sym *sym, uint64_t addend,
5152 break;
5153
5154 case RV_BDREL:
5155- val -= (uint64_t) (in_init(mod, val) ? mod->module_init : mod->module_core);
5156+ if (in_init_rx(mod, val))
5157+ val -= (uint64_t) mod->module_init_rx;
5158+ else if (in_init_rw(mod, val))
5159+ val -= (uint64_t) mod->module_init_rw;
5160+ else if (in_core_rx(mod, val))
5161+ val -= (uint64_t) mod->module_core_rx;
5162+ else if (in_core_rw(mod, val))
5163+ val -= (uint64_t) mod->module_core_rw;
5164 break;
5165
5166 case RV_LTV:
5167@@ -820,15 +850,15 @@ apply_relocate_add (Elf64_Shdr *sechdrs, const char *strtab, unsigned int symind
5168 * addresses have been selected...
5169 */
5170 uint64_t gp;
5171- if (mod->core_size > MAX_LTOFF)
5172+ if (mod->core_size_rx + mod->core_size_rw > MAX_LTOFF)
5173 /*
5174 * This takes advantage of fact that SHF_ARCH_SMALL gets allocated
5175 * at the end of the module.
5176 */
5177- gp = mod->core_size - MAX_LTOFF / 2;
5178+ gp = mod->core_size_rx + mod->core_size_rw - MAX_LTOFF / 2;
5179 else
5180- gp = mod->core_size / 2;
5181- gp = (uint64_t) mod->module_core + ((gp + 7) & -8);
5182+ gp = (mod->core_size_rx + mod->core_size_rw) / 2;
5183+ gp = (uint64_t) mod->module_core_rx + ((gp + 7) & -8);
5184 mod->arch.gp = gp;
5185 DEBUGP("%s: placing gp at 0x%lx\n", __func__, gp);
5186 }
5187diff --git a/arch/ia64/kernel/palinfo.c b/arch/ia64/kernel/palinfo.c
5188index ab33328..f39506c 100644
5189--- a/arch/ia64/kernel/palinfo.c
5190+++ b/arch/ia64/kernel/palinfo.c
5191@@ -980,7 +980,7 @@ static int palinfo_cpu_callback(struct notifier_block *nfb,
5192 return NOTIFY_OK;
5193 }
5194
5195-static struct notifier_block __refdata palinfo_cpu_notifier =
5196+static struct notifier_block palinfo_cpu_notifier =
5197 {
5198 .notifier_call = palinfo_cpu_callback,
5199 .priority = 0,
5200diff --git a/arch/ia64/kernel/sys_ia64.c b/arch/ia64/kernel/sys_ia64.c
5201index 41e33f8..65180b2a 100644
5202--- a/arch/ia64/kernel/sys_ia64.c
5203+++ b/arch/ia64/kernel/sys_ia64.c
5204@@ -28,6 +28,7 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
5205 unsigned long align_mask = 0;
5206 struct mm_struct *mm = current->mm;
5207 struct vm_unmapped_area_info info;
5208+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
5209
5210 if (len > RGN_MAP_LIMIT)
5211 return -ENOMEM;
5212@@ -43,6 +44,13 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
5213 if (REGION_NUMBER(addr) == RGN_HPAGE)
5214 addr = 0;
5215 #endif
5216+
5217+#ifdef CONFIG_PAX_RANDMMAP
5218+ if (mm->pax_flags & MF_PAX_RANDMMAP)
5219+ addr = mm->free_area_cache;
5220+ else
5221+#endif
5222+
5223 if (!addr)
5224 addr = TASK_UNMAPPED_BASE;
5225
5226@@ -61,6 +69,7 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
5227 info.high_limit = TASK_SIZE;
5228 info.align_mask = align_mask;
5229 info.align_offset = 0;
5230+ info.threadstack_offset = offset;
5231 return vm_unmapped_area(&info);
5232 }
5233
5234diff --git a/arch/ia64/kernel/vmlinux.lds.S b/arch/ia64/kernel/vmlinux.lds.S
5235index 0ccb28f..8992469 100644
5236--- a/arch/ia64/kernel/vmlinux.lds.S
5237+++ b/arch/ia64/kernel/vmlinux.lds.S
5238@@ -198,7 +198,7 @@ SECTIONS {
5239 /* Per-cpu data: */
5240 . = ALIGN(PERCPU_PAGE_SIZE);
5241 PERCPU_VADDR(SMP_CACHE_BYTES, PERCPU_ADDR, :percpu)
5242- __phys_per_cpu_start = __per_cpu_load;
5243+ __phys_per_cpu_start = per_cpu_load;
5244 /*
5245 * ensure percpu data fits
5246 * into percpu page size
5247diff --git a/arch/ia64/mm/fault.c b/arch/ia64/mm/fault.c
5248index 7225dad..2a7c8256 100644
5249--- a/arch/ia64/mm/fault.c
5250+++ b/arch/ia64/mm/fault.c
5251@@ -72,6 +72,23 @@ mapped_kernel_page_is_present (unsigned long address)
5252 return pte_present(pte);
5253 }
5254
5255+#ifdef CONFIG_PAX_PAGEEXEC
5256+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
5257+{
5258+ unsigned long i;
5259+
5260+ printk(KERN_ERR "PAX: bytes at PC: ");
5261+ for (i = 0; i < 8; i++) {
5262+ unsigned int c;
5263+ if (get_user(c, (unsigned int *)pc+i))
5264+ printk(KERN_CONT "???????? ");
5265+ else
5266+ printk(KERN_CONT "%08x ", c);
5267+ }
5268+ printk("\n");
5269+}
5270+#endif
5271+
5272 # define VM_READ_BIT 0
5273 # define VM_WRITE_BIT 1
5274 # define VM_EXEC_BIT 2
5275@@ -151,8 +168,21 @@ retry:
5276 if (((isr >> IA64_ISR_R_BIT) & 1UL) && (!(vma->vm_flags & (VM_READ | VM_WRITE))))
5277 goto bad_area;
5278
5279- if ((vma->vm_flags & mask) != mask)
5280+ if ((vma->vm_flags & mask) != mask) {
5281+
5282+#ifdef CONFIG_PAX_PAGEEXEC
5283+ if (!(vma->vm_flags & VM_EXEC) && (mask & VM_EXEC)) {
5284+ if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->cr_iip)
5285+ goto bad_area;
5286+
5287+ up_read(&mm->mmap_sem);
5288+ pax_report_fault(regs, (void *)regs->cr_iip, (void *)regs->r12);
5289+ do_group_exit(SIGKILL);
5290+ }
5291+#endif
5292+
5293 goto bad_area;
5294+ }
5295
5296 /*
5297 * If for any reason at all we couldn't handle the fault, make
5298diff --git a/arch/ia64/mm/hugetlbpage.c b/arch/ia64/mm/hugetlbpage.c
5299index 68232db..6ca80af 100644
5300--- a/arch/ia64/mm/hugetlbpage.c
5301+++ b/arch/ia64/mm/hugetlbpage.c
5302@@ -154,6 +154,7 @@ unsigned long hugetlb_get_unmapped_area(struct file *file, unsigned long addr, u
5303 unsigned long pgoff, unsigned long flags)
5304 {
5305 struct vm_unmapped_area_info info;
5306+ unsigned long offset = gr_rand_threadstack_offset(current->mm, file, flags);
5307
5308 if (len > RGN_MAP_LIMIT)
5309 return -ENOMEM;
5310@@ -177,6 +178,7 @@ unsigned long hugetlb_get_unmapped_area(struct file *file, unsigned long addr, u
5311 info.high_limit = HPAGE_REGION_BASE + RGN_MAP_LIMIT;
5312 info.align_mask = PAGE_MASK & (HPAGE_SIZE - 1);
5313 info.align_offset = 0;
5314+ info.threadstack_offset = offset;
5315 return vm_unmapped_area(&info);
5316 }
5317
5318diff --git a/arch/ia64/mm/init.c b/arch/ia64/mm/init.c
5319index b6f7f43..c04320d 100644
5320--- a/arch/ia64/mm/init.c
5321+++ b/arch/ia64/mm/init.c
5322@@ -120,6 +120,19 @@ ia64_init_addr_space (void)
5323 vma->vm_start = current->thread.rbs_bot & PAGE_MASK;
5324 vma->vm_end = vma->vm_start + PAGE_SIZE;
5325 vma->vm_flags = VM_DATA_DEFAULT_FLAGS|VM_GROWSUP|VM_ACCOUNT;
5326+
5327+#ifdef CONFIG_PAX_PAGEEXEC
5328+ if (current->mm->pax_flags & MF_PAX_PAGEEXEC) {
5329+ vma->vm_flags &= ~VM_EXEC;
5330+
5331+#ifdef CONFIG_PAX_MPROTECT
5332+ if (current->mm->pax_flags & MF_PAX_MPROTECT)
5333+ vma->vm_flags &= ~VM_MAYEXEC;
5334+#endif
5335+
5336+ }
5337+#endif
5338+
5339 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
5340 down_write(&current->mm->mmap_sem);
5341 if (insert_vm_struct(current->mm, vma)) {
5342diff --git a/arch/m32r/include/asm/cache.h b/arch/m32r/include/asm/cache.h
5343index 40b3ee9..8c2c112 100644
5344--- a/arch/m32r/include/asm/cache.h
5345+++ b/arch/m32r/include/asm/cache.h
5346@@ -1,8 +1,10 @@
5347 #ifndef _ASM_M32R_CACHE_H
5348 #define _ASM_M32R_CACHE_H
5349
5350+#include <linux/const.h>
5351+
5352 /* L1 cache line size */
5353 #define L1_CACHE_SHIFT 4
5354-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5355+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5356
5357 #endif /* _ASM_M32R_CACHE_H */
5358diff --git a/arch/m32r/lib/usercopy.c b/arch/m32r/lib/usercopy.c
5359index 82abd15..d95ae5d 100644
5360--- a/arch/m32r/lib/usercopy.c
5361+++ b/arch/m32r/lib/usercopy.c
5362@@ -14,6 +14,9 @@
5363 unsigned long
5364 __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
5365 {
5366+ if ((long)n < 0)
5367+ return n;
5368+
5369 prefetch(from);
5370 if (access_ok(VERIFY_WRITE, to, n))
5371 __copy_user(to,from,n);
5372@@ -23,6 +26,9 @@ __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
5373 unsigned long
5374 __generic_copy_from_user(void *to, const void __user *from, unsigned long n)
5375 {
5376+ if ((long)n < 0)
5377+ return n;
5378+
5379 prefetchw(to);
5380 if (access_ok(VERIFY_READ, from, n))
5381 __copy_user_zeroing(to,from,n);
5382diff --git a/arch/m68k/include/asm/cache.h b/arch/m68k/include/asm/cache.h
5383index 0395c51..5f26031 100644
5384--- a/arch/m68k/include/asm/cache.h
5385+++ b/arch/m68k/include/asm/cache.h
5386@@ -4,9 +4,11 @@
5387 #ifndef __ARCH_M68K_CACHE_H
5388 #define __ARCH_M68K_CACHE_H
5389
5390+#include <linux/const.h>
5391+
5392 /* bytes per L1 cache line */
5393 #define L1_CACHE_SHIFT 4
5394-#define L1_CACHE_BYTES (1<< L1_CACHE_SHIFT)
5395+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5396
5397 #define ARCH_DMA_MINALIGN L1_CACHE_BYTES
5398
5399diff --git a/arch/metag/mm/hugetlbpage.c b/arch/metag/mm/hugetlbpage.c
5400index 0424315..defcca9 100644
5401--- a/arch/metag/mm/hugetlbpage.c
5402+++ b/arch/metag/mm/hugetlbpage.c
5403@@ -205,6 +205,7 @@ hugetlb_get_unmapped_area_new_pmd(unsigned long len)
5404 info.high_limit = TASK_SIZE;
5405 info.align_mask = PAGE_MASK & HUGEPT_MASK;
5406 info.align_offset = 0;
5407+ info.threadstack_offset = 0;
5408 return vm_unmapped_area(&info);
5409 }
5410
5411diff --git a/arch/microblaze/include/asm/cache.h b/arch/microblaze/include/asm/cache.h
5412index 4efe96a..60e8699 100644
5413--- a/arch/microblaze/include/asm/cache.h
5414+++ b/arch/microblaze/include/asm/cache.h
5415@@ -13,11 +13,12 @@
5416 #ifndef _ASM_MICROBLAZE_CACHE_H
5417 #define _ASM_MICROBLAZE_CACHE_H
5418
5419+#include <linux/const.h>
5420 #include <asm/registers.h>
5421
5422 #define L1_CACHE_SHIFT 5
5423 /* word-granular cache in microblaze */
5424-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5425+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5426
5427 #define SMP_CACHE_BYTES L1_CACHE_BYTES
5428
5429diff --git a/arch/mips/Kconfig b/arch/mips/Kconfig
5430index f75ab4a..adc6968 100644
5431--- a/arch/mips/Kconfig
5432+++ b/arch/mips/Kconfig
5433@@ -2283,6 +2283,7 @@ source "kernel/Kconfig.preempt"
5434
5435 config KEXEC
5436 bool "Kexec system call"
5437+ depends on !GRKERNSEC_KMEM
5438 help
5439 kexec is a system call that implements the ability to shutdown your
5440 current kernel, and to start another kernel. It is like a reboot
5441diff --git a/arch/mips/include/asm/atomic.h b/arch/mips/include/asm/atomic.h
5442index 08b6079..8b554d2 100644
5443--- a/arch/mips/include/asm/atomic.h
5444+++ b/arch/mips/include/asm/atomic.h
5445@@ -21,15 +21,39 @@
5446 #include <asm/cmpxchg.h>
5447 #include <asm/war.h>
5448
5449+#ifdef CONFIG_GENERIC_ATOMIC64
5450+#include <asm-generic/atomic64.h>
5451+#endif
5452+
5453 #define ATOMIC_INIT(i) { (i) }
5454
5455+#ifdef CONFIG_64BIT
5456+#define _ASM_EXTABLE(from, to) \
5457+" .section __ex_table,\"a\"\n" \
5458+" .dword " #from ", " #to"\n" \
5459+" .previous\n"
5460+#else
5461+#define _ASM_EXTABLE(from, to) \
5462+" .section __ex_table,\"a\"\n" \
5463+" .word " #from ", " #to"\n" \
5464+" .previous\n"
5465+#endif
5466+
5467 /*
5468 * atomic_read - read atomic variable
5469 * @v: pointer of type atomic_t
5470 *
5471 * Atomically reads the value of @v.
5472 */
5473-#define atomic_read(v) (*(volatile int *)&(v)->counter)
5474+static inline int atomic_read(const atomic_t *v)
5475+{
5476+ return (*(volatile const int *) &v->counter);
5477+}
5478+
5479+static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
5480+{
5481+ return (*(volatile const int *) &v->counter);
5482+}
5483
5484 /*
5485 * atomic_set - set atomic variable
5486@@ -38,7 +62,15 @@
5487 *
5488 * Atomically sets the value of @v to @i.
5489 */
5490-#define atomic_set(v, i) ((v)->counter = (i))
5491+static inline void atomic_set(atomic_t *v, int i)
5492+{
5493+ v->counter = i;
5494+}
5495+
5496+static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
5497+{
5498+ v->counter = i;
5499+}
5500
5501 /*
5502 * atomic_add - add integer to atomic variable
5503@@ -47,7 +79,67 @@
5504 *
5505 * Atomically adds @i to @v.
5506 */
5507-static __inline__ void atomic_add(int i, atomic_t * v)
5508+static __inline__ void atomic_add(int i, atomic_t *v)
5509+{
5510+ int temp;
5511+
5512+ if (kernel_uses_llsc && R10000_LLSC_WAR) {
5513+ __asm__ __volatile__(
5514+ " .set mips3 \n"
5515+ "1: ll %0, %1 # atomic_add \n"
5516+#ifdef CONFIG_PAX_REFCOUNT
5517+ /* Exception on overflow. */
5518+ "2: add %0, %2 \n"
5519+#else
5520+ " addu %0, %2 \n"
5521+#endif
5522+ " sc %0, %1 \n"
5523+ " beqzl %0, 1b \n"
5524+#ifdef CONFIG_PAX_REFCOUNT
5525+ "3: \n"
5526+ _ASM_EXTABLE(2b, 3b)
5527+#endif
5528+ " .set mips0 \n"
5529+ : "=&r" (temp), "+m" (v->counter)
5530+ : "Ir" (i));
5531+ } else if (kernel_uses_llsc) {
5532+ __asm__ __volatile__(
5533+ " .set mips3 \n"
5534+ "1: ll %0, %1 # atomic_add \n"
5535+#ifdef CONFIG_PAX_REFCOUNT
5536+ /* Exception on overflow. */
5537+ "2: add %0, %2 \n"
5538+#else
5539+ " addu %0, %2 \n"
5540+#endif
5541+ " sc %0, %1 \n"
5542+ " beqz %0, 1b \n"
5543+#ifdef CONFIG_PAX_REFCOUNT
5544+ "3: \n"
5545+ _ASM_EXTABLE(2b, 3b)
5546+#endif
5547+ " .set mips0 \n"
5548+ : "=&r" (temp), "+m" (v->counter)
5549+ : "Ir" (i));
5550+ } else {
5551+ unsigned long flags;
5552+
5553+ raw_local_irq_save(flags);
5554+ __asm__ __volatile__(
5555+#ifdef CONFIG_PAX_REFCOUNT
5556+ /* Exception on overflow. */
5557+ "1: add %0, %1 \n"
5558+ "2: \n"
5559+ _ASM_EXTABLE(1b, 2b)
5560+#else
5561+ " addu %0, %1 \n"
5562+#endif
5563+ : "+r" (v->counter) : "Ir" (i));
5564+ raw_local_irq_restore(flags);
5565+ }
5566+}
5567+
5568+static __inline__ void atomic_add_unchecked(int i, atomic_unchecked_t *v)
5569 {
5570 if (kernel_uses_llsc && R10000_LLSC_WAR) {
5571 int temp;
5572@@ -90,7 +182,67 @@ static __inline__ void atomic_add(int i, atomic_t * v)
5573 *
5574 * Atomically subtracts @i from @v.
5575 */
5576-static __inline__ void atomic_sub(int i, atomic_t * v)
5577+static __inline__ void atomic_sub(int i, atomic_t *v)
5578+{
5579+ int temp;
5580+
5581+ if (kernel_uses_llsc && R10000_LLSC_WAR) {
5582+ __asm__ __volatile__(
5583+ " .set mips3 \n"
5584+ "1: ll %0, %1 # atomic64_sub \n"
5585+#ifdef CONFIG_PAX_REFCOUNT
5586+ /* Exception on overflow. */
5587+ "2: sub %0, %2 \n"
5588+#else
5589+ " subu %0, %2 \n"
5590+#endif
5591+ " sc %0, %1 \n"
5592+ " beqzl %0, 1b \n"
5593+#ifdef CONFIG_PAX_REFCOUNT
5594+ "3: \n"
5595+ _ASM_EXTABLE(2b, 3b)
5596+#endif
5597+ " .set mips0 \n"
5598+ : "=&r" (temp), "+m" (v->counter)
5599+ : "Ir" (i));
5600+ } else if (kernel_uses_llsc) {
5601+ __asm__ __volatile__(
5602+ " .set mips3 \n"
5603+ "1: ll %0, %1 # atomic64_sub \n"
5604+#ifdef CONFIG_PAX_REFCOUNT
5605+ /* Exception on overflow. */
5606+ "2: sub %0, %2 \n"
5607+#else
5608+ " subu %0, %2 \n"
5609+#endif
5610+ " sc %0, %1 \n"
5611+ " beqz %0, 1b \n"
5612+#ifdef CONFIG_PAX_REFCOUNT
5613+ "3: \n"
5614+ _ASM_EXTABLE(2b, 3b)
5615+#endif
5616+ " .set mips0 \n"
5617+ : "=&r" (temp), "+m" (v->counter)
5618+ : "Ir" (i));
5619+ } else {
5620+ unsigned long flags;
5621+
5622+ raw_local_irq_save(flags);
5623+ __asm__ __volatile__(
5624+#ifdef CONFIG_PAX_REFCOUNT
5625+ /* Exception on overflow. */
5626+ "1: sub %0, %1 \n"
5627+ "2: \n"
5628+ _ASM_EXTABLE(1b, 2b)
5629+#else
5630+ " subu %0, %1 \n"
5631+#endif
5632+ : "+r" (v->counter) : "Ir" (i));
5633+ raw_local_irq_restore(flags);
5634+ }
5635+}
5636+
5637+static __inline__ void atomic_sub_unchecked(long i, atomic_unchecked_t *v)
5638 {
5639 if (kernel_uses_llsc && R10000_LLSC_WAR) {
5640 int temp;
5641@@ -129,7 +281,93 @@ static __inline__ void atomic_sub(int i, atomic_t * v)
5642 /*
5643 * Same as above, but return the result value
5644 */
5645-static __inline__ int atomic_add_return(int i, atomic_t * v)
5646+static __inline__ int atomic_add_return(int i, atomic_t *v)
5647+{
5648+ int result;
5649+ int temp;
5650+
5651+ smp_mb__before_llsc();
5652+
5653+ if (kernel_uses_llsc && R10000_LLSC_WAR) {
5654+ __asm__ __volatile__(
5655+ " .set mips3 \n"
5656+ "1: ll %1, %2 # atomic_add_return \n"
5657+#ifdef CONFIG_PAX_REFCOUNT
5658+ "2: add %0, %1, %3 \n"
5659+#else
5660+ " addu %0, %1, %3 \n"
5661+#endif
5662+ " sc %0, %2 \n"
5663+ " beqzl %0, 1b \n"
5664+#ifdef CONFIG_PAX_REFCOUNT
5665+ " b 4f \n"
5666+ " .set noreorder \n"
5667+ "3: b 5f \n"
5668+ " move %0, %1 \n"
5669+ " .set reorder \n"
5670+ _ASM_EXTABLE(2b, 3b)
5671+#endif
5672+ "4: addu %0, %1, %3 \n"
5673+#ifdef CONFIG_PAX_REFCOUNT
5674+ "5: \n"
5675+#endif
5676+ " .set mips0 \n"
5677+ : "=&r" (result), "=&r" (temp), "+m" (v->counter)
5678+ : "Ir" (i));
5679+ } else if (kernel_uses_llsc) {
5680+ __asm__ __volatile__(
5681+ " .set mips3 \n"
5682+ "1: ll %1, %2 # atomic_add_return \n"
5683+#ifdef CONFIG_PAX_REFCOUNT
5684+ "2: add %0, %1, %3 \n"
5685+#else
5686+ " addu %0, %1, %3 \n"
5687+#endif
5688+ " sc %0, %2 \n"
5689+ " bnez %0, 4f \n"
5690+ " b 1b \n"
5691+#ifdef CONFIG_PAX_REFCOUNT
5692+ " .set noreorder \n"
5693+ "3: b 5f \n"
5694+ " move %0, %1 \n"
5695+ " .set reorder \n"
5696+ _ASM_EXTABLE(2b, 3b)
5697+#endif
5698+ "4: addu %0, %1, %3 \n"
5699+#ifdef CONFIG_PAX_REFCOUNT
5700+ "5: \n"
5701+#endif
5702+ " .set mips0 \n"
5703+ : "=&r" (result), "=&r" (temp), "+m" (v->counter)
5704+ : "Ir" (i));
5705+ } else {
5706+ unsigned long flags;
5707+
5708+ raw_local_irq_save(flags);
5709+ __asm__ __volatile__(
5710+ " lw %0, %1 \n"
5711+#ifdef CONFIG_PAX_REFCOUNT
5712+ /* Exception on overflow. */
5713+ "1: add %0, %2 \n"
5714+#else
5715+ " addu %0, %2 \n"
5716+#endif
5717+ " sw %0, %1 \n"
5718+#ifdef CONFIG_PAX_REFCOUNT
5719+ /* Note: Dest reg is not modified on overflow */
5720+ "2: \n"
5721+ _ASM_EXTABLE(1b, 2b)
5722+#endif
5723+ : "=&r" (result), "+m" (v->counter) : "Ir" (i));
5724+ raw_local_irq_restore(flags);
5725+ }
5726+
5727+ smp_llsc_mb();
5728+
5729+ return result;
5730+}
5731+
5732+static __inline__ int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
5733 {
5734 int result;
5735
5736@@ -178,7 +416,93 @@ static __inline__ int atomic_add_return(int i, atomic_t * v)
5737 return result;
5738 }
5739
5740-static __inline__ int atomic_sub_return(int i, atomic_t * v)
5741+static __inline__ int atomic_sub_return(int i, atomic_t *v)
5742+{
5743+ int result;
5744+ int temp;
5745+
5746+ smp_mb__before_llsc();
5747+
5748+ if (kernel_uses_llsc && R10000_LLSC_WAR) {
5749+ __asm__ __volatile__(
5750+ " .set mips3 \n"
5751+ "1: ll %1, %2 # atomic_sub_return \n"
5752+#ifdef CONFIG_PAX_REFCOUNT
5753+ "2: sub %0, %1, %3 \n"
5754+#else
5755+ " subu %0, %1, %3 \n"
5756+#endif
5757+ " sc %0, %2 \n"
5758+ " beqzl %0, 1b \n"
5759+#ifdef CONFIG_PAX_REFCOUNT
5760+ " b 4f \n"
5761+ " .set noreorder \n"
5762+ "3: b 5f \n"
5763+ " move %0, %1 \n"
5764+ " .set reorder \n"
5765+ _ASM_EXTABLE(2b, 3b)
5766+#endif
5767+ "4: subu %0, %1, %3 \n"
5768+#ifdef CONFIG_PAX_REFCOUNT
5769+ "5: \n"
5770+#endif
5771+ " .set mips0 \n"
5772+ : "=&r" (result), "=&r" (temp), "=m" (v->counter)
5773+ : "Ir" (i), "m" (v->counter)
5774+ : "memory");
5775+ } else if (kernel_uses_llsc) {
5776+ __asm__ __volatile__(
5777+ " .set mips3 \n"
5778+ "1: ll %1, %2 # atomic_sub_return \n"
5779+#ifdef CONFIG_PAX_REFCOUNT
5780+ "2: sub %0, %1, %3 \n"
5781+#else
5782+ " subu %0, %1, %3 \n"
5783+#endif
5784+ " sc %0, %2 \n"
5785+ " bnez %0, 4f \n"
5786+ " b 1b \n"
5787+#ifdef CONFIG_PAX_REFCOUNT
5788+ " .set noreorder \n"
5789+ "3: b 5f \n"
5790+ " move %0, %1 \n"
5791+ " .set reorder \n"
5792+ _ASM_EXTABLE(2b, 3b)
5793+#endif
5794+ "4: subu %0, %1, %3 \n"
5795+#ifdef CONFIG_PAX_REFCOUNT
5796+ "5: \n"
5797+#endif
5798+ " .set mips0 \n"
5799+ : "=&r" (result), "=&r" (temp), "+m" (v->counter)
5800+ : "Ir" (i));
5801+ } else {
5802+ unsigned long flags;
5803+
5804+ raw_local_irq_save(flags);
5805+ __asm__ __volatile__(
5806+ " lw %0, %1 \n"
5807+#ifdef CONFIG_PAX_REFCOUNT
5808+ /* Exception on overflow. */
5809+ "1: sub %0, %2 \n"
5810+#else
5811+ " subu %0, %2 \n"
5812+#endif
5813+ " sw %0, %1 \n"
5814+#ifdef CONFIG_PAX_REFCOUNT
5815+ /* Note: Dest reg is not modified on overflow */
5816+ "2: \n"
5817+ _ASM_EXTABLE(1b, 2b)
5818+#endif
5819+ : "=&r" (result), "+m" (v->counter) : "Ir" (i));
5820+ raw_local_irq_restore(flags);
5821+ }
5822+
5823+ smp_llsc_mb();
5824+
5825+ return result;
5826+}
5827+static __inline__ int atomic_sub_return_unchecked(int i, atomic_unchecked_t *v)
5828 {
5829 int result;
5830
5831@@ -238,7 +562,7 @@ static __inline__ int atomic_sub_return(int i, atomic_t * v)
5832 * Atomically test @v and subtract @i if @v is greater or equal than @i.
5833 * The function returns the old value of @v minus @i.
5834 */
5835-static __inline__ int atomic_sub_if_positive(int i, atomic_t * v)
5836+static __inline__ int atomic_sub_if_positive(int i, atomic_t *v)
5837 {
5838 int result;
5839
5840@@ -295,8 +619,26 @@ static __inline__ int atomic_sub_if_positive(int i, atomic_t * v)
5841 return result;
5842 }
5843
5844-#define atomic_cmpxchg(v, o, n) (cmpxchg(&((v)->counter), (o), (n)))
5845-#define atomic_xchg(v, new) (xchg(&((v)->counter), (new)))
5846+static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
5847+{
5848+ return cmpxchg(&v->counter, old, new);
5849+}
5850+
5851+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old,
5852+ int new)
5853+{
5854+ return cmpxchg(&(v->counter), old, new);
5855+}
5856+
5857+static inline int atomic_xchg(atomic_t *v, int new)
5858+{
5859+ return xchg(&v->counter, new);
5860+}
5861+
5862+static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
5863+{
5864+ return xchg(&(v->counter), new);
5865+}
5866
5867 /**
5868 * __atomic_add_unless - add unless the number is a given value
5869@@ -324,6 +666,10 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
5870
5871 #define atomic_dec_return(v) atomic_sub_return(1, (v))
5872 #define atomic_inc_return(v) atomic_add_return(1, (v))
5873+static __inline__ int atomic_inc_return_unchecked(atomic_unchecked_t *v)
5874+{
5875+ return atomic_add_return_unchecked(1, v);
5876+}
5877
5878 /*
5879 * atomic_sub_and_test - subtract value from variable and test result
5880@@ -345,6 +691,10 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
5881 * other cases.
5882 */
5883 #define atomic_inc_and_test(v) (atomic_inc_return(v) == 0)
5884+static __inline__ int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
5885+{
5886+ return atomic_add_return_unchecked(1, v) == 0;
5887+}
5888
5889 /*
5890 * atomic_dec_and_test - decrement by 1 and test
5891@@ -369,6 +719,10 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
5892 * Atomically increments @v by 1.
5893 */
5894 #define atomic_inc(v) atomic_add(1, (v))
5895+static __inline__ void atomic_inc_unchecked(atomic_unchecked_t *v)
5896+{
5897+ atomic_add_unchecked(1, v);
5898+}
5899
5900 /*
5901 * atomic_dec - decrement and test
5902@@ -377,6 +731,10 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
5903 * Atomically decrements @v by 1.
5904 */
5905 #define atomic_dec(v) atomic_sub(1, (v))
5906+static __inline__ void atomic_dec_unchecked(atomic_unchecked_t *v)
5907+{
5908+ atomic_sub_unchecked(1, v);
5909+}
5910
5911 /*
5912 * atomic_add_negative - add and test if negative
5913@@ -398,14 +756,30 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
5914 * @v: pointer of type atomic64_t
5915 *
5916 */
5917-#define atomic64_read(v) (*(volatile long *)&(v)->counter)
5918+static inline long atomic64_read(const atomic64_t *v)
5919+{
5920+ return (*(volatile const long *) &v->counter);
5921+}
5922+
5923+static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
5924+{
5925+ return (*(volatile const long *) &v->counter);
5926+}
5927
5928 /*
5929 * atomic64_set - set atomic variable
5930 * @v: pointer of type atomic64_t
5931 * @i: required value
5932 */
5933-#define atomic64_set(v, i) ((v)->counter = (i))
5934+static inline void atomic64_set(atomic64_t *v, long i)
5935+{
5936+ v->counter = i;
5937+}
5938+
5939+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
5940+{
5941+ v->counter = i;
5942+}
5943
5944 /*
5945 * atomic64_add - add integer to atomic variable
5946@@ -414,7 +788,66 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
5947 *
5948 * Atomically adds @i to @v.
5949 */
5950-static __inline__ void atomic64_add(long i, atomic64_t * v)
5951+static __inline__ void atomic64_add(long i, atomic64_t *v)
5952+{
5953+ long temp;
5954+
5955+ if (kernel_uses_llsc && R10000_LLSC_WAR) {
5956+ __asm__ __volatile__(
5957+ " .set mips3 \n"
5958+ "1: lld %0, %1 # atomic64_add \n"
5959+#ifdef CONFIG_PAX_REFCOUNT
5960+ /* Exception on overflow. */
5961+ "2: dadd %0, %2 \n"
5962+#else
5963+ " daddu %0, %2 \n"
5964+#endif
5965+ " scd %0, %1 \n"
5966+ " beqzl %0, 1b \n"
5967+#ifdef CONFIG_PAX_REFCOUNT
5968+ "3: \n"
5969+ _ASM_EXTABLE(2b, 3b)
5970+#endif
5971+ " .set mips0 \n"
5972+ : "=&r" (temp), "+m" (v->counter)
5973+ : "Ir" (i));
5974+ } else if (kernel_uses_llsc) {
5975+ __asm__ __volatile__(
5976+ " .set mips3 \n"
5977+ "1: lld %0, %1 # atomic64_add \n"
5978+#ifdef CONFIG_PAX_REFCOUNT
5979+ /* Exception on overflow. */
5980+ "2: dadd %0, %2 \n"
5981+#else
5982+ " daddu %0, %2 \n"
5983+#endif
5984+ " scd %0, %1 \n"
5985+ " beqz %0, 1b \n"
5986+#ifdef CONFIG_PAX_REFCOUNT
5987+ "3: \n"
5988+ _ASM_EXTABLE(2b, 3b)
5989+#endif
5990+ " .set mips0 \n"
5991+ : "=&r" (temp), "+m" (v->counter)
5992+ : "Ir" (i));
5993+ } else {
5994+ unsigned long flags;
5995+
5996+ raw_local_irq_save(flags);
5997+ __asm__ __volatile__(
5998+#ifdef CONFIG_PAX_REFCOUNT
5999+ /* Exception on overflow. */
6000+ "1: dadd %0, %1 \n"
6001+ "2: \n"
6002+ _ASM_EXTABLE(1b, 2b)
6003+#else
6004+ " daddu %0, %1 \n"
6005+#endif
6006+ : "+r" (v->counter) : "Ir" (i));
6007+ raw_local_irq_restore(flags);
6008+ }
6009+}
6010+static __inline__ void atomic64_add_unchecked(long i, atomic64_unchecked_t *v)
6011 {
6012 if (kernel_uses_llsc && R10000_LLSC_WAR) {
6013 long temp;
6014@@ -457,7 +890,67 @@ static __inline__ void atomic64_add(long i, atomic64_t * v)
6015 *
6016 * Atomically subtracts @i from @v.
6017 */
6018-static __inline__ void atomic64_sub(long i, atomic64_t * v)
6019+static __inline__ void atomic64_sub(long i, atomic64_t *v)
6020+{
6021+ long temp;
6022+
6023+ if (kernel_uses_llsc && R10000_LLSC_WAR) {
6024+ __asm__ __volatile__(
6025+ " .set mips3 \n"
6026+ "1: lld %0, %1 # atomic64_sub \n"
6027+#ifdef CONFIG_PAX_REFCOUNT
6028+ /* Exception on overflow. */
6029+ "2: dsub %0, %2 \n"
6030+#else
6031+ " dsubu %0, %2 \n"
6032+#endif
6033+ " scd %0, %1 \n"
6034+ " beqzl %0, 1b \n"
6035+#ifdef CONFIG_PAX_REFCOUNT
6036+ "3: \n"
6037+ _ASM_EXTABLE(2b, 3b)
6038+#endif
6039+ " .set mips0 \n"
6040+ : "=&r" (temp), "+m" (v->counter)
6041+ : "Ir" (i));
6042+ } else if (kernel_uses_llsc) {
6043+ __asm__ __volatile__(
6044+ " .set mips3 \n"
6045+ "1: lld %0, %1 # atomic64_sub \n"
6046+#ifdef CONFIG_PAX_REFCOUNT
6047+ /* Exception on overflow. */
6048+ "2: dsub %0, %2 \n"
6049+#else
6050+ " dsubu %0, %2 \n"
6051+#endif
6052+ " scd %0, %1 \n"
6053+ " beqz %0, 1b \n"
6054+#ifdef CONFIG_PAX_REFCOUNT
6055+ "3: \n"
6056+ _ASM_EXTABLE(2b, 3b)
6057+#endif
6058+ " .set mips0 \n"
6059+ : "=&r" (temp), "+m" (v->counter)
6060+ : "Ir" (i));
6061+ } else {
6062+ unsigned long flags;
6063+
6064+ raw_local_irq_save(flags);
6065+ __asm__ __volatile__(
6066+#ifdef CONFIG_PAX_REFCOUNT
6067+ /* Exception on overflow. */
6068+ "1: dsub %0, %1 \n"
6069+ "2: \n"
6070+ _ASM_EXTABLE(1b, 2b)
6071+#else
6072+ " dsubu %0, %1 \n"
6073+#endif
6074+ : "+r" (v->counter) : "Ir" (i));
6075+ raw_local_irq_restore(flags);
6076+ }
6077+}
6078+
6079+static __inline__ void atomic64_sub_unchecked(long i, atomic64_unchecked_t *v)
6080 {
6081 if (kernel_uses_llsc && R10000_LLSC_WAR) {
6082 long temp;
6083@@ -496,7 +989,93 @@ static __inline__ void atomic64_sub(long i, atomic64_t * v)
6084 /*
6085 * Same as above, but return the result value
6086 */
6087-static __inline__ long atomic64_add_return(long i, atomic64_t * v)
6088+static __inline__ long atomic64_add_return(long i, atomic64_t *v)
6089+{
6090+ long result;
6091+ long temp;
6092+
6093+ smp_mb__before_llsc();
6094+
6095+ if (kernel_uses_llsc && R10000_LLSC_WAR) {
6096+ __asm__ __volatile__(
6097+ " .set mips3 \n"
6098+ "1: lld %1, %2 # atomic64_add_return \n"
6099+#ifdef CONFIG_PAX_REFCOUNT
6100+ "2: dadd %0, %1, %3 \n"
6101+#else
6102+ " daddu %0, %1, %3 \n"
6103+#endif
6104+ " scd %0, %2 \n"
6105+ " beqzl %0, 1b \n"
6106+#ifdef CONFIG_PAX_REFCOUNT
6107+ " b 4f \n"
6108+ " .set noreorder \n"
6109+ "3: b 5f \n"
6110+ " move %0, %1 \n"
6111+ " .set reorder \n"
6112+ _ASM_EXTABLE(2b, 3b)
6113+#endif
6114+ "4: daddu %0, %1, %3 \n"
6115+#ifdef CONFIG_PAX_REFCOUNT
6116+ "5: \n"
6117+#endif
6118+ " .set mips0 \n"
6119+ : "=&r" (result), "=&r" (temp), "+m" (v->counter)
6120+ : "Ir" (i));
6121+ } else if (kernel_uses_llsc) {
6122+ __asm__ __volatile__(
6123+ " .set mips3 \n"
6124+ "1: lld %1, %2 # atomic64_add_return \n"
6125+#ifdef CONFIG_PAX_REFCOUNT
6126+ "2: dadd %0, %1, %3 \n"
6127+#else
6128+ " daddu %0, %1, %3 \n"
6129+#endif
6130+ " scd %0, %2 \n"
6131+ " bnez %0, 4f \n"
6132+ " b 1b \n"
6133+#ifdef CONFIG_PAX_REFCOUNT
6134+ " .set noreorder \n"
6135+ "3: b 5f \n"
6136+ " move %0, %1 \n"
6137+ " .set reorder \n"
6138+ _ASM_EXTABLE(2b, 3b)
6139+#endif
6140+ "4: daddu %0, %1, %3 \n"
6141+#ifdef CONFIG_PAX_REFCOUNT
6142+ "5: \n"
6143+#endif
6144+ " .set mips0 \n"
6145+ : "=&r" (result), "=&r" (temp), "=m" (v->counter)
6146+ : "Ir" (i), "m" (v->counter)
6147+ : "memory");
6148+ } else {
6149+ unsigned long flags;
6150+
6151+ raw_local_irq_save(flags);
6152+ __asm__ __volatile__(
6153+ " ld %0, %1 \n"
6154+#ifdef CONFIG_PAX_REFCOUNT
6155+ /* Exception on overflow. */
6156+ "1: dadd %0, %2 \n"
6157+#else
6158+ " daddu %0, %2 \n"
6159+#endif
6160+ " sd %0, %1 \n"
6161+#ifdef CONFIG_PAX_REFCOUNT
6162+ /* Note: Dest reg is not modified on overflow */
6163+ "2: \n"
6164+ _ASM_EXTABLE(1b, 2b)
6165+#endif
6166+ : "=&r" (result), "+m" (v->counter) : "Ir" (i));
6167+ raw_local_irq_restore(flags);
6168+ }
6169+
6170+ smp_llsc_mb();
6171+
6172+ return result;
6173+}
6174+static __inline__ long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
6175 {
6176 long result;
6177
6178@@ -546,7 +1125,97 @@ static __inline__ long atomic64_add_return(long i, atomic64_t * v)
6179 return result;
6180 }
6181
6182-static __inline__ long atomic64_sub_return(long i, atomic64_t * v)
6183+static __inline__ long atomic64_sub_return(long i, atomic64_t *v)
6184+{
6185+ long result;
6186+ long temp;
6187+
6188+ smp_mb__before_llsc();
6189+
6190+ if (kernel_uses_llsc && R10000_LLSC_WAR) {
6191+ long temp;
6192+
6193+ __asm__ __volatile__(
6194+ " .set mips3 \n"
6195+ "1: lld %1, %2 # atomic64_sub_return \n"
6196+#ifdef CONFIG_PAX_REFCOUNT
6197+ "2: dsub %0, %1, %3 \n"
6198+#else
6199+ " dsubu %0, %1, %3 \n"
6200+#endif
6201+ " scd %0, %2 \n"
6202+ " beqzl %0, 1b \n"
6203+#ifdef CONFIG_PAX_REFCOUNT
6204+ " b 4f \n"
6205+ " .set noreorder \n"
6206+ "3: b 5f \n"
6207+ " move %0, %1 \n"
6208+ " .set reorder \n"
6209+ _ASM_EXTABLE(2b, 3b)
6210+#endif
6211+ "4: dsubu %0, %1, %3 \n"
6212+#ifdef CONFIG_PAX_REFCOUNT
6213+ "5: \n"
6214+#endif
6215+ " .set mips0 \n"
6216+ : "=&r" (result), "=&r" (temp), "=m" (v->counter)
6217+ : "Ir" (i), "m" (v->counter)
6218+ : "memory");
6219+ } else if (kernel_uses_llsc) {
6220+ __asm__ __volatile__(
6221+ " .set mips3 \n"
6222+ "1: lld %1, %2 # atomic64_sub_return \n"
6223+#ifdef CONFIG_PAX_REFCOUNT
6224+ "2: dsub %0, %1, %3 \n"
6225+#else
6226+ " dsubu %0, %1, %3 \n"
6227+#endif
6228+ " scd %0, %2 \n"
6229+ " bnez %0, 4f \n"
6230+ " b 1b \n"
6231+#ifdef CONFIG_PAX_REFCOUNT
6232+ " .set noreorder \n"
6233+ "3: b 5f \n"
6234+ " move %0, %1 \n"
6235+ " .set reorder \n"
6236+ _ASM_EXTABLE(2b, 3b)
6237+#endif
6238+ "4: dsubu %0, %1, %3 \n"
6239+#ifdef CONFIG_PAX_REFCOUNT
6240+ "5: \n"
6241+#endif
6242+ " .set mips0 \n"
6243+ : "=&r" (result), "=&r" (temp), "=m" (v->counter)
6244+ : "Ir" (i), "m" (v->counter)
6245+ : "memory");
6246+ } else {
6247+ unsigned long flags;
6248+
6249+ raw_local_irq_save(flags);
6250+ __asm__ __volatile__(
6251+ " ld %0, %1 \n"
6252+#ifdef CONFIG_PAX_REFCOUNT
6253+ /* Exception on overflow. */
6254+ "1: dsub %0, %2 \n"
6255+#else
6256+ " dsubu %0, %2 \n"
6257+#endif
6258+ " sd %0, %1 \n"
6259+#ifdef CONFIG_PAX_REFCOUNT
6260+ /* Note: Dest reg is not modified on overflow */
6261+ "2: \n"
6262+ _ASM_EXTABLE(1b, 2b)
6263+#endif
6264+ : "=&r" (result), "+m" (v->counter) : "Ir" (i));
6265+ raw_local_irq_restore(flags);
6266+ }
6267+
6268+ smp_llsc_mb();
6269+
6270+ return result;
6271+}
6272+
6273+static __inline__ long atomic64_sub_return_unchecked(long i, atomic64_unchecked_t *v)
6274 {
6275 long result;
6276
6277@@ -605,7 +1274,7 @@ static __inline__ long atomic64_sub_return(long i, atomic64_t * v)
6278 * Atomically test @v and subtract @i if @v is greater or equal than @i.
6279 * The function returns the old value of @v minus @i.
6280 */
6281-static __inline__ long atomic64_sub_if_positive(long i, atomic64_t * v)
6282+static __inline__ long atomic64_sub_if_positive(long i, atomic64_t *v)
6283 {
6284 long result;
6285
6286@@ -662,9 +1331,26 @@ static __inline__ long atomic64_sub_if_positive(long i, atomic64_t * v)
6287 return result;
6288 }
6289
6290-#define atomic64_cmpxchg(v, o, n) \
6291- ((__typeof__((v)->counter))cmpxchg(&((v)->counter), (o), (n)))
6292-#define atomic64_xchg(v, new) (xchg(&((v)->counter), (new)))
6293+static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
6294+{
6295+ return cmpxchg(&v->counter, old, new);
6296+}
6297+
6298+static inline long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long old,
6299+ long new)
6300+{
6301+ return cmpxchg(&(v->counter), old, new);
6302+}
6303+
6304+static inline long atomic64_xchg(atomic64_t *v, long new)
6305+{
6306+ return xchg(&v->counter, new);
6307+}
6308+
6309+static inline long atomic64_xchg_unchecked(atomic64_unchecked_t *v, long new)
6310+{
6311+ return xchg(&(v->counter), new);
6312+}
6313
6314 /**
6315 * atomic64_add_unless - add unless the number is a given value
6316@@ -694,6 +1380,7 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
6317
6318 #define atomic64_dec_return(v) atomic64_sub_return(1, (v))
6319 #define atomic64_inc_return(v) atomic64_add_return(1, (v))
6320+#define atomic64_inc_return_unchecked(v) atomic64_add_return_unchecked(1, (v))
6321
6322 /*
6323 * atomic64_sub_and_test - subtract value from variable and test result
6324@@ -715,6 +1402,7 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
6325 * other cases.
6326 */
6327 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
6328+#define atomic64_inc_and_test_unchecked(v) atomic64_add_return_unchecked(1, (v)) == 0)
6329
6330 /*
6331 * atomic64_dec_and_test - decrement by 1 and test
6332@@ -739,6 +1427,7 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
6333 * Atomically increments @v by 1.
6334 */
6335 #define atomic64_inc(v) atomic64_add(1, (v))
6336+#define atomic64_inc_unchecked(v) atomic64_add_unchecked(1, (v))
6337
6338 /*
6339 * atomic64_dec - decrement and test
6340@@ -747,6 +1436,7 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
6341 * Atomically decrements @v by 1.
6342 */
6343 #define atomic64_dec(v) atomic64_sub(1, (v))
6344+#define atomic64_dec_unchecked(v) atomic64_sub_unchecked(1, (v))
6345
6346 /*
6347 * atomic64_add_negative - add and test if negative
6348diff --git a/arch/mips/include/asm/cache.h b/arch/mips/include/asm/cache.h
6349index b4db69f..8f3b093 100644
6350--- a/arch/mips/include/asm/cache.h
6351+++ b/arch/mips/include/asm/cache.h
6352@@ -9,10 +9,11 @@
6353 #ifndef _ASM_CACHE_H
6354 #define _ASM_CACHE_H
6355
6356+#include <linux/const.h>
6357 #include <kmalloc.h>
6358
6359 #define L1_CACHE_SHIFT CONFIG_MIPS_L1_CACHE_SHIFT
6360-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
6361+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
6362
6363 #define SMP_CACHE_SHIFT L1_CACHE_SHIFT
6364 #define SMP_CACHE_BYTES L1_CACHE_BYTES
6365diff --git a/arch/mips/include/asm/elf.h b/arch/mips/include/asm/elf.h
6366index cf3ae24..238d22f 100644
6367--- a/arch/mips/include/asm/elf.h
6368+++ b/arch/mips/include/asm/elf.h
6369@@ -372,13 +372,16 @@ extern const char *__elf_platform;
6370 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
6371 #endif
6372
6373+#ifdef CONFIG_PAX_ASLR
6374+#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
6375+
6376+#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6377+#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6378+#endif
6379+
6380 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
6381 struct linux_binprm;
6382 extern int arch_setup_additional_pages(struct linux_binprm *bprm,
6383 int uses_interp);
6384
6385-struct mm_struct;
6386-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
6387-#define arch_randomize_brk arch_randomize_brk
6388-
6389 #endif /* _ASM_ELF_H */
6390diff --git a/arch/mips/include/asm/exec.h b/arch/mips/include/asm/exec.h
6391index c1f6afa..38cc6e9 100644
6392--- a/arch/mips/include/asm/exec.h
6393+++ b/arch/mips/include/asm/exec.h
6394@@ -12,6 +12,6 @@
6395 #ifndef _ASM_EXEC_H
6396 #define _ASM_EXEC_H
6397
6398-extern unsigned long arch_align_stack(unsigned long sp);
6399+#define arch_align_stack(x) ((x) & ~0xfUL)
6400
6401 #endif /* _ASM_EXEC_H */
6402diff --git a/arch/mips/include/asm/local.h b/arch/mips/include/asm/local.h
6403index d44622c..64990d2 100644
6404--- a/arch/mips/include/asm/local.h
6405+++ b/arch/mips/include/asm/local.h
6406@@ -12,15 +12,25 @@ typedef struct
6407 atomic_long_t a;
6408 } local_t;
6409
6410+typedef struct {
6411+ atomic_long_unchecked_t a;
6412+} local_unchecked_t;
6413+
6414 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
6415
6416 #define local_read(l) atomic_long_read(&(l)->a)
6417+#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
6418 #define local_set(l, i) atomic_long_set(&(l)->a, (i))
6419+#define local_set_unchecked(l, i) atomic_long_set_unchecked(&(l)->a, (i))
6420
6421 #define local_add(i, l) atomic_long_add((i), (&(l)->a))
6422+#define local_add_unchecked(i, l) atomic_long_add_unchecked((i), (&(l)->a))
6423 #define local_sub(i, l) atomic_long_sub((i), (&(l)->a))
6424+#define local_sub_unchecked(i, l) atomic_long_sub_unchecked((i), (&(l)->a))
6425 #define local_inc(l) atomic_long_inc(&(l)->a)
6426+#define local_inc_unchecked(l) atomic_long_inc_unchecked(&(l)->a)
6427 #define local_dec(l) atomic_long_dec(&(l)->a)
6428+#define local_dec_unchecked(l) atomic_long_dec_unchecked(&(l)->a)
6429
6430 /*
6431 * Same as above, but return the result value
6432@@ -70,6 +80,51 @@ static __inline__ long local_add_return(long i, local_t * l)
6433 return result;
6434 }
6435
6436+static __inline__ long local_add_return_unchecked(long i, local_unchecked_t * l)
6437+{
6438+ unsigned long result;
6439+
6440+ if (kernel_uses_llsc && R10000_LLSC_WAR) {
6441+ unsigned long temp;
6442+
6443+ __asm__ __volatile__(
6444+ " .set mips3 \n"
6445+ "1:" __LL "%1, %2 # local_add_return \n"
6446+ " addu %0, %1, %3 \n"
6447+ __SC "%0, %2 \n"
6448+ " beqzl %0, 1b \n"
6449+ " addu %0, %1, %3 \n"
6450+ " .set mips0 \n"
6451+ : "=&r" (result), "=&r" (temp), "=m" (l->a.counter)
6452+ : "Ir" (i), "m" (l->a.counter)
6453+ : "memory");
6454+ } else if (kernel_uses_llsc) {
6455+ unsigned long temp;
6456+
6457+ __asm__ __volatile__(
6458+ " .set mips3 \n"
6459+ "1:" __LL "%1, %2 # local_add_return \n"
6460+ " addu %0, %1, %3 \n"
6461+ __SC "%0, %2 \n"
6462+ " beqz %0, 1b \n"
6463+ " addu %0, %1, %3 \n"
6464+ " .set mips0 \n"
6465+ : "=&r" (result), "=&r" (temp), "=m" (l->a.counter)
6466+ : "Ir" (i), "m" (l->a.counter)
6467+ : "memory");
6468+ } else {
6469+ unsigned long flags;
6470+
6471+ local_irq_save(flags);
6472+ result = l->a.counter;
6473+ result += i;
6474+ l->a.counter = result;
6475+ local_irq_restore(flags);
6476+ }
6477+
6478+ return result;
6479+}
6480+
6481 static __inline__ long local_sub_return(long i, local_t * l)
6482 {
6483 unsigned long result;
6484@@ -117,6 +172,8 @@ static __inline__ long local_sub_return(long i, local_t * l)
6485
6486 #define local_cmpxchg(l, o, n) \
6487 ((long)cmpxchg_local(&((l)->a.counter), (o), (n)))
6488+#define local_cmpxchg_unchecked(l, o, n) \
6489+ ((long)cmpxchg_local(&((l)->a.counter), (o), (n)))
6490 #define local_xchg(l, n) (atomic_long_xchg((&(l)->a), (n)))
6491
6492 /**
6493diff --git a/arch/mips/include/asm/page.h b/arch/mips/include/asm/page.h
6494index f6be474..12ad554 100644
6495--- a/arch/mips/include/asm/page.h
6496+++ b/arch/mips/include/asm/page.h
6497@@ -95,7 +95,7 @@ extern void copy_user_highpage(struct page *to, struct page *from,
6498 #ifdef CONFIG_CPU_MIPS32
6499 typedef struct { unsigned long pte_low, pte_high; } pte_t;
6500 #define pte_val(x) ((x).pte_low | ((unsigned long long)(x).pte_high << 32))
6501- #define __pte(x) ({ pte_t __pte = {(x), ((unsigned long long)(x)) >> 32}; __pte; })
6502+ #define __pte(x) ({ pte_t __pte = {(x), (x) >> 32}; __pte; })
6503 #else
6504 typedef struct { unsigned long long pte; } pte_t;
6505 #define pte_val(x) ((x).pte)
6506diff --git a/arch/mips/include/asm/pgalloc.h b/arch/mips/include/asm/pgalloc.h
6507index 881d18b..cea38bc 100644
6508--- a/arch/mips/include/asm/pgalloc.h
6509+++ b/arch/mips/include/asm/pgalloc.h
6510@@ -37,6 +37,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
6511 {
6512 set_pud(pud, __pud((unsigned long)pmd));
6513 }
6514+
6515+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
6516+{
6517+ pud_populate(mm, pud, pmd);
6518+}
6519 #endif
6520
6521 /*
6522diff --git a/arch/mips/include/asm/smtc_proc.h b/arch/mips/include/asm/smtc_proc.h
6523index 25da651..ae2a259 100644
6524--- a/arch/mips/include/asm/smtc_proc.h
6525+++ b/arch/mips/include/asm/smtc_proc.h
6526@@ -18,6 +18,6 @@ extern struct smtc_cpu_proc smtc_cpu_stats[NR_CPUS];
6527
6528 /* Count of number of recoveries of "stolen" FPU access rights on 34K */
6529
6530-extern atomic_t smtc_fpu_recoveries;
6531+extern atomic_unchecked_t smtc_fpu_recoveries;
6532
6533 #endif /* __ASM_SMTC_PROC_H */
6534diff --git a/arch/mips/include/asm/thread_info.h b/arch/mips/include/asm/thread_info.h
6535index 61215a3..213ee0e 100644
6536--- a/arch/mips/include/asm/thread_info.h
6537+++ b/arch/mips/include/asm/thread_info.h
6538@@ -116,6 +116,8 @@ static inline struct thread_info *current_thread_info(void)
6539 #define TIF_32BIT_ADDR 23 /* 32-bit address space (o32/n32) */
6540 #define TIF_FPUBOUND 24 /* thread bound to FPU-full CPU set */
6541 #define TIF_LOAD_WATCH 25 /* If set, load watch registers */
6542+/* li takes a 32bit immediate */
6543+#define TIF_GRSEC_SETXID 29 /* update credentials on syscall entry/exit */
6544 #define TIF_SYSCALL_TRACE 31 /* syscall trace active */
6545
6546 #define _TIF_SYSCALL_TRACE (1<<TIF_SYSCALL_TRACE)
6547@@ -132,20 +134,18 @@ static inline struct thread_info *current_thread_info(void)
6548 #define _TIF_32BIT_ADDR (1<<TIF_32BIT_ADDR)
6549 #define _TIF_FPUBOUND (1<<TIF_FPUBOUND)
6550 #define _TIF_LOAD_WATCH (1<<TIF_LOAD_WATCH)
6551+#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
6552
6553-#define _TIF_WORK_SYSCALL_ENTRY (_TIF_NOHZ | _TIF_SYSCALL_TRACE | \
6554- _TIF_SYSCALL_AUDIT)
6555+#define _TIF_WORK_SYSCALL_ENTRY (_TIF_NOHZ | _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_GRSEC_SETXID)
6556
6557 /* work to do in syscall_trace_leave() */
6558-#define _TIF_WORK_SYSCALL_EXIT (_TIF_NOHZ | _TIF_SYSCALL_TRACE | \
6559- _TIF_SYSCALL_AUDIT)
6560+#define _TIF_WORK_SYSCALL_EXIT (_TIF_NOHZ | _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_GRSEC_SETXID)
6561
6562 /* work to do on interrupt/exception return */
6563 #define _TIF_WORK_MASK \
6564 (_TIF_SIGPENDING | _TIF_NEED_RESCHED | _TIF_NOTIFY_RESUME)
6565 /* work to do on any return to u-space */
6566-#define _TIF_ALLWORK_MASK (_TIF_NOHZ | _TIF_WORK_MASK | \
6567- _TIF_WORK_SYSCALL_EXIT)
6568+#define _TIF_ALLWORK_MASK (_TIF_NOHZ | _TIF_WORK_MASK | _TIF_WORK_SYSCALL_EXIT | _TIF_GRSEC_SETXID)
6569
6570 #endif /* __KERNEL__ */
6571
6572diff --git a/arch/mips/kernel/binfmt_elfn32.c b/arch/mips/kernel/binfmt_elfn32.c
6573index 1188e00..41cf144 100644
6574--- a/arch/mips/kernel/binfmt_elfn32.c
6575+++ b/arch/mips/kernel/binfmt_elfn32.c
6576@@ -50,6 +50,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
6577 #undef ELF_ET_DYN_BASE
6578 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
6579
6580+#ifdef CONFIG_PAX_ASLR
6581+#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
6582+
6583+#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6584+#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6585+#endif
6586+
6587 #include <asm/processor.h>
6588 #include <linux/module.h>
6589 #include <linux/elfcore.h>
6590diff --git a/arch/mips/kernel/binfmt_elfo32.c b/arch/mips/kernel/binfmt_elfo32.c
6591index 202e581..689ca79 100644
6592--- a/arch/mips/kernel/binfmt_elfo32.c
6593+++ b/arch/mips/kernel/binfmt_elfo32.c
6594@@ -56,6 +56,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
6595 #undef ELF_ET_DYN_BASE
6596 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
6597
6598+#ifdef CONFIG_PAX_ASLR
6599+#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
6600+
6601+#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6602+#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6603+#endif
6604+
6605 #include <asm/processor.h>
6606
6607 /*
6608diff --git a/arch/mips/kernel/irq.c b/arch/mips/kernel/irq.c
6609index d1fea7a..45602ea 100644
6610--- a/arch/mips/kernel/irq.c
6611+++ b/arch/mips/kernel/irq.c
6612@@ -77,17 +77,17 @@ void ack_bad_irq(unsigned int irq)
6613 printk("unexpected IRQ # %d\n", irq);
6614 }
6615
6616-atomic_t irq_err_count;
6617+atomic_unchecked_t irq_err_count;
6618
6619 int arch_show_interrupts(struct seq_file *p, int prec)
6620 {
6621- seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read(&irq_err_count));
6622+ seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read_unchecked(&irq_err_count));
6623 return 0;
6624 }
6625
6626 asmlinkage void spurious_interrupt(void)
6627 {
6628- atomic_inc(&irq_err_count);
6629+ atomic_inc_unchecked(&irq_err_count);
6630 }
6631
6632 void __init init_IRQ(void)
6633diff --git a/arch/mips/kernel/process.c b/arch/mips/kernel/process.c
6634index ddc7610..8c58f17 100644
6635--- a/arch/mips/kernel/process.c
6636+++ b/arch/mips/kernel/process.c
6637@@ -566,15 +566,3 @@ unsigned long get_wchan(struct task_struct *task)
6638 out:
6639 return pc;
6640 }
6641-
6642-/*
6643- * Don't forget that the stack pointer must be aligned on a 8 bytes
6644- * boundary for 32-bits ABI and 16 bytes for 64-bits ABI.
6645- */
6646-unsigned long arch_align_stack(unsigned long sp)
6647-{
6648- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
6649- sp -= get_random_int() & ~PAGE_MASK;
6650-
6651- return sp & ALMASK;
6652-}
6653diff --git a/arch/mips/kernel/ptrace.c b/arch/mips/kernel/ptrace.c
6654index 8ae1ebe..1bcbf47 100644
6655--- a/arch/mips/kernel/ptrace.c
6656+++ b/arch/mips/kernel/ptrace.c
6657@@ -529,6 +529,10 @@ static inline int audit_arch(void)
6658 return arch;
6659 }
6660
6661+#ifdef CONFIG_GRKERNSEC_SETXID
6662+extern void gr_delayed_cred_worker(void);
6663+#endif
6664+
6665 /*
6666 * Notification of system call entry/exit
6667 * - triggered by current->work.syscall_trace
6668@@ -540,6 +544,11 @@ asmlinkage void syscall_trace_enter(struct pt_regs *regs)
6669 /* do the secure computing check first */
6670 secure_computing_strict(regs->regs[2]);
6671
6672+#ifdef CONFIG_GRKERNSEC_SETXID
6673+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
6674+ gr_delayed_cred_worker();
6675+#endif
6676+
6677 if (!(current->ptrace & PT_PTRACED))
6678 goto out;
6679
6680diff --git a/arch/mips/kernel/smtc-proc.c b/arch/mips/kernel/smtc-proc.c
6681index c10aa84..9ec2e60 100644
6682--- a/arch/mips/kernel/smtc-proc.c
6683+++ b/arch/mips/kernel/smtc-proc.c
6684@@ -31,7 +31,7 @@ unsigned long selfipis[NR_CPUS];
6685
6686 struct smtc_cpu_proc smtc_cpu_stats[NR_CPUS];
6687
6688-atomic_t smtc_fpu_recoveries;
6689+atomic_unchecked_t smtc_fpu_recoveries;
6690
6691 static int smtc_proc_show(struct seq_file *m, void *v)
6692 {
6693@@ -48,7 +48,7 @@ static int smtc_proc_show(struct seq_file *m, void *v)
6694 for(i = 0; i < NR_CPUS; i++)
6695 seq_printf(m, "%d: %ld\n", i, smtc_cpu_stats[i].selfipis);
6696 seq_printf(m, "%d Recoveries of \"stolen\" FPU\n",
6697- atomic_read(&smtc_fpu_recoveries));
6698+ atomic_read_unchecked(&smtc_fpu_recoveries));
6699 return 0;
6700 }
6701
6702@@ -73,7 +73,7 @@ void init_smtc_stats(void)
6703 smtc_cpu_stats[i].selfipis = 0;
6704 }
6705
6706- atomic_set(&smtc_fpu_recoveries, 0);
6707+ atomic_set_unchecked(&smtc_fpu_recoveries, 0);
6708
6709 proc_create("smtc", 0444, NULL, &smtc_proc_fops);
6710 }
6711diff --git a/arch/mips/kernel/smtc.c b/arch/mips/kernel/smtc.c
6712index dfc1b91..11a2c07 100644
6713--- a/arch/mips/kernel/smtc.c
6714+++ b/arch/mips/kernel/smtc.c
6715@@ -1359,7 +1359,7 @@ void smtc_soft_dump(void)
6716 }
6717 smtc_ipi_qdump();
6718 printk("%d Recoveries of \"stolen\" FPU\n",
6719- atomic_read(&smtc_fpu_recoveries));
6720+ atomic_read_unchecked(&smtc_fpu_recoveries));
6721 }
6722
6723
6724diff --git a/arch/mips/kernel/sync-r4k.c b/arch/mips/kernel/sync-r4k.c
6725index 84536bf..79caa4d 100644
6726--- a/arch/mips/kernel/sync-r4k.c
6727+++ b/arch/mips/kernel/sync-r4k.c
6728@@ -21,8 +21,8 @@
6729 #include <asm/mipsregs.h>
6730
6731 static atomic_t count_start_flag = ATOMIC_INIT(0);
6732-static atomic_t count_count_start = ATOMIC_INIT(0);
6733-static atomic_t count_count_stop = ATOMIC_INIT(0);
6734+static atomic_unchecked_t count_count_start = ATOMIC_INIT(0);
6735+static atomic_unchecked_t count_count_stop = ATOMIC_INIT(0);
6736 static atomic_t count_reference = ATOMIC_INIT(0);
6737
6738 #define COUNTON 100
6739@@ -69,13 +69,13 @@ void synchronise_count_master(int cpu)
6740
6741 for (i = 0; i < NR_LOOPS; i++) {
6742 /* slaves loop on '!= 2' */
6743- while (atomic_read(&count_count_start) != 1)
6744+ while (atomic_read_unchecked(&count_count_start) != 1)
6745 mb();
6746- atomic_set(&count_count_stop, 0);
6747+ atomic_set_unchecked(&count_count_stop, 0);
6748 smp_wmb();
6749
6750 /* this lets the slaves write their count register */
6751- atomic_inc(&count_count_start);
6752+ atomic_inc_unchecked(&count_count_start);
6753
6754 /*
6755 * Everyone initialises count in the last loop:
6756@@ -86,11 +86,11 @@ void synchronise_count_master(int cpu)
6757 /*
6758 * Wait for all slaves to leave the synchronization point:
6759 */
6760- while (atomic_read(&count_count_stop) != 1)
6761+ while (atomic_read_unchecked(&count_count_stop) != 1)
6762 mb();
6763- atomic_set(&count_count_start, 0);
6764+ atomic_set_unchecked(&count_count_start, 0);
6765 smp_wmb();
6766- atomic_inc(&count_count_stop);
6767+ atomic_inc_unchecked(&count_count_stop);
6768 }
6769 /* Arrange for an interrupt in a short while */
6770 write_c0_compare(read_c0_count() + COUNTON);
6771@@ -131,8 +131,8 @@ void synchronise_count_slave(int cpu)
6772 initcount = atomic_read(&count_reference);
6773
6774 for (i = 0; i < NR_LOOPS; i++) {
6775- atomic_inc(&count_count_start);
6776- while (atomic_read(&count_count_start) != 2)
6777+ atomic_inc_unchecked(&count_count_start);
6778+ while (atomic_read_unchecked(&count_count_start) != 2)
6779 mb();
6780
6781 /*
6782@@ -141,8 +141,8 @@ void synchronise_count_slave(int cpu)
6783 if (i == NR_LOOPS-1)
6784 write_c0_count(initcount);
6785
6786- atomic_inc(&count_count_stop);
6787- while (atomic_read(&count_count_stop) != 2)
6788+ atomic_inc_unchecked(&count_count_stop);
6789+ while (atomic_read_unchecked(&count_count_stop) != 2)
6790 mb();
6791 }
6792 /* Arrange for an interrupt in a short while */
6793diff --git a/arch/mips/kernel/traps.c b/arch/mips/kernel/traps.c
6794index 524841f..3eef41e 100644
6795--- a/arch/mips/kernel/traps.c
6796+++ b/arch/mips/kernel/traps.c
6797@@ -684,7 +684,18 @@ asmlinkage void do_ov(struct pt_regs *regs)
6798 siginfo_t info;
6799
6800 prev_state = exception_enter();
6801- die_if_kernel("Integer overflow", regs);
6802+ if (unlikely(!user_mode(regs))) {
6803+
6804+#ifdef CONFIG_PAX_REFCOUNT
6805+ if (fixup_exception(regs)) {
6806+ pax_report_refcount_overflow(regs);
6807+ exception_exit(prev_state);
6808+ return;
6809+ }
6810+#endif
6811+
6812+ die("Integer overflow", regs);
6813+ }
6814
6815 info.si_code = FPE_INTOVF;
6816 info.si_signo = SIGFPE;
6817diff --git a/arch/mips/mm/fault.c b/arch/mips/mm/fault.c
6818index becc42b..9e43d4b 100644
6819--- a/arch/mips/mm/fault.c
6820+++ b/arch/mips/mm/fault.c
6821@@ -28,6 +28,23 @@
6822 #include <asm/highmem.h> /* For VMALLOC_END */
6823 #include <linux/kdebug.h>
6824
6825+#ifdef CONFIG_PAX_PAGEEXEC
6826+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
6827+{
6828+ unsigned long i;
6829+
6830+ printk(KERN_ERR "PAX: bytes at PC: ");
6831+ for (i = 0; i < 5; i++) {
6832+ unsigned int c;
6833+ if (get_user(c, (unsigned int *)pc+i))
6834+ printk(KERN_CONT "???????? ");
6835+ else
6836+ printk(KERN_CONT "%08x ", c);
6837+ }
6838+ printk("\n");
6839+}
6840+#endif
6841+
6842 /*
6843 * This routine handles page faults. It determines the address,
6844 * and the problem, and then passes it off to one of the appropriate
6845@@ -199,6 +216,14 @@ bad_area:
6846 bad_area_nosemaphore:
6847 /* User mode accesses just cause a SIGSEGV */
6848 if (user_mode(regs)) {
6849+
6850+#ifdef CONFIG_PAX_PAGEEXEC
6851+ if (cpu_has_rixi && (mm->pax_flags & MF_PAX_PAGEEXEC) && !write && address == instruction_pointer(regs)) {
6852+ pax_report_fault(regs, (void *)address, (void *)user_stack_pointer(regs));
6853+ do_group_exit(SIGKILL);
6854+ }
6855+#endif
6856+
6857 tsk->thread.cp0_badvaddr = address;
6858 tsk->thread.error_code = write;
6859 #if 0
6860diff --git a/arch/mips/mm/mmap.c b/arch/mips/mm/mmap.c
6861index f1baadd..8537544 100644
6862--- a/arch/mips/mm/mmap.c
6863+++ b/arch/mips/mm/mmap.c
6864@@ -59,6 +59,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
6865 struct vm_area_struct *vma;
6866 unsigned long addr = addr0;
6867 int do_color_align;
6868+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
6869 struct vm_unmapped_area_info info;
6870
6871 if (unlikely(len > TASK_SIZE))
6872@@ -84,6 +85,11 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
6873 do_color_align = 1;
6874
6875 /* requesting a specific address */
6876+
6877+#ifdef CONFIG_PAX_RANDMMAP
6878+ if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
6879+#endif
6880+
6881 if (addr) {
6882 if (do_color_align)
6883 addr = COLOUR_ALIGN(addr, pgoff);
6884@@ -91,14 +97,14 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
6885 addr = PAGE_ALIGN(addr);
6886
6887 vma = find_vma(mm, addr);
6888- if (TASK_SIZE - len >= addr &&
6889- (!vma || addr + len <= vma->vm_start))
6890+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vmm, addr, len, offset))
6891 return addr;
6892 }
6893
6894 info.length = len;
6895 info.align_mask = do_color_align ? (PAGE_MASK & shm_align_mask) : 0;
6896 info.align_offset = pgoff << PAGE_SHIFT;
6897+ info.threadstack_offset = offset;
6898
6899 if (dir == DOWN) {
6900 info.flags = VM_UNMAPPED_AREA_TOPDOWN;
6901@@ -146,6 +152,10 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
6902 {
6903 unsigned long random_factor = 0UL;
6904
6905+#ifdef CONFIG_PAX_RANDMMAP
6906+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
6907+#endif
6908+
6909 if (current->flags & PF_RANDOMIZE) {
6910 random_factor = get_random_int();
6911 random_factor = random_factor << PAGE_SHIFT;
6912@@ -157,40 +167,25 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
6913
6914 if (mmap_is_legacy()) {
6915 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
6916+
6917+#ifdef CONFIG_PAX_RANDMMAP
6918+ if (mm->pax_flags & MF_PAX_RANDMMAP)
6919+ mm->mmap_base += mm->delta_mmap;
6920+#endif
6921+
6922 mm->get_unmapped_area = arch_get_unmapped_area;
6923 } else {
6924 mm->mmap_base = mmap_base(random_factor);
6925+
6926+#ifdef CONFIG_PAX_RANDMMAP
6927+ if (mm->pax_flags & MF_PAX_RANDMMAP)
6928+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
6929+#endif
6930+
6931 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
6932 }
6933 }
6934
6935-static inline unsigned long brk_rnd(void)
6936-{
6937- unsigned long rnd = get_random_int();
6938-
6939- rnd = rnd << PAGE_SHIFT;
6940- /* 8MB for 32bit, 256MB for 64bit */
6941- if (TASK_IS_32BIT_ADDR)
6942- rnd = rnd & 0x7ffffful;
6943- else
6944- rnd = rnd & 0xffffffful;
6945-
6946- return rnd;
6947-}
6948-
6949-unsigned long arch_randomize_brk(struct mm_struct *mm)
6950-{
6951- unsigned long base = mm->brk;
6952- unsigned long ret;
6953-
6954- ret = PAGE_ALIGN(base + brk_rnd());
6955-
6956- if (ret < mm->brk)
6957- return mm->brk;
6958-
6959- return ret;
6960-}
6961-
6962 int __virt_addr_valid(const volatile void *kaddr)
6963 {
6964 return pfn_valid(PFN_DOWN(virt_to_phys(kaddr)));
6965diff --git a/arch/mips/sgi-ip27/ip27-nmi.c b/arch/mips/sgi-ip27/ip27-nmi.c
6966index a2358b4..7cead4f 100644
6967--- a/arch/mips/sgi-ip27/ip27-nmi.c
6968+++ b/arch/mips/sgi-ip27/ip27-nmi.c
6969@@ -187,9 +187,9 @@ void
6970 cont_nmi_dump(void)
6971 {
6972 #ifndef REAL_NMI_SIGNAL
6973- static atomic_t nmied_cpus = ATOMIC_INIT(0);
6974+ static atomic_unchecked_t nmied_cpus = ATOMIC_INIT(0);
6975
6976- atomic_inc(&nmied_cpus);
6977+ atomic_inc_unchecked(&nmied_cpus);
6978 #endif
6979 /*
6980 * Only allow 1 cpu to proceed
6981@@ -233,7 +233,7 @@ cont_nmi_dump(void)
6982 udelay(10000);
6983 }
6984 #else
6985- while (atomic_read(&nmied_cpus) != num_online_cpus());
6986+ while (atomic_read_unchecked(&nmied_cpus) != num_online_cpus());
6987 #endif
6988
6989 /*
6990diff --git a/arch/mn10300/proc-mn103e010/include/proc/cache.h b/arch/mn10300/proc-mn103e010/include/proc/cache.h
6991index 967d144..db12197 100644
6992--- a/arch/mn10300/proc-mn103e010/include/proc/cache.h
6993+++ b/arch/mn10300/proc-mn103e010/include/proc/cache.h
6994@@ -11,12 +11,14 @@
6995 #ifndef _ASM_PROC_CACHE_H
6996 #define _ASM_PROC_CACHE_H
6997
6998+#include <linux/const.h>
6999+
7000 /* L1 cache */
7001
7002 #define L1_CACHE_NWAYS 4 /* number of ways in caches */
7003 #define L1_CACHE_NENTRIES 256 /* number of entries in each way */
7004-#define L1_CACHE_BYTES 16 /* bytes per entry */
7005 #define L1_CACHE_SHIFT 4 /* shift for bytes per entry */
7006+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT) /* bytes per entry */
7007 #define L1_CACHE_WAYDISP 0x1000 /* displacement of one way from the next */
7008
7009 #define L1_CACHE_TAG_VALID 0x00000001 /* cache tag valid bit */
7010diff --git a/arch/mn10300/proc-mn2ws0050/include/proc/cache.h b/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
7011index bcb5df2..84fabd2 100644
7012--- a/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
7013+++ b/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
7014@@ -16,13 +16,15 @@
7015 #ifndef _ASM_PROC_CACHE_H
7016 #define _ASM_PROC_CACHE_H
7017
7018+#include <linux/const.h>
7019+
7020 /*
7021 * L1 cache
7022 */
7023 #define L1_CACHE_NWAYS 4 /* number of ways in caches */
7024 #define L1_CACHE_NENTRIES 128 /* number of entries in each way */
7025-#define L1_CACHE_BYTES 32 /* bytes per entry */
7026 #define L1_CACHE_SHIFT 5 /* shift for bytes per entry */
7027+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT) /* bytes per entry */
7028 #define L1_CACHE_WAYDISP 0x1000 /* distance from one way to the next */
7029
7030 #define L1_CACHE_TAG_VALID 0x00000001 /* cache tag valid bit */
7031diff --git a/arch/openrisc/include/asm/cache.h b/arch/openrisc/include/asm/cache.h
7032index 4ce7a01..449202a 100644
7033--- a/arch/openrisc/include/asm/cache.h
7034+++ b/arch/openrisc/include/asm/cache.h
7035@@ -19,11 +19,13 @@
7036 #ifndef __ASM_OPENRISC_CACHE_H
7037 #define __ASM_OPENRISC_CACHE_H
7038
7039+#include <linux/const.h>
7040+
7041 /* FIXME: How can we replace these with values from the CPU...
7042 * they shouldn't be hard-coded!
7043 */
7044
7045-#define L1_CACHE_BYTES 16
7046 #define L1_CACHE_SHIFT 4
7047+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7048
7049 #endif /* __ASM_OPENRISC_CACHE_H */
7050diff --git a/arch/parisc/include/asm/atomic.h b/arch/parisc/include/asm/atomic.h
7051index 472886c..00e7df9 100644
7052--- a/arch/parisc/include/asm/atomic.h
7053+++ b/arch/parisc/include/asm/atomic.h
7054@@ -252,6 +252,16 @@ static inline long atomic64_dec_if_positive(atomic64_t *v)
7055 return dec;
7056 }
7057
7058+#define atomic64_read_unchecked(v) atomic64_read(v)
7059+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
7060+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
7061+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
7062+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
7063+#define atomic64_inc_unchecked(v) atomic64_inc(v)
7064+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
7065+#define atomic64_dec_unchecked(v) atomic64_dec(v)
7066+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
7067+
7068 #endif /* !CONFIG_64BIT */
7069
7070
7071diff --git a/arch/parisc/include/asm/cache.h b/arch/parisc/include/asm/cache.h
7072index 47f11c7..3420df2 100644
7073--- a/arch/parisc/include/asm/cache.h
7074+++ b/arch/parisc/include/asm/cache.h
7075@@ -5,6 +5,7 @@
7076 #ifndef __ARCH_PARISC_CACHE_H
7077 #define __ARCH_PARISC_CACHE_H
7078
7079+#include <linux/const.h>
7080
7081 /*
7082 * PA 2.0 processors have 64-byte cachelines; PA 1.1 processors have
7083@@ -15,13 +16,13 @@
7084 * just ruin performance.
7085 */
7086 #ifdef CONFIG_PA20
7087-#define L1_CACHE_BYTES 64
7088 #define L1_CACHE_SHIFT 6
7089 #else
7090-#define L1_CACHE_BYTES 32
7091 #define L1_CACHE_SHIFT 5
7092 #endif
7093
7094+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7095+
7096 #ifndef __ASSEMBLY__
7097
7098 #define SMP_CACHE_BYTES L1_CACHE_BYTES
7099diff --git a/arch/parisc/include/asm/elf.h b/arch/parisc/include/asm/elf.h
7100index ad2b503..bdf1651 100644
7101--- a/arch/parisc/include/asm/elf.h
7102+++ b/arch/parisc/include/asm/elf.h
7103@@ -342,6 +342,13 @@ struct pt_regs; /* forward declaration... */
7104
7105 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x01000000)
7106
7107+#ifdef CONFIG_PAX_ASLR
7108+#define PAX_ELF_ET_DYN_BASE 0x10000UL
7109+
7110+#define PAX_DELTA_MMAP_LEN 16
7111+#define PAX_DELTA_STACK_LEN 16
7112+#endif
7113+
7114 /* This yields a mask that user programs can use to figure out what
7115 instruction set this CPU supports. This could be done in user space,
7116 but it's not easy, and we've already done it here. */
7117diff --git a/arch/parisc/include/asm/pgalloc.h b/arch/parisc/include/asm/pgalloc.h
7118index fc987a1..6e068ef 100644
7119--- a/arch/parisc/include/asm/pgalloc.h
7120+++ b/arch/parisc/include/asm/pgalloc.h
7121@@ -61,6 +61,11 @@ static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
7122 (__u32)(__pa((unsigned long)pmd) >> PxD_VALUE_SHIFT));
7123 }
7124
7125+static inline void pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
7126+{
7127+ pgd_populate(mm, pgd, pmd);
7128+}
7129+
7130 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long address)
7131 {
7132 pmd_t *pmd = (pmd_t *)__get_free_pages(GFP_KERNEL|__GFP_REPEAT,
7133@@ -93,6 +98,7 @@ static inline void pmd_free(struct mm_struct *mm, pmd_t *pmd)
7134 #define pmd_alloc_one(mm, addr) ({ BUG(); ((pmd_t *)2); })
7135 #define pmd_free(mm, x) do { } while (0)
7136 #define pgd_populate(mm, pmd, pte) BUG()
7137+#define pgd_populate_kernel(mm, pmd, pte) BUG()
7138
7139 #endif
7140
7141diff --git a/arch/parisc/include/asm/pgtable.h b/arch/parisc/include/asm/pgtable.h
7142index 34899b5..02dd060 100644
7143--- a/arch/parisc/include/asm/pgtable.h
7144+++ b/arch/parisc/include/asm/pgtable.h
7145@@ -223,6 +223,17 @@ extern void purge_tlb_entries(struct mm_struct *, unsigned long);
7146 #define PAGE_EXECREAD __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_EXEC |_PAGE_ACCESSED)
7147 #define PAGE_COPY PAGE_EXECREAD
7148 #define PAGE_RWX __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_EXEC |_PAGE_ACCESSED)
7149+
7150+#ifdef CONFIG_PAX_PAGEEXEC
7151+# define PAGE_SHARED_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_ACCESSED)
7152+# define PAGE_COPY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
7153+# define PAGE_READONLY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
7154+#else
7155+# define PAGE_SHARED_NOEXEC PAGE_SHARED
7156+# define PAGE_COPY_NOEXEC PAGE_COPY
7157+# define PAGE_READONLY_NOEXEC PAGE_READONLY
7158+#endif
7159+
7160 #define PAGE_KERNEL __pgprot(_PAGE_KERNEL)
7161 #define PAGE_KERNEL_EXEC __pgprot(_PAGE_KERNEL_EXEC)
7162 #define PAGE_KERNEL_RWX __pgprot(_PAGE_KERNEL_RWX)
7163diff --git a/arch/parisc/include/asm/uaccess.h b/arch/parisc/include/asm/uaccess.h
7164index e0a8235..ce2f1e1 100644
7165--- a/arch/parisc/include/asm/uaccess.h
7166+++ b/arch/parisc/include/asm/uaccess.h
7167@@ -245,10 +245,10 @@ static inline unsigned long __must_check copy_from_user(void *to,
7168 const void __user *from,
7169 unsigned long n)
7170 {
7171- int sz = __compiletime_object_size(to);
7172+ size_t sz = __compiletime_object_size(to);
7173 int ret = -EFAULT;
7174
7175- if (likely(sz == -1 || !__builtin_constant_p(n) || sz >= n))
7176+ if (likely(sz == (size_t)-1 || !__builtin_constant_p(n) || sz >= n))
7177 ret = __copy_from_user(to, from, n);
7178 else
7179 copy_from_user_overflow();
7180diff --git a/arch/parisc/kernel/module.c b/arch/parisc/kernel/module.c
7181index 2a625fb..9908930 100644
7182--- a/arch/parisc/kernel/module.c
7183+++ b/arch/parisc/kernel/module.c
7184@@ -98,16 +98,38 @@
7185
7186 /* three functions to determine where in the module core
7187 * or init pieces the location is */
7188+static inline int in_init_rx(struct module *me, void *loc)
7189+{
7190+ return (loc >= me->module_init_rx &&
7191+ loc < (me->module_init_rx + me->init_size_rx));
7192+}
7193+
7194+static inline int in_init_rw(struct module *me, void *loc)
7195+{
7196+ return (loc >= me->module_init_rw &&
7197+ loc < (me->module_init_rw + me->init_size_rw));
7198+}
7199+
7200 static inline int in_init(struct module *me, void *loc)
7201 {
7202- return (loc >= me->module_init &&
7203- loc <= (me->module_init + me->init_size));
7204+ return in_init_rx(me, loc) || in_init_rw(me, loc);
7205+}
7206+
7207+static inline int in_core_rx(struct module *me, void *loc)
7208+{
7209+ return (loc >= me->module_core_rx &&
7210+ loc < (me->module_core_rx + me->core_size_rx));
7211+}
7212+
7213+static inline int in_core_rw(struct module *me, void *loc)
7214+{
7215+ return (loc >= me->module_core_rw &&
7216+ loc < (me->module_core_rw + me->core_size_rw));
7217 }
7218
7219 static inline int in_core(struct module *me, void *loc)
7220 {
7221- return (loc >= me->module_core &&
7222- loc <= (me->module_core + me->core_size));
7223+ return in_core_rx(me, loc) || in_core_rw(me, loc);
7224 }
7225
7226 static inline int in_local(struct module *me, void *loc)
7227@@ -371,13 +393,13 @@ int module_frob_arch_sections(CONST Elf_Ehdr *hdr,
7228 }
7229
7230 /* align things a bit */
7231- me->core_size = ALIGN(me->core_size, 16);
7232- me->arch.got_offset = me->core_size;
7233- me->core_size += gots * sizeof(struct got_entry);
7234+ me->core_size_rw = ALIGN(me->core_size_rw, 16);
7235+ me->arch.got_offset = me->core_size_rw;
7236+ me->core_size_rw += gots * sizeof(struct got_entry);
7237
7238- me->core_size = ALIGN(me->core_size, 16);
7239- me->arch.fdesc_offset = me->core_size;
7240- me->core_size += fdescs * sizeof(Elf_Fdesc);
7241+ me->core_size_rw = ALIGN(me->core_size_rw, 16);
7242+ me->arch.fdesc_offset = me->core_size_rw;
7243+ me->core_size_rw += fdescs * sizeof(Elf_Fdesc);
7244
7245 me->arch.got_max = gots;
7246 me->arch.fdesc_max = fdescs;
7247@@ -395,7 +417,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
7248
7249 BUG_ON(value == 0);
7250
7251- got = me->module_core + me->arch.got_offset;
7252+ got = me->module_core_rw + me->arch.got_offset;
7253 for (i = 0; got[i].addr; i++)
7254 if (got[i].addr == value)
7255 goto out;
7256@@ -413,7 +435,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
7257 #ifdef CONFIG_64BIT
7258 static Elf_Addr get_fdesc(struct module *me, unsigned long value)
7259 {
7260- Elf_Fdesc *fdesc = me->module_core + me->arch.fdesc_offset;
7261+ Elf_Fdesc *fdesc = me->module_core_rw + me->arch.fdesc_offset;
7262
7263 if (!value) {
7264 printk(KERN_ERR "%s: zero OPD requested!\n", me->name);
7265@@ -431,7 +453,7 @@ static Elf_Addr get_fdesc(struct module *me, unsigned long value)
7266
7267 /* Create new one */
7268 fdesc->addr = value;
7269- fdesc->gp = (Elf_Addr)me->module_core + me->arch.got_offset;
7270+ fdesc->gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
7271 return (Elf_Addr)fdesc;
7272 }
7273 #endif /* CONFIG_64BIT */
7274@@ -843,7 +865,7 @@ register_unwind_table(struct module *me,
7275
7276 table = (unsigned char *)sechdrs[me->arch.unwind_section].sh_addr;
7277 end = table + sechdrs[me->arch.unwind_section].sh_size;
7278- gp = (Elf_Addr)me->module_core + me->arch.got_offset;
7279+ gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
7280
7281 DEBUGP("register_unwind_table(), sect = %d at 0x%p - 0x%p (gp=0x%lx)\n",
7282 me->arch.unwind_section, table, end, gp);
7283diff --git a/arch/parisc/kernel/sys_parisc.c b/arch/parisc/kernel/sys_parisc.c
7284index 0d3a9d4..44975d0 100644
7285--- a/arch/parisc/kernel/sys_parisc.c
7286+++ b/arch/parisc/kernel/sys_parisc.c
7287@@ -33,9 +33,11 @@
7288 #include <linux/utsname.h>
7289 #include <linux/personality.h>
7290
7291-static unsigned long get_unshared_area(unsigned long addr, unsigned long len)
7292+static unsigned long get_unshared_area(struct file *filp, unsigned long addr, unsigned long len,
7293+ unsigned long flags)
7294 {
7295 struct vm_unmapped_area_info info;
7296+ unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
7297
7298 info.flags = 0;
7299 info.length = len;
7300@@ -43,6 +45,7 @@ static unsigned long get_unshared_area(unsigned long addr, unsigned long len)
7301 info.high_limit = TASK_SIZE;
7302 info.align_mask = 0;
7303 info.align_offset = 0;
7304+ info.threadstack_offset = offset;
7305 return vm_unmapped_area(&info);
7306 }
7307
7308@@ -69,15 +72,17 @@ static unsigned long shared_align_offset(struct file *filp, unsigned long pgoff)
7309 }
7310
7311 static unsigned long get_shared_area(struct file *filp, unsigned long addr,
7312- unsigned long len, unsigned long pgoff)
7313+ unsigned long len, unsigned long pgoff, unsigned long flags)
7314 {
7315 struct vm_unmapped_area_info info;
7316+ unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
7317
7318 info.flags = 0;
7319 info.length = len;
7320 info.low_limit = PAGE_ALIGN(addr);
7321 info.high_limit = TASK_SIZE;
7322 info.align_mask = PAGE_MASK & (SHMLBA - 1);
7323+ info.threadstack_offset = offset;
7324 info.align_offset = shared_align_offset(filp, pgoff);
7325 return vm_unmapped_area(&info);
7326 }
7327@@ -93,13 +98,20 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
7328 return -EINVAL;
7329 return addr;
7330 }
7331- if (!addr)
7332+ if (!addr) {
7333 addr = TASK_UNMAPPED_BASE;
7334
7335+#ifdef CONFIG_PAX_RANDMMAP
7336+ if (current->mm->pax_flags & MF_PAX_RANDMMAP)
7337+ addr += current->mm->delta_mmap;
7338+#endif
7339+
7340+ }
7341+
7342 if (filp || (flags & MAP_SHARED))
7343- addr = get_shared_area(filp, addr, len, pgoff);
7344+ addr = get_shared_area(filp, addr, len, pgoff, flags);
7345 else
7346- addr = get_unshared_area(addr, len);
7347+ addr = get_unshared_area(addr, len, flags);
7348
7349 return addr;
7350 }
7351diff --git a/arch/parisc/kernel/traps.c b/arch/parisc/kernel/traps.c
7352index 1cd1d0c..44ec918 100644
7353--- a/arch/parisc/kernel/traps.c
7354+++ b/arch/parisc/kernel/traps.c
7355@@ -722,9 +722,7 @@ void notrace handle_interruption(int code, struct pt_regs *regs)
7356
7357 down_read(&current->mm->mmap_sem);
7358 vma = find_vma(current->mm,regs->iaoq[0]);
7359- if (vma && (regs->iaoq[0] >= vma->vm_start)
7360- && (vma->vm_flags & VM_EXEC)) {
7361-
7362+ if (vma && (regs->iaoq[0] >= vma->vm_start)) {
7363 fault_address = regs->iaoq[0];
7364 fault_space = regs->iasq[0];
7365
7366diff --git a/arch/parisc/mm/fault.c b/arch/parisc/mm/fault.c
7367index 0293588..3b229aa 100644
7368--- a/arch/parisc/mm/fault.c
7369+++ b/arch/parisc/mm/fault.c
7370@@ -15,6 +15,7 @@
7371 #include <linux/sched.h>
7372 #include <linux/interrupt.h>
7373 #include <linux/module.h>
7374+#include <linux/unistd.h>
7375
7376 #include <asm/uaccess.h>
7377 #include <asm/traps.h>
7378@@ -52,7 +53,7 @@ DEFINE_PER_CPU(struct exception_data, exception_data);
7379 static unsigned long
7380 parisc_acctyp(unsigned long code, unsigned int inst)
7381 {
7382- if (code == 6 || code == 16)
7383+ if (code == 6 || code == 7 || code == 16)
7384 return VM_EXEC;
7385
7386 switch (inst & 0xf0000000) {
7387@@ -138,6 +139,116 @@ parisc_acctyp(unsigned long code, unsigned int inst)
7388 }
7389 #endif
7390
7391+#ifdef CONFIG_PAX_PAGEEXEC
7392+/*
7393+ * PaX: decide what to do with offenders (instruction_pointer(regs) = fault address)
7394+ *
7395+ * returns 1 when task should be killed
7396+ * 2 when rt_sigreturn trampoline was detected
7397+ * 3 when unpatched PLT trampoline was detected
7398+ */
7399+static int pax_handle_fetch_fault(struct pt_regs *regs)
7400+{
7401+
7402+#ifdef CONFIG_PAX_EMUPLT
7403+ int err;
7404+
7405+ do { /* PaX: unpatched PLT emulation */
7406+ unsigned int bl, depwi;
7407+
7408+ err = get_user(bl, (unsigned int *)instruction_pointer(regs));
7409+ err |= get_user(depwi, (unsigned int *)(instruction_pointer(regs)+4));
7410+
7411+ if (err)
7412+ break;
7413+
7414+ if (bl == 0xEA9F1FDDU && depwi == 0xD6801C1EU) {
7415+ unsigned int ldw, bv, ldw2, addr = instruction_pointer(regs)-12;
7416+
7417+ err = get_user(ldw, (unsigned int *)addr);
7418+ err |= get_user(bv, (unsigned int *)(addr+4));
7419+ err |= get_user(ldw2, (unsigned int *)(addr+8));
7420+
7421+ if (err)
7422+ break;
7423+
7424+ if (ldw == 0x0E801096U &&
7425+ bv == 0xEAC0C000U &&
7426+ ldw2 == 0x0E881095U)
7427+ {
7428+ unsigned int resolver, map;
7429+
7430+ err = get_user(resolver, (unsigned int *)(instruction_pointer(regs)+8));
7431+ err |= get_user(map, (unsigned int *)(instruction_pointer(regs)+12));
7432+ if (err)
7433+ break;
7434+
7435+ regs->gr[20] = instruction_pointer(regs)+8;
7436+ regs->gr[21] = map;
7437+ regs->gr[22] = resolver;
7438+ regs->iaoq[0] = resolver | 3UL;
7439+ regs->iaoq[1] = regs->iaoq[0] + 4;
7440+ return 3;
7441+ }
7442+ }
7443+ } while (0);
7444+#endif
7445+
7446+#ifdef CONFIG_PAX_EMUTRAMP
7447+
7448+#ifndef CONFIG_PAX_EMUSIGRT
7449+ if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
7450+ return 1;
7451+#endif
7452+
7453+ do { /* PaX: rt_sigreturn emulation */
7454+ unsigned int ldi1, ldi2, bel, nop;
7455+
7456+ err = get_user(ldi1, (unsigned int *)instruction_pointer(regs));
7457+ err |= get_user(ldi2, (unsigned int *)(instruction_pointer(regs)+4));
7458+ err |= get_user(bel, (unsigned int *)(instruction_pointer(regs)+8));
7459+ err |= get_user(nop, (unsigned int *)(instruction_pointer(regs)+12));
7460+
7461+ if (err)
7462+ break;
7463+
7464+ if ((ldi1 == 0x34190000U || ldi1 == 0x34190002U) &&
7465+ ldi2 == 0x3414015AU &&
7466+ bel == 0xE4008200U &&
7467+ nop == 0x08000240U)
7468+ {
7469+ regs->gr[25] = (ldi1 & 2) >> 1;
7470+ regs->gr[20] = __NR_rt_sigreturn;
7471+ regs->gr[31] = regs->iaoq[1] + 16;
7472+ regs->sr[0] = regs->iasq[1];
7473+ regs->iaoq[0] = 0x100UL;
7474+ regs->iaoq[1] = regs->iaoq[0] + 4;
7475+ regs->iasq[0] = regs->sr[2];
7476+ regs->iasq[1] = regs->sr[2];
7477+ return 2;
7478+ }
7479+ } while (0);
7480+#endif
7481+
7482+ return 1;
7483+}
7484+
7485+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
7486+{
7487+ unsigned long i;
7488+
7489+ printk(KERN_ERR "PAX: bytes at PC: ");
7490+ for (i = 0; i < 5; i++) {
7491+ unsigned int c;
7492+ if (get_user(c, (unsigned int *)pc+i))
7493+ printk(KERN_CONT "???????? ");
7494+ else
7495+ printk(KERN_CONT "%08x ", c);
7496+ }
7497+ printk("\n");
7498+}
7499+#endif
7500+
7501 int fixup_exception(struct pt_regs *regs)
7502 {
7503 const struct exception_table_entry *fix;
7504@@ -204,8 +315,33 @@ retry:
7505
7506 good_area:
7507
7508- if ((vma->vm_flags & acc_type) != acc_type)
7509+ if ((vma->vm_flags & acc_type) != acc_type) {
7510+
7511+#ifdef CONFIG_PAX_PAGEEXEC
7512+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && (acc_type & VM_EXEC) &&
7513+ (address & ~3UL) == instruction_pointer(regs))
7514+ {
7515+ up_read(&mm->mmap_sem);
7516+ switch (pax_handle_fetch_fault(regs)) {
7517+
7518+#ifdef CONFIG_PAX_EMUPLT
7519+ case 3:
7520+ return;
7521+#endif
7522+
7523+#ifdef CONFIG_PAX_EMUTRAMP
7524+ case 2:
7525+ return;
7526+#endif
7527+
7528+ }
7529+ pax_report_fault(regs, (void *)instruction_pointer(regs), (void *)regs->gr[30]);
7530+ do_group_exit(SIGKILL);
7531+ }
7532+#endif
7533+
7534 goto bad_area;
7535+ }
7536
7537 /*
7538 * If for any reason at all we couldn't handle the fault, make
7539diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig
7540index 38f3b7e..7e485c0 100644
7541--- a/arch/powerpc/Kconfig
7542+++ b/arch/powerpc/Kconfig
7543@@ -378,6 +378,7 @@ config ARCH_ENABLE_MEMORY_HOTREMOVE
7544 config KEXEC
7545 bool "kexec system call"
7546 depends on (PPC_BOOK3S || FSL_BOOKE || (44x && !SMP))
7547+ depends on !GRKERNSEC_KMEM
7548 help
7549 kexec is a system call that implements the ability to shutdown your
7550 current kernel, and to start another kernel. It is like a reboot
7551diff --git a/arch/powerpc/include/asm/atomic.h b/arch/powerpc/include/asm/atomic.h
7552index e3b1d41..8e81edf 100644
7553--- a/arch/powerpc/include/asm/atomic.h
7554+++ b/arch/powerpc/include/asm/atomic.h
7555@@ -523,6 +523,16 @@ static __inline__ long atomic64_inc_not_zero(atomic64_t *v)
7556 return t1;
7557 }
7558
7559+#define atomic64_read_unchecked(v) atomic64_read(v)
7560+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
7561+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
7562+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
7563+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
7564+#define atomic64_inc_unchecked(v) atomic64_inc(v)
7565+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
7566+#define atomic64_dec_unchecked(v) atomic64_dec(v)
7567+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
7568+
7569 #endif /* __powerpc64__ */
7570
7571 #endif /* __KERNEL__ */
7572diff --git a/arch/powerpc/include/asm/cache.h b/arch/powerpc/include/asm/cache.h
7573index 9e495c9..b6878e5 100644
7574--- a/arch/powerpc/include/asm/cache.h
7575+++ b/arch/powerpc/include/asm/cache.h
7576@@ -3,6 +3,7 @@
7577
7578 #ifdef __KERNEL__
7579
7580+#include <linux/const.h>
7581
7582 /* bytes per L1 cache line */
7583 #if defined(CONFIG_8xx) || defined(CONFIG_403GCX)
7584@@ -22,7 +23,7 @@
7585 #define L1_CACHE_SHIFT 7
7586 #endif
7587
7588-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
7589+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7590
7591 #define SMP_CACHE_BYTES L1_CACHE_BYTES
7592
7593diff --git a/arch/powerpc/include/asm/elf.h b/arch/powerpc/include/asm/elf.h
7594index cc0655a..13eac2e 100644
7595--- a/arch/powerpc/include/asm/elf.h
7596+++ b/arch/powerpc/include/asm/elf.h
7597@@ -28,8 +28,19 @@
7598 the loader. We need to make sure that it is out of the way of the program
7599 that it will "exec", and that there is sufficient room for the brk. */
7600
7601-extern unsigned long randomize_et_dyn(unsigned long base);
7602-#define ELF_ET_DYN_BASE (randomize_et_dyn(0x20000000))
7603+#define ELF_ET_DYN_BASE (0x20000000)
7604+
7605+#ifdef CONFIG_PAX_ASLR
7606+#define PAX_ELF_ET_DYN_BASE (0x10000000UL)
7607+
7608+#ifdef __powerpc64__
7609+#define PAX_DELTA_MMAP_LEN (is_32bit_task() ? 16 : 28)
7610+#define PAX_DELTA_STACK_LEN (is_32bit_task() ? 16 : 28)
7611+#else
7612+#define PAX_DELTA_MMAP_LEN 15
7613+#define PAX_DELTA_STACK_LEN 15
7614+#endif
7615+#endif
7616
7617 /*
7618 * Our registers are always unsigned longs, whether we're a 32 bit
7619@@ -123,10 +134,6 @@ extern int arch_setup_additional_pages(struct linux_binprm *bprm,
7620 (0x7ff >> (PAGE_SHIFT - 12)) : \
7621 (0x3ffff >> (PAGE_SHIFT - 12)))
7622
7623-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
7624-#define arch_randomize_brk arch_randomize_brk
7625-
7626-
7627 #ifdef CONFIG_SPU_BASE
7628 /* Notes used in ET_CORE. Note name is "SPU/<fd>/<filename>". */
7629 #define NT_SPU 1
7630diff --git a/arch/powerpc/include/asm/exec.h b/arch/powerpc/include/asm/exec.h
7631index 8196e9c..d83a9f3 100644
7632--- a/arch/powerpc/include/asm/exec.h
7633+++ b/arch/powerpc/include/asm/exec.h
7634@@ -4,6 +4,6 @@
7635 #ifndef _ASM_POWERPC_EXEC_H
7636 #define _ASM_POWERPC_EXEC_H
7637
7638-extern unsigned long arch_align_stack(unsigned long sp);
7639+#define arch_align_stack(x) ((x) & ~0xfUL)
7640
7641 #endif /* _ASM_POWERPC_EXEC_H */
7642diff --git a/arch/powerpc/include/asm/kmap_types.h b/arch/powerpc/include/asm/kmap_types.h
7643index 5acabbd..7ea14fa 100644
7644--- a/arch/powerpc/include/asm/kmap_types.h
7645+++ b/arch/powerpc/include/asm/kmap_types.h
7646@@ -10,7 +10,7 @@
7647 * 2 of the License, or (at your option) any later version.
7648 */
7649
7650-#define KM_TYPE_NR 16
7651+#define KM_TYPE_NR 17
7652
7653 #endif /* __KERNEL__ */
7654 #endif /* _ASM_POWERPC_KMAP_TYPES_H */
7655diff --git a/arch/powerpc/include/asm/mman.h b/arch/powerpc/include/asm/mman.h
7656index 8565c25..2865190 100644
7657--- a/arch/powerpc/include/asm/mman.h
7658+++ b/arch/powerpc/include/asm/mman.h
7659@@ -24,7 +24,7 @@ static inline unsigned long arch_calc_vm_prot_bits(unsigned long prot)
7660 }
7661 #define arch_calc_vm_prot_bits(prot) arch_calc_vm_prot_bits(prot)
7662
7663-static inline pgprot_t arch_vm_get_page_prot(unsigned long vm_flags)
7664+static inline pgprot_t arch_vm_get_page_prot(vm_flags_t vm_flags)
7665 {
7666 return (vm_flags & VM_SAO) ? __pgprot(_PAGE_SAO) : __pgprot(0);
7667 }
7668diff --git a/arch/powerpc/include/asm/page.h b/arch/powerpc/include/asm/page.h
7669index b9f4262..dcf04f7 100644
7670--- a/arch/powerpc/include/asm/page.h
7671+++ b/arch/powerpc/include/asm/page.h
7672@@ -230,8 +230,9 @@ extern long long virt_phys_offset;
7673 * and needs to be executable. This means the whole heap ends
7674 * up being executable.
7675 */
7676-#define VM_DATA_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
7677- VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
7678+#define VM_DATA_DEFAULT_FLAGS32 \
7679+ (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
7680+ VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
7681
7682 #define VM_DATA_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
7683 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
7684@@ -259,6 +260,9 @@ extern long long virt_phys_offset;
7685 #define is_kernel_addr(x) ((x) >= PAGE_OFFSET)
7686 #endif
7687
7688+#define ktla_ktva(addr) (addr)
7689+#define ktva_ktla(addr) (addr)
7690+
7691 #ifndef CONFIG_PPC_BOOK3S_64
7692 /*
7693 * Use the top bit of the higher-level page table entries to indicate whether
7694diff --git a/arch/powerpc/include/asm/page_64.h b/arch/powerpc/include/asm/page_64.h
7695index 88693ce..ac6f9ab 100644
7696--- a/arch/powerpc/include/asm/page_64.h
7697+++ b/arch/powerpc/include/asm/page_64.h
7698@@ -153,15 +153,18 @@ do { \
7699 * stack by default, so in the absence of a PT_GNU_STACK program header
7700 * we turn execute permission off.
7701 */
7702-#define VM_STACK_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
7703- VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
7704+#define VM_STACK_DEFAULT_FLAGS32 \
7705+ (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
7706+ VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
7707
7708 #define VM_STACK_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
7709 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
7710
7711+#ifndef CONFIG_PAX_PAGEEXEC
7712 #define VM_STACK_DEFAULT_FLAGS \
7713 (is_32bit_task() ? \
7714 VM_STACK_DEFAULT_FLAGS32 : VM_STACK_DEFAULT_FLAGS64)
7715+#endif
7716
7717 #include <asm-generic/getorder.h>
7718
7719diff --git a/arch/powerpc/include/asm/pgalloc-64.h b/arch/powerpc/include/asm/pgalloc-64.h
7720index 256d6f8..b0166a7 100644
7721--- a/arch/powerpc/include/asm/pgalloc-64.h
7722+++ b/arch/powerpc/include/asm/pgalloc-64.h
7723@@ -53,6 +53,7 @@ static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
7724 #ifndef CONFIG_PPC_64K_PAGES
7725
7726 #define pgd_populate(MM, PGD, PUD) pgd_set(PGD, PUD)
7727+#define pgd_populate_kernel(MM, PGD, PUD) pgd_populate((MM), (PGD), (PUD))
7728
7729 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
7730 {
7731@@ -70,6 +71,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
7732 pud_set(pud, (unsigned long)pmd);
7733 }
7734
7735+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
7736+{
7737+ pud_populate(mm, pud, pmd);
7738+}
7739+
7740 #define pmd_populate(mm, pmd, pte_page) \
7741 pmd_populate_kernel(mm, pmd, page_address(pte_page))
7742 #define pmd_populate_kernel(mm, pmd, pte) pmd_set(pmd, (unsigned long)(pte))
7743@@ -169,6 +175,7 @@ extern void __tlb_remove_table(void *_table);
7744 #endif
7745
7746 #define pud_populate(mm, pud, pmd) pud_set(pud, (unsigned long)pmd)
7747+#define pud_populate_kernel(mm, pud, pmd) pud_populate((mm), (pud), (pmd))
7748
7749 static inline void pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmd,
7750 pte_t *pte)
7751diff --git a/arch/powerpc/include/asm/pgtable.h b/arch/powerpc/include/asm/pgtable.h
7752index 7d6eacf..14c0240 100644
7753--- a/arch/powerpc/include/asm/pgtable.h
7754+++ b/arch/powerpc/include/asm/pgtable.h
7755@@ -2,6 +2,7 @@
7756 #define _ASM_POWERPC_PGTABLE_H
7757 #ifdef __KERNEL__
7758
7759+#include <linux/const.h>
7760 #ifndef __ASSEMBLY__
7761 #include <asm/processor.h> /* For TASK_SIZE */
7762 #include <asm/mmu.h>
7763diff --git a/arch/powerpc/include/asm/pte-hash32.h b/arch/powerpc/include/asm/pte-hash32.h
7764index 4aad413..85d86bf 100644
7765--- a/arch/powerpc/include/asm/pte-hash32.h
7766+++ b/arch/powerpc/include/asm/pte-hash32.h
7767@@ -21,6 +21,7 @@
7768 #define _PAGE_FILE 0x004 /* when !present: nonlinear file mapping */
7769 #define _PAGE_USER 0x004 /* usermode access allowed */
7770 #define _PAGE_GUARDED 0x008 /* G: prohibit speculative access */
7771+#define _PAGE_EXEC _PAGE_GUARDED
7772 #define _PAGE_COHERENT 0x010 /* M: enforce memory coherence (SMP systems) */
7773 #define _PAGE_NO_CACHE 0x020 /* I: cache inhibit */
7774 #define _PAGE_WRITETHRU 0x040 /* W: cache write-through */
7775diff --git a/arch/powerpc/include/asm/reg.h b/arch/powerpc/include/asm/reg.h
7776index 10d1ef0..8f83abc 100644
7777--- a/arch/powerpc/include/asm/reg.h
7778+++ b/arch/powerpc/include/asm/reg.h
7779@@ -234,6 +234,7 @@
7780 #define SPRN_DBCR 0x136 /* e300 Data Breakpoint Control Reg */
7781 #define SPRN_DSISR 0x012 /* Data Storage Interrupt Status Register */
7782 #define DSISR_NOHPTE 0x40000000 /* no translation found */
7783+#define DSISR_GUARDED 0x10000000 /* fetch from guarded storage */
7784 #define DSISR_PROTFAULT 0x08000000 /* protection fault */
7785 #define DSISR_ISSTORE 0x02000000 /* access was a store */
7786 #define DSISR_DABRMATCH 0x00400000 /* hit data breakpoint */
7787diff --git a/arch/powerpc/include/asm/smp.h b/arch/powerpc/include/asm/smp.h
7788index 98da78e..dc68271 100644
7789--- a/arch/powerpc/include/asm/smp.h
7790+++ b/arch/powerpc/include/asm/smp.h
7791@@ -50,7 +50,7 @@ struct smp_ops_t {
7792 int (*cpu_disable)(void);
7793 void (*cpu_die)(unsigned int nr);
7794 int (*cpu_bootable)(unsigned int nr);
7795-};
7796+} __no_const;
7797
7798 extern void smp_send_debugger_break(void);
7799 extern void start_secondary_resume(void);
7800diff --git a/arch/powerpc/include/asm/thread_info.h b/arch/powerpc/include/asm/thread_info.h
7801index ba7b197..d292e26 100644
7802--- a/arch/powerpc/include/asm/thread_info.h
7803+++ b/arch/powerpc/include/asm/thread_info.h
7804@@ -93,7 +93,6 @@ static inline struct thread_info *current_thread_info(void)
7805 #define TIF_POLLING_NRFLAG 3 /* true if poll_idle() is polling
7806 TIF_NEED_RESCHED */
7807 #define TIF_32BIT 4 /* 32 bit binary */
7808-#define TIF_PERFMON_WORK 5 /* work for pfm_handle_work() */
7809 #define TIF_PERFMON_CTXSW 6 /* perfmon needs ctxsw calls */
7810 #define TIF_SYSCALL_AUDIT 7 /* syscall auditing active */
7811 #define TIF_SINGLESTEP 8 /* singlestepping active */
7812@@ -107,6 +106,9 @@ static inline struct thread_info *current_thread_info(void)
7813 #define TIF_EMULATE_STACK_STORE 16 /* Is an instruction emulation
7814 for stack store? */
7815 #define TIF_MEMDIE 17 /* is terminating due to OOM killer */
7816+#define TIF_PERFMON_WORK 18 /* work for pfm_handle_work() */
7817+/* mask must be expressable within 16 bits to satisfy 'andi' instruction reqs */
7818+#define TIF_GRSEC_SETXID 5 /* update credentials on syscall entry/exit */
7819
7820 /* as above, but as bit values */
7821 #define _TIF_SYSCALL_TRACE (1<<TIF_SYSCALL_TRACE)
7822@@ -126,9 +128,10 @@ static inline struct thread_info *current_thread_info(void)
7823 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
7824 #define _TIF_EMULATE_STACK_STORE (1<<TIF_EMULATE_STACK_STORE)
7825 #define _TIF_NOHZ (1<<TIF_NOHZ)
7826+#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
7827 #define _TIF_SYSCALL_T_OR_A (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \
7828 _TIF_SECCOMP | _TIF_SYSCALL_TRACEPOINT | \
7829- _TIF_NOHZ)
7830+ _TIF_NOHZ | _TIF_GRSEC_SETXID)
7831
7832 #define _TIF_USER_WORK_MASK (_TIF_SIGPENDING | _TIF_NEED_RESCHED | \
7833 _TIF_NOTIFY_RESUME | _TIF_UPROBE)
7834diff --git a/arch/powerpc/include/asm/uaccess.h b/arch/powerpc/include/asm/uaccess.h
7835index 9485b43..4718d50 100644
7836--- a/arch/powerpc/include/asm/uaccess.h
7837+++ b/arch/powerpc/include/asm/uaccess.h
7838@@ -318,52 +318,6 @@ do { \
7839 extern unsigned long __copy_tofrom_user(void __user *to,
7840 const void __user *from, unsigned long size);
7841
7842-#ifndef __powerpc64__
7843-
7844-static inline unsigned long copy_from_user(void *to,
7845- const void __user *from, unsigned long n)
7846-{
7847- unsigned long over;
7848-
7849- if (access_ok(VERIFY_READ, from, n))
7850- return __copy_tofrom_user((__force void __user *)to, from, n);
7851- if ((unsigned long)from < TASK_SIZE) {
7852- over = (unsigned long)from + n - TASK_SIZE;
7853- return __copy_tofrom_user((__force void __user *)to, from,
7854- n - over) + over;
7855- }
7856- return n;
7857-}
7858-
7859-static inline unsigned long copy_to_user(void __user *to,
7860- const void *from, unsigned long n)
7861-{
7862- unsigned long over;
7863-
7864- if (access_ok(VERIFY_WRITE, to, n))
7865- return __copy_tofrom_user(to, (__force void __user *)from, n);
7866- if ((unsigned long)to < TASK_SIZE) {
7867- over = (unsigned long)to + n - TASK_SIZE;
7868- return __copy_tofrom_user(to, (__force void __user *)from,
7869- n - over) + over;
7870- }
7871- return n;
7872-}
7873-
7874-#else /* __powerpc64__ */
7875-
7876-#define __copy_in_user(to, from, size) \
7877- __copy_tofrom_user((to), (from), (size))
7878-
7879-extern unsigned long copy_from_user(void *to, const void __user *from,
7880- unsigned long n);
7881-extern unsigned long copy_to_user(void __user *to, const void *from,
7882- unsigned long n);
7883-extern unsigned long copy_in_user(void __user *to, const void __user *from,
7884- unsigned long n);
7885-
7886-#endif /* __powerpc64__ */
7887-
7888 static inline unsigned long __copy_from_user_inatomic(void *to,
7889 const void __user *from, unsigned long n)
7890 {
7891@@ -387,6 +341,10 @@ static inline unsigned long __copy_from_user_inatomic(void *to,
7892 if (ret == 0)
7893 return 0;
7894 }
7895+
7896+ if (!__builtin_constant_p(n))
7897+ check_object_size(to, n, false);
7898+
7899 return __copy_tofrom_user((__force void __user *)to, from, n);
7900 }
7901
7902@@ -413,6 +371,10 @@ static inline unsigned long __copy_to_user_inatomic(void __user *to,
7903 if (ret == 0)
7904 return 0;
7905 }
7906+
7907+ if (!__builtin_constant_p(n))
7908+ check_object_size(from, n, true);
7909+
7910 return __copy_tofrom_user(to, (__force const void __user *)from, n);
7911 }
7912
7913@@ -430,6 +392,92 @@ static inline unsigned long __copy_to_user(void __user *to,
7914 return __copy_to_user_inatomic(to, from, size);
7915 }
7916
7917+#ifndef __powerpc64__
7918+
7919+static inline unsigned long __must_check copy_from_user(void *to,
7920+ const void __user *from, unsigned long n)
7921+{
7922+ unsigned long over;
7923+
7924+ if ((long)n < 0)
7925+ return n;
7926+
7927+ if (access_ok(VERIFY_READ, from, n)) {
7928+ if (!__builtin_constant_p(n))
7929+ check_object_size(to, n, false);
7930+ return __copy_tofrom_user((__force void __user *)to, from, n);
7931+ }
7932+ if ((unsigned long)from < TASK_SIZE) {
7933+ over = (unsigned long)from + n - TASK_SIZE;
7934+ if (!__builtin_constant_p(n - over))
7935+ check_object_size(to, n - over, false);
7936+ return __copy_tofrom_user((__force void __user *)to, from,
7937+ n - over) + over;
7938+ }
7939+ return n;
7940+}
7941+
7942+static inline unsigned long __must_check copy_to_user(void __user *to,
7943+ const void *from, unsigned long n)
7944+{
7945+ unsigned long over;
7946+
7947+ if ((long)n < 0)
7948+ return n;
7949+
7950+ if (access_ok(VERIFY_WRITE, to, n)) {
7951+ if (!__builtin_constant_p(n))
7952+ check_object_size(from, n, true);
7953+ return __copy_tofrom_user(to, (__force void __user *)from, n);
7954+ }
7955+ if ((unsigned long)to < TASK_SIZE) {
7956+ over = (unsigned long)to + n - TASK_SIZE;
7957+ if (!__builtin_constant_p(n))
7958+ check_object_size(from, n - over, true);
7959+ return __copy_tofrom_user(to, (__force void __user *)from,
7960+ n - over) + over;
7961+ }
7962+ return n;
7963+}
7964+
7965+#else /* __powerpc64__ */
7966+
7967+#define __copy_in_user(to, from, size) \
7968+ __copy_tofrom_user((to), (from), (size))
7969+
7970+static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
7971+{
7972+ if ((long)n < 0 || n > INT_MAX)
7973+ return n;
7974+
7975+ if (!__builtin_constant_p(n))
7976+ check_object_size(to, n, false);
7977+
7978+ if (likely(access_ok(VERIFY_READ, from, n)))
7979+ n = __copy_from_user(to, from, n);
7980+ else
7981+ memset(to, 0, n);
7982+ return n;
7983+}
7984+
7985+static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
7986+{
7987+ if ((long)n < 0 || n > INT_MAX)
7988+ return n;
7989+
7990+ if (likely(access_ok(VERIFY_WRITE, to, n))) {
7991+ if (!__builtin_constant_p(n))
7992+ check_object_size(from, n, true);
7993+ n = __copy_to_user(to, from, n);
7994+ }
7995+ return n;
7996+}
7997+
7998+extern unsigned long copy_in_user(void __user *to, const void __user *from,
7999+ unsigned long n);
8000+
8001+#endif /* __powerpc64__ */
8002+
8003 extern unsigned long __clear_user(void __user *addr, unsigned long size);
8004
8005 static inline unsigned long clear_user(void __user *addr, unsigned long size)
8006diff --git a/arch/powerpc/kernel/exceptions-64e.S b/arch/powerpc/kernel/exceptions-64e.S
8007index 2d06704..1616f1b 100644
8008--- a/arch/powerpc/kernel/exceptions-64e.S
8009+++ b/arch/powerpc/kernel/exceptions-64e.S
8010@@ -757,6 +757,7 @@ storage_fault_common:
8011 std r14,_DAR(r1)
8012 std r15,_DSISR(r1)
8013 addi r3,r1,STACK_FRAME_OVERHEAD
8014+ bl .save_nvgprs
8015 mr r4,r14
8016 mr r5,r15
8017 ld r14,PACA_EXGEN+EX_R14(r13)
8018@@ -765,8 +766,7 @@ storage_fault_common:
8019 cmpdi r3,0
8020 bne- 1f
8021 b .ret_from_except_lite
8022-1: bl .save_nvgprs
8023- mr r5,r3
8024+1: mr r5,r3
8025 addi r3,r1,STACK_FRAME_OVERHEAD
8026 ld r4,_DAR(r1)
8027 bl .bad_page_fault
8028diff --git a/arch/powerpc/kernel/exceptions-64s.S b/arch/powerpc/kernel/exceptions-64s.S
8029index 3a9ed6a..b534681 100644
8030--- a/arch/powerpc/kernel/exceptions-64s.S
8031+++ b/arch/powerpc/kernel/exceptions-64s.S
8032@@ -1364,10 +1364,10 @@ handle_page_fault:
8033 11: ld r4,_DAR(r1)
8034 ld r5,_DSISR(r1)
8035 addi r3,r1,STACK_FRAME_OVERHEAD
8036+ bl .save_nvgprs
8037 bl .do_page_fault
8038 cmpdi r3,0
8039 beq+ 12f
8040- bl .save_nvgprs
8041 mr r5,r3
8042 addi r3,r1,STACK_FRAME_OVERHEAD
8043 lwz r4,_DAR(r1)
8044diff --git a/arch/powerpc/kernel/module_32.c b/arch/powerpc/kernel/module_32.c
8045index 2e3200c..7118986 100644
8046--- a/arch/powerpc/kernel/module_32.c
8047+++ b/arch/powerpc/kernel/module_32.c
8048@@ -162,7 +162,7 @@ int module_frob_arch_sections(Elf32_Ehdr *hdr,
8049 me->arch.core_plt_section = i;
8050 }
8051 if (!me->arch.core_plt_section || !me->arch.init_plt_section) {
8052- printk("Module doesn't contain .plt or .init.plt sections.\n");
8053+ printk("Module %s doesn't contain .plt or .init.plt sections.\n", me->name);
8054 return -ENOEXEC;
8055 }
8056
8057@@ -192,11 +192,16 @@ static uint32_t do_plt_call(void *location,
8058
8059 DEBUGP("Doing plt for call to 0x%x at 0x%x\n", val, (unsigned int)location);
8060 /* Init, or core PLT? */
8061- if (location >= mod->module_core
8062- && location < mod->module_core + mod->core_size)
8063+ if ((location >= mod->module_core_rx && location < mod->module_core_rx + mod->core_size_rx) ||
8064+ (location >= mod->module_core_rw && location < mod->module_core_rw + mod->core_size_rw))
8065 entry = (void *)sechdrs[mod->arch.core_plt_section].sh_addr;
8066- else
8067+ else if ((location >= mod->module_init_rx && location < mod->module_init_rx + mod->init_size_rx) ||
8068+ (location >= mod->module_init_rw && location < mod->module_init_rw + mod->init_size_rw))
8069 entry = (void *)sechdrs[mod->arch.init_plt_section].sh_addr;
8070+ else {
8071+ printk(KERN_ERR "%s: invalid R_PPC_REL24 entry found\n", mod->name);
8072+ return ~0UL;
8073+ }
8074
8075 /* Find this entry, or if that fails, the next avail. entry */
8076 while (entry->jump[0]) {
8077@@ -300,7 +305,7 @@ int apply_relocate_add(Elf32_Shdr *sechdrs,
8078 }
8079 #ifdef CONFIG_DYNAMIC_FTRACE
8080 module->arch.tramp =
8081- do_plt_call(module->module_core,
8082+ do_plt_call(module->module_core_rx,
8083 (unsigned long)ftrace_caller,
8084 sechdrs, module);
8085 #endif
8086diff --git a/arch/powerpc/kernel/process.c b/arch/powerpc/kernel/process.c
8087index 96d2fdf..f6d10c8 100644
8088--- a/arch/powerpc/kernel/process.c
8089+++ b/arch/powerpc/kernel/process.c
8090@@ -886,8 +886,8 @@ void show_regs(struct pt_regs * regs)
8091 * Lookup NIP late so we have the best change of getting the
8092 * above info out without failing
8093 */
8094- printk("NIP ["REG"] %pS\n", regs->nip, (void *)regs->nip);
8095- printk("LR ["REG"] %pS\n", regs->link, (void *)regs->link);
8096+ printk("NIP ["REG"] %pA\n", regs->nip, (void *)regs->nip);
8097+ printk("LR ["REG"] %pA\n", regs->link, (void *)regs->link);
8098 #endif
8099 #ifdef CONFIG_PPC_TRANSACTIONAL_MEM
8100 printk("PACATMSCRATCH [%llx]\n", get_paca()->tm_scratch);
8101@@ -1352,10 +1352,10 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
8102 newsp = stack[0];
8103 ip = stack[STACK_FRAME_LR_SAVE];
8104 if (!firstframe || ip != lr) {
8105- printk("["REG"] ["REG"] %pS", sp, ip, (void *)ip);
8106+ printk("["REG"] ["REG"] %pA", sp, ip, (void *)ip);
8107 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
8108 if ((ip == rth || ip == mrth) && curr_frame >= 0) {
8109- printk(" (%pS)",
8110+ printk(" (%pA)",
8111 (void *)current->ret_stack[curr_frame].ret);
8112 curr_frame--;
8113 }
8114@@ -1375,7 +1375,7 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
8115 struct pt_regs *regs = (struct pt_regs *)
8116 (sp + STACK_FRAME_OVERHEAD);
8117 lr = regs->link;
8118- printk("--- Exception: %lx at %pS\n LR = %pS\n",
8119+ printk("--- Exception: %lx at %pA\n LR = %pA\n",
8120 regs->trap, (void *)regs->nip, (void *)lr);
8121 firstframe = 1;
8122 }
8123@@ -1411,58 +1411,3 @@ void notrace __ppc64_runlatch_off(void)
8124 mtspr(SPRN_CTRLT, ctrl);
8125 }
8126 #endif /* CONFIG_PPC64 */
8127-
8128-unsigned long arch_align_stack(unsigned long sp)
8129-{
8130- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
8131- sp -= get_random_int() & ~PAGE_MASK;
8132- return sp & ~0xf;
8133-}
8134-
8135-static inline unsigned long brk_rnd(void)
8136-{
8137- unsigned long rnd = 0;
8138-
8139- /* 8MB for 32bit, 1GB for 64bit */
8140- if (is_32bit_task())
8141- rnd = (long)(get_random_int() % (1<<(23-PAGE_SHIFT)));
8142- else
8143- rnd = (long)(get_random_int() % (1<<(30-PAGE_SHIFT)));
8144-
8145- return rnd << PAGE_SHIFT;
8146-}
8147-
8148-unsigned long arch_randomize_brk(struct mm_struct *mm)
8149-{
8150- unsigned long base = mm->brk;
8151- unsigned long ret;
8152-
8153-#ifdef CONFIG_PPC_STD_MMU_64
8154- /*
8155- * If we are using 1TB segments and we are allowed to randomise
8156- * the heap, we can put it above 1TB so it is backed by a 1TB
8157- * segment. Otherwise the heap will be in the bottom 1TB
8158- * which always uses 256MB segments and this may result in a
8159- * performance penalty.
8160- */
8161- if (!is_32bit_task() && (mmu_highuser_ssize == MMU_SEGSIZE_1T))
8162- base = max_t(unsigned long, mm->brk, 1UL << SID_SHIFT_1T);
8163-#endif
8164-
8165- ret = PAGE_ALIGN(base + brk_rnd());
8166-
8167- if (ret < mm->brk)
8168- return mm->brk;
8169-
8170- return ret;
8171-}
8172-
8173-unsigned long randomize_et_dyn(unsigned long base)
8174-{
8175- unsigned long ret = PAGE_ALIGN(base + brk_rnd());
8176-
8177- if (ret < base)
8178- return base;
8179-
8180- return ret;
8181-}
8182diff --git a/arch/powerpc/kernel/ptrace.c b/arch/powerpc/kernel/ptrace.c
8183index 9a0d24c..e7fbedf 100644
8184--- a/arch/powerpc/kernel/ptrace.c
8185+++ b/arch/powerpc/kernel/ptrace.c
8186@@ -1761,6 +1761,10 @@ long arch_ptrace(struct task_struct *child, long request,
8187 return ret;
8188 }
8189
8190+#ifdef CONFIG_GRKERNSEC_SETXID
8191+extern void gr_delayed_cred_worker(void);
8192+#endif
8193+
8194 /*
8195 * We must return the syscall number to actually look up in the table.
8196 * This can be -1L to skip running any syscall at all.
8197@@ -1773,6 +1777,11 @@ long do_syscall_trace_enter(struct pt_regs *regs)
8198
8199 secure_computing_strict(regs->gpr[0]);
8200
8201+#ifdef CONFIG_GRKERNSEC_SETXID
8202+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
8203+ gr_delayed_cred_worker();
8204+#endif
8205+
8206 if (test_thread_flag(TIF_SYSCALL_TRACE) &&
8207 tracehook_report_syscall_entry(regs))
8208 /*
8209@@ -1807,6 +1816,11 @@ void do_syscall_trace_leave(struct pt_regs *regs)
8210 {
8211 int step;
8212
8213+#ifdef CONFIG_GRKERNSEC_SETXID
8214+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
8215+ gr_delayed_cred_worker();
8216+#endif
8217+
8218 audit_syscall_exit(regs);
8219
8220 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
8221diff --git a/arch/powerpc/kernel/signal_32.c b/arch/powerpc/kernel/signal_32.c
8222index fea2dba..a779f6b 100644
8223--- a/arch/powerpc/kernel/signal_32.c
8224+++ b/arch/powerpc/kernel/signal_32.c
8225@@ -1002,7 +1002,7 @@ int handle_rt_signal32(unsigned long sig, struct k_sigaction *ka,
8226 /* Save user registers on the stack */
8227 frame = &rt_sf->uc.uc_mcontext;
8228 addr = frame;
8229- if (vdso32_rt_sigtramp && current->mm->context.vdso_base) {
8230+ if (vdso32_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
8231 sigret = 0;
8232 tramp = current->mm->context.vdso_base + vdso32_rt_sigtramp;
8233 } else {
8234diff --git a/arch/powerpc/kernel/signal_64.c b/arch/powerpc/kernel/signal_64.c
8235index 1e7ba88..17afb1b 100644
8236--- a/arch/powerpc/kernel/signal_64.c
8237+++ b/arch/powerpc/kernel/signal_64.c
8238@@ -763,7 +763,7 @@ int handle_rt_signal64(int signr, struct k_sigaction *ka, siginfo_t *info,
8239 #endif
8240
8241 /* Set up to return from userspace. */
8242- if (vdso64_rt_sigtramp && current->mm->context.vdso_base) {
8243+ if (vdso64_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
8244 regs->link = current->mm->context.vdso_base + vdso64_rt_sigtramp;
8245 } else {
8246 err |= setup_trampoline(__NR_rt_sigreturn, &frame->tramp[0]);
8247diff --git a/arch/powerpc/kernel/traps.c b/arch/powerpc/kernel/traps.c
8248index f783c93..619baf1 100644
8249--- a/arch/powerpc/kernel/traps.c
8250+++ b/arch/powerpc/kernel/traps.c
8251@@ -142,6 +142,8 @@ static unsigned __kprobes long oops_begin(struct pt_regs *regs)
8252 return flags;
8253 }
8254
8255+extern void gr_handle_kernel_exploit(void);
8256+
8257 static void __kprobes oops_end(unsigned long flags, struct pt_regs *regs,
8258 int signr)
8259 {
8260@@ -191,6 +193,9 @@ static void __kprobes oops_end(unsigned long flags, struct pt_regs *regs,
8261 panic("Fatal exception in interrupt");
8262 if (panic_on_oops)
8263 panic("Fatal exception");
8264+
8265+ gr_handle_kernel_exploit();
8266+
8267 do_exit(signr);
8268 }
8269
8270diff --git a/arch/powerpc/kernel/vdso.c b/arch/powerpc/kernel/vdso.c
8271index 1d9c926..25f4741 100644
8272--- a/arch/powerpc/kernel/vdso.c
8273+++ b/arch/powerpc/kernel/vdso.c
8274@@ -34,6 +34,7 @@
8275 #include <asm/firmware.h>
8276 #include <asm/vdso.h>
8277 #include <asm/vdso_datapage.h>
8278+#include <asm/mman.h>
8279
8280 #include "setup.h"
8281
8282@@ -222,7 +223,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
8283 vdso_base = VDSO32_MBASE;
8284 #endif
8285
8286- current->mm->context.vdso_base = 0;
8287+ current->mm->context.vdso_base = ~0UL;
8288
8289 /* vDSO has a problem and was disabled, just don't "enable" it for the
8290 * process
8291@@ -242,7 +243,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
8292 vdso_base = get_unmapped_area(NULL, vdso_base,
8293 (vdso_pages << PAGE_SHIFT) +
8294 ((VDSO_ALIGNMENT - 1) & PAGE_MASK),
8295- 0, 0);
8296+ 0, MAP_PRIVATE | MAP_EXECUTABLE);
8297 if (IS_ERR_VALUE(vdso_base)) {
8298 rc = vdso_base;
8299 goto fail_mmapsem;
8300diff --git a/arch/powerpc/lib/usercopy_64.c b/arch/powerpc/lib/usercopy_64.c
8301index 5eea6f3..5d10396 100644
8302--- a/arch/powerpc/lib/usercopy_64.c
8303+++ b/arch/powerpc/lib/usercopy_64.c
8304@@ -9,22 +9,6 @@
8305 #include <linux/module.h>
8306 #include <asm/uaccess.h>
8307
8308-unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
8309-{
8310- if (likely(access_ok(VERIFY_READ, from, n)))
8311- n = __copy_from_user(to, from, n);
8312- else
8313- memset(to, 0, n);
8314- return n;
8315-}
8316-
8317-unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
8318-{
8319- if (likely(access_ok(VERIFY_WRITE, to, n)))
8320- n = __copy_to_user(to, from, n);
8321- return n;
8322-}
8323-
8324 unsigned long copy_in_user(void __user *to, const void __user *from,
8325 unsigned long n)
8326 {
8327@@ -35,7 +19,5 @@ unsigned long copy_in_user(void __user *to, const void __user *from,
8328 return n;
8329 }
8330
8331-EXPORT_SYMBOL(copy_from_user);
8332-EXPORT_SYMBOL(copy_to_user);
8333 EXPORT_SYMBOL(copy_in_user);
8334
8335diff --git a/arch/powerpc/mm/fault.c b/arch/powerpc/mm/fault.c
8336index 51ab9e7..7d3c78b 100644
8337--- a/arch/powerpc/mm/fault.c
8338+++ b/arch/powerpc/mm/fault.c
8339@@ -33,6 +33,10 @@
8340 #include <linux/magic.h>
8341 #include <linux/ratelimit.h>
8342 #include <linux/context_tracking.h>
8343+#include <linux/slab.h>
8344+#include <linux/pagemap.h>
8345+#include <linux/compiler.h>
8346+#include <linux/unistd.h>
8347
8348 #include <asm/firmware.h>
8349 #include <asm/page.h>
8350@@ -69,6 +73,33 @@ static inline int notify_page_fault(struct pt_regs *regs)
8351 }
8352 #endif
8353
8354+#ifdef CONFIG_PAX_PAGEEXEC
8355+/*
8356+ * PaX: decide what to do with offenders (regs->nip = fault address)
8357+ *
8358+ * returns 1 when task should be killed
8359+ */
8360+static int pax_handle_fetch_fault(struct pt_regs *regs)
8361+{
8362+ return 1;
8363+}
8364+
8365+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
8366+{
8367+ unsigned long i;
8368+
8369+ printk(KERN_ERR "PAX: bytes at PC: ");
8370+ for (i = 0; i < 5; i++) {
8371+ unsigned int c;
8372+ if (get_user(c, (unsigned int __user *)pc+i))
8373+ printk(KERN_CONT "???????? ");
8374+ else
8375+ printk(KERN_CONT "%08x ", c);
8376+ }
8377+ printk("\n");
8378+}
8379+#endif
8380+
8381 /*
8382 * Check whether the instruction at regs->nip is a store using
8383 * an update addressing form which will update r1.
8384@@ -216,7 +247,7 @@ int __kprobes do_page_fault(struct pt_regs *regs, unsigned long address,
8385 * indicate errors in DSISR but can validly be set in SRR1.
8386 */
8387 if (trap == 0x400)
8388- error_code &= 0x48200000;
8389+ error_code &= 0x58200000;
8390 else
8391 is_write = error_code & DSISR_ISSTORE;
8392 #else
8393@@ -378,7 +409,7 @@ good_area:
8394 * "undefined". Of those that can be set, this is the only
8395 * one which seems bad.
8396 */
8397- if (error_code & 0x10000000)
8398+ if (error_code & DSISR_GUARDED)
8399 /* Guarded storage error. */
8400 goto bad_area;
8401 #endif /* CONFIG_8xx */
8402@@ -393,7 +424,7 @@ good_area:
8403 * processors use the same I/D cache coherency mechanism
8404 * as embedded.
8405 */
8406- if (error_code & DSISR_PROTFAULT)
8407+ if (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))
8408 goto bad_area;
8409 #endif /* CONFIG_PPC_STD_MMU */
8410
8411@@ -483,6 +514,23 @@ bad_area:
8412 bad_area_nosemaphore:
8413 /* User mode accesses cause a SIGSEGV */
8414 if (user_mode(regs)) {
8415+
8416+#ifdef CONFIG_PAX_PAGEEXEC
8417+ if (mm->pax_flags & MF_PAX_PAGEEXEC) {
8418+#ifdef CONFIG_PPC_STD_MMU
8419+ if (is_exec && (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))) {
8420+#else
8421+ if (is_exec && regs->nip == address) {
8422+#endif
8423+ switch (pax_handle_fetch_fault(regs)) {
8424+ }
8425+
8426+ pax_report_fault(regs, (void *)regs->nip, (void *)regs->gpr[PT_R1]);
8427+ do_group_exit(SIGKILL);
8428+ }
8429+ }
8430+#endif
8431+
8432 _exception(SIGSEGV, regs, code, address);
8433 goto bail;
8434 }
8435diff --git a/arch/powerpc/mm/mmap.c b/arch/powerpc/mm/mmap.c
8436index cb8bdbe..d770680 100644
8437--- a/arch/powerpc/mm/mmap.c
8438+++ b/arch/powerpc/mm/mmap.c
8439@@ -57,6 +57,10 @@ static unsigned long mmap_rnd(void)
8440 {
8441 unsigned long rnd = 0;
8442
8443+#ifdef CONFIG_PAX_RANDMMAP
8444+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
8445+#endif
8446+
8447 if (current->flags & PF_RANDOMIZE) {
8448 /* 8MB for 32bit, 1GB for 64bit */
8449 if (is_32bit_task())
8450@@ -91,9 +95,21 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
8451 */
8452 if (mmap_is_legacy()) {
8453 mm->mmap_base = TASK_UNMAPPED_BASE;
8454+
8455+#ifdef CONFIG_PAX_RANDMMAP
8456+ if (mm->pax_flags & MF_PAX_RANDMMAP)
8457+ mm->mmap_base += mm->delta_mmap;
8458+#endif
8459+
8460 mm->get_unmapped_area = arch_get_unmapped_area;
8461 } else {
8462 mm->mmap_base = mmap_base();
8463+
8464+#ifdef CONFIG_PAX_RANDMMAP
8465+ if (mm->pax_flags & MF_PAX_RANDMMAP)
8466+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
8467+#endif
8468+
8469 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
8470 }
8471 }
8472diff --git a/arch/powerpc/mm/slice.c b/arch/powerpc/mm/slice.c
8473index 7ce9cf3..a964087 100644
8474--- a/arch/powerpc/mm/slice.c
8475+++ b/arch/powerpc/mm/slice.c
8476@@ -103,7 +103,7 @@ static int slice_area_is_free(struct mm_struct *mm, unsigned long addr,
8477 if ((mm->task_size - len) < addr)
8478 return 0;
8479 vma = find_vma(mm, addr);
8480- return (!vma || (addr + len) <= vma->vm_start);
8481+ return check_heap_stack_gap(vma, addr, len, 0);
8482 }
8483
8484 static int slice_low_has_vma(struct mm_struct *mm, unsigned long slice)
8485@@ -277,6 +277,12 @@ static unsigned long slice_find_area_bottomup(struct mm_struct *mm,
8486 info.align_offset = 0;
8487
8488 addr = TASK_UNMAPPED_BASE;
8489+
8490+#ifdef CONFIG_PAX_RANDMMAP
8491+ if (mm->pax_flags & MF_PAX_RANDMMAP)
8492+ addr += mm->delta_mmap;
8493+#endif
8494+
8495 while (addr < TASK_SIZE) {
8496 info.low_limit = addr;
8497 if (!slice_scan_available(addr, available, 1, &addr))
8498@@ -410,6 +416,11 @@ unsigned long slice_get_unmapped_area(unsigned long addr, unsigned long len,
8499 if (fixed && addr > (mm->task_size - len))
8500 return -EINVAL;
8501
8502+#ifdef CONFIG_PAX_RANDMMAP
8503+ if (!fixed && (mm->pax_flags & MF_PAX_RANDMMAP))
8504+ addr = 0;
8505+#endif
8506+
8507 /* If hint, make sure it matches our alignment restrictions */
8508 if (!fixed && addr) {
8509 addr = _ALIGN_UP(addr, 1ul << pshift);
8510diff --git a/arch/powerpc/net/bpf_jit_comp.c b/arch/powerpc/net/bpf_jit_comp.c
8511index 2345bdb..ebbb2f1 100644
8512--- a/arch/powerpc/net/bpf_jit_comp.c
8513+++ b/arch/powerpc/net/bpf_jit_comp.c
8514@@ -209,10 +209,11 @@ static int bpf_jit_build_body(struct sk_filter *fp, u32 *image,
8515 }
8516 PPC_DIVWU(r_A, r_A, r_X);
8517 break;
8518- case BPF_S_ALU_DIV_K: /* A = reciprocal_divide(A, K); */
8519+ case BPF_S_ALU_DIV_K: /* A /= K */
8520+ if (K == 1)
8521+ break;
8522 PPC_LI32(r_scratch1, K);
8523- /* Top 32 bits of 64bit result -> A */
8524- PPC_MULHWU(r_A, r_A, r_scratch1);
8525+ PPC_DIVWU(r_A, r_A, r_scratch1);
8526 break;
8527 case BPF_S_ALU_AND_X:
8528 ctx->seen |= SEEN_XREG;
8529diff --git a/arch/powerpc/platforms/cell/spufs/file.c b/arch/powerpc/platforms/cell/spufs/file.c
8530index 9098692..3d54cd1 100644
8531--- a/arch/powerpc/platforms/cell/spufs/file.c
8532+++ b/arch/powerpc/platforms/cell/spufs/file.c
8533@@ -280,9 +280,9 @@ spufs_mem_mmap_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
8534 return VM_FAULT_NOPAGE;
8535 }
8536
8537-static int spufs_mem_mmap_access(struct vm_area_struct *vma,
8538+static ssize_t spufs_mem_mmap_access(struct vm_area_struct *vma,
8539 unsigned long address,
8540- void *buf, int len, int write)
8541+ void *buf, size_t len, int write)
8542 {
8543 struct spu_context *ctx = vma->vm_file->private_data;
8544 unsigned long offset = address - vma->vm_start;
8545diff --git a/arch/s390/include/asm/atomic.h b/arch/s390/include/asm/atomic.h
8546index c797832..ce575c8 100644
8547--- a/arch/s390/include/asm/atomic.h
8548+++ b/arch/s390/include/asm/atomic.h
8549@@ -326,6 +326,16 @@ static inline long long atomic64_dec_if_positive(atomic64_t *v)
8550 #define atomic64_dec_and_test(_v) (atomic64_sub_return(1, _v) == 0)
8551 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
8552
8553+#define atomic64_read_unchecked(v) atomic64_read(v)
8554+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
8555+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
8556+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
8557+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
8558+#define atomic64_inc_unchecked(v) atomic64_inc(v)
8559+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
8560+#define atomic64_dec_unchecked(v) atomic64_dec(v)
8561+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
8562+
8563 #define smp_mb__before_atomic_dec() smp_mb()
8564 #define smp_mb__after_atomic_dec() smp_mb()
8565 #define smp_mb__before_atomic_inc() smp_mb()
8566diff --git a/arch/s390/include/asm/cache.h b/arch/s390/include/asm/cache.h
8567index 4d7ccac..d03d0ad 100644
8568--- a/arch/s390/include/asm/cache.h
8569+++ b/arch/s390/include/asm/cache.h
8570@@ -9,8 +9,10 @@
8571 #ifndef __ARCH_S390_CACHE_H
8572 #define __ARCH_S390_CACHE_H
8573
8574-#define L1_CACHE_BYTES 256
8575+#include <linux/const.h>
8576+
8577 #define L1_CACHE_SHIFT 8
8578+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
8579 #define NET_SKB_PAD 32
8580
8581 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
8582diff --git a/arch/s390/include/asm/elf.h b/arch/s390/include/asm/elf.h
8583index 78f4f87..598ce39 100644
8584--- a/arch/s390/include/asm/elf.h
8585+++ b/arch/s390/include/asm/elf.h
8586@@ -162,8 +162,14 @@ extern unsigned int vdso_enabled;
8587 the loader. We need to make sure that it is out of the way of the program
8588 that it will "exec", and that there is sufficient room for the brk. */
8589
8590-extern unsigned long randomize_et_dyn(unsigned long base);
8591-#define ELF_ET_DYN_BASE (randomize_et_dyn(STACK_TOP / 3 * 2))
8592+#define ELF_ET_DYN_BASE (STACK_TOP / 3 * 2)
8593+
8594+#ifdef CONFIG_PAX_ASLR
8595+#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_31BIT) ? 0x10000UL : 0x80000000UL)
8596+
8597+#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
8598+#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
8599+#endif
8600
8601 /* This yields a mask that user programs can use to figure out what
8602 instruction set this CPU supports. */
8603@@ -222,9 +228,6 @@ struct linux_binprm;
8604 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
8605 int arch_setup_additional_pages(struct linux_binprm *, int);
8606
8607-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
8608-#define arch_randomize_brk arch_randomize_brk
8609-
8610 void *fill_cpu_elf_notes(void *ptr, struct save_area *sa);
8611
8612 #endif
8613diff --git a/arch/s390/include/asm/exec.h b/arch/s390/include/asm/exec.h
8614index c4a93d6..4d2a9b4 100644
8615--- a/arch/s390/include/asm/exec.h
8616+++ b/arch/s390/include/asm/exec.h
8617@@ -7,6 +7,6 @@
8618 #ifndef __ASM_EXEC_H
8619 #define __ASM_EXEC_H
8620
8621-extern unsigned long arch_align_stack(unsigned long sp);
8622+#define arch_align_stack(x) ((x) & ~0xfUL)
8623
8624 #endif /* __ASM_EXEC_H */
8625diff --git a/arch/s390/include/asm/uaccess.h b/arch/s390/include/asm/uaccess.h
8626index 9c33ed4..e40cbef 100644
8627--- a/arch/s390/include/asm/uaccess.h
8628+++ b/arch/s390/include/asm/uaccess.h
8629@@ -252,6 +252,10 @@ static inline unsigned long __must_check
8630 copy_to_user(void __user *to, const void *from, unsigned long n)
8631 {
8632 might_fault();
8633+
8634+ if ((long)n < 0)
8635+ return n;
8636+
8637 return __copy_to_user(to, from, n);
8638 }
8639
8640@@ -275,6 +279,9 @@ copy_to_user(void __user *to, const void *from, unsigned long n)
8641 static inline unsigned long __must_check
8642 __copy_from_user(void *to, const void __user *from, unsigned long n)
8643 {
8644+ if ((long)n < 0)
8645+ return n;
8646+
8647 if (__builtin_constant_p(n) && (n <= 256))
8648 return uaccess.copy_from_user_small(n, from, to);
8649 else
8650@@ -306,10 +313,14 @@ __compiletime_warning("copy_from_user() buffer size is not provably correct")
8651 static inline unsigned long __must_check
8652 copy_from_user(void *to, const void __user *from, unsigned long n)
8653 {
8654- unsigned int sz = __compiletime_object_size(to);
8655+ size_t sz = __compiletime_object_size(to);
8656
8657 might_fault();
8658- if (unlikely(sz != -1 && sz < n)) {
8659+
8660+ if ((long)n < 0)
8661+ return n;
8662+
8663+ if (unlikely(sz != (size_t)-1 && sz < n)) {
8664 copy_from_user_overflow();
8665 return n;
8666 }
8667diff --git a/arch/s390/kernel/module.c b/arch/s390/kernel/module.c
8668index 7845e15..59c4353 100644
8669--- a/arch/s390/kernel/module.c
8670+++ b/arch/s390/kernel/module.c
8671@@ -169,11 +169,11 @@ int module_frob_arch_sections(Elf_Ehdr *hdr, Elf_Shdr *sechdrs,
8672
8673 /* Increase core size by size of got & plt and set start
8674 offsets for got and plt. */
8675- me->core_size = ALIGN(me->core_size, 4);
8676- me->arch.got_offset = me->core_size;
8677- me->core_size += me->arch.got_size;
8678- me->arch.plt_offset = me->core_size;
8679- me->core_size += me->arch.plt_size;
8680+ me->core_size_rw = ALIGN(me->core_size_rw, 4);
8681+ me->arch.got_offset = me->core_size_rw;
8682+ me->core_size_rw += me->arch.got_size;
8683+ me->arch.plt_offset = me->core_size_rx;
8684+ me->core_size_rx += me->arch.plt_size;
8685 return 0;
8686 }
8687
8688@@ -289,7 +289,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
8689 if (info->got_initialized == 0) {
8690 Elf_Addr *gotent;
8691
8692- gotent = me->module_core + me->arch.got_offset +
8693+ gotent = me->module_core_rw + me->arch.got_offset +
8694 info->got_offset;
8695 *gotent = val;
8696 info->got_initialized = 1;
8697@@ -312,7 +312,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
8698 rc = apply_rela_bits(loc, val, 0, 64, 0);
8699 else if (r_type == R_390_GOTENT ||
8700 r_type == R_390_GOTPLTENT) {
8701- val += (Elf_Addr) me->module_core - loc;
8702+ val += (Elf_Addr) me->module_core_rw - loc;
8703 rc = apply_rela_bits(loc, val, 1, 32, 1);
8704 }
8705 break;
8706@@ -325,7 +325,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
8707 case R_390_PLTOFF64: /* 16 bit offset from GOT to PLT. */
8708 if (info->plt_initialized == 0) {
8709 unsigned int *ip;
8710- ip = me->module_core + me->arch.plt_offset +
8711+ ip = me->module_core_rx + me->arch.plt_offset +
8712 info->plt_offset;
8713 #ifndef CONFIG_64BIT
8714 ip[0] = 0x0d105810; /* basr 1,0; l 1,6(1); br 1 */
8715@@ -350,7 +350,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
8716 val - loc + 0xffffUL < 0x1ffffeUL) ||
8717 (r_type == R_390_PLT32DBL &&
8718 val - loc + 0xffffffffULL < 0x1fffffffeULL)))
8719- val = (Elf_Addr) me->module_core +
8720+ val = (Elf_Addr) me->module_core_rx +
8721 me->arch.plt_offset +
8722 info->plt_offset;
8723 val += rela->r_addend - loc;
8724@@ -372,7 +372,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
8725 case R_390_GOTOFF32: /* 32 bit offset to GOT. */
8726 case R_390_GOTOFF64: /* 64 bit offset to GOT. */
8727 val = val + rela->r_addend -
8728- ((Elf_Addr) me->module_core + me->arch.got_offset);
8729+ ((Elf_Addr) me->module_core_rw + me->arch.got_offset);
8730 if (r_type == R_390_GOTOFF16)
8731 rc = apply_rela_bits(loc, val, 0, 16, 0);
8732 else if (r_type == R_390_GOTOFF32)
8733@@ -382,7 +382,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
8734 break;
8735 case R_390_GOTPC: /* 32 bit PC relative offset to GOT. */
8736 case R_390_GOTPCDBL: /* 32 bit PC rel. off. to GOT shifted by 1. */
8737- val = (Elf_Addr) me->module_core + me->arch.got_offset +
8738+ val = (Elf_Addr) me->module_core_rw + me->arch.got_offset +
8739 rela->r_addend - loc;
8740 if (r_type == R_390_GOTPC)
8741 rc = apply_rela_bits(loc, val, 1, 32, 0);
8742diff --git a/arch/s390/kernel/process.c b/arch/s390/kernel/process.c
8743index c5dbb33..b41f4ee 100644
8744--- a/arch/s390/kernel/process.c
8745+++ b/arch/s390/kernel/process.c
8746@@ -237,39 +237,3 @@ unsigned long get_wchan(struct task_struct *p)
8747 }
8748 return 0;
8749 }
8750-
8751-unsigned long arch_align_stack(unsigned long sp)
8752-{
8753- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
8754- sp -= get_random_int() & ~PAGE_MASK;
8755- return sp & ~0xf;
8756-}
8757-
8758-static inline unsigned long brk_rnd(void)
8759-{
8760- /* 8MB for 32bit, 1GB for 64bit */
8761- if (is_32bit_task())
8762- return (get_random_int() & 0x7ffUL) << PAGE_SHIFT;
8763- else
8764- return (get_random_int() & 0x3ffffUL) << PAGE_SHIFT;
8765-}
8766-
8767-unsigned long arch_randomize_brk(struct mm_struct *mm)
8768-{
8769- unsigned long ret = PAGE_ALIGN(mm->brk + brk_rnd());
8770-
8771- if (ret < mm->brk)
8772- return mm->brk;
8773- return ret;
8774-}
8775-
8776-unsigned long randomize_et_dyn(unsigned long base)
8777-{
8778- unsigned long ret = PAGE_ALIGN(base + brk_rnd());
8779-
8780- if (!(current->flags & PF_RANDOMIZE))
8781- return base;
8782- if (ret < base)
8783- return base;
8784- return ret;
8785-}
8786diff --git a/arch/s390/mm/mmap.c b/arch/s390/mm/mmap.c
8787index 4002329..99b67cb 100644
8788--- a/arch/s390/mm/mmap.c
8789+++ b/arch/s390/mm/mmap.c
8790@@ -90,9 +90,21 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
8791 */
8792 if (mmap_is_legacy()) {
8793 mm->mmap_base = TASK_UNMAPPED_BASE;
8794+
8795+#ifdef CONFIG_PAX_RANDMMAP
8796+ if (mm->pax_flags & MF_PAX_RANDMMAP)
8797+ mm->mmap_base += mm->delta_mmap;
8798+#endif
8799+
8800 mm->get_unmapped_area = arch_get_unmapped_area;
8801 } else {
8802 mm->mmap_base = mmap_base();
8803+
8804+#ifdef CONFIG_PAX_RANDMMAP
8805+ if (mm->pax_flags & MF_PAX_RANDMMAP)
8806+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
8807+#endif
8808+
8809 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
8810 }
8811 }
8812@@ -173,9 +185,21 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
8813 */
8814 if (mmap_is_legacy()) {
8815 mm->mmap_base = TASK_UNMAPPED_BASE;
8816+
8817+#ifdef CONFIG_PAX_RANDMMAP
8818+ if (mm->pax_flags & MF_PAX_RANDMMAP)
8819+ mm->mmap_base += mm->delta_mmap;
8820+#endif
8821+
8822 mm->get_unmapped_area = s390_get_unmapped_area;
8823 } else {
8824 mm->mmap_base = mmap_base();
8825+
8826+#ifdef CONFIG_PAX_RANDMMAP
8827+ if (mm->pax_flags & MF_PAX_RANDMMAP)
8828+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
8829+#endif
8830+
8831 mm->get_unmapped_area = s390_get_unmapped_area_topdown;
8832 }
8833 }
8834diff --git a/arch/s390/net/bpf_jit_comp.c b/arch/s390/net/bpf_jit_comp.c
8835index a5df511..06f5acc 100644
8836--- a/arch/s390/net/bpf_jit_comp.c
8837+++ b/arch/s390/net/bpf_jit_comp.c
8838@@ -371,11 +371,13 @@ static int bpf_jit_insn(struct bpf_jit *jit, struct sock_filter *filter,
8839 /* dr %r4,%r12 */
8840 EMIT2(0x1d4c);
8841 break;
8842- case BPF_S_ALU_DIV_K: /* A = reciprocal_divide(A, K) */
8843- /* m %r4,<d(K)>(%r13) */
8844- EMIT4_DISP(0x5c40d000, EMIT_CONST(K));
8845- /* lr %r5,%r4 */
8846- EMIT2(0x1854);
8847+ case BPF_S_ALU_DIV_K: /* A /= K */
8848+ if (K == 1)
8849+ break;
8850+ /* lhi %r4,0 */
8851+ EMIT4(0xa7480000);
8852+ /* d %r4,<d(K)>(%r13) */
8853+ EMIT4_DISP(0x5d40d000, EMIT_CONST(K));
8854 break;
8855 case BPF_S_ALU_MOD_X: /* A %= X */
8856 jit->seen |= SEEN_XREG | SEEN_RET0;
8857@@ -391,6 +393,11 @@ static int bpf_jit_insn(struct bpf_jit *jit, struct sock_filter *filter,
8858 EMIT2(0x1854);
8859 break;
8860 case BPF_S_ALU_MOD_K: /* A %= K */
8861+ if (K == 1) {
8862+ /* lhi %r5,0 */
8863+ EMIT4(0xa7580000);
8864+ break;
8865+ }
8866 /* lhi %r4,0 */
8867 EMIT4(0xa7480000);
8868 /* d %r4,<d(K)>(%r13) */
8869diff --git a/arch/score/include/asm/cache.h b/arch/score/include/asm/cache.h
8870index ae3d59f..f65f075 100644
8871--- a/arch/score/include/asm/cache.h
8872+++ b/arch/score/include/asm/cache.h
8873@@ -1,7 +1,9 @@
8874 #ifndef _ASM_SCORE_CACHE_H
8875 #define _ASM_SCORE_CACHE_H
8876
8877+#include <linux/const.h>
8878+
8879 #define L1_CACHE_SHIFT 4
8880-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
8881+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
8882
8883 #endif /* _ASM_SCORE_CACHE_H */
8884diff --git a/arch/score/include/asm/exec.h b/arch/score/include/asm/exec.h
8885index f9f3cd5..58ff438 100644
8886--- a/arch/score/include/asm/exec.h
8887+++ b/arch/score/include/asm/exec.h
8888@@ -1,6 +1,6 @@
8889 #ifndef _ASM_SCORE_EXEC_H
8890 #define _ASM_SCORE_EXEC_H
8891
8892-extern unsigned long arch_align_stack(unsigned long sp);
8893+#define arch_align_stack(x) (x)
8894
8895 #endif /* _ASM_SCORE_EXEC_H */
8896diff --git a/arch/score/kernel/process.c b/arch/score/kernel/process.c
8897index a1519ad3..e8ac1ff 100644
8898--- a/arch/score/kernel/process.c
8899+++ b/arch/score/kernel/process.c
8900@@ -116,8 +116,3 @@ unsigned long get_wchan(struct task_struct *task)
8901
8902 return task_pt_regs(task)->cp0_epc;
8903 }
8904-
8905-unsigned long arch_align_stack(unsigned long sp)
8906-{
8907- return sp;
8908-}
8909diff --git a/arch/sh/include/asm/cache.h b/arch/sh/include/asm/cache.h
8910index ef9e555..331bd29 100644
8911--- a/arch/sh/include/asm/cache.h
8912+++ b/arch/sh/include/asm/cache.h
8913@@ -9,10 +9,11 @@
8914 #define __ASM_SH_CACHE_H
8915 #ifdef __KERNEL__
8916
8917+#include <linux/const.h>
8918 #include <linux/init.h>
8919 #include <cpu/cache.h>
8920
8921-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
8922+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
8923
8924 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
8925
8926diff --git a/arch/sh/mm/mmap.c b/arch/sh/mm/mmap.c
8927index 6777177..cb5e44f 100644
8928--- a/arch/sh/mm/mmap.c
8929+++ b/arch/sh/mm/mmap.c
8930@@ -36,6 +36,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
8931 struct mm_struct *mm = current->mm;
8932 struct vm_area_struct *vma;
8933 int do_colour_align;
8934+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
8935 struct vm_unmapped_area_info info;
8936
8937 if (flags & MAP_FIXED) {
8938@@ -55,6 +56,10 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
8939 if (filp || (flags & MAP_SHARED))
8940 do_colour_align = 1;
8941
8942+#ifdef CONFIG_PAX_RANDMMAP
8943+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
8944+#endif
8945+
8946 if (addr) {
8947 if (do_colour_align)
8948 addr = COLOUR_ALIGN(addr, pgoff);
8949@@ -62,14 +67,13 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
8950 addr = PAGE_ALIGN(addr);
8951
8952 vma = find_vma(mm, addr);
8953- if (TASK_SIZE - len >= addr &&
8954- (!vma || addr + len <= vma->vm_start))
8955+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
8956 return addr;
8957 }
8958
8959 info.flags = 0;
8960 info.length = len;
8961- info.low_limit = TASK_UNMAPPED_BASE;
8962+ info.low_limit = mm->mmap_base;
8963 info.high_limit = TASK_SIZE;
8964 info.align_mask = do_colour_align ? (PAGE_MASK & shm_align_mask) : 0;
8965 info.align_offset = pgoff << PAGE_SHIFT;
8966@@ -85,6 +89,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
8967 struct mm_struct *mm = current->mm;
8968 unsigned long addr = addr0;
8969 int do_colour_align;
8970+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
8971 struct vm_unmapped_area_info info;
8972
8973 if (flags & MAP_FIXED) {
8974@@ -104,6 +109,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
8975 if (filp || (flags & MAP_SHARED))
8976 do_colour_align = 1;
8977
8978+#ifdef CONFIG_PAX_RANDMMAP
8979+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
8980+#endif
8981+
8982 /* requesting a specific address */
8983 if (addr) {
8984 if (do_colour_align)
8985@@ -112,8 +121,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
8986 addr = PAGE_ALIGN(addr);
8987
8988 vma = find_vma(mm, addr);
8989- if (TASK_SIZE - len >= addr &&
8990- (!vma || addr + len <= vma->vm_start))
8991+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
8992 return addr;
8993 }
8994
8995@@ -135,6 +143,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
8996 VM_BUG_ON(addr != -ENOMEM);
8997 info.flags = 0;
8998 info.low_limit = TASK_UNMAPPED_BASE;
8999+
9000+#ifdef CONFIG_PAX_RANDMMAP
9001+ if (mm->pax_flags & MF_PAX_RANDMMAP)
9002+ info.low_limit += mm->delta_mmap;
9003+#endif
9004+
9005 info.high_limit = TASK_SIZE;
9006 addr = vm_unmapped_area(&info);
9007 }
9008diff --git a/arch/sparc/include/asm/atomic_64.h b/arch/sparc/include/asm/atomic_64.h
9009index be56a24..443328f 100644
9010--- a/arch/sparc/include/asm/atomic_64.h
9011+++ b/arch/sparc/include/asm/atomic_64.h
9012@@ -14,18 +14,40 @@
9013 #define ATOMIC64_INIT(i) { (i) }
9014
9015 #define atomic_read(v) (*(volatile int *)&(v)->counter)
9016+static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
9017+{
9018+ return v->counter;
9019+}
9020 #define atomic64_read(v) (*(volatile long *)&(v)->counter)
9021+static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
9022+{
9023+ return v->counter;
9024+}
9025
9026 #define atomic_set(v, i) (((v)->counter) = i)
9027+static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
9028+{
9029+ v->counter = i;
9030+}
9031 #define atomic64_set(v, i) (((v)->counter) = i)
9032+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
9033+{
9034+ v->counter = i;
9035+}
9036
9037 extern void atomic_add(int, atomic_t *);
9038+extern void atomic_add_unchecked(int, atomic_unchecked_t *);
9039 extern void atomic64_add(long, atomic64_t *);
9040+extern void atomic64_add_unchecked(long, atomic64_unchecked_t *);
9041 extern void atomic_sub(int, atomic_t *);
9042+extern void atomic_sub_unchecked(int, atomic_unchecked_t *);
9043 extern void atomic64_sub(long, atomic64_t *);
9044+extern void atomic64_sub_unchecked(long, atomic64_unchecked_t *);
9045
9046 extern int atomic_add_ret(int, atomic_t *);
9047+extern int atomic_add_ret_unchecked(int, atomic_unchecked_t *);
9048 extern long atomic64_add_ret(long, atomic64_t *);
9049+extern long atomic64_add_ret_unchecked(long, atomic64_unchecked_t *);
9050 extern int atomic_sub_ret(int, atomic_t *);
9051 extern long atomic64_sub_ret(long, atomic64_t *);
9052
9053@@ -33,13 +55,29 @@ extern long atomic64_sub_ret(long, atomic64_t *);
9054 #define atomic64_dec_return(v) atomic64_sub_ret(1, v)
9055
9056 #define atomic_inc_return(v) atomic_add_ret(1, v)
9057+static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
9058+{
9059+ return atomic_add_ret_unchecked(1, v);
9060+}
9061 #define atomic64_inc_return(v) atomic64_add_ret(1, v)
9062+static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
9063+{
9064+ return atomic64_add_ret_unchecked(1, v);
9065+}
9066
9067 #define atomic_sub_return(i, v) atomic_sub_ret(i, v)
9068 #define atomic64_sub_return(i, v) atomic64_sub_ret(i, v)
9069
9070 #define atomic_add_return(i, v) atomic_add_ret(i, v)
9071+static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
9072+{
9073+ return atomic_add_ret_unchecked(i, v);
9074+}
9075 #define atomic64_add_return(i, v) atomic64_add_ret(i, v)
9076+static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
9077+{
9078+ return atomic64_add_ret_unchecked(i, v);
9079+}
9080
9081 /*
9082 * atomic_inc_and_test - increment and test
9083@@ -50,6 +88,10 @@ extern long atomic64_sub_ret(long, atomic64_t *);
9084 * other cases.
9085 */
9086 #define atomic_inc_and_test(v) (atomic_inc_return(v) == 0)
9087+static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
9088+{
9089+ return atomic_inc_return_unchecked(v) == 0;
9090+}
9091 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
9092
9093 #define atomic_sub_and_test(i, v) (atomic_sub_ret(i, v) == 0)
9094@@ -59,25 +101,60 @@ extern long atomic64_sub_ret(long, atomic64_t *);
9095 #define atomic64_dec_and_test(v) (atomic64_sub_ret(1, v) == 0)
9096
9097 #define atomic_inc(v) atomic_add(1, v)
9098+static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
9099+{
9100+ atomic_add_unchecked(1, v);
9101+}
9102 #define atomic64_inc(v) atomic64_add(1, v)
9103+static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
9104+{
9105+ atomic64_add_unchecked(1, v);
9106+}
9107
9108 #define atomic_dec(v) atomic_sub(1, v)
9109+static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
9110+{
9111+ atomic_sub_unchecked(1, v);
9112+}
9113 #define atomic64_dec(v) atomic64_sub(1, v)
9114+static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
9115+{
9116+ atomic64_sub_unchecked(1, v);
9117+}
9118
9119 #define atomic_add_negative(i, v) (atomic_add_ret(i, v) < 0)
9120 #define atomic64_add_negative(i, v) (atomic64_add_ret(i, v) < 0)
9121
9122 #define atomic_cmpxchg(v, o, n) (cmpxchg(&((v)->counter), (o), (n)))
9123+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
9124+{
9125+ return cmpxchg(&v->counter, old, new);
9126+}
9127 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
9128+static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
9129+{
9130+ return xchg(&v->counter, new);
9131+}
9132
9133 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
9134 {
9135- int c, old;
9136+ int c, old, new;
9137 c = atomic_read(v);
9138 for (;;) {
9139- if (unlikely(c == (u)))
9140+ if (unlikely(c == u))
9141 break;
9142- old = atomic_cmpxchg((v), c, c + (a));
9143+
9144+ asm volatile("addcc %2, %0, %0\n"
9145+
9146+#ifdef CONFIG_PAX_REFCOUNT
9147+ "tvs %%icc, 6\n"
9148+#endif
9149+
9150+ : "=r" (new)
9151+ : "0" (c), "ir" (a)
9152+ : "cc");
9153+
9154+ old = atomic_cmpxchg(v, c, new);
9155 if (likely(old == c))
9156 break;
9157 c = old;
9158@@ -88,20 +165,35 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
9159 #define atomic64_cmpxchg(v, o, n) \
9160 ((__typeof__((v)->counter))cmpxchg(&((v)->counter), (o), (n)))
9161 #define atomic64_xchg(v, new) (xchg(&((v)->counter), new))
9162+static inline long atomic64_xchg_unchecked(atomic64_unchecked_t *v, long new)
9163+{
9164+ return xchg(&v->counter, new);
9165+}
9166
9167 static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
9168 {
9169- long c, old;
9170+ long c, old, new;
9171 c = atomic64_read(v);
9172 for (;;) {
9173- if (unlikely(c == (u)))
9174+ if (unlikely(c == u))
9175 break;
9176- old = atomic64_cmpxchg((v), c, c + (a));
9177+
9178+ asm volatile("addcc %2, %0, %0\n"
9179+
9180+#ifdef CONFIG_PAX_REFCOUNT
9181+ "tvs %%xcc, 6\n"
9182+#endif
9183+
9184+ : "=r" (new)
9185+ : "0" (c), "ir" (a)
9186+ : "cc");
9187+
9188+ old = atomic64_cmpxchg(v, c, new);
9189 if (likely(old == c))
9190 break;
9191 c = old;
9192 }
9193- return c != (u);
9194+ return c != u;
9195 }
9196
9197 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
9198diff --git a/arch/sparc/include/asm/cache.h b/arch/sparc/include/asm/cache.h
9199index 5bb6991..5c2132e 100644
9200--- a/arch/sparc/include/asm/cache.h
9201+++ b/arch/sparc/include/asm/cache.h
9202@@ -7,10 +7,12 @@
9203 #ifndef _SPARC_CACHE_H
9204 #define _SPARC_CACHE_H
9205
9206+#include <linux/const.h>
9207+
9208 #define ARCH_SLAB_MINALIGN __alignof__(unsigned long long)
9209
9210 #define L1_CACHE_SHIFT 5
9211-#define L1_CACHE_BYTES 32
9212+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
9213
9214 #ifdef CONFIG_SPARC32
9215 #define SMP_CACHE_BYTES_SHIFT 5
9216diff --git a/arch/sparc/include/asm/elf_32.h b/arch/sparc/include/asm/elf_32.h
9217index a24e41f..47677ff 100644
9218--- a/arch/sparc/include/asm/elf_32.h
9219+++ b/arch/sparc/include/asm/elf_32.h
9220@@ -114,6 +114,13 @@ typedef struct {
9221
9222 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE)
9223
9224+#ifdef CONFIG_PAX_ASLR
9225+#define PAX_ELF_ET_DYN_BASE 0x10000UL
9226+
9227+#define PAX_DELTA_MMAP_LEN 16
9228+#define PAX_DELTA_STACK_LEN 16
9229+#endif
9230+
9231 /* This yields a mask that user programs can use to figure out what
9232 instruction set this cpu supports. This can NOT be done in userspace
9233 on Sparc. */
9234diff --git a/arch/sparc/include/asm/elf_64.h b/arch/sparc/include/asm/elf_64.h
9235index 370ca1e..d4f4a98 100644
9236--- a/arch/sparc/include/asm/elf_64.h
9237+++ b/arch/sparc/include/asm/elf_64.h
9238@@ -189,6 +189,13 @@ typedef struct {
9239 #define ELF_ET_DYN_BASE 0x0000010000000000UL
9240 #define COMPAT_ELF_ET_DYN_BASE 0x0000000070000000UL
9241
9242+#ifdef CONFIG_PAX_ASLR
9243+#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_32BIT) ? 0x10000UL : 0x100000UL)
9244+
9245+#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_32BIT) ? 14 : 28)
9246+#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_32BIT) ? 15 : 29)
9247+#endif
9248+
9249 extern unsigned long sparc64_elf_hwcap;
9250 #define ELF_HWCAP sparc64_elf_hwcap
9251
9252diff --git a/arch/sparc/include/asm/pgalloc_32.h b/arch/sparc/include/asm/pgalloc_32.h
9253index 9b1c36d..209298b 100644
9254--- a/arch/sparc/include/asm/pgalloc_32.h
9255+++ b/arch/sparc/include/asm/pgalloc_32.h
9256@@ -33,6 +33,7 @@ static inline void pgd_set(pgd_t * pgdp, pmd_t * pmdp)
9257 }
9258
9259 #define pgd_populate(MM, PGD, PMD) pgd_set(PGD, PMD)
9260+#define pgd_populate_kernel(MM, PGD, PMD) pgd_populate((MM), (PGD), (PMD))
9261
9262 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm,
9263 unsigned long address)
9264diff --git a/arch/sparc/include/asm/pgalloc_64.h b/arch/sparc/include/asm/pgalloc_64.h
9265index bcfe063..b333142 100644
9266--- a/arch/sparc/include/asm/pgalloc_64.h
9267+++ b/arch/sparc/include/asm/pgalloc_64.h
9268@@ -26,6 +26,7 @@ static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
9269 }
9270
9271 #define pud_populate(MM, PUD, PMD) pud_set(PUD, PMD)
9272+#define pud_populate_kernel(MM, PUD, PMD) pud_populate((MM), (PUD), (PMD))
9273
9274 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
9275 {
9276diff --git a/arch/sparc/include/asm/pgtable_32.h b/arch/sparc/include/asm/pgtable_32.h
9277index 502f632..da1917f 100644
9278--- a/arch/sparc/include/asm/pgtable_32.h
9279+++ b/arch/sparc/include/asm/pgtable_32.h
9280@@ -50,6 +50,9 @@ extern unsigned long calc_highpages(void);
9281 #define PAGE_SHARED SRMMU_PAGE_SHARED
9282 #define PAGE_COPY SRMMU_PAGE_COPY
9283 #define PAGE_READONLY SRMMU_PAGE_RDONLY
9284+#define PAGE_SHARED_NOEXEC SRMMU_PAGE_SHARED_NOEXEC
9285+#define PAGE_COPY_NOEXEC SRMMU_PAGE_COPY_NOEXEC
9286+#define PAGE_READONLY_NOEXEC SRMMU_PAGE_RDONLY_NOEXEC
9287 #define PAGE_KERNEL SRMMU_PAGE_KERNEL
9288
9289 /* Top-level page directory - dummy used by init-mm.
9290@@ -62,18 +65,18 @@ extern unsigned long ptr_in_current_pgd;
9291
9292 /* xwr */
9293 #define __P000 PAGE_NONE
9294-#define __P001 PAGE_READONLY
9295-#define __P010 PAGE_COPY
9296-#define __P011 PAGE_COPY
9297+#define __P001 PAGE_READONLY_NOEXEC
9298+#define __P010 PAGE_COPY_NOEXEC
9299+#define __P011 PAGE_COPY_NOEXEC
9300 #define __P100 PAGE_READONLY
9301 #define __P101 PAGE_READONLY
9302 #define __P110 PAGE_COPY
9303 #define __P111 PAGE_COPY
9304
9305 #define __S000 PAGE_NONE
9306-#define __S001 PAGE_READONLY
9307-#define __S010 PAGE_SHARED
9308-#define __S011 PAGE_SHARED
9309+#define __S001 PAGE_READONLY_NOEXEC
9310+#define __S010 PAGE_SHARED_NOEXEC
9311+#define __S011 PAGE_SHARED_NOEXEC
9312 #define __S100 PAGE_READONLY
9313 #define __S101 PAGE_READONLY
9314 #define __S110 PAGE_SHARED
9315diff --git a/arch/sparc/include/asm/pgtsrmmu.h b/arch/sparc/include/asm/pgtsrmmu.h
9316index 79da178..c2eede8 100644
9317--- a/arch/sparc/include/asm/pgtsrmmu.h
9318+++ b/arch/sparc/include/asm/pgtsrmmu.h
9319@@ -115,6 +115,11 @@
9320 SRMMU_EXEC | SRMMU_REF)
9321 #define SRMMU_PAGE_RDONLY __pgprot(SRMMU_VALID | SRMMU_CACHE | \
9322 SRMMU_EXEC | SRMMU_REF)
9323+
9324+#define SRMMU_PAGE_SHARED_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_WRITE | SRMMU_REF)
9325+#define SRMMU_PAGE_COPY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
9326+#define SRMMU_PAGE_RDONLY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
9327+
9328 #define SRMMU_PAGE_KERNEL __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_PRIV | \
9329 SRMMU_DIRTY | SRMMU_REF)
9330
9331diff --git a/arch/sparc/include/asm/spinlock_64.h b/arch/sparc/include/asm/spinlock_64.h
9332index 9689176..63c18ea 100644
9333--- a/arch/sparc/include/asm/spinlock_64.h
9334+++ b/arch/sparc/include/asm/spinlock_64.h
9335@@ -92,14 +92,19 @@ static inline void arch_spin_lock_flags(arch_spinlock_t *lock, unsigned long fla
9336
9337 /* Multi-reader locks, these are much saner than the 32-bit Sparc ones... */
9338
9339-static void inline arch_read_lock(arch_rwlock_t *lock)
9340+static inline void arch_read_lock(arch_rwlock_t *lock)
9341 {
9342 unsigned long tmp1, tmp2;
9343
9344 __asm__ __volatile__ (
9345 "1: ldsw [%2], %0\n"
9346 " brlz,pn %0, 2f\n"
9347-"4: add %0, 1, %1\n"
9348+"4: addcc %0, 1, %1\n"
9349+
9350+#ifdef CONFIG_PAX_REFCOUNT
9351+" tvs %%icc, 6\n"
9352+#endif
9353+
9354 " cas [%2], %0, %1\n"
9355 " cmp %0, %1\n"
9356 " bne,pn %%icc, 1b\n"
9357@@ -112,10 +117,10 @@ static void inline arch_read_lock(arch_rwlock_t *lock)
9358 " .previous"
9359 : "=&r" (tmp1), "=&r" (tmp2)
9360 : "r" (lock)
9361- : "memory");
9362+ : "memory", "cc");
9363 }
9364
9365-static int inline arch_read_trylock(arch_rwlock_t *lock)
9366+static inline int arch_read_trylock(arch_rwlock_t *lock)
9367 {
9368 int tmp1, tmp2;
9369
9370@@ -123,7 +128,12 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
9371 "1: ldsw [%2], %0\n"
9372 " brlz,a,pn %0, 2f\n"
9373 " mov 0, %0\n"
9374-" add %0, 1, %1\n"
9375+" addcc %0, 1, %1\n"
9376+
9377+#ifdef CONFIG_PAX_REFCOUNT
9378+" tvs %%icc, 6\n"
9379+#endif
9380+
9381 " cas [%2], %0, %1\n"
9382 " cmp %0, %1\n"
9383 " bne,pn %%icc, 1b\n"
9384@@ -136,13 +146,18 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
9385 return tmp1;
9386 }
9387
9388-static void inline arch_read_unlock(arch_rwlock_t *lock)
9389+static inline void arch_read_unlock(arch_rwlock_t *lock)
9390 {
9391 unsigned long tmp1, tmp2;
9392
9393 __asm__ __volatile__(
9394 "1: lduw [%2], %0\n"
9395-" sub %0, 1, %1\n"
9396+" subcc %0, 1, %1\n"
9397+
9398+#ifdef CONFIG_PAX_REFCOUNT
9399+" tvs %%icc, 6\n"
9400+#endif
9401+
9402 " cas [%2], %0, %1\n"
9403 " cmp %0, %1\n"
9404 " bne,pn %%xcc, 1b\n"
9405@@ -152,7 +167,7 @@ static void inline arch_read_unlock(arch_rwlock_t *lock)
9406 : "memory");
9407 }
9408
9409-static void inline arch_write_lock(arch_rwlock_t *lock)
9410+static inline void arch_write_lock(arch_rwlock_t *lock)
9411 {
9412 unsigned long mask, tmp1, tmp2;
9413
9414@@ -177,7 +192,7 @@ static void inline arch_write_lock(arch_rwlock_t *lock)
9415 : "memory");
9416 }
9417
9418-static void inline arch_write_unlock(arch_rwlock_t *lock)
9419+static inline void arch_write_unlock(arch_rwlock_t *lock)
9420 {
9421 __asm__ __volatile__(
9422 " stw %%g0, [%0]"
9423@@ -186,7 +201,7 @@ static void inline arch_write_unlock(arch_rwlock_t *lock)
9424 : "memory");
9425 }
9426
9427-static int inline arch_write_trylock(arch_rwlock_t *lock)
9428+static inline int arch_write_trylock(arch_rwlock_t *lock)
9429 {
9430 unsigned long mask, tmp1, tmp2, result;
9431
9432diff --git a/arch/sparc/include/asm/thread_info_32.h b/arch/sparc/include/asm/thread_info_32.h
9433index dd38075..e7cac83 100644
9434--- a/arch/sparc/include/asm/thread_info_32.h
9435+++ b/arch/sparc/include/asm/thread_info_32.h
9436@@ -49,6 +49,8 @@ struct thread_info {
9437 unsigned long w_saved;
9438
9439 struct restart_block restart_block;
9440+
9441+ unsigned long lowest_stack;
9442 };
9443
9444 /*
9445diff --git a/arch/sparc/include/asm/thread_info_64.h b/arch/sparc/include/asm/thread_info_64.h
9446index d5e5042..9bfee76 100644
9447--- a/arch/sparc/include/asm/thread_info_64.h
9448+++ b/arch/sparc/include/asm/thread_info_64.h
9449@@ -63,6 +63,8 @@ struct thread_info {
9450 struct pt_regs *kern_una_regs;
9451 unsigned int kern_una_insn;
9452
9453+ unsigned long lowest_stack;
9454+
9455 unsigned long fpregs[0] __attribute__ ((aligned(64)));
9456 };
9457
9458@@ -192,10 +194,11 @@ register struct thread_info *current_thread_info_reg asm("g6");
9459 #define TIF_UNALIGNED 5 /* allowed to do unaligned accesses */
9460 /* flag bit 6 is available */
9461 #define TIF_32BIT 7 /* 32-bit binary */
9462-/* flag bit 8 is available */
9463+#define TIF_GRSEC_SETXID 8 /* update credentials on syscall entry/exit */
9464 #define TIF_SECCOMP 9 /* secure computing */
9465 #define TIF_SYSCALL_AUDIT 10 /* syscall auditing active */
9466 #define TIF_SYSCALL_TRACEPOINT 11 /* syscall tracepoint instrumentation */
9467+
9468 /* NOTE: Thread flags >= 12 should be ones we have no interest
9469 * in using in assembly, else we can't use the mask as
9470 * an immediate value in instructions such as andcc.
9471@@ -214,12 +217,18 @@ register struct thread_info *current_thread_info_reg asm("g6");
9472 #define _TIF_SYSCALL_AUDIT (1<<TIF_SYSCALL_AUDIT)
9473 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
9474 #define _TIF_POLLING_NRFLAG (1<<TIF_POLLING_NRFLAG)
9475+#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
9476
9477 #define _TIF_USER_WORK_MASK ((0xff << TI_FLAG_WSAVED_SHIFT) | \
9478 _TIF_DO_NOTIFY_RESUME_MASK | \
9479 _TIF_NEED_RESCHED)
9480 #define _TIF_DO_NOTIFY_RESUME_MASK (_TIF_NOTIFY_RESUME | _TIF_SIGPENDING)
9481
9482+#define _TIF_WORK_SYSCALL \
9483+ (_TIF_SYSCALL_TRACE | _TIF_SECCOMP | _TIF_SYSCALL_AUDIT | \
9484+ _TIF_SYSCALL_TRACEPOINT | _TIF_GRSEC_SETXID)
9485+
9486+
9487 /*
9488 * Thread-synchronous status.
9489 *
9490diff --git a/arch/sparc/include/asm/uaccess.h b/arch/sparc/include/asm/uaccess.h
9491index 0167d26..767bb0c 100644
9492--- a/arch/sparc/include/asm/uaccess.h
9493+++ b/arch/sparc/include/asm/uaccess.h
9494@@ -1,5 +1,6 @@
9495 #ifndef ___ASM_SPARC_UACCESS_H
9496 #define ___ASM_SPARC_UACCESS_H
9497+
9498 #if defined(__sparc__) && defined(__arch64__)
9499 #include <asm/uaccess_64.h>
9500 #else
9501diff --git a/arch/sparc/include/asm/uaccess_32.h b/arch/sparc/include/asm/uaccess_32.h
9502index 53a28dd..50c38c3 100644
9503--- a/arch/sparc/include/asm/uaccess_32.h
9504+++ b/arch/sparc/include/asm/uaccess_32.h
9505@@ -250,27 +250,46 @@ extern unsigned long __copy_user(void __user *to, const void __user *from, unsig
9506
9507 static inline unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
9508 {
9509- if (n && __access_ok((unsigned long) to, n))
9510+ if ((long)n < 0)
9511+ return n;
9512+
9513+ if (n && __access_ok((unsigned long) to, n)) {
9514+ if (!__builtin_constant_p(n))
9515+ check_object_size(from, n, true);
9516 return __copy_user(to, (__force void __user *) from, n);
9517- else
9518+ } else
9519 return n;
9520 }
9521
9522 static inline unsigned long __copy_to_user(void __user *to, const void *from, unsigned long n)
9523 {
9524+ if ((long)n < 0)
9525+ return n;
9526+
9527+ if (!__builtin_constant_p(n))
9528+ check_object_size(from, n, true);
9529+
9530 return __copy_user(to, (__force void __user *) from, n);
9531 }
9532
9533 static inline unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
9534 {
9535- if (n && __access_ok((unsigned long) from, n))
9536+ if ((long)n < 0)
9537+ return n;
9538+
9539+ if (n && __access_ok((unsigned long) from, n)) {
9540+ if (!__builtin_constant_p(n))
9541+ check_object_size(to, n, false);
9542 return __copy_user((__force void __user *) to, from, n);
9543- else
9544+ } else
9545 return n;
9546 }
9547
9548 static inline unsigned long __copy_from_user(void *to, const void __user *from, unsigned long n)
9549 {
9550+ if ((long)n < 0)
9551+ return n;
9552+
9553 return __copy_user((__force void __user *) to, from, n);
9554 }
9555
9556diff --git a/arch/sparc/include/asm/uaccess_64.h b/arch/sparc/include/asm/uaccess_64.h
9557index e562d3c..191f176 100644
9558--- a/arch/sparc/include/asm/uaccess_64.h
9559+++ b/arch/sparc/include/asm/uaccess_64.h
9560@@ -10,6 +10,7 @@
9561 #include <linux/compiler.h>
9562 #include <linux/string.h>
9563 #include <linux/thread_info.h>
9564+#include <linux/kernel.h>
9565 #include <asm/asi.h>
9566 #include <asm/spitfire.h>
9567 #include <asm-generic/uaccess-unaligned.h>
9568@@ -214,8 +215,15 @@ extern unsigned long copy_from_user_fixup(void *to, const void __user *from,
9569 static inline unsigned long __must_check
9570 copy_from_user(void *to, const void __user *from, unsigned long size)
9571 {
9572- unsigned long ret = ___copy_from_user(to, from, size);
9573+ unsigned long ret;
9574
9575+ if ((long)size < 0 || size > INT_MAX)
9576+ return size;
9577+
9578+ if (!__builtin_constant_p(size))
9579+ check_object_size(to, size, false);
9580+
9581+ ret = ___copy_from_user(to, from, size);
9582 if (unlikely(ret))
9583 ret = copy_from_user_fixup(to, from, size);
9584
9585@@ -231,8 +239,15 @@ extern unsigned long copy_to_user_fixup(void __user *to, const void *from,
9586 static inline unsigned long __must_check
9587 copy_to_user(void __user *to, const void *from, unsigned long size)
9588 {
9589- unsigned long ret = ___copy_to_user(to, from, size);
9590+ unsigned long ret;
9591
9592+ if ((long)size < 0 || size > INT_MAX)
9593+ return size;
9594+
9595+ if (!__builtin_constant_p(size))
9596+ check_object_size(from, size, true);
9597+
9598+ ret = ___copy_to_user(to, from, size);
9599 if (unlikely(ret))
9600 ret = copy_to_user_fixup(to, from, size);
9601 return ret;
9602diff --git a/arch/sparc/kernel/Makefile b/arch/sparc/kernel/Makefile
9603index d15cc17..d0ae796 100644
9604--- a/arch/sparc/kernel/Makefile
9605+++ b/arch/sparc/kernel/Makefile
9606@@ -4,7 +4,7 @@
9607 #
9608
9609 asflags-y := -ansi
9610-ccflags-y := -Werror
9611+#ccflags-y := -Werror
9612
9613 extra-y := head_$(BITS).o
9614
9615diff --git a/arch/sparc/kernel/process_32.c b/arch/sparc/kernel/process_32.c
9616index fdd819d..5af08c8 100644
9617--- a/arch/sparc/kernel/process_32.c
9618+++ b/arch/sparc/kernel/process_32.c
9619@@ -116,14 +116,14 @@ void show_regs(struct pt_regs *r)
9620
9621 printk("PSR: %08lx PC: %08lx NPC: %08lx Y: %08lx %s\n",
9622 r->psr, r->pc, r->npc, r->y, print_tainted());
9623- printk("PC: <%pS>\n", (void *) r->pc);
9624+ printk("PC: <%pA>\n", (void *) r->pc);
9625 printk("%%G: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
9626 r->u_regs[0], r->u_regs[1], r->u_regs[2], r->u_regs[3],
9627 r->u_regs[4], r->u_regs[5], r->u_regs[6], r->u_regs[7]);
9628 printk("%%O: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
9629 r->u_regs[8], r->u_regs[9], r->u_regs[10], r->u_regs[11],
9630 r->u_regs[12], r->u_regs[13], r->u_regs[14], r->u_regs[15]);
9631- printk("RPC: <%pS>\n", (void *) r->u_regs[15]);
9632+ printk("RPC: <%pA>\n", (void *) r->u_regs[15]);
9633
9634 printk("%%L: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
9635 rw->locals[0], rw->locals[1], rw->locals[2], rw->locals[3],
9636@@ -160,7 +160,7 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
9637 rw = (struct reg_window32 *) fp;
9638 pc = rw->ins[7];
9639 printk("[%08lx : ", pc);
9640- printk("%pS ] ", (void *) pc);
9641+ printk("%pA ] ", (void *) pc);
9642 fp = rw->ins[6];
9643 } while (++count < 16);
9644 printk("\n");
9645diff --git a/arch/sparc/kernel/process_64.c b/arch/sparc/kernel/process_64.c
9646index baebab2..9cd13b1 100644
9647--- a/arch/sparc/kernel/process_64.c
9648+++ b/arch/sparc/kernel/process_64.c
9649@@ -158,7 +158,7 @@ static void show_regwindow(struct pt_regs *regs)
9650 printk("i4: %016lx i5: %016lx i6: %016lx i7: %016lx\n",
9651 rwk->ins[4], rwk->ins[5], rwk->ins[6], rwk->ins[7]);
9652 if (regs->tstate & TSTATE_PRIV)
9653- printk("I7: <%pS>\n", (void *) rwk->ins[7]);
9654+ printk("I7: <%pA>\n", (void *) rwk->ins[7]);
9655 }
9656
9657 void show_regs(struct pt_regs *regs)
9658@@ -167,7 +167,7 @@ void show_regs(struct pt_regs *regs)
9659
9660 printk("TSTATE: %016lx TPC: %016lx TNPC: %016lx Y: %08x %s\n", regs->tstate,
9661 regs->tpc, regs->tnpc, regs->y, print_tainted());
9662- printk("TPC: <%pS>\n", (void *) regs->tpc);
9663+ printk("TPC: <%pA>\n", (void *) regs->tpc);
9664 printk("g0: %016lx g1: %016lx g2: %016lx g3: %016lx\n",
9665 regs->u_regs[0], regs->u_regs[1], regs->u_regs[2],
9666 regs->u_regs[3]);
9667@@ -180,7 +180,7 @@ void show_regs(struct pt_regs *regs)
9668 printk("o4: %016lx o5: %016lx sp: %016lx ret_pc: %016lx\n",
9669 regs->u_regs[12], regs->u_regs[13], regs->u_regs[14],
9670 regs->u_regs[15]);
9671- printk("RPC: <%pS>\n", (void *) regs->u_regs[15]);
9672+ printk("RPC: <%pA>\n", (void *) regs->u_regs[15]);
9673 show_regwindow(regs);
9674 show_stack(current, (unsigned long *) regs->u_regs[UREG_FP]);
9675 }
9676@@ -269,7 +269,7 @@ void arch_trigger_all_cpu_backtrace(void)
9677 ((tp && tp->task) ? tp->task->pid : -1));
9678
9679 if (gp->tstate & TSTATE_PRIV) {
9680- printk(" TPC[%pS] O7[%pS] I7[%pS] RPC[%pS]\n",
9681+ printk(" TPC[%pA] O7[%pA] I7[%pA] RPC[%pA]\n",
9682 (void *) gp->tpc,
9683 (void *) gp->o7,
9684 (void *) gp->i7,
9685diff --git a/arch/sparc/kernel/prom_common.c b/arch/sparc/kernel/prom_common.c
9686index 79cc0d1..ec62734 100644
9687--- a/arch/sparc/kernel/prom_common.c
9688+++ b/arch/sparc/kernel/prom_common.c
9689@@ -144,7 +144,7 @@ static int __init prom_common_nextprop(phandle node, char *prev, char *buf)
9690
9691 unsigned int prom_early_allocated __initdata;
9692
9693-static struct of_pdt_ops prom_sparc_ops __initdata = {
9694+static struct of_pdt_ops prom_sparc_ops __initconst = {
9695 .nextprop = prom_common_nextprop,
9696 .getproplen = prom_getproplen,
9697 .getproperty = prom_getproperty,
9698diff --git a/arch/sparc/kernel/ptrace_64.c b/arch/sparc/kernel/ptrace_64.c
9699index 773c1f2..a8bdd87 100644
9700--- a/arch/sparc/kernel/ptrace_64.c
9701+++ b/arch/sparc/kernel/ptrace_64.c
9702@@ -1059,6 +1059,10 @@ long arch_ptrace(struct task_struct *child, long request,
9703 return ret;
9704 }
9705
9706+#ifdef CONFIG_GRKERNSEC_SETXID
9707+extern void gr_delayed_cred_worker(void);
9708+#endif
9709+
9710 asmlinkage int syscall_trace_enter(struct pt_regs *regs)
9711 {
9712 int ret = 0;
9713@@ -1066,6 +1070,11 @@ asmlinkage int syscall_trace_enter(struct pt_regs *regs)
9714 /* do the secure computing check first */
9715 secure_computing_strict(regs->u_regs[UREG_G1]);
9716
9717+#ifdef CONFIG_GRKERNSEC_SETXID
9718+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
9719+ gr_delayed_cred_worker();
9720+#endif
9721+
9722 if (test_thread_flag(TIF_SYSCALL_TRACE))
9723 ret = tracehook_report_syscall_entry(regs);
9724
9725@@ -1086,6 +1095,11 @@ asmlinkage int syscall_trace_enter(struct pt_regs *regs)
9726
9727 asmlinkage void syscall_trace_leave(struct pt_regs *regs)
9728 {
9729+#ifdef CONFIG_GRKERNSEC_SETXID
9730+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
9731+ gr_delayed_cred_worker();
9732+#endif
9733+
9734 audit_syscall_exit(regs);
9735
9736 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
9737diff --git a/arch/sparc/kernel/smp_64.c b/arch/sparc/kernel/smp_64.c
9738index e142545..fd29654 100644
9739--- a/arch/sparc/kernel/smp_64.c
9740+++ b/arch/sparc/kernel/smp_64.c
9741@@ -869,8 +869,8 @@ extern unsigned long xcall_flush_dcache_page_cheetah;
9742 extern unsigned long xcall_flush_dcache_page_spitfire;
9743
9744 #ifdef CONFIG_DEBUG_DCFLUSH
9745-extern atomic_t dcpage_flushes;
9746-extern atomic_t dcpage_flushes_xcall;
9747+extern atomic_unchecked_t dcpage_flushes;
9748+extern atomic_unchecked_t dcpage_flushes_xcall;
9749 #endif
9750
9751 static inline void __local_flush_dcache_page(struct page *page)
9752@@ -894,7 +894,7 @@ void smp_flush_dcache_page_impl(struct page *page, int cpu)
9753 return;
9754
9755 #ifdef CONFIG_DEBUG_DCFLUSH
9756- atomic_inc(&dcpage_flushes);
9757+ atomic_inc_unchecked(&dcpage_flushes);
9758 #endif
9759
9760 this_cpu = get_cpu();
9761@@ -918,7 +918,7 @@ void smp_flush_dcache_page_impl(struct page *page, int cpu)
9762 xcall_deliver(data0, __pa(pg_addr),
9763 (u64) pg_addr, cpumask_of(cpu));
9764 #ifdef CONFIG_DEBUG_DCFLUSH
9765- atomic_inc(&dcpage_flushes_xcall);
9766+ atomic_inc_unchecked(&dcpage_flushes_xcall);
9767 #endif
9768 }
9769 }
9770@@ -937,7 +937,7 @@ void flush_dcache_page_all(struct mm_struct *mm, struct page *page)
9771 preempt_disable();
9772
9773 #ifdef CONFIG_DEBUG_DCFLUSH
9774- atomic_inc(&dcpage_flushes);
9775+ atomic_inc_unchecked(&dcpage_flushes);
9776 #endif
9777 data0 = 0;
9778 pg_addr = page_address(page);
9779@@ -954,7 +954,7 @@ void flush_dcache_page_all(struct mm_struct *mm, struct page *page)
9780 xcall_deliver(data0, __pa(pg_addr),
9781 (u64) pg_addr, cpu_online_mask);
9782 #ifdef CONFIG_DEBUG_DCFLUSH
9783- atomic_inc(&dcpage_flushes_xcall);
9784+ atomic_inc_unchecked(&dcpage_flushes_xcall);
9785 #endif
9786 }
9787 __local_flush_dcache_page(page);
9788diff --git a/arch/sparc/kernel/sys_sparc_32.c b/arch/sparc/kernel/sys_sparc_32.c
9789index 3a8d184..49498a8 100644
9790--- a/arch/sparc/kernel/sys_sparc_32.c
9791+++ b/arch/sparc/kernel/sys_sparc_32.c
9792@@ -52,7 +52,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
9793 if (len > TASK_SIZE - PAGE_SIZE)
9794 return -ENOMEM;
9795 if (!addr)
9796- addr = TASK_UNMAPPED_BASE;
9797+ addr = current->mm->mmap_base;
9798
9799 info.flags = 0;
9800 info.length = len;
9801diff --git a/arch/sparc/kernel/sys_sparc_64.c b/arch/sparc/kernel/sys_sparc_64.c
9802index 51561b8..8256764 100644
9803--- a/arch/sparc/kernel/sys_sparc_64.c
9804+++ b/arch/sparc/kernel/sys_sparc_64.c
9805@@ -90,13 +90,14 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
9806 struct vm_area_struct * vma;
9807 unsigned long task_size = TASK_SIZE;
9808 int do_color_align;
9809+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
9810 struct vm_unmapped_area_info info;
9811
9812 if (flags & MAP_FIXED) {
9813 /* We do not accept a shared mapping if it would violate
9814 * cache aliasing constraints.
9815 */
9816- if ((flags & MAP_SHARED) &&
9817+ if ((filp || (flags & MAP_SHARED)) &&
9818 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
9819 return -EINVAL;
9820 return addr;
9821@@ -111,6 +112,10 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
9822 if (filp || (flags & MAP_SHARED))
9823 do_color_align = 1;
9824
9825+#ifdef CONFIG_PAX_RANDMMAP
9826+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
9827+#endif
9828+
9829 if (addr) {
9830 if (do_color_align)
9831 addr = COLOR_ALIGN(addr, pgoff);
9832@@ -118,22 +123,28 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
9833 addr = PAGE_ALIGN(addr);
9834
9835 vma = find_vma(mm, addr);
9836- if (task_size - len >= addr &&
9837- (!vma || addr + len <= vma->vm_start))
9838+ if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
9839 return addr;
9840 }
9841
9842 info.flags = 0;
9843 info.length = len;
9844- info.low_limit = TASK_UNMAPPED_BASE;
9845+ info.low_limit = mm->mmap_base;
9846 info.high_limit = min(task_size, VA_EXCLUDE_START);
9847 info.align_mask = do_color_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
9848 info.align_offset = pgoff << PAGE_SHIFT;
9849+ info.threadstack_offset = offset;
9850 addr = vm_unmapped_area(&info);
9851
9852 if ((addr & ~PAGE_MASK) && task_size > VA_EXCLUDE_END) {
9853 VM_BUG_ON(addr != -ENOMEM);
9854 info.low_limit = VA_EXCLUDE_END;
9855+
9856+#ifdef CONFIG_PAX_RANDMMAP
9857+ if (mm->pax_flags & MF_PAX_RANDMMAP)
9858+ info.low_limit += mm->delta_mmap;
9859+#endif
9860+
9861 info.high_limit = task_size;
9862 addr = vm_unmapped_area(&info);
9863 }
9864@@ -151,6 +162,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
9865 unsigned long task_size = STACK_TOP32;
9866 unsigned long addr = addr0;
9867 int do_color_align;
9868+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
9869 struct vm_unmapped_area_info info;
9870
9871 /* This should only ever run for 32-bit processes. */
9872@@ -160,7 +172,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
9873 /* We do not accept a shared mapping if it would violate
9874 * cache aliasing constraints.
9875 */
9876- if ((flags & MAP_SHARED) &&
9877+ if ((filp || (flags & MAP_SHARED)) &&
9878 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
9879 return -EINVAL;
9880 return addr;
9881@@ -173,6 +185,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
9882 if (filp || (flags & MAP_SHARED))
9883 do_color_align = 1;
9884
9885+#ifdef CONFIG_PAX_RANDMMAP
9886+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
9887+#endif
9888+
9889 /* requesting a specific address */
9890 if (addr) {
9891 if (do_color_align)
9892@@ -181,8 +197,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
9893 addr = PAGE_ALIGN(addr);
9894
9895 vma = find_vma(mm, addr);
9896- if (task_size - len >= addr &&
9897- (!vma || addr + len <= vma->vm_start))
9898+ if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
9899 return addr;
9900 }
9901
9902@@ -192,6 +207,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
9903 info.high_limit = mm->mmap_base;
9904 info.align_mask = do_color_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
9905 info.align_offset = pgoff << PAGE_SHIFT;
9906+ info.threadstack_offset = offset;
9907 addr = vm_unmapped_area(&info);
9908
9909 /*
9910@@ -204,6 +220,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
9911 VM_BUG_ON(addr != -ENOMEM);
9912 info.flags = 0;
9913 info.low_limit = TASK_UNMAPPED_BASE;
9914+
9915+#ifdef CONFIG_PAX_RANDMMAP
9916+ if (mm->pax_flags & MF_PAX_RANDMMAP)
9917+ info.low_limit += mm->delta_mmap;
9918+#endif
9919+
9920 info.high_limit = STACK_TOP32;
9921 addr = vm_unmapped_area(&info);
9922 }
9923@@ -260,10 +282,14 @@ unsigned long get_fb_unmapped_area(struct file *filp, unsigned long orig_addr, u
9924 EXPORT_SYMBOL(get_fb_unmapped_area);
9925
9926 /* Essentially the same as PowerPC. */
9927-static unsigned long mmap_rnd(void)
9928+static unsigned long mmap_rnd(struct mm_struct *mm)
9929 {
9930 unsigned long rnd = 0UL;
9931
9932+#ifdef CONFIG_PAX_RANDMMAP
9933+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
9934+#endif
9935+
9936 if (current->flags & PF_RANDOMIZE) {
9937 unsigned long val = get_random_int();
9938 if (test_thread_flag(TIF_32BIT))
9939@@ -276,7 +302,7 @@ static unsigned long mmap_rnd(void)
9940
9941 void arch_pick_mmap_layout(struct mm_struct *mm)
9942 {
9943- unsigned long random_factor = mmap_rnd();
9944+ unsigned long random_factor = mmap_rnd(mm);
9945 unsigned long gap;
9946
9947 /*
9948@@ -289,6 +315,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
9949 gap == RLIM_INFINITY ||
9950 sysctl_legacy_va_layout) {
9951 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
9952+
9953+#ifdef CONFIG_PAX_RANDMMAP
9954+ if (mm->pax_flags & MF_PAX_RANDMMAP)
9955+ mm->mmap_base += mm->delta_mmap;
9956+#endif
9957+
9958 mm->get_unmapped_area = arch_get_unmapped_area;
9959 } else {
9960 /* We know it's 32-bit */
9961@@ -300,6 +332,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
9962 gap = (task_size / 6 * 5);
9963
9964 mm->mmap_base = PAGE_ALIGN(task_size - gap - random_factor);
9965+
9966+#ifdef CONFIG_PAX_RANDMMAP
9967+ if (mm->pax_flags & MF_PAX_RANDMMAP)
9968+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
9969+#endif
9970+
9971 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
9972 }
9973 }
9974diff --git a/arch/sparc/kernel/syscalls.S b/arch/sparc/kernel/syscalls.S
9975index d950197..192f9d8 100644
9976--- a/arch/sparc/kernel/syscalls.S
9977+++ b/arch/sparc/kernel/syscalls.S
9978@@ -52,7 +52,7 @@ sys32_rt_sigreturn:
9979 #endif
9980 .align 32
9981 1: ldx [%g6 + TI_FLAGS], %l5
9982- andcc %l5, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
9983+ andcc %l5, _TIF_WORK_SYSCALL, %g0
9984 be,pt %icc, rtrap
9985 nop
9986 call syscall_trace_leave
9987@@ -184,7 +184,7 @@ linux_sparc_syscall32:
9988
9989 srl %i3, 0, %o3 ! IEU0
9990 srl %i2, 0, %o2 ! IEU0 Group
9991- andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
9992+ andcc %l0, _TIF_WORK_SYSCALL, %g0
9993 bne,pn %icc, linux_syscall_trace32 ! CTI
9994 mov %i0, %l5 ! IEU1
9995 5: call %l7 ! CTI Group brk forced
9996@@ -207,7 +207,7 @@ linux_sparc_syscall:
9997
9998 mov %i3, %o3 ! IEU1
9999 mov %i4, %o4 ! IEU0 Group
10000- andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
10001+ andcc %l0, _TIF_WORK_SYSCALL, %g0
10002 bne,pn %icc, linux_syscall_trace ! CTI Group
10003 mov %i0, %l5 ! IEU0
10004 2: call %l7 ! CTI Group brk forced
10005@@ -223,7 +223,7 @@ ret_sys_call:
10006
10007 cmp %o0, -ERESTART_RESTARTBLOCK
10008 bgeu,pn %xcc, 1f
10009- andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
10010+ andcc %l0, _TIF_WORK_SYSCALL, %g0
10011 ldx [%sp + PTREGS_OFF + PT_V9_TNPC], %l1 ! pc = npc
10012
10013 2:
10014diff --git a/arch/sparc/kernel/traps_32.c b/arch/sparc/kernel/traps_32.c
10015index 6629829..036032d 100644
10016--- a/arch/sparc/kernel/traps_32.c
10017+++ b/arch/sparc/kernel/traps_32.c
10018@@ -44,6 +44,8 @@ static void instruction_dump(unsigned long *pc)
10019 #define __SAVE __asm__ __volatile__("save %sp, -0x40, %sp\n\t")
10020 #define __RESTORE __asm__ __volatile__("restore %g0, %g0, %g0\n\t")
10021
10022+extern void gr_handle_kernel_exploit(void);
10023+
10024 void die_if_kernel(char *str, struct pt_regs *regs)
10025 {
10026 static int die_counter;
10027@@ -76,15 +78,17 @@ void die_if_kernel(char *str, struct pt_regs *regs)
10028 count++ < 30 &&
10029 (((unsigned long) rw) >= PAGE_OFFSET) &&
10030 !(((unsigned long) rw) & 0x7)) {
10031- printk("Caller[%08lx]: %pS\n", rw->ins[7],
10032+ printk("Caller[%08lx]: %pA\n", rw->ins[7],
10033 (void *) rw->ins[7]);
10034 rw = (struct reg_window32 *)rw->ins[6];
10035 }
10036 }
10037 printk("Instruction DUMP:");
10038 instruction_dump ((unsigned long *) regs->pc);
10039- if(regs->psr & PSR_PS)
10040+ if(regs->psr & PSR_PS) {
10041+ gr_handle_kernel_exploit();
10042 do_exit(SIGKILL);
10043+ }
10044 do_exit(SIGSEGV);
10045 }
10046
10047diff --git a/arch/sparc/kernel/traps_64.c b/arch/sparc/kernel/traps_64.c
10048index b3f833a..f485f80 100644
10049--- a/arch/sparc/kernel/traps_64.c
10050+++ b/arch/sparc/kernel/traps_64.c
10051@@ -76,7 +76,7 @@ static void dump_tl1_traplog(struct tl1_traplog *p)
10052 i + 1,
10053 p->trapstack[i].tstate, p->trapstack[i].tpc,
10054 p->trapstack[i].tnpc, p->trapstack[i].tt);
10055- printk("TRAPLOG: TPC<%pS>\n", (void *) p->trapstack[i].tpc);
10056+ printk("TRAPLOG: TPC<%pA>\n", (void *) p->trapstack[i].tpc);
10057 }
10058 }
10059
10060@@ -96,6 +96,12 @@ void bad_trap(struct pt_regs *regs, long lvl)
10061
10062 lvl -= 0x100;
10063 if (regs->tstate & TSTATE_PRIV) {
10064+
10065+#ifdef CONFIG_PAX_REFCOUNT
10066+ if (lvl == 6)
10067+ pax_report_refcount_overflow(regs);
10068+#endif
10069+
10070 sprintf(buffer, "Kernel bad sw trap %lx", lvl);
10071 die_if_kernel(buffer, regs);
10072 }
10073@@ -114,11 +120,16 @@ void bad_trap(struct pt_regs *regs, long lvl)
10074 void bad_trap_tl1(struct pt_regs *regs, long lvl)
10075 {
10076 char buffer[32];
10077-
10078+
10079 if (notify_die(DIE_TRAP_TL1, "bad trap tl1", regs,
10080 0, lvl, SIGTRAP) == NOTIFY_STOP)
10081 return;
10082
10083+#ifdef CONFIG_PAX_REFCOUNT
10084+ if (lvl == 6)
10085+ pax_report_refcount_overflow(regs);
10086+#endif
10087+
10088 dump_tl1_traplog((struct tl1_traplog *)(regs + 1));
10089
10090 sprintf (buffer, "Bad trap %lx at tl>0", lvl);
10091@@ -1142,7 +1153,7 @@ static void cheetah_log_errors(struct pt_regs *regs, struct cheetah_err_info *in
10092 regs->tpc, regs->tnpc, regs->u_regs[UREG_I7], regs->tstate);
10093 printk("%s" "ERROR(%d): ",
10094 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id());
10095- printk("TPC<%pS>\n", (void *) regs->tpc);
10096+ printk("TPC<%pA>\n", (void *) regs->tpc);
10097 printk("%s" "ERROR(%d): M_SYND(%lx), E_SYND(%lx)%s%s\n",
10098 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id(),
10099 (afsr & CHAFSR_M_SYNDROME) >> CHAFSR_M_SYNDROME_SHIFT,
10100@@ -1749,7 +1760,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
10101 smp_processor_id(),
10102 (type & 0x1) ? 'I' : 'D',
10103 regs->tpc);
10104- printk(KERN_EMERG "TPC<%pS>\n", (void *) regs->tpc);
10105+ printk(KERN_EMERG "TPC<%pA>\n", (void *) regs->tpc);
10106 panic("Irrecoverable Cheetah+ parity error.");
10107 }
10108
10109@@ -1757,7 +1768,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
10110 smp_processor_id(),
10111 (type & 0x1) ? 'I' : 'D',
10112 regs->tpc);
10113- printk(KERN_WARNING "TPC<%pS>\n", (void *) regs->tpc);
10114+ printk(KERN_WARNING "TPC<%pA>\n", (void *) regs->tpc);
10115 }
10116
10117 struct sun4v_error_entry {
10118@@ -1830,8 +1841,8 @@ struct sun4v_error_entry {
10119 /*0x38*/u64 reserved_5;
10120 };
10121
10122-static atomic_t sun4v_resum_oflow_cnt = ATOMIC_INIT(0);
10123-static atomic_t sun4v_nonresum_oflow_cnt = ATOMIC_INIT(0);
10124+static atomic_unchecked_t sun4v_resum_oflow_cnt = ATOMIC_INIT(0);
10125+static atomic_unchecked_t sun4v_nonresum_oflow_cnt = ATOMIC_INIT(0);
10126
10127 static const char *sun4v_err_type_to_str(u8 type)
10128 {
10129@@ -1923,7 +1934,7 @@ static void sun4v_report_real_raddr(const char *pfx, struct pt_regs *regs)
10130 }
10131
10132 static void sun4v_log_error(struct pt_regs *regs, struct sun4v_error_entry *ent,
10133- int cpu, const char *pfx, atomic_t *ocnt)
10134+ int cpu, const char *pfx, atomic_unchecked_t *ocnt)
10135 {
10136 u64 *raw_ptr = (u64 *) ent;
10137 u32 attrs;
10138@@ -1981,8 +1992,8 @@ static void sun4v_log_error(struct pt_regs *regs, struct sun4v_error_entry *ent,
10139
10140 show_regs(regs);
10141
10142- if ((cnt = atomic_read(ocnt)) != 0) {
10143- atomic_set(ocnt, 0);
10144+ if ((cnt = atomic_read_unchecked(ocnt)) != 0) {
10145+ atomic_set_unchecked(ocnt, 0);
10146 wmb();
10147 printk("%s: Queue overflowed %d times.\n",
10148 pfx, cnt);
10149@@ -2036,7 +2047,7 @@ void sun4v_resum_error(struct pt_regs *regs, unsigned long offset)
10150 */
10151 void sun4v_resum_overflow(struct pt_regs *regs)
10152 {
10153- atomic_inc(&sun4v_resum_oflow_cnt);
10154+ atomic_inc_unchecked(&sun4v_resum_oflow_cnt);
10155 }
10156
10157 /* We run with %pil set to PIL_NORMAL_MAX and PSTATE_IE enabled in %pstate.
10158@@ -2089,7 +2100,7 @@ void sun4v_nonresum_overflow(struct pt_regs *regs)
10159 /* XXX Actually even this can make not that much sense. Perhaps
10160 * XXX we should just pull the plug and panic directly from here?
10161 */
10162- atomic_inc(&sun4v_nonresum_oflow_cnt);
10163+ atomic_inc_unchecked(&sun4v_nonresum_oflow_cnt);
10164 }
10165
10166 unsigned long sun4v_err_itlb_vaddr;
10167@@ -2104,9 +2115,9 @@ void sun4v_itlb_error_report(struct pt_regs *regs, int tl)
10168
10169 printk(KERN_EMERG "SUN4V-ITLB: Error at TPC[%lx], tl %d\n",
10170 regs->tpc, tl);
10171- printk(KERN_EMERG "SUN4V-ITLB: TPC<%pS>\n", (void *) regs->tpc);
10172+ printk(KERN_EMERG "SUN4V-ITLB: TPC<%pA>\n", (void *) regs->tpc);
10173 printk(KERN_EMERG "SUN4V-ITLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
10174- printk(KERN_EMERG "SUN4V-ITLB: O7<%pS>\n",
10175+ printk(KERN_EMERG "SUN4V-ITLB: O7<%pA>\n",
10176 (void *) regs->u_regs[UREG_I7]);
10177 printk(KERN_EMERG "SUN4V-ITLB: vaddr[%lx] ctx[%lx] "
10178 "pte[%lx] error[%lx]\n",
10179@@ -2128,9 +2139,9 @@ void sun4v_dtlb_error_report(struct pt_regs *regs, int tl)
10180
10181 printk(KERN_EMERG "SUN4V-DTLB: Error at TPC[%lx], tl %d\n",
10182 regs->tpc, tl);
10183- printk(KERN_EMERG "SUN4V-DTLB: TPC<%pS>\n", (void *) regs->tpc);
10184+ printk(KERN_EMERG "SUN4V-DTLB: TPC<%pA>\n", (void *) regs->tpc);
10185 printk(KERN_EMERG "SUN4V-DTLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
10186- printk(KERN_EMERG "SUN4V-DTLB: O7<%pS>\n",
10187+ printk(KERN_EMERG "SUN4V-DTLB: O7<%pA>\n",
10188 (void *) regs->u_regs[UREG_I7]);
10189 printk(KERN_EMERG "SUN4V-DTLB: vaddr[%lx] ctx[%lx] "
10190 "pte[%lx] error[%lx]\n",
10191@@ -2336,13 +2347,13 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
10192 fp = (unsigned long)sf->fp + STACK_BIAS;
10193 }
10194
10195- printk(" [%016lx] %pS\n", pc, (void *) pc);
10196+ printk(" [%016lx] %pA\n", pc, (void *) pc);
10197 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
10198 if ((pc + 8UL) == (unsigned long) &return_to_handler) {
10199 int index = tsk->curr_ret_stack;
10200 if (tsk->ret_stack && index >= graph) {
10201 pc = tsk->ret_stack[index - graph].ret;
10202- printk(" [%016lx] %pS\n", pc, (void *) pc);
10203+ printk(" [%016lx] %pA\n", pc, (void *) pc);
10204 graph++;
10205 }
10206 }
10207@@ -2360,6 +2371,8 @@ static inline struct reg_window *kernel_stack_up(struct reg_window *rw)
10208 return (struct reg_window *) (fp + STACK_BIAS);
10209 }
10210
10211+extern void gr_handle_kernel_exploit(void);
10212+
10213 void die_if_kernel(char *str, struct pt_regs *regs)
10214 {
10215 static int die_counter;
10216@@ -2388,7 +2401,7 @@ void die_if_kernel(char *str, struct pt_regs *regs)
10217 while (rw &&
10218 count++ < 30 &&
10219 kstack_valid(tp, (unsigned long) rw)) {
10220- printk("Caller[%016lx]: %pS\n", rw->ins[7],
10221+ printk("Caller[%016lx]: %pA\n", rw->ins[7],
10222 (void *) rw->ins[7]);
10223
10224 rw = kernel_stack_up(rw);
10225@@ -2401,8 +2414,10 @@ void die_if_kernel(char *str, struct pt_regs *regs)
10226 }
10227 user_instruction_dump ((unsigned int __user *) regs->tpc);
10228 }
10229- if (regs->tstate & TSTATE_PRIV)
10230+ if (regs->tstate & TSTATE_PRIV) {
10231+ gr_handle_kernel_exploit();
10232 do_exit(SIGKILL);
10233+ }
10234 do_exit(SIGSEGV);
10235 }
10236 EXPORT_SYMBOL(die_if_kernel);
10237diff --git a/arch/sparc/kernel/unaligned_64.c b/arch/sparc/kernel/unaligned_64.c
10238index 8201c25e..072a2a7 100644
10239--- a/arch/sparc/kernel/unaligned_64.c
10240+++ b/arch/sparc/kernel/unaligned_64.c
10241@@ -286,7 +286,7 @@ static void log_unaligned(struct pt_regs *regs)
10242 static DEFINE_RATELIMIT_STATE(ratelimit, 5 * HZ, 5);
10243
10244 if (__ratelimit(&ratelimit)) {
10245- printk("Kernel unaligned access at TPC[%lx] %pS\n",
10246+ printk("Kernel unaligned access at TPC[%lx] %pA\n",
10247 regs->tpc, (void *) regs->tpc);
10248 }
10249 }
10250diff --git a/arch/sparc/lib/Makefile b/arch/sparc/lib/Makefile
10251index dbe119b..089c7c1 100644
10252--- a/arch/sparc/lib/Makefile
10253+++ b/arch/sparc/lib/Makefile
10254@@ -2,7 +2,7 @@
10255 #
10256
10257 asflags-y := -ansi -DST_DIV0=0x02
10258-ccflags-y := -Werror
10259+#ccflags-y := -Werror
10260
10261 lib-$(CONFIG_SPARC32) += ashrdi3.o
10262 lib-$(CONFIG_SPARC32) += memcpy.o memset.o
10263diff --git a/arch/sparc/lib/atomic_64.S b/arch/sparc/lib/atomic_64.S
10264index 85c233d..68500e0 100644
10265--- a/arch/sparc/lib/atomic_64.S
10266+++ b/arch/sparc/lib/atomic_64.S
10267@@ -17,7 +17,12 @@
10268 ENTRY(atomic_add) /* %o0 = increment, %o1 = atomic_ptr */
10269 BACKOFF_SETUP(%o2)
10270 1: lduw [%o1], %g1
10271- add %g1, %o0, %g7
10272+ addcc %g1, %o0, %g7
10273+
10274+#ifdef CONFIG_PAX_REFCOUNT
10275+ tvs %icc, 6
10276+#endif
10277+
10278 cas [%o1], %g1, %g7
10279 cmp %g1, %g7
10280 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
10281@@ -27,10 +32,28 @@ ENTRY(atomic_add) /* %o0 = increment, %o1 = atomic_ptr */
10282 2: BACKOFF_SPIN(%o2, %o3, 1b)
10283 ENDPROC(atomic_add)
10284
10285+ENTRY(atomic_add_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
10286+ BACKOFF_SETUP(%o2)
10287+1: lduw [%o1], %g1
10288+ add %g1, %o0, %g7
10289+ cas [%o1], %g1, %g7
10290+ cmp %g1, %g7
10291+ bne,pn %icc, 2f
10292+ nop
10293+ retl
10294+ nop
10295+2: BACKOFF_SPIN(%o2, %o3, 1b)
10296+ENDPROC(atomic_add_unchecked)
10297+
10298 ENTRY(atomic_sub) /* %o0 = decrement, %o1 = atomic_ptr */
10299 BACKOFF_SETUP(%o2)
10300 1: lduw [%o1], %g1
10301- sub %g1, %o0, %g7
10302+ subcc %g1, %o0, %g7
10303+
10304+#ifdef CONFIG_PAX_REFCOUNT
10305+ tvs %icc, 6
10306+#endif
10307+
10308 cas [%o1], %g1, %g7
10309 cmp %g1, %g7
10310 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
10311@@ -40,10 +63,28 @@ ENTRY(atomic_sub) /* %o0 = decrement, %o1 = atomic_ptr */
10312 2: BACKOFF_SPIN(%o2, %o3, 1b)
10313 ENDPROC(atomic_sub)
10314
10315+ENTRY(atomic_sub_unchecked) /* %o0 = decrement, %o1 = atomic_ptr */
10316+ BACKOFF_SETUP(%o2)
10317+1: lduw [%o1], %g1
10318+ sub %g1, %o0, %g7
10319+ cas [%o1], %g1, %g7
10320+ cmp %g1, %g7
10321+ bne,pn %icc, 2f
10322+ nop
10323+ retl
10324+ nop
10325+2: BACKOFF_SPIN(%o2, %o3, 1b)
10326+ENDPROC(atomic_sub_unchecked)
10327+
10328 ENTRY(atomic_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
10329 BACKOFF_SETUP(%o2)
10330 1: lduw [%o1], %g1
10331- add %g1, %o0, %g7
10332+ addcc %g1, %o0, %g7
10333+
10334+#ifdef CONFIG_PAX_REFCOUNT
10335+ tvs %icc, 6
10336+#endif
10337+
10338 cas [%o1], %g1, %g7
10339 cmp %g1, %g7
10340 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
10341@@ -53,10 +94,29 @@ ENTRY(atomic_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
10342 2: BACKOFF_SPIN(%o2, %o3, 1b)
10343 ENDPROC(atomic_add_ret)
10344
10345+ENTRY(atomic_add_ret_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
10346+ BACKOFF_SETUP(%o2)
10347+1: lduw [%o1], %g1
10348+ addcc %g1, %o0, %g7
10349+ cas [%o1], %g1, %g7
10350+ cmp %g1, %g7
10351+ bne,pn %icc, 2f
10352+ add %g7, %o0, %g7
10353+ sra %g7, 0, %o0
10354+ retl
10355+ nop
10356+2: BACKOFF_SPIN(%o2, %o3, 1b)
10357+ENDPROC(atomic_add_ret_unchecked)
10358+
10359 ENTRY(atomic_sub_ret) /* %o0 = decrement, %o1 = atomic_ptr */
10360 BACKOFF_SETUP(%o2)
10361 1: lduw [%o1], %g1
10362- sub %g1, %o0, %g7
10363+ subcc %g1, %o0, %g7
10364+
10365+#ifdef CONFIG_PAX_REFCOUNT
10366+ tvs %icc, 6
10367+#endif
10368+
10369 cas [%o1], %g1, %g7
10370 cmp %g1, %g7
10371 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
10372@@ -69,7 +129,12 @@ ENDPROC(atomic_sub_ret)
10373 ENTRY(atomic64_add) /* %o0 = increment, %o1 = atomic_ptr */
10374 BACKOFF_SETUP(%o2)
10375 1: ldx [%o1], %g1
10376- add %g1, %o0, %g7
10377+ addcc %g1, %o0, %g7
10378+
10379+#ifdef CONFIG_PAX_REFCOUNT
10380+ tvs %xcc, 6
10381+#endif
10382+
10383 casx [%o1], %g1, %g7
10384 cmp %g1, %g7
10385 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
10386@@ -79,10 +144,28 @@ ENTRY(atomic64_add) /* %o0 = increment, %o1 = atomic_ptr */
10387 2: BACKOFF_SPIN(%o2, %o3, 1b)
10388 ENDPROC(atomic64_add)
10389
10390+ENTRY(atomic64_add_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
10391+ BACKOFF_SETUP(%o2)
10392+1: ldx [%o1], %g1
10393+ addcc %g1, %o0, %g7
10394+ casx [%o1], %g1, %g7
10395+ cmp %g1, %g7
10396+ bne,pn %xcc, 2f
10397+ nop
10398+ retl
10399+ nop
10400+2: BACKOFF_SPIN(%o2, %o3, 1b)
10401+ENDPROC(atomic64_add_unchecked)
10402+
10403 ENTRY(atomic64_sub) /* %o0 = decrement, %o1 = atomic_ptr */
10404 BACKOFF_SETUP(%o2)
10405 1: ldx [%o1], %g1
10406- sub %g1, %o0, %g7
10407+ subcc %g1, %o0, %g7
10408+
10409+#ifdef CONFIG_PAX_REFCOUNT
10410+ tvs %xcc, 6
10411+#endif
10412+
10413 casx [%o1], %g1, %g7
10414 cmp %g1, %g7
10415 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
10416@@ -92,10 +175,28 @@ ENTRY(atomic64_sub) /* %o0 = decrement, %o1 = atomic_ptr */
10417 2: BACKOFF_SPIN(%o2, %o3, 1b)
10418 ENDPROC(atomic64_sub)
10419
10420+ENTRY(atomic64_sub_unchecked) /* %o0 = decrement, %o1 = atomic_ptr */
10421+ BACKOFF_SETUP(%o2)
10422+1: ldx [%o1], %g1
10423+ subcc %g1, %o0, %g7
10424+ casx [%o1], %g1, %g7
10425+ cmp %g1, %g7
10426+ bne,pn %xcc, 2f
10427+ nop
10428+ retl
10429+ nop
10430+2: BACKOFF_SPIN(%o2, %o3, 1b)
10431+ENDPROC(atomic64_sub_unchecked)
10432+
10433 ENTRY(atomic64_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
10434 BACKOFF_SETUP(%o2)
10435 1: ldx [%o1], %g1
10436- add %g1, %o0, %g7
10437+ addcc %g1, %o0, %g7
10438+
10439+#ifdef CONFIG_PAX_REFCOUNT
10440+ tvs %xcc, 6
10441+#endif
10442+
10443 casx [%o1], %g1, %g7
10444 cmp %g1, %g7
10445 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
10446@@ -105,10 +206,29 @@ ENTRY(atomic64_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
10447 2: BACKOFF_SPIN(%o2, %o3, 1b)
10448 ENDPROC(atomic64_add_ret)
10449
10450+ENTRY(atomic64_add_ret_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
10451+ BACKOFF_SETUP(%o2)
10452+1: ldx [%o1], %g1
10453+ addcc %g1, %o0, %g7
10454+ casx [%o1], %g1, %g7
10455+ cmp %g1, %g7
10456+ bne,pn %xcc, 2f
10457+ add %g7, %o0, %g7
10458+ mov %g7, %o0
10459+ retl
10460+ nop
10461+2: BACKOFF_SPIN(%o2, %o3, 1b)
10462+ENDPROC(atomic64_add_ret_unchecked)
10463+
10464 ENTRY(atomic64_sub_ret) /* %o0 = decrement, %o1 = atomic_ptr */
10465 BACKOFF_SETUP(%o2)
10466 1: ldx [%o1], %g1
10467- sub %g1, %o0, %g7
10468+ subcc %g1, %o0, %g7
10469+
10470+#ifdef CONFIG_PAX_REFCOUNT
10471+ tvs %xcc, 6
10472+#endif
10473+
10474 casx [%o1], %g1, %g7
10475 cmp %g1, %g7
10476 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
10477diff --git a/arch/sparc/lib/ksyms.c b/arch/sparc/lib/ksyms.c
10478index 323335b..ed85ea2 100644
10479--- a/arch/sparc/lib/ksyms.c
10480+++ b/arch/sparc/lib/ksyms.c
10481@@ -100,12 +100,18 @@ EXPORT_SYMBOL(__clear_user);
10482
10483 /* Atomic counter implementation. */
10484 EXPORT_SYMBOL(atomic_add);
10485+EXPORT_SYMBOL(atomic_add_unchecked);
10486 EXPORT_SYMBOL(atomic_add_ret);
10487+EXPORT_SYMBOL(atomic_add_ret_unchecked);
10488 EXPORT_SYMBOL(atomic_sub);
10489+EXPORT_SYMBOL(atomic_sub_unchecked);
10490 EXPORT_SYMBOL(atomic_sub_ret);
10491 EXPORT_SYMBOL(atomic64_add);
10492+EXPORT_SYMBOL(atomic64_add_unchecked);
10493 EXPORT_SYMBOL(atomic64_add_ret);
10494+EXPORT_SYMBOL(atomic64_add_ret_unchecked);
10495 EXPORT_SYMBOL(atomic64_sub);
10496+EXPORT_SYMBOL(atomic64_sub_unchecked);
10497 EXPORT_SYMBOL(atomic64_sub_ret);
10498 EXPORT_SYMBOL(atomic64_dec_if_positive);
10499
10500diff --git a/arch/sparc/mm/Makefile b/arch/sparc/mm/Makefile
10501index 30c3ecc..736f015 100644
10502--- a/arch/sparc/mm/Makefile
10503+++ b/arch/sparc/mm/Makefile
10504@@ -2,7 +2,7 @@
10505 #
10506
10507 asflags-y := -ansi
10508-ccflags-y := -Werror
10509+#ccflags-y := -Werror
10510
10511 obj-$(CONFIG_SPARC64) += ultra.o tlb.o tsb.o gup.o
10512 obj-y += fault_$(BITS).o
10513diff --git a/arch/sparc/mm/fault_32.c b/arch/sparc/mm/fault_32.c
10514index 59dbd46..1dd7f5e 100644
10515--- a/arch/sparc/mm/fault_32.c
10516+++ b/arch/sparc/mm/fault_32.c
10517@@ -21,6 +21,9 @@
10518 #include <linux/perf_event.h>
10519 #include <linux/interrupt.h>
10520 #include <linux/kdebug.h>
10521+#include <linux/slab.h>
10522+#include <linux/pagemap.h>
10523+#include <linux/compiler.h>
10524
10525 #include <asm/page.h>
10526 #include <asm/pgtable.h>
10527@@ -159,6 +162,277 @@ static unsigned long compute_si_addr(struct pt_regs *regs, int text_fault)
10528 return safe_compute_effective_address(regs, insn);
10529 }
10530
10531+#ifdef CONFIG_PAX_PAGEEXEC
10532+#ifdef CONFIG_PAX_DLRESOLVE
10533+static void pax_emuplt_close(struct vm_area_struct *vma)
10534+{
10535+ vma->vm_mm->call_dl_resolve = 0UL;
10536+}
10537+
10538+static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
10539+{
10540+ unsigned int *kaddr;
10541+
10542+ vmf->page = alloc_page(GFP_HIGHUSER);
10543+ if (!vmf->page)
10544+ return VM_FAULT_OOM;
10545+
10546+ kaddr = kmap(vmf->page);
10547+ memset(kaddr, 0, PAGE_SIZE);
10548+ kaddr[0] = 0x9DE3BFA8U; /* save */
10549+ flush_dcache_page(vmf->page);
10550+ kunmap(vmf->page);
10551+ return VM_FAULT_MAJOR;
10552+}
10553+
10554+static const struct vm_operations_struct pax_vm_ops = {
10555+ .close = pax_emuplt_close,
10556+ .fault = pax_emuplt_fault
10557+};
10558+
10559+static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
10560+{
10561+ int ret;
10562+
10563+ INIT_LIST_HEAD(&vma->anon_vma_chain);
10564+ vma->vm_mm = current->mm;
10565+ vma->vm_start = addr;
10566+ vma->vm_end = addr + PAGE_SIZE;
10567+ vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
10568+ vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
10569+ vma->vm_ops = &pax_vm_ops;
10570+
10571+ ret = insert_vm_struct(current->mm, vma);
10572+ if (ret)
10573+ return ret;
10574+
10575+ ++current->mm->total_vm;
10576+ return 0;
10577+}
10578+#endif
10579+
10580+/*
10581+ * PaX: decide what to do with offenders (regs->pc = fault address)
10582+ *
10583+ * returns 1 when task should be killed
10584+ * 2 when patched PLT trampoline was detected
10585+ * 3 when unpatched PLT trampoline was detected
10586+ */
10587+static int pax_handle_fetch_fault(struct pt_regs *regs)
10588+{
10589+
10590+#ifdef CONFIG_PAX_EMUPLT
10591+ int err;
10592+
10593+ do { /* PaX: patched PLT emulation #1 */
10594+ unsigned int sethi1, sethi2, jmpl;
10595+
10596+ err = get_user(sethi1, (unsigned int *)regs->pc);
10597+ err |= get_user(sethi2, (unsigned int *)(regs->pc+4));
10598+ err |= get_user(jmpl, (unsigned int *)(regs->pc+8));
10599+
10600+ if (err)
10601+ break;
10602+
10603+ if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
10604+ (sethi2 & 0xFFC00000U) == 0x03000000U &&
10605+ (jmpl & 0xFFFFE000U) == 0x81C06000U)
10606+ {
10607+ unsigned int addr;
10608+
10609+ regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
10610+ addr = regs->u_regs[UREG_G1];
10611+ addr += (((jmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
10612+ regs->pc = addr;
10613+ regs->npc = addr+4;
10614+ return 2;
10615+ }
10616+ } while (0);
10617+
10618+ do { /* PaX: patched PLT emulation #2 */
10619+ unsigned int ba;
10620+
10621+ err = get_user(ba, (unsigned int *)regs->pc);
10622+
10623+ if (err)
10624+ break;
10625+
10626+ if ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30480000U) {
10627+ unsigned int addr;
10628+
10629+ if ((ba & 0xFFC00000U) == 0x30800000U)
10630+ addr = regs->pc + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
10631+ else
10632+ addr = regs->pc + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
10633+ regs->pc = addr;
10634+ regs->npc = addr+4;
10635+ return 2;
10636+ }
10637+ } while (0);
10638+
10639+ do { /* PaX: patched PLT emulation #3 */
10640+ unsigned int sethi, bajmpl, nop;
10641+
10642+ err = get_user(sethi, (unsigned int *)regs->pc);
10643+ err |= get_user(bajmpl, (unsigned int *)(regs->pc+4));
10644+ err |= get_user(nop, (unsigned int *)(regs->pc+8));
10645+
10646+ if (err)
10647+ break;
10648+
10649+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
10650+ ((bajmpl & 0xFFFFE000U) == 0x81C06000U || (bajmpl & 0xFFF80000U) == 0x30480000U) &&
10651+ nop == 0x01000000U)
10652+ {
10653+ unsigned int addr;
10654+
10655+ addr = (sethi & 0x003FFFFFU) << 10;
10656+ regs->u_regs[UREG_G1] = addr;
10657+ if ((bajmpl & 0xFFFFE000U) == 0x81C06000U)
10658+ addr += (((bajmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
10659+ else
10660+ addr = regs->pc + ((((bajmpl | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
10661+ regs->pc = addr;
10662+ regs->npc = addr+4;
10663+ return 2;
10664+ }
10665+ } while (0);
10666+
10667+ do { /* PaX: unpatched PLT emulation step 1 */
10668+ unsigned int sethi, ba, nop;
10669+
10670+ err = get_user(sethi, (unsigned int *)regs->pc);
10671+ err |= get_user(ba, (unsigned int *)(regs->pc+4));
10672+ err |= get_user(nop, (unsigned int *)(regs->pc+8));
10673+
10674+ if (err)
10675+ break;
10676+
10677+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
10678+ ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
10679+ nop == 0x01000000U)
10680+ {
10681+ unsigned int addr, save, call;
10682+
10683+ if ((ba & 0xFFC00000U) == 0x30800000U)
10684+ addr = regs->pc + 4 + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
10685+ else
10686+ addr = regs->pc + 4 + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
10687+
10688+ err = get_user(save, (unsigned int *)addr);
10689+ err |= get_user(call, (unsigned int *)(addr+4));
10690+ err |= get_user(nop, (unsigned int *)(addr+8));
10691+ if (err)
10692+ break;
10693+
10694+#ifdef CONFIG_PAX_DLRESOLVE
10695+ if (save == 0x9DE3BFA8U &&
10696+ (call & 0xC0000000U) == 0x40000000U &&
10697+ nop == 0x01000000U)
10698+ {
10699+ struct vm_area_struct *vma;
10700+ unsigned long call_dl_resolve;
10701+
10702+ down_read(&current->mm->mmap_sem);
10703+ call_dl_resolve = current->mm->call_dl_resolve;
10704+ up_read(&current->mm->mmap_sem);
10705+ if (likely(call_dl_resolve))
10706+ goto emulate;
10707+
10708+ vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
10709+
10710+ down_write(&current->mm->mmap_sem);
10711+ if (current->mm->call_dl_resolve) {
10712+ call_dl_resolve = current->mm->call_dl_resolve;
10713+ up_write(&current->mm->mmap_sem);
10714+ if (vma)
10715+ kmem_cache_free(vm_area_cachep, vma);
10716+ goto emulate;
10717+ }
10718+
10719+ call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
10720+ if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
10721+ up_write(&current->mm->mmap_sem);
10722+ if (vma)
10723+ kmem_cache_free(vm_area_cachep, vma);
10724+ return 1;
10725+ }
10726+
10727+ if (pax_insert_vma(vma, call_dl_resolve)) {
10728+ up_write(&current->mm->mmap_sem);
10729+ kmem_cache_free(vm_area_cachep, vma);
10730+ return 1;
10731+ }
10732+
10733+ current->mm->call_dl_resolve = call_dl_resolve;
10734+ up_write(&current->mm->mmap_sem);
10735+
10736+emulate:
10737+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
10738+ regs->pc = call_dl_resolve;
10739+ regs->npc = addr+4;
10740+ return 3;
10741+ }
10742+#endif
10743+
10744+ /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
10745+ if ((save & 0xFFC00000U) == 0x05000000U &&
10746+ (call & 0xFFFFE000U) == 0x85C0A000U &&
10747+ nop == 0x01000000U)
10748+ {
10749+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
10750+ regs->u_regs[UREG_G2] = addr + 4;
10751+ addr = (save & 0x003FFFFFU) << 10;
10752+ addr += (((call | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
10753+ regs->pc = addr;
10754+ regs->npc = addr+4;
10755+ return 3;
10756+ }
10757+ }
10758+ } while (0);
10759+
10760+ do { /* PaX: unpatched PLT emulation step 2 */
10761+ unsigned int save, call, nop;
10762+
10763+ err = get_user(save, (unsigned int *)(regs->pc-4));
10764+ err |= get_user(call, (unsigned int *)regs->pc);
10765+ err |= get_user(nop, (unsigned int *)(regs->pc+4));
10766+ if (err)
10767+ break;
10768+
10769+ if (save == 0x9DE3BFA8U &&
10770+ (call & 0xC0000000U) == 0x40000000U &&
10771+ nop == 0x01000000U)
10772+ {
10773+ unsigned int dl_resolve = regs->pc + ((((call | 0xC0000000U) ^ 0x20000000U) + 0x20000000U) << 2);
10774+
10775+ regs->u_regs[UREG_RETPC] = regs->pc;
10776+ regs->pc = dl_resolve;
10777+ regs->npc = dl_resolve+4;
10778+ return 3;
10779+ }
10780+ } while (0);
10781+#endif
10782+
10783+ return 1;
10784+}
10785+
10786+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
10787+{
10788+ unsigned long i;
10789+
10790+ printk(KERN_ERR "PAX: bytes at PC: ");
10791+ for (i = 0; i < 8; i++) {
10792+ unsigned int c;
10793+ if (get_user(c, (unsigned int *)pc+i))
10794+ printk(KERN_CONT "???????? ");
10795+ else
10796+ printk(KERN_CONT "%08x ", c);
10797+ }
10798+ printk("\n");
10799+}
10800+#endif
10801+
10802 static noinline void do_fault_siginfo(int code, int sig, struct pt_regs *regs,
10803 int text_fault)
10804 {
10805@@ -229,6 +503,24 @@ good_area:
10806 if (!(vma->vm_flags & VM_WRITE))
10807 goto bad_area;
10808 } else {
10809+
10810+#ifdef CONFIG_PAX_PAGEEXEC
10811+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && text_fault && !(vma->vm_flags & VM_EXEC)) {
10812+ up_read(&mm->mmap_sem);
10813+ switch (pax_handle_fetch_fault(regs)) {
10814+
10815+#ifdef CONFIG_PAX_EMUPLT
10816+ case 2:
10817+ case 3:
10818+ return;
10819+#endif
10820+
10821+ }
10822+ pax_report_fault(regs, (void *)regs->pc, (void *)regs->u_regs[UREG_FP]);
10823+ do_group_exit(SIGKILL);
10824+ }
10825+#endif
10826+
10827 /* Allow reads even for write-only mappings */
10828 if (!(vma->vm_flags & (VM_READ | VM_EXEC)))
10829 goto bad_area;
10830diff --git a/arch/sparc/mm/fault_64.c b/arch/sparc/mm/fault_64.c
10831index 2ebec26..b212598 100644
10832--- a/arch/sparc/mm/fault_64.c
10833+++ b/arch/sparc/mm/fault_64.c
10834@@ -21,6 +21,9 @@
10835 #include <linux/kprobes.h>
10836 #include <linux/kdebug.h>
10837 #include <linux/percpu.h>
10838+#include <linux/slab.h>
10839+#include <linux/pagemap.h>
10840+#include <linux/compiler.h>
10841
10842 #include <asm/page.h>
10843 #include <asm/pgtable.h>
10844@@ -74,7 +77,7 @@ static void __kprobes bad_kernel_pc(struct pt_regs *regs, unsigned long vaddr)
10845 printk(KERN_CRIT "OOPS: Bogus kernel PC [%016lx] in fault handler\n",
10846 regs->tpc);
10847 printk(KERN_CRIT "OOPS: RPC [%016lx]\n", regs->u_regs[15]);
10848- printk("OOPS: RPC <%pS>\n", (void *) regs->u_regs[15]);
10849+ printk("OOPS: RPC <%pA>\n", (void *) regs->u_regs[15]);
10850 printk(KERN_CRIT "OOPS: Fault was to vaddr[%lx]\n", vaddr);
10851 dump_stack();
10852 unhandled_fault(regs->tpc, current, regs);
10853@@ -270,6 +273,466 @@ static void noinline __kprobes bogus_32bit_fault_address(struct pt_regs *regs,
10854 show_regs(regs);
10855 }
10856
10857+#ifdef CONFIG_PAX_PAGEEXEC
10858+#ifdef CONFIG_PAX_DLRESOLVE
10859+static void pax_emuplt_close(struct vm_area_struct *vma)
10860+{
10861+ vma->vm_mm->call_dl_resolve = 0UL;
10862+}
10863+
10864+static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
10865+{
10866+ unsigned int *kaddr;
10867+
10868+ vmf->page = alloc_page(GFP_HIGHUSER);
10869+ if (!vmf->page)
10870+ return VM_FAULT_OOM;
10871+
10872+ kaddr = kmap(vmf->page);
10873+ memset(kaddr, 0, PAGE_SIZE);
10874+ kaddr[0] = 0x9DE3BFA8U; /* save */
10875+ flush_dcache_page(vmf->page);
10876+ kunmap(vmf->page);
10877+ return VM_FAULT_MAJOR;
10878+}
10879+
10880+static const struct vm_operations_struct pax_vm_ops = {
10881+ .close = pax_emuplt_close,
10882+ .fault = pax_emuplt_fault
10883+};
10884+
10885+static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
10886+{
10887+ int ret;
10888+
10889+ INIT_LIST_HEAD(&vma->anon_vma_chain);
10890+ vma->vm_mm = current->mm;
10891+ vma->vm_start = addr;
10892+ vma->vm_end = addr + PAGE_SIZE;
10893+ vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
10894+ vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
10895+ vma->vm_ops = &pax_vm_ops;
10896+
10897+ ret = insert_vm_struct(current->mm, vma);
10898+ if (ret)
10899+ return ret;
10900+
10901+ ++current->mm->total_vm;
10902+ return 0;
10903+}
10904+#endif
10905+
10906+/*
10907+ * PaX: decide what to do with offenders (regs->tpc = fault address)
10908+ *
10909+ * returns 1 when task should be killed
10910+ * 2 when patched PLT trampoline was detected
10911+ * 3 when unpatched PLT trampoline was detected
10912+ */
10913+static int pax_handle_fetch_fault(struct pt_regs *regs)
10914+{
10915+
10916+#ifdef CONFIG_PAX_EMUPLT
10917+ int err;
10918+
10919+ do { /* PaX: patched PLT emulation #1 */
10920+ unsigned int sethi1, sethi2, jmpl;
10921+
10922+ err = get_user(sethi1, (unsigned int *)regs->tpc);
10923+ err |= get_user(sethi2, (unsigned int *)(regs->tpc+4));
10924+ err |= get_user(jmpl, (unsigned int *)(regs->tpc+8));
10925+
10926+ if (err)
10927+ break;
10928+
10929+ if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
10930+ (sethi2 & 0xFFC00000U) == 0x03000000U &&
10931+ (jmpl & 0xFFFFE000U) == 0x81C06000U)
10932+ {
10933+ unsigned long addr;
10934+
10935+ regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
10936+ addr = regs->u_regs[UREG_G1];
10937+ addr += (((jmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
10938+
10939+ if (test_thread_flag(TIF_32BIT))
10940+ addr &= 0xFFFFFFFFUL;
10941+
10942+ regs->tpc = addr;
10943+ regs->tnpc = addr+4;
10944+ return 2;
10945+ }
10946+ } while (0);
10947+
10948+ do { /* PaX: patched PLT emulation #2 */
10949+ unsigned int ba;
10950+
10951+ err = get_user(ba, (unsigned int *)regs->tpc);
10952+
10953+ if (err)
10954+ break;
10955+
10956+ if ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30480000U) {
10957+ unsigned long addr;
10958+
10959+ if ((ba & 0xFFC00000U) == 0x30800000U)
10960+ addr = regs->tpc + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
10961+ else
10962+ addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
10963+
10964+ if (test_thread_flag(TIF_32BIT))
10965+ addr &= 0xFFFFFFFFUL;
10966+
10967+ regs->tpc = addr;
10968+ regs->tnpc = addr+4;
10969+ return 2;
10970+ }
10971+ } while (0);
10972+
10973+ do { /* PaX: patched PLT emulation #3 */
10974+ unsigned int sethi, bajmpl, nop;
10975+
10976+ err = get_user(sethi, (unsigned int *)regs->tpc);
10977+ err |= get_user(bajmpl, (unsigned int *)(regs->tpc+4));
10978+ err |= get_user(nop, (unsigned int *)(regs->tpc+8));
10979+
10980+ if (err)
10981+ break;
10982+
10983+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
10984+ ((bajmpl & 0xFFFFE000U) == 0x81C06000U || (bajmpl & 0xFFF80000U) == 0x30480000U) &&
10985+ nop == 0x01000000U)
10986+ {
10987+ unsigned long addr;
10988+
10989+ addr = (sethi & 0x003FFFFFU) << 10;
10990+ regs->u_regs[UREG_G1] = addr;
10991+ if ((bajmpl & 0xFFFFE000U) == 0x81C06000U)
10992+ addr += (((bajmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
10993+ else
10994+ addr = regs->tpc + ((((bajmpl | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
10995+
10996+ if (test_thread_flag(TIF_32BIT))
10997+ addr &= 0xFFFFFFFFUL;
10998+
10999+ regs->tpc = addr;
11000+ regs->tnpc = addr+4;
11001+ return 2;
11002+ }
11003+ } while (0);
11004+
11005+ do { /* PaX: patched PLT emulation #4 */
11006+ unsigned int sethi, mov1, call, mov2;
11007+
11008+ err = get_user(sethi, (unsigned int *)regs->tpc);
11009+ err |= get_user(mov1, (unsigned int *)(regs->tpc+4));
11010+ err |= get_user(call, (unsigned int *)(regs->tpc+8));
11011+ err |= get_user(mov2, (unsigned int *)(regs->tpc+12));
11012+
11013+ if (err)
11014+ break;
11015+
11016+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
11017+ mov1 == 0x8210000FU &&
11018+ (call & 0xC0000000U) == 0x40000000U &&
11019+ mov2 == 0x9E100001U)
11020+ {
11021+ unsigned long addr;
11022+
11023+ regs->u_regs[UREG_G1] = regs->u_regs[UREG_RETPC];
11024+ addr = regs->tpc + 4 + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
11025+
11026+ if (test_thread_flag(TIF_32BIT))
11027+ addr &= 0xFFFFFFFFUL;
11028+
11029+ regs->tpc = addr;
11030+ regs->tnpc = addr+4;
11031+ return 2;
11032+ }
11033+ } while (0);
11034+
11035+ do { /* PaX: patched PLT emulation #5 */
11036+ unsigned int sethi, sethi1, sethi2, or1, or2, sllx, jmpl, nop;
11037+
11038+ err = get_user(sethi, (unsigned int *)regs->tpc);
11039+ err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
11040+ err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
11041+ err |= get_user(or1, (unsigned int *)(regs->tpc+12));
11042+ err |= get_user(or2, (unsigned int *)(regs->tpc+16));
11043+ err |= get_user(sllx, (unsigned int *)(regs->tpc+20));
11044+ err |= get_user(jmpl, (unsigned int *)(regs->tpc+24));
11045+ err |= get_user(nop, (unsigned int *)(regs->tpc+28));
11046+
11047+ if (err)
11048+ break;
11049+
11050+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
11051+ (sethi1 & 0xFFC00000U) == 0x03000000U &&
11052+ (sethi2 & 0xFFC00000U) == 0x0B000000U &&
11053+ (or1 & 0xFFFFE000U) == 0x82106000U &&
11054+ (or2 & 0xFFFFE000U) == 0x8A116000U &&
11055+ sllx == 0x83287020U &&
11056+ jmpl == 0x81C04005U &&
11057+ nop == 0x01000000U)
11058+ {
11059+ unsigned long addr;
11060+
11061+ regs->u_regs[UREG_G1] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
11062+ regs->u_regs[UREG_G1] <<= 32;
11063+ regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
11064+ addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
11065+ regs->tpc = addr;
11066+ regs->tnpc = addr+4;
11067+ return 2;
11068+ }
11069+ } while (0);
11070+
11071+ do { /* PaX: patched PLT emulation #6 */
11072+ unsigned int sethi, sethi1, sethi2, sllx, or, jmpl, nop;
11073+
11074+ err = get_user(sethi, (unsigned int *)regs->tpc);
11075+ err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
11076+ err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
11077+ err |= get_user(sllx, (unsigned int *)(regs->tpc+12));
11078+ err |= get_user(or, (unsigned int *)(regs->tpc+16));
11079+ err |= get_user(jmpl, (unsigned int *)(regs->tpc+20));
11080+ err |= get_user(nop, (unsigned int *)(regs->tpc+24));
11081+
11082+ if (err)
11083+ break;
11084+
11085+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
11086+ (sethi1 & 0xFFC00000U) == 0x03000000U &&
11087+ (sethi2 & 0xFFC00000U) == 0x0B000000U &&
11088+ sllx == 0x83287020U &&
11089+ (or & 0xFFFFE000U) == 0x8A116000U &&
11090+ jmpl == 0x81C04005U &&
11091+ nop == 0x01000000U)
11092+ {
11093+ unsigned long addr;
11094+
11095+ regs->u_regs[UREG_G1] = (sethi1 & 0x003FFFFFU) << 10;
11096+ regs->u_regs[UREG_G1] <<= 32;
11097+ regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or & 0x3FFU);
11098+ addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
11099+ regs->tpc = addr;
11100+ regs->tnpc = addr+4;
11101+ return 2;
11102+ }
11103+ } while (0);
11104+
11105+ do { /* PaX: unpatched PLT emulation step 1 */
11106+ unsigned int sethi, ba, nop;
11107+
11108+ err = get_user(sethi, (unsigned int *)regs->tpc);
11109+ err |= get_user(ba, (unsigned int *)(regs->tpc+4));
11110+ err |= get_user(nop, (unsigned int *)(regs->tpc+8));
11111+
11112+ if (err)
11113+ break;
11114+
11115+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
11116+ ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
11117+ nop == 0x01000000U)
11118+ {
11119+ unsigned long addr;
11120+ unsigned int save, call;
11121+ unsigned int sethi1, sethi2, or1, or2, sllx, add, jmpl;
11122+
11123+ if ((ba & 0xFFC00000U) == 0x30800000U)
11124+ addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
11125+ else
11126+ addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
11127+
11128+ if (test_thread_flag(TIF_32BIT))
11129+ addr &= 0xFFFFFFFFUL;
11130+
11131+ err = get_user(save, (unsigned int *)addr);
11132+ err |= get_user(call, (unsigned int *)(addr+4));
11133+ err |= get_user(nop, (unsigned int *)(addr+8));
11134+ if (err)
11135+ break;
11136+
11137+#ifdef CONFIG_PAX_DLRESOLVE
11138+ if (save == 0x9DE3BFA8U &&
11139+ (call & 0xC0000000U) == 0x40000000U &&
11140+ nop == 0x01000000U)
11141+ {
11142+ struct vm_area_struct *vma;
11143+ unsigned long call_dl_resolve;
11144+
11145+ down_read(&current->mm->mmap_sem);
11146+ call_dl_resolve = current->mm->call_dl_resolve;
11147+ up_read(&current->mm->mmap_sem);
11148+ if (likely(call_dl_resolve))
11149+ goto emulate;
11150+
11151+ vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
11152+
11153+ down_write(&current->mm->mmap_sem);
11154+ if (current->mm->call_dl_resolve) {
11155+ call_dl_resolve = current->mm->call_dl_resolve;
11156+ up_write(&current->mm->mmap_sem);
11157+ if (vma)
11158+ kmem_cache_free(vm_area_cachep, vma);
11159+ goto emulate;
11160+ }
11161+
11162+ call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
11163+ if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
11164+ up_write(&current->mm->mmap_sem);
11165+ if (vma)
11166+ kmem_cache_free(vm_area_cachep, vma);
11167+ return 1;
11168+ }
11169+
11170+ if (pax_insert_vma(vma, call_dl_resolve)) {
11171+ up_write(&current->mm->mmap_sem);
11172+ kmem_cache_free(vm_area_cachep, vma);
11173+ return 1;
11174+ }
11175+
11176+ current->mm->call_dl_resolve = call_dl_resolve;
11177+ up_write(&current->mm->mmap_sem);
11178+
11179+emulate:
11180+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
11181+ regs->tpc = call_dl_resolve;
11182+ regs->tnpc = addr+4;
11183+ return 3;
11184+ }
11185+#endif
11186+
11187+ /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
11188+ if ((save & 0xFFC00000U) == 0x05000000U &&
11189+ (call & 0xFFFFE000U) == 0x85C0A000U &&
11190+ nop == 0x01000000U)
11191+ {
11192+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
11193+ regs->u_regs[UREG_G2] = addr + 4;
11194+ addr = (save & 0x003FFFFFU) << 10;
11195+ addr += (((call | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
11196+
11197+ if (test_thread_flag(TIF_32BIT))
11198+ addr &= 0xFFFFFFFFUL;
11199+
11200+ regs->tpc = addr;
11201+ regs->tnpc = addr+4;
11202+ return 3;
11203+ }
11204+
11205+ /* PaX: 64-bit PLT stub */
11206+ err = get_user(sethi1, (unsigned int *)addr);
11207+ err |= get_user(sethi2, (unsigned int *)(addr+4));
11208+ err |= get_user(or1, (unsigned int *)(addr+8));
11209+ err |= get_user(or2, (unsigned int *)(addr+12));
11210+ err |= get_user(sllx, (unsigned int *)(addr+16));
11211+ err |= get_user(add, (unsigned int *)(addr+20));
11212+ err |= get_user(jmpl, (unsigned int *)(addr+24));
11213+ err |= get_user(nop, (unsigned int *)(addr+28));
11214+ if (err)
11215+ break;
11216+
11217+ if ((sethi1 & 0xFFC00000U) == 0x09000000U &&
11218+ (sethi2 & 0xFFC00000U) == 0x0B000000U &&
11219+ (or1 & 0xFFFFE000U) == 0x88112000U &&
11220+ (or2 & 0xFFFFE000U) == 0x8A116000U &&
11221+ sllx == 0x89293020U &&
11222+ add == 0x8A010005U &&
11223+ jmpl == 0x89C14000U &&
11224+ nop == 0x01000000U)
11225+ {
11226+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
11227+ regs->u_regs[UREG_G4] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
11228+ regs->u_regs[UREG_G4] <<= 32;
11229+ regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
11230+ regs->u_regs[UREG_G5] += regs->u_regs[UREG_G4];
11231+ regs->u_regs[UREG_G4] = addr + 24;
11232+ addr = regs->u_regs[UREG_G5];
11233+ regs->tpc = addr;
11234+ regs->tnpc = addr+4;
11235+ return 3;
11236+ }
11237+ }
11238+ } while (0);
11239+
11240+#ifdef CONFIG_PAX_DLRESOLVE
11241+ do { /* PaX: unpatched PLT emulation step 2 */
11242+ unsigned int save, call, nop;
11243+
11244+ err = get_user(save, (unsigned int *)(regs->tpc-4));
11245+ err |= get_user(call, (unsigned int *)regs->tpc);
11246+ err |= get_user(nop, (unsigned int *)(regs->tpc+4));
11247+ if (err)
11248+ break;
11249+
11250+ if (save == 0x9DE3BFA8U &&
11251+ (call & 0xC0000000U) == 0x40000000U &&
11252+ nop == 0x01000000U)
11253+ {
11254+ unsigned long dl_resolve = regs->tpc + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
11255+
11256+ if (test_thread_flag(TIF_32BIT))
11257+ dl_resolve &= 0xFFFFFFFFUL;
11258+
11259+ regs->u_regs[UREG_RETPC] = regs->tpc;
11260+ regs->tpc = dl_resolve;
11261+ regs->tnpc = dl_resolve+4;
11262+ return 3;
11263+ }
11264+ } while (0);
11265+#endif
11266+
11267+ do { /* PaX: patched PLT emulation #7, must be AFTER the unpatched PLT emulation */
11268+ unsigned int sethi, ba, nop;
11269+
11270+ err = get_user(sethi, (unsigned int *)regs->tpc);
11271+ err |= get_user(ba, (unsigned int *)(regs->tpc+4));
11272+ err |= get_user(nop, (unsigned int *)(regs->tpc+8));
11273+
11274+ if (err)
11275+ break;
11276+
11277+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
11278+ (ba & 0xFFF00000U) == 0x30600000U &&
11279+ nop == 0x01000000U)
11280+ {
11281+ unsigned long addr;
11282+
11283+ addr = (sethi & 0x003FFFFFU) << 10;
11284+ regs->u_regs[UREG_G1] = addr;
11285+ addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
11286+
11287+ if (test_thread_flag(TIF_32BIT))
11288+ addr &= 0xFFFFFFFFUL;
11289+
11290+ regs->tpc = addr;
11291+ regs->tnpc = addr+4;
11292+ return 2;
11293+ }
11294+ } while (0);
11295+
11296+#endif
11297+
11298+ return 1;
11299+}
11300+
11301+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
11302+{
11303+ unsigned long i;
11304+
11305+ printk(KERN_ERR "PAX: bytes at PC: ");
11306+ for (i = 0; i < 8; i++) {
11307+ unsigned int c;
11308+ if (get_user(c, (unsigned int *)pc+i))
11309+ printk(KERN_CONT "???????? ");
11310+ else
11311+ printk(KERN_CONT "%08x ", c);
11312+ }
11313+ printk("\n");
11314+}
11315+#endif
11316+
11317 asmlinkage void __kprobes do_sparc64_fault(struct pt_regs *regs)
11318 {
11319 struct mm_struct *mm = current->mm;
11320@@ -342,6 +805,29 @@ retry:
11321 if (!vma)
11322 goto bad_area;
11323
11324+#ifdef CONFIG_PAX_PAGEEXEC
11325+ /* PaX: detect ITLB misses on non-exec pages */
11326+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && vma->vm_start <= address &&
11327+ !(vma->vm_flags & VM_EXEC) && (fault_code & FAULT_CODE_ITLB))
11328+ {
11329+ if (address != regs->tpc)
11330+ goto good_area;
11331+
11332+ up_read(&mm->mmap_sem);
11333+ switch (pax_handle_fetch_fault(regs)) {
11334+
11335+#ifdef CONFIG_PAX_EMUPLT
11336+ case 2:
11337+ case 3:
11338+ return;
11339+#endif
11340+
11341+ }
11342+ pax_report_fault(regs, (void *)regs->tpc, (void *)(regs->u_regs[UREG_FP] + STACK_BIAS));
11343+ do_group_exit(SIGKILL);
11344+ }
11345+#endif
11346+
11347 /* Pure DTLB misses do not tell us whether the fault causing
11348 * load/store/atomic was a write or not, it only says that there
11349 * was no match. So in such a case we (carefully) read the
11350diff --git a/arch/sparc/mm/hugetlbpage.c b/arch/sparc/mm/hugetlbpage.c
11351index 9639964..806cd0c 100644
11352--- a/arch/sparc/mm/hugetlbpage.c
11353+++ b/arch/sparc/mm/hugetlbpage.c
11354@@ -28,7 +28,8 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *filp,
11355 unsigned long addr,
11356 unsigned long len,
11357 unsigned long pgoff,
11358- unsigned long flags)
11359+ unsigned long flags,
11360+ unsigned long offset)
11361 {
11362 unsigned long task_size = TASK_SIZE;
11363 struct vm_unmapped_area_info info;
11364@@ -38,15 +39,22 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *filp,
11365
11366 info.flags = 0;
11367 info.length = len;
11368- info.low_limit = TASK_UNMAPPED_BASE;
11369+ info.low_limit = mm->mmap_base;
11370 info.high_limit = min(task_size, VA_EXCLUDE_START);
11371 info.align_mask = PAGE_MASK & ~HPAGE_MASK;
11372 info.align_offset = 0;
11373+ info.threadstack_offset = offset;
11374 addr = vm_unmapped_area(&info);
11375
11376 if ((addr & ~PAGE_MASK) && task_size > VA_EXCLUDE_END) {
11377 VM_BUG_ON(addr != -ENOMEM);
11378 info.low_limit = VA_EXCLUDE_END;
11379+
11380+#ifdef CONFIG_PAX_RANDMMAP
11381+ if (mm->pax_flags & MF_PAX_RANDMMAP)
11382+ info.low_limit += mm->delta_mmap;
11383+#endif
11384+
11385 info.high_limit = task_size;
11386 addr = vm_unmapped_area(&info);
11387 }
11388@@ -58,7 +66,8 @@ static unsigned long
11389 hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
11390 const unsigned long len,
11391 const unsigned long pgoff,
11392- const unsigned long flags)
11393+ const unsigned long flags,
11394+ const unsigned long offset)
11395 {
11396 struct mm_struct *mm = current->mm;
11397 unsigned long addr = addr0;
11398@@ -73,6 +82,7 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
11399 info.high_limit = mm->mmap_base;
11400 info.align_mask = PAGE_MASK & ~HPAGE_MASK;
11401 info.align_offset = 0;
11402+ info.threadstack_offset = offset;
11403 addr = vm_unmapped_area(&info);
11404
11405 /*
11406@@ -85,6 +95,12 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
11407 VM_BUG_ON(addr != -ENOMEM);
11408 info.flags = 0;
11409 info.low_limit = TASK_UNMAPPED_BASE;
11410+
11411+#ifdef CONFIG_PAX_RANDMMAP
11412+ if (mm->pax_flags & MF_PAX_RANDMMAP)
11413+ info.low_limit += mm->delta_mmap;
11414+#endif
11415+
11416 info.high_limit = STACK_TOP32;
11417 addr = vm_unmapped_area(&info);
11418 }
11419@@ -99,6 +115,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
11420 struct mm_struct *mm = current->mm;
11421 struct vm_area_struct *vma;
11422 unsigned long task_size = TASK_SIZE;
11423+ unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
11424
11425 if (test_thread_flag(TIF_32BIT))
11426 task_size = STACK_TOP32;
11427@@ -114,19 +131,22 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
11428 return addr;
11429 }
11430
11431+#ifdef CONFIG_PAX_RANDMMAP
11432+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
11433+#endif
11434+
11435 if (addr) {
11436 addr = ALIGN(addr, HPAGE_SIZE);
11437 vma = find_vma(mm, addr);
11438- if (task_size - len >= addr &&
11439- (!vma || addr + len <= vma->vm_start))
11440+ if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
11441 return addr;
11442 }
11443 if (mm->get_unmapped_area == arch_get_unmapped_area)
11444 return hugetlb_get_unmapped_area_bottomup(file, addr, len,
11445- pgoff, flags);
11446+ pgoff, flags, offset);
11447 else
11448 return hugetlb_get_unmapped_area_topdown(file, addr, len,
11449- pgoff, flags);
11450+ pgoff, flags, offset);
11451 }
11452
11453 pte_t *huge_pte_alloc(struct mm_struct *mm,
11454diff --git a/arch/sparc/mm/init_64.c b/arch/sparc/mm/init_64.c
11455index ed82eda..0d80e77 100644
11456--- a/arch/sparc/mm/init_64.c
11457+++ b/arch/sparc/mm/init_64.c
11458@@ -188,9 +188,9 @@ unsigned long sparc64_kern_sec_context __read_mostly;
11459 int num_kernel_image_mappings;
11460
11461 #ifdef CONFIG_DEBUG_DCFLUSH
11462-atomic_t dcpage_flushes = ATOMIC_INIT(0);
11463+atomic_unchecked_t dcpage_flushes = ATOMIC_INIT(0);
11464 #ifdef CONFIG_SMP
11465-atomic_t dcpage_flushes_xcall = ATOMIC_INIT(0);
11466+atomic_unchecked_t dcpage_flushes_xcall = ATOMIC_INIT(0);
11467 #endif
11468 #endif
11469
11470@@ -198,7 +198,7 @@ inline void flush_dcache_page_impl(struct page *page)
11471 {
11472 BUG_ON(tlb_type == hypervisor);
11473 #ifdef CONFIG_DEBUG_DCFLUSH
11474- atomic_inc(&dcpage_flushes);
11475+ atomic_inc_unchecked(&dcpage_flushes);
11476 #endif
11477
11478 #ifdef DCACHE_ALIASING_POSSIBLE
11479@@ -466,10 +466,10 @@ void mmu_info(struct seq_file *m)
11480
11481 #ifdef CONFIG_DEBUG_DCFLUSH
11482 seq_printf(m, "DCPageFlushes\t: %d\n",
11483- atomic_read(&dcpage_flushes));
11484+ atomic_read_unchecked(&dcpage_flushes));
11485 #ifdef CONFIG_SMP
11486 seq_printf(m, "DCPageFlushesXC\t: %d\n",
11487- atomic_read(&dcpage_flushes_xcall));
11488+ atomic_read_unchecked(&dcpage_flushes_xcall));
11489 #endif /* CONFIG_SMP */
11490 #endif /* CONFIG_DEBUG_DCFLUSH */
11491 }
11492diff --git a/arch/sparc/net/bpf_jit_comp.c b/arch/sparc/net/bpf_jit_comp.c
11493index 218b6b2..01fe994 100644
11494--- a/arch/sparc/net/bpf_jit_comp.c
11495+++ b/arch/sparc/net/bpf_jit_comp.c
11496@@ -497,9 +497,20 @@ void bpf_jit_compile(struct sk_filter *fp)
11497 case BPF_S_ALU_MUL_K: /* A *= K */
11498 emit_alu_K(MUL, K);
11499 break;
11500- case BPF_S_ALU_DIV_K: /* A /= K */
11501- emit_alu_K(MUL, K);
11502- emit_read_y(r_A);
11503+ case BPF_S_ALU_DIV_K: /* A /= K with K != 0*/
11504+ if (K == 1)
11505+ break;
11506+ emit_write_y(G0);
11507+#ifdef CONFIG_SPARC32
11508+ /* The Sparc v8 architecture requires
11509+ * three instructions between a %y
11510+ * register write and the first use.
11511+ */
11512+ emit_nop();
11513+ emit_nop();
11514+ emit_nop();
11515+#endif
11516+ emit_alu_K(DIV, K);
11517 break;
11518 case BPF_S_ALU_DIV_X: /* A /= X; */
11519 emit_cmpi(r_X, 0);
11520diff --git a/arch/tile/Kconfig b/arch/tile/Kconfig
11521index d45a2c4..3c05a78 100644
11522--- a/arch/tile/Kconfig
11523+++ b/arch/tile/Kconfig
11524@@ -185,6 +185,7 @@ source "kernel/Kconfig.hz"
11525
11526 config KEXEC
11527 bool "kexec system call"
11528+ depends on !GRKERNSEC_KMEM
11529 ---help---
11530 kexec is a system call that implements the ability to shutdown your
11531 current kernel, and to start another kernel. It is like a reboot
11532diff --git a/arch/tile/include/asm/atomic_64.h b/arch/tile/include/asm/atomic_64.h
11533index ad220ee..2f537b3 100644
11534--- a/arch/tile/include/asm/atomic_64.h
11535+++ b/arch/tile/include/asm/atomic_64.h
11536@@ -105,6 +105,16 @@ static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
11537
11538 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
11539
11540+#define atomic64_read_unchecked(v) atomic64_read(v)
11541+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
11542+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
11543+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
11544+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
11545+#define atomic64_inc_unchecked(v) atomic64_inc(v)
11546+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
11547+#define atomic64_dec_unchecked(v) atomic64_dec(v)
11548+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
11549+
11550 /* Atomic dec and inc don't implement barrier, so provide them if needed. */
11551 #define smp_mb__before_atomic_dec() smp_mb()
11552 #define smp_mb__after_atomic_dec() smp_mb()
11553diff --git a/arch/tile/include/asm/cache.h b/arch/tile/include/asm/cache.h
11554index 6160761..00cac88 100644
11555--- a/arch/tile/include/asm/cache.h
11556+++ b/arch/tile/include/asm/cache.h
11557@@ -15,11 +15,12 @@
11558 #ifndef _ASM_TILE_CACHE_H
11559 #define _ASM_TILE_CACHE_H
11560
11561+#include <linux/const.h>
11562 #include <arch/chip.h>
11563
11564 /* bytes per L1 data cache line */
11565 #define L1_CACHE_SHIFT CHIP_L1D_LOG_LINE_SIZE()
11566-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
11567+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
11568
11569 /* bytes per L2 cache line */
11570 #define L2_CACHE_SHIFT CHIP_L2_LOG_LINE_SIZE()
11571diff --git a/arch/tile/include/asm/uaccess.h b/arch/tile/include/asm/uaccess.h
11572index b6cde32..c0cb736 100644
11573--- a/arch/tile/include/asm/uaccess.h
11574+++ b/arch/tile/include/asm/uaccess.h
11575@@ -414,9 +414,9 @@ static inline unsigned long __must_check copy_from_user(void *to,
11576 const void __user *from,
11577 unsigned long n)
11578 {
11579- int sz = __compiletime_object_size(to);
11580+ size_t sz = __compiletime_object_size(to);
11581
11582- if (likely(sz == -1 || sz >= n))
11583+ if (likely(sz == (size_t)-1 || sz >= n))
11584 n = _copy_from_user(to, from, n);
11585 else
11586 copy_from_user_overflow();
11587diff --git a/arch/tile/mm/hugetlbpage.c b/arch/tile/mm/hugetlbpage.c
11588index 0cb3bba..7338b2d 100644
11589--- a/arch/tile/mm/hugetlbpage.c
11590+++ b/arch/tile/mm/hugetlbpage.c
11591@@ -212,6 +212,7 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *file,
11592 info.high_limit = TASK_SIZE;
11593 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
11594 info.align_offset = 0;
11595+ info.threadstack_offset = 0;
11596 return vm_unmapped_area(&info);
11597 }
11598
11599@@ -229,6 +230,7 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
11600 info.high_limit = current->mm->mmap_base;
11601 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
11602 info.align_offset = 0;
11603+ info.threadstack_offset = 0;
11604 addr = vm_unmapped_area(&info);
11605
11606 /*
11607diff --git a/arch/um/Makefile b/arch/um/Makefile
11608index 133f7de..1d6f2f1 100644
11609--- a/arch/um/Makefile
11610+++ b/arch/um/Makefile
11611@@ -62,6 +62,10 @@ USER_CFLAGS = $(patsubst $(KERNEL_DEFINES),,$(patsubst -D__KERNEL__,,\
11612 $(patsubst -I%,,$(KBUILD_CFLAGS)))) $(ARCH_INCLUDE) $(MODE_INCLUDE) \
11613 $(filter -I%,$(CFLAGS)) -D_FILE_OFFSET_BITS=64 -idirafter include
11614
11615+ifdef CONSTIFY_PLUGIN
11616+USER_CFLAGS += -fplugin-arg-constify_plugin-no-constify
11617+endif
11618+
11619 #This will adjust *FLAGS accordingly to the platform.
11620 include $(srctree)/$(ARCH_DIR)/Makefile-os-$(OS)
11621
11622diff --git a/arch/um/defconfig b/arch/um/defconfig
11623index 2665e6b..3e3822b 100644
11624--- a/arch/um/defconfig
11625+++ b/arch/um/defconfig
11626@@ -51,7 +51,6 @@ CONFIG_X86_CMPXCHG=y
11627 CONFIG_X86_L1_CACHE_SHIFT=5
11628 CONFIG_X86_XADD=y
11629 CONFIG_X86_PPRO_FENCE=y
11630-CONFIG_X86_WP_WORKS_OK=y
11631 CONFIG_X86_INVLPG=y
11632 CONFIG_X86_BSWAP=y
11633 CONFIG_X86_POPAD_OK=y
11634diff --git a/arch/um/include/asm/cache.h b/arch/um/include/asm/cache.h
11635index 19e1bdd..3665b77 100644
11636--- a/arch/um/include/asm/cache.h
11637+++ b/arch/um/include/asm/cache.h
11638@@ -1,6 +1,7 @@
11639 #ifndef __UM_CACHE_H
11640 #define __UM_CACHE_H
11641
11642+#include <linux/const.h>
11643
11644 #if defined(CONFIG_UML_X86) && !defined(CONFIG_64BIT)
11645 # define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
11646@@ -12,6 +13,6 @@
11647 # define L1_CACHE_SHIFT 5
11648 #endif
11649
11650-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
11651+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
11652
11653 #endif
11654diff --git a/arch/um/include/asm/kmap_types.h b/arch/um/include/asm/kmap_types.h
11655index 2e0a6b1..a64d0f5 100644
11656--- a/arch/um/include/asm/kmap_types.h
11657+++ b/arch/um/include/asm/kmap_types.h
11658@@ -8,6 +8,6 @@
11659
11660 /* No more #include "asm/arch/kmap_types.h" ! */
11661
11662-#define KM_TYPE_NR 14
11663+#define KM_TYPE_NR 15
11664
11665 #endif
11666diff --git a/arch/um/include/asm/page.h b/arch/um/include/asm/page.h
11667index 5ff53d9..5850cdf 100644
11668--- a/arch/um/include/asm/page.h
11669+++ b/arch/um/include/asm/page.h
11670@@ -14,6 +14,9 @@
11671 #define PAGE_SIZE (_AC(1, UL) << PAGE_SHIFT)
11672 #define PAGE_MASK (~(PAGE_SIZE-1))
11673
11674+#define ktla_ktva(addr) (addr)
11675+#define ktva_ktla(addr) (addr)
11676+
11677 #ifndef __ASSEMBLY__
11678
11679 struct page;
11680diff --git a/arch/um/include/asm/pgtable-3level.h b/arch/um/include/asm/pgtable-3level.h
11681index 0032f92..cd151e0 100644
11682--- a/arch/um/include/asm/pgtable-3level.h
11683+++ b/arch/um/include/asm/pgtable-3level.h
11684@@ -58,6 +58,7 @@
11685 #define pud_present(x) (pud_val(x) & _PAGE_PRESENT)
11686 #define pud_populate(mm, pud, pmd) \
11687 set_pud(pud, __pud(_PAGE_TABLE + __pa(pmd)))
11688+#define pud_populate_kernel(mm, pud, pmd) pud_populate((mm), (pud), (pmd))
11689
11690 #ifdef CONFIG_64BIT
11691 #define set_pud(pudptr, pudval) set_64bit((u64 *) (pudptr), pud_val(pudval))
11692diff --git a/arch/um/kernel/process.c b/arch/um/kernel/process.c
11693index bbcef52..6a2a483 100644
11694--- a/arch/um/kernel/process.c
11695+++ b/arch/um/kernel/process.c
11696@@ -367,22 +367,6 @@ int singlestepping(void * t)
11697 return 2;
11698 }
11699
11700-/*
11701- * Only x86 and x86_64 have an arch_align_stack().
11702- * All other arches have "#define arch_align_stack(x) (x)"
11703- * in their asm/system.h
11704- * As this is included in UML from asm-um/system-generic.h,
11705- * we can use it to behave as the subarch does.
11706- */
11707-#ifndef arch_align_stack
11708-unsigned long arch_align_stack(unsigned long sp)
11709-{
11710- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
11711- sp -= get_random_int() % 8192;
11712- return sp & ~0xf;
11713-}
11714-#endif
11715-
11716 unsigned long get_wchan(struct task_struct *p)
11717 {
11718 unsigned long stack_page, sp, ip;
11719diff --git a/arch/unicore32/include/asm/cache.h b/arch/unicore32/include/asm/cache.h
11720index ad8f795..2c7eec6 100644
11721--- a/arch/unicore32/include/asm/cache.h
11722+++ b/arch/unicore32/include/asm/cache.h
11723@@ -12,8 +12,10 @@
11724 #ifndef __UNICORE_CACHE_H__
11725 #define __UNICORE_CACHE_H__
11726
11727-#define L1_CACHE_SHIFT (5)
11728-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
11729+#include <linux/const.h>
11730+
11731+#define L1_CACHE_SHIFT 5
11732+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
11733
11734 /*
11735 * Memory returned by kmalloc() may be used for DMA, so we must make
11736diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
11737index f67e839..bfd4748 100644
11738--- a/arch/x86/Kconfig
11739+++ b/arch/x86/Kconfig
11740@@ -247,7 +247,7 @@ config X86_HT
11741
11742 config X86_32_LAZY_GS
11743 def_bool y
11744- depends on X86_32 && !CC_STACKPROTECTOR
11745+ depends on X86_32 && !CC_STACKPROTECTOR && !PAX_MEMORY_UDEREF
11746
11747 config ARCH_HWEIGHT_CFLAGS
11748 string
11749@@ -1099,6 +1099,7 @@ config MICROCODE_EARLY
11750
11751 config X86_MSR
11752 tristate "/dev/cpu/*/msr - Model-specific register support"
11753+ depends on !GRKERNSEC_KMEM
11754 ---help---
11755 This device gives privileged processes access to the x86
11756 Model-Specific Registers (MSRs). It is a character device with
11757@@ -1122,7 +1123,7 @@ choice
11758
11759 config NOHIGHMEM
11760 bool "off"
11761- depends on !X86_NUMAQ
11762+ depends on !X86_NUMAQ && !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
11763 ---help---
11764 Linux can use up to 64 Gigabytes of physical memory on x86 systems.
11765 However, the address space of 32-bit x86 processors is only 4
11766@@ -1159,7 +1160,7 @@ config NOHIGHMEM
11767
11768 config HIGHMEM4G
11769 bool "4GB"
11770- depends on !X86_NUMAQ
11771+ depends on !X86_NUMAQ && !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
11772 ---help---
11773 Select this if you have a 32-bit processor and between 1 and 4
11774 gigabytes of physical RAM.
11775@@ -1212,7 +1213,7 @@ config PAGE_OFFSET
11776 hex
11777 default 0xB0000000 if VMSPLIT_3G_OPT
11778 default 0x80000000 if VMSPLIT_2G
11779- default 0x78000000 if VMSPLIT_2G_OPT
11780+ default 0x70000000 if VMSPLIT_2G_OPT
11781 default 0x40000000 if VMSPLIT_1G
11782 default 0xC0000000
11783 depends on X86_32
11784@@ -1614,6 +1615,7 @@ config SECCOMP
11785
11786 config CC_STACKPROTECTOR
11787 bool "Enable -fstack-protector buffer overflow detection"
11788+ depends on X86_64 || !PAX_MEMORY_UDEREF
11789 ---help---
11790 This option turns on the -fstack-protector GCC feature. This
11791 feature puts, at the beginning of functions, a canary value on
11792@@ -1632,6 +1634,7 @@ source kernel/Kconfig.hz
11793
11794 config KEXEC
11795 bool "kexec system call"
11796+ depends on !GRKERNSEC_KMEM
11797 ---help---
11798 kexec is a system call that implements the ability to shutdown your
11799 current kernel, and to start another kernel. It is like a reboot
11800@@ -1733,6 +1736,8 @@ config X86_NEED_RELOCS
11801 config PHYSICAL_ALIGN
11802 hex "Alignment value to which kernel should be aligned"
11803 default "0x1000000"
11804+ range 0x200000 0x1000000 if PAX_KERNEXEC && X86_PAE
11805+ range 0x400000 0x1000000 if PAX_KERNEXEC && !X86_PAE
11806 range 0x2000 0x1000000 if X86_32
11807 range 0x200000 0x1000000 if X86_64
11808 ---help---
11809@@ -1812,9 +1817,10 @@ config DEBUG_HOTPLUG_CPU0
11810 If unsure, say N.
11811
11812 config COMPAT_VDSO
11813- def_bool y
11814+ def_bool n
11815 prompt "Compat VDSO support"
11816 depends on X86_32 || IA32_EMULATION
11817+ depends on !PAX_PAGEEXEC && !PAX_SEGMEXEC && !PAX_KERNEXEC && !PAX_MEMORY_UDEREF
11818 ---help---
11819 Map the 32-bit VDSO to the predictable old-style address too.
11820
11821diff --git a/arch/x86/Kconfig.cpu b/arch/x86/Kconfig.cpu
11822index c026cca..14657ae 100644
11823--- a/arch/x86/Kconfig.cpu
11824+++ b/arch/x86/Kconfig.cpu
11825@@ -319,7 +319,7 @@ config X86_PPRO_FENCE
11826
11827 config X86_F00F_BUG
11828 def_bool y
11829- depends on M586MMX || M586TSC || M586 || M486
11830+ depends on (M586MMX || M586TSC || M586 || M486) && !PAX_KERNEXEC
11831
11832 config X86_INVD_BUG
11833 def_bool y
11834@@ -327,7 +327,7 @@ config X86_INVD_BUG
11835
11836 config X86_ALIGNMENT_16
11837 def_bool y
11838- depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || MELAN || MK6 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
11839+ depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || X86_ELAN || MK8 || MK7 || MK6 || MCORE2 || MPENTIUM4 || MPENTIUMIII || MPENTIUMII || M686 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
11840
11841 config X86_INTEL_USERCOPY
11842 def_bool y
11843@@ -373,7 +373,7 @@ config X86_CMPXCHG64
11844 # generates cmov.
11845 config X86_CMOV
11846 def_bool y
11847- depends on (MK8 || MK7 || MCORE2 || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
11848+ depends on (MK8 || MK7 || MCORE2 || MPSC || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
11849
11850 config X86_MINIMUM_CPU_FAMILY
11851 int
11852diff --git a/arch/x86/Kconfig.debug b/arch/x86/Kconfig.debug
11853index 78d91af..8ceb94b 100644
11854--- a/arch/x86/Kconfig.debug
11855+++ b/arch/x86/Kconfig.debug
11856@@ -74,7 +74,7 @@ config X86_PTDUMP
11857 config DEBUG_RODATA
11858 bool "Write protect kernel read-only data structures"
11859 default y
11860- depends on DEBUG_KERNEL
11861+ depends on DEBUG_KERNEL && BROKEN
11862 ---help---
11863 Mark the kernel read-only data as write-protected in the pagetables,
11864 in order to catch accidental (and incorrect) writes to such const
11865@@ -92,7 +92,7 @@ config DEBUG_RODATA_TEST
11866
11867 config DEBUG_SET_MODULE_RONX
11868 bool "Set loadable kernel module data as NX and text as RO"
11869- depends on MODULES
11870+ depends on MODULES && BROKEN
11871 ---help---
11872 This option helps catch unintended modifications to loadable
11873 kernel module's text and read-only data. It also prevents execution
11874diff --git a/arch/x86/Makefile b/arch/x86/Makefile
11875index 57d0215..b4373fb 100644
11876--- a/arch/x86/Makefile
11877+++ b/arch/x86/Makefile
11878@@ -49,14 +49,12 @@ ifeq ($(CONFIG_X86_32),y)
11879 # CPU-specific tuning. Anything which can be shared with UML should go here.
11880 include $(srctree)/arch/x86/Makefile_32.cpu
11881 KBUILD_CFLAGS += $(cflags-y)
11882-
11883- # temporary until string.h is fixed
11884- KBUILD_CFLAGS += -ffreestanding
11885 else
11886 BITS := 64
11887 UTS_MACHINE := x86_64
11888 CHECKFLAGS += -D__x86_64__ -m64
11889
11890+ biarch := $(call cc-option,-m64)
11891 KBUILD_AFLAGS += -m64
11892 KBUILD_CFLAGS += -m64
11893
11894@@ -89,6 +87,9 @@ else
11895 KBUILD_CFLAGS += -maccumulate-outgoing-args
11896 endif
11897
11898+# temporary until string.h is fixed
11899+KBUILD_CFLAGS += -ffreestanding
11900+
11901 ifdef CONFIG_CC_STACKPROTECTOR
11902 cc_has_sp := $(srctree)/scripts/gcc-x86_$(BITS)-has-stack-protector.sh
11903 ifeq ($(shell $(CONFIG_SHELL) $(cc_has_sp) $(CC) $(KBUILD_CPPFLAGS) $(biarch)),y)
11904@@ -247,3 +248,12 @@ define archhelp
11905 echo ' FDINITRD=file initrd for the booted kernel'
11906 echo ' kvmconfig - Enable additional options for guest kernel support'
11907 endef
11908+
11909+define OLD_LD
11910+
11911+*** ${VERSION}.${PATCHLEVEL} PaX kernels no longer build correctly with old versions of binutils.
11912+*** Please upgrade your binutils to 2.18 or newer
11913+endef
11914+
11915+archprepare:
11916+ $(if $(LDFLAGS_BUILD_ID),,$(error $(OLD_LD)))
11917diff --git a/arch/x86/boot/Makefile b/arch/x86/boot/Makefile
11918index 6cf0111..f2e2398 100644
11919--- a/arch/x86/boot/Makefile
11920+++ b/arch/x86/boot/Makefile
11921@@ -65,6 +65,9 @@ KBUILD_CFLAGS := $(USERINCLUDE) -m32 -g -Os -D_SETUP -D__KERNEL__ \
11922 $(call cc-option, -fno-unit-at-a-time)) \
11923 $(call cc-option, -fno-stack-protector) \
11924 $(call cc-option, -mpreferred-stack-boundary=2)
11925+ifdef CONSTIFY_PLUGIN
11926+KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
11927+endif
11928 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
11929 GCOV_PROFILE := n
11930
11931diff --git a/arch/x86/boot/bitops.h b/arch/x86/boot/bitops.h
11932index 878e4b9..20537ab 100644
11933--- a/arch/x86/boot/bitops.h
11934+++ b/arch/x86/boot/bitops.h
11935@@ -26,7 +26,7 @@ static inline int variable_test_bit(int nr, const void *addr)
11936 u8 v;
11937 const u32 *p = (const u32 *)addr;
11938
11939- asm("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
11940+ asm volatile("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
11941 return v;
11942 }
11943
11944@@ -37,7 +37,7 @@ static inline int variable_test_bit(int nr, const void *addr)
11945
11946 static inline void set_bit(int nr, void *addr)
11947 {
11948- asm("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
11949+ asm volatile("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
11950 }
11951
11952 #endif /* BOOT_BITOPS_H */
11953diff --git a/arch/x86/boot/boot.h b/arch/x86/boot/boot.h
11954index ef72bae..353a184 100644
11955--- a/arch/x86/boot/boot.h
11956+++ b/arch/x86/boot/boot.h
11957@@ -85,7 +85,7 @@ static inline void io_delay(void)
11958 static inline u16 ds(void)
11959 {
11960 u16 seg;
11961- asm("movw %%ds,%0" : "=rm" (seg));
11962+ asm volatile("movw %%ds,%0" : "=rm" (seg));
11963 return seg;
11964 }
11965
11966@@ -181,7 +181,7 @@ static inline void wrgs32(u32 v, addr_t addr)
11967 static inline int memcmp(const void *s1, const void *s2, size_t len)
11968 {
11969 u8 diff;
11970- asm("repe; cmpsb; setnz %0"
11971+ asm volatile("repe; cmpsb; setnz %0"
11972 : "=qm" (diff), "+D" (s1), "+S" (s2), "+c" (len));
11973 return diff;
11974 }
11975diff --git a/arch/x86/boot/compressed/Makefile b/arch/x86/boot/compressed/Makefile
11976index c8a6792..2402765 100644
11977--- a/arch/x86/boot/compressed/Makefile
11978+++ b/arch/x86/boot/compressed/Makefile
11979@@ -16,6 +16,9 @@ KBUILD_CFLAGS += $(cflags-y)
11980 KBUILD_CFLAGS += -mno-mmx -mno-sse
11981 KBUILD_CFLAGS += $(call cc-option,-ffreestanding)
11982 KBUILD_CFLAGS += $(call cc-option,-fno-stack-protector)
11983+ifdef CONSTIFY_PLUGIN
11984+KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
11985+endif
11986
11987 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
11988 GCOV_PROFILE := n
11989diff --git a/arch/x86/boot/compressed/eboot.c b/arch/x86/boot/compressed/eboot.c
11990index b7388a4..03844ec 100644
11991--- a/arch/x86/boot/compressed/eboot.c
11992+++ b/arch/x86/boot/compressed/eboot.c
11993@@ -150,7 +150,6 @@ again:
11994 *addr = max_addr;
11995 }
11996
11997-free_pool:
11998 efi_call_phys1(sys_table->boottime->free_pool, map);
11999
12000 fail:
12001@@ -214,7 +213,6 @@ static efi_status_t low_alloc(unsigned long size, unsigned long align,
12002 if (i == map_size / desc_size)
12003 status = EFI_NOT_FOUND;
12004
12005-free_pool:
12006 efi_call_phys1(sys_table->boottime->free_pool, map);
12007 fail:
12008 return status;
12009diff --git a/arch/x86/boot/compressed/efi_stub_32.S b/arch/x86/boot/compressed/efi_stub_32.S
12010index a53440e..c3dbf1e 100644
12011--- a/arch/x86/boot/compressed/efi_stub_32.S
12012+++ b/arch/x86/boot/compressed/efi_stub_32.S
12013@@ -46,16 +46,13 @@ ENTRY(efi_call_phys)
12014 * parameter 2, ..., param n. To make things easy, we save the return
12015 * address of efi_call_phys in a global variable.
12016 */
12017- popl %ecx
12018- movl %ecx, saved_return_addr(%edx)
12019- /* get the function pointer into ECX*/
12020- popl %ecx
12021- movl %ecx, efi_rt_function_ptr(%edx)
12022+ popl saved_return_addr(%edx)
12023+ popl efi_rt_function_ptr(%edx)
12024
12025 /*
12026 * 3. Call the physical function.
12027 */
12028- call *%ecx
12029+ call *efi_rt_function_ptr(%edx)
12030
12031 /*
12032 * 4. Balance the stack. And because EAX contain the return value,
12033@@ -67,15 +64,12 @@ ENTRY(efi_call_phys)
12034 1: popl %edx
12035 subl $1b, %edx
12036
12037- movl efi_rt_function_ptr(%edx), %ecx
12038- pushl %ecx
12039+ pushl efi_rt_function_ptr(%edx)
12040
12041 /*
12042 * 10. Push the saved return address onto the stack and return.
12043 */
12044- movl saved_return_addr(%edx), %ecx
12045- pushl %ecx
12046- ret
12047+ jmpl *saved_return_addr(%edx)
12048 ENDPROC(efi_call_phys)
12049 .previous
12050
12051diff --git a/arch/x86/boot/compressed/head_32.S b/arch/x86/boot/compressed/head_32.S
12052index 5d6f689..9d06730 100644
12053--- a/arch/x86/boot/compressed/head_32.S
12054+++ b/arch/x86/boot/compressed/head_32.S
12055@@ -118,7 +118,7 @@ preferred_addr:
12056 notl %eax
12057 andl %eax, %ebx
12058 #else
12059- movl $LOAD_PHYSICAL_ADDR, %ebx
12060+ movl $____LOAD_PHYSICAL_ADDR, %ebx
12061 #endif
12062
12063 /* Target address to relocate to for decompression */
12064diff --git a/arch/x86/boot/compressed/head_64.S b/arch/x86/boot/compressed/head_64.S
12065index c337422..2c5be72 100644
12066--- a/arch/x86/boot/compressed/head_64.S
12067+++ b/arch/x86/boot/compressed/head_64.S
12068@@ -95,7 +95,7 @@ ENTRY(startup_32)
12069 notl %eax
12070 andl %eax, %ebx
12071 #else
12072- movl $LOAD_PHYSICAL_ADDR, %ebx
12073+ movl $____LOAD_PHYSICAL_ADDR, %ebx
12074 #endif
12075
12076 /* Target address to relocate to for decompression */
12077@@ -270,7 +270,7 @@ preferred_addr:
12078 notq %rax
12079 andq %rax, %rbp
12080 #else
12081- movq $LOAD_PHYSICAL_ADDR, %rbp
12082+ movq $____LOAD_PHYSICAL_ADDR, %rbp
12083 #endif
12084
12085 /* Target address to relocate to for decompression */
12086@@ -362,8 +362,8 @@ gdt:
12087 .long gdt
12088 .word 0
12089 .quad 0x0000000000000000 /* NULL descriptor */
12090- .quad 0x00af9a000000ffff /* __KERNEL_CS */
12091- .quad 0x00cf92000000ffff /* __KERNEL_DS */
12092+ .quad 0x00af9b000000ffff /* __KERNEL_CS */
12093+ .quad 0x00cf93000000ffff /* __KERNEL_DS */
12094 .quad 0x0080890000000000 /* TS descriptor */
12095 .quad 0x0000000000000000 /* TS continued */
12096 gdt_end:
12097diff --git a/arch/x86/boot/compressed/misc.c b/arch/x86/boot/compressed/misc.c
12098index 434f077..b6b4b38 100644
12099--- a/arch/x86/boot/compressed/misc.c
12100+++ b/arch/x86/boot/compressed/misc.c
12101@@ -283,7 +283,7 @@ static void handle_relocations(void *output, unsigned long output_len)
12102 * Calculate the delta between where vmlinux was linked to load
12103 * and where it was actually loaded.
12104 */
12105- delta = min_addr - LOAD_PHYSICAL_ADDR;
12106+ delta = min_addr - ____LOAD_PHYSICAL_ADDR;
12107 if (!delta) {
12108 debug_putstr("No relocation needed... ");
12109 return;
12110@@ -380,7 +380,7 @@ static void parse_elf(void *output)
12111 case PT_LOAD:
12112 #ifdef CONFIG_RELOCATABLE
12113 dest = output;
12114- dest += (phdr->p_paddr - LOAD_PHYSICAL_ADDR);
12115+ dest += (phdr->p_paddr - ____LOAD_PHYSICAL_ADDR);
12116 #else
12117 dest = (void *)(phdr->p_paddr);
12118 #endif
12119@@ -432,7 +432,7 @@ asmlinkage void decompress_kernel(void *rmode, memptr heap,
12120 error("Destination address too large");
12121 #endif
12122 #ifndef CONFIG_RELOCATABLE
12123- if ((unsigned long)output != LOAD_PHYSICAL_ADDR)
12124+ if ((unsigned long)output != ____LOAD_PHYSICAL_ADDR)
12125 error("Wrong destination address");
12126 #endif
12127
12128diff --git a/arch/x86/boot/cpucheck.c b/arch/x86/boot/cpucheck.c
12129index 4d3ff03..e4972ff 100644
12130--- a/arch/x86/boot/cpucheck.c
12131+++ b/arch/x86/boot/cpucheck.c
12132@@ -74,7 +74,7 @@ static int has_fpu(void)
12133 u16 fcw = -1, fsw = -1;
12134 u32 cr0;
12135
12136- asm("movl %%cr0,%0" : "=r" (cr0));
12137+ asm volatile("movl %%cr0,%0" : "=r" (cr0));
12138 if (cr0 & (X86_CR0_EM|X86_CR0_TS)) {
12139 cr0 &= ~(X86_CR0_EM|X86_CR0_TS);
12140 asm volatile("movl %0,%%cr0" : : "r" (cr0));
12141@@ -90,7 +90,7 @@ static int has_eflag(u32 mask)
12142 {
12143 u32 f0, f1;
12144
12145- asm("pushfl ; "
12146+ asm volatile("pushfl ; "
12147 "pushfl ; "
12148 "popl %0 ; "
12149 "movl %0,%1 ; "
12150@@ -115,7 +115,7 @@ static void get_flags(void)
12151 set_bit(X86_FEATURE_FPU, cpu.flags);
12152
12153 if (has_eflag(X86_EFLAGS_ID)) {
12154- asm("cpuid"
12155+ asm volatile("cpuid"
12156 : "=a" (max_intel_level),
12157 "=b" (cpu_vendor[0]),
12158 "=d" (cpu_vendor[1]),
12159@@ -124,7 +124,7 @@ static void get_flags(void)
12160
12161 if (max_intel_level >= 0x00000001 &&
12162 max_intel_level <= 0x0000ffff) {
12163- asm("cpuid"
12164+ asm volatile("cpuid"
12165 : "=a" (tfms),
12166 "=c" (cpu.flags[4]),
12167 "=d" (cpu.flags[0])
12168@@ -136,7 +136,7 @@ static void get_flags(void)
12169 cpu.model += ((tfms >> 16) & 0xf) << 4;
12170 }
12171
12172- asm("cpuid"
12173+ asm volatile("cpuid"
12174 : "=a" (max_amd_level)
12175 : "a" (0x80000000)
12176 : "ebx", "ecx", "edx");
12177@@ -144,7 +144,7 @@ static void get_flags(void)
12178 if (max_amd_level >= 0x80000001 &&
12179 max_amd_level <= 0x8000ffff) {
12180 u32 eax = 0x80000001;
12181- asm("cpuid"
12182+ asm volatile("cpuid"
12183 : "+a" (eax),
12184 "=c" (cpu.flags[6]),
12185 "=d" (cpu.flags[1])
12186@@ -203,9 +203,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
12187 u32 ecx = MSR_K7_HWCR;
12188 u32 eax, edx;
12189
12190- asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
12191+ asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
12192 eax &= ~(1 << 15);
12193- asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
12194+ asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
12195
12196 get_flags(); /* Make sure it really did something */
12197 err = check_flags();
12198@@ -218,9 +218,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
12199 u32 ecx = MSR_VIA_FCR;
12200 u32 eax, edx;
12201
12202- asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
12203+ asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
12204 eax |= (1<<1)|(1<<7);
12205- asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
12206+ asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
12207
12208 set_bit(X86_FEATURE_CX8, cpu.flags);
12209 err = check_flags();
12210@@ -231,12 +231,12 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
12211 u32 eax, edx;
12212 u32 level = 1;
12213
12214- asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
12215- asm("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
12216- asm("cpuid"
12217+ asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
12218+ asm volatile("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
12219+ asm volatile("cpuid"
12220 : "+a" (level), "=d" (cpu.flags[0])
12221 : : "ecx", "ebx");
12222- asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
12223+ asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
12224
12225 err = check_flags();
12226 }
12227diff --git a/arch/x86/boot/header.S b/arch/x86/boot/header.S
12228index 9ec06a1..2c25e79 100644
12229--- a/arch/x86/boot/header.S
12230+++ b/arch/x86/boot/header.S
12231@@ -409,10 +409,14 @@ setup_data: .quad 0 # 64-bit physical pointer to
12232 # single linked list of
12233 # struct setup_data
12234
12235-pref_address: .quad LOAD_PHYSICAL_ADDR # preferred load addr
12236+pref_address: .quad ____LOAD_PHYSICAL_ADDR # preferred load addr
12237
12238 #define ZO_INIT_SIZE (ZO__end - ZO_startup_32 + ZO_z_extract_offset)
12239+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
12240+#define VO_INIT_SIZE (VO__end - VO__text - __PAGE_OFFSET - ____LOAD_PHYSICAL_ADDR)
12241+#else
12242 #define VO_INIT_SIZE (VO__end - VO__text)
12243+#endif
12244 #if ZO_INIT_SIZE > VO_INIT_SIZE
12245 #define INIT_SIZE ZO_INIT_SIZE
12246 #else
12247diff --git a/arch/x86/boot/memory.c b/arch/x86/boot/memory.c
12248index db75d07..8e6d0af 100644
12249--- a/arch/x86/boot/memory.c
12250+++ b/arch/x86/boot/memory.c
12251@@ -19,7 +19,7 @@
12252
12253 static int detect_memory_e820(void)
12254 {
12255- int count = 0;
12256+ unsigned int count = 0;
12257 struct biosregs ireg, oreg;
12258 struct e820entry *desc = boot_params.e820_map;
12259 static struct e820entry buf; /* static so it is zeroed */
12260diff --git a/arch/x86/boot/video-vesa.c b/arch/x86/boot/video-vesa.c
12261index 11e8c6e..fdbb1ed 100644
12262--- a/arch/x86/boot/video-vesa.c
12263+++ b/arch/x86/boot/video-vesa.c
12264@@ -200,6 +200,7 @@ static void vesa_store_pm_info(void)
12265
12266 boot_params.screen_info.vesapm_seg = oreg.es;
12267 boot_params.screen_info.vesapm_off = oreg.di;
12268+ boot_params.screen_info.vesapm_size = oreg.cx;
12269 }
12270
12271 /*
12272diff --git a/arch/x86/boot/video.c b/arch/x86/boot/video.c
12273index 43eda28..5ab5fdb 100644
12274--- a/arch/x86/boot/video.c
12275+++ b/arch/x86/boot/video.c
12276@@ -96,7 +96,7 @@ static void store_mode_params(void)
12277 static unsigned int get_entry(void)
12278 {
12279 char entry_buf[4];
12280- int i, len = 0;
12281+ unsigned int i, len = 0;
12282 int key;
12283 unsigned int v;
12284
12285diff --git a/arch/x86/crypto/aes-x86_64-asm_64.S b/arch/x86/crypto/aes-x86_64-asm_64.S
12286index 9105655..41779c1 100644
12287--- a/arch/x86/crypto/aes-x86_64-asm_64.S
12288+++ b/arch/x86/crypto/aes-x86_64-asm_64.S
12289@@ -8,6 +8,8 @@
12290 * including this sentence is retained in full.
12291 */
12292
12293+#include <asm/alternative-asm.h>
12294+
12295 .extern crypto_ft_tab
12296 .extern crypto_it_tab
12297 .extern crypto_fl_tab
12298@@ -70,6 +72,8 @@
12299 je B192; \
12300 leaq 32(r9),r9;
12301
12302+#define ret pax_force_retaddr; ret
12303+
12304 #define epilogue(FUNC,r1,r2,r3,r4,r5,r6,r7,r8,r9) \
12305 movq r1,r2; \
12306 movq r3,r4; \
12307diff --git a/arch/x86/crypto/aesni-intel_asm.S b/arch/x86/crypto/aesni-intel_asm.S
12308index 477e9d7..c92c7d8 100644
12309--- a/arch/x86/crypto/aesni-intel_asm.S
12310+++ b/arch/x86/crypto/aesni-intel_asm.S
12311@@ -31,6 +31,7 @@
12312
12313 #include <linux/linkage.h>
12314 #include <asm/inst.h>
12315+#include <asm/alternative-asm.h>
12316
12317 #ifdef __x86_64__
12318 .data
12319@@ -205,7 +206,7 @@ enc: .octa 0x2
12320 * num_initial_blocks = b mod 4
12321 * encrypt the initial num_initial_blocks blocks and apply ghash on
12322 * the ciphertext
12323-* %r10, %r11, %r12, %rax, %xmm5, %xmm6, %xmm7, %xmm8, %xmm9 registers
12324+* %r10, %r11, %r15, %rax, %xmm5, %xmm6, %xmm7, %xmm8, %xmm9 registers
12325 * are clobbered
12326 * arg1, %arg2, %arg3, %r14 are used as a pointer only, not modified
12327 */
12328@@ -214,8 +215,8 @@ enc: .octa 0x2
12329 .macro INITIAL_BLOCKS_DEC num_initial_blocks TMP1 TMP2 TMP3 TMP4 TMP5 XMM0 XMM1 \
12330 XMM2 XMM3 XMM4 XMMDst TMP6 TMP7 i i_seq operation
12331 mov arg7, %r10 # %r10 = AAD
12332- mov arg8, %r12 # %r12 = aadLen
12333- mov %r12, %r11
12334+ mov arg8, %r15 # %r15 = aadLen
12335+ mov %r15, %r11
12336 pxor %xmm\i, %xmm\i
12337 _get_AAD_loop\num_initial_blocks\operation:
12338 movd (%r10), \TMP1
12339@@ -223,15 +224,15 @@ _get_AAD_loop\num_initial_blocks\operation:
12340 psrldq $4, %xmm\i
12341 pxor \TMP1, %xmm\i
12342 add $4, %r10
12343- sub $4, %r12
12344+ sub $4, %r15
12345 jne _get_AAD_loop\num_initial_blocks\operation
12346 cmp $16, %r11
12347 je _get_AAD_loop2_done\num_initial_blocks\operation
12348- mov $16, %r12
12349+ mov $16, %r15
12350 _get_AAD_loop2\num_initial_blocks\operation:
12351 psrldq $4, %xmm\i
12352- sub $4, %r12
12353- cmp %r11, %r12
12354+ sub $4, %r15
12355+ cmp %r11, %r15
12356 jne _get_AAD_loop2\num_initial_blocks\operation
12357 _get_AAD_loop2_done\num_initial_blocks\operation:
12358 movdqa SHUF_MASK(%rip), %xmm14
12359@@ -443,7 +444,7 @@ _initial_blocks_done\num_initial_blocks\operation:
12360 * num_initial_blocks = b mod 4
12361 * encrypt the initial num_initial_blocks blocks and apply ghash on
12362 * the ciphertext
12363-* %r10, %r11, %r12, %rax, %xmm5, %xmm6, %xmm7, %xmm8, %xmm9 registers
12364+* %r10, %r11, %r15, %rax, %xmm5, %xmm6, %xmm7, %xmm8, %xmm9 registers
12365 * are clobbered
12366 * arg1, %arg2, %arg3, %r14 are used as a pointer only, not modified
12367 */
12368@@ -452,8 +453,8 @@ _initial_blocks_done\num_initial_blocks\operation:
12369 .macro INITIAL_BLOCKS_ENC num_initial_blocks TMP1 TMP2 TMP3 TMP4 TMP5 XMM0 XMM1 \
12370 XMM2 XMM3 XMM4 XMMDst TMP6 TMP7 i i_seq operation
12371 mov arg7, %r10 # %r10 = AAD
12372- mov arg8, %r12 # %r12 = aadLen
12373- mov %r12, %r11
12374+ mov arg8, %r15 # %r15 = aadLen
12375+ mov %r15, %r11
12376 pxor %xmm\i, %xmm\i
12377 _get_AAD_loop\num_initial_blocks\operation:
12378 movd (%r10), \TMP1
12379@@ -461,15 +462,15 @@ _get_AAD_loop\num_initial_blocks\operation:
12380 psrldq $4, %xmm\i
12381 pxor \TMP1, %xmm\i
12382 add $4, %r10
12383- sub $4, %r12
12384+ sub $4, %r15
12385 jne _get_AAD_loop\num_initial_blocks\operation
12386 cmp $16, %r11
12387 je _get_AAD_loop2_done\num_initial_blocks\operation
12388- mov $16, %r12
12389+ mov $16, %r15
12390 _get_AAD_loop2\num_initial_blocks\operation:
12391 psrldq $4, %xmm\i
12392- sub $4, %r12
12393- cmp %r11, %r12
12394+ sub $4, %r15
12395+ cmp %r11, %r15
12396 jne _get_AAD_loop2\num_initial_blocks\operation
12397 _get_AAD_loop2_done\num_initial_blocks\operation:
12398 movdqa SHUF_MASK(%rip), %xmm14
12399@@ -1269,7 +1270,7 @@ TMP7 XMM1 XMM2 XMM3 XMM4 XMMDst
12400 *
12401 *****************************************************************************/
12402 ENTRY(aesni_gcm_dec)
12403- push %r12
12404+ push %r15
12405 push %r13
12406 push %r14
12407 mov %rsp, %r14
12408@@ -1279,8 +1280,8 @@ ENTRY(aesni_gcm_dec)
12409 */
12410 sub $VARIABLE_OFFSET, %rsp
12411 and $~63, %rsp # align rsp to 64 bytes
12412- mov %arg6, %r12
12413- movdqu (%r12), %xmm13 # %xmm13 = HashKey
12414+ mov %arg6, %r15
12415+ movdqu (%r15), %xmm13 # %xmm13 = HashKey
12416 movdqa SHUF_MASK(%rip), %xmm2
12417 PSHUFB_XMM %xmm2, %xmm13
12418
12419@@ -1308,10 +1309,10 @@ ENTRY(aesni_gcm_dec)
12420 movdqa %xmm13, HashKey(%rsp) # store HashKey<<1 (mod poly)
12421 mov %arg4, %r13 # save the number of bytes of plaintext/ciphertext
12422 and $-16, %r13 # %r13 = %r13 - (%r13 mod 16)
12423- mov %r13, %r12
12424- and $(3<<4), %r12
12425+ mov %r13, %r15
12426+ and $(3<<4), %r15
12427 jz _initial_num_blocks_is_0_decrypt
12428- cmp $(2<<4), %r12
12429+ cmp $(2<<4), %r15
12430 jb _initial_num_blocks_is_1_decrypt
12431 je _initial_num_blocks_is_2_decrypt
12432 _initial_num_blocks_is_3_decrypt:
12433@@ -1361,16 +1362,16 @@ _zero_cipher_left_decrypt:
12434 sub $16, %r11
12435 add %r13, %r11
12436 movdqu (%arg3,%r11,1), %xmm1 # receive the last <16 byte block
12437- lea SHIFT_MASK+16(%rip), %r12
12438- sub %r13, %r12
12439+ lea SHIFT_MASK+16(%rip), %r15
12440+ sub %r13, %r15
12441 # adjust the shuffle mask pointer to be able to shift 16-%r13 bytes
12442 # (%r13 is the number of bytes in plaintext mod 16)
12443- movdqu (%r12), %xmm2 # get the appropriate shuffle mask
12444+ movdqu (%r15), %xmm2 # get the appropriate shuffle mask
12445 PSHUFB_XMM %xmm2, %xmm1 # right shift 16-%r13 butes
12446
12447 movdqa %xmm1, %xmm2
12448 pxor %xmm1, %xmm0 # Ciphertext XOR E(K, Yn)
12449- movdqu ALL_F-SHIFT_MASK(%r12), %xmm1
12450+ movdqu ALL_F-SHIFT_MASK(%r15), %xmm1
12451 # get the appropriate mask to mask out top 16-%r13 bytes of %xmm0
12452 pand %xmm1, %xmm0 # mask out top 16-%r13 bytes of %xmm0
12453 pand %xmm1, %xmm2
12454@@ -1399,9 +1400,9 @@ _less_than_8_bytes_left_decrypt:
12455 sub $1, %r13
12456 jne _less_than_8_bytes_left_decrypt
12457 _multiple_of_16_bytes_decrypt:
12458- mov arg8, %r12 # %r13 = aadLen (number of bytes)
12459- shl $3, %r12 # convert into number of bits
12460- movd %r12d, %xmm15 # len(A) in %xmm15
12461+ mov arg8, %r15 # %r13 = aadLen (number of bytes)
12462+ shl $3, %r15 # convert into number of bits
12463+ movd %r15d, %xmm15 # len(A) in %xmm15
12464 shl $3, %arg4 # len(C) in bits (*128)
12465 MOVQ_R64_XMM %arg4, %xmm1
12466 pslldq $8, %xmm15 # %xmm15 = len(A)||0x0000000000000000
12467@@ -1440,7 +1441,8 @@ _return_T_done_decrypt:
12468 mov %r14, %rsp
12469 pop %r14
12470 pop %r13
12471- pop %r12
12472+ pop %r15
12473+ pax_force_retaddr
12474 ret
12475 ENDPROC(aesni_gcm_dec)
12476
12477@@ -1529,7 +1531,7 @@ ENDPROC(aesni_gcm_dec)
12478 * poly = x^128 + x^127 + x^126 + x^121 + 1
12479 ***************************************************************************/
12480 ENTRY(aesni_gcm_enc)
12481- push %r12
12482+ push %r15
12483 push %r13
12484 push %r14
12485 mov %rsp, %r14
12486@@ -1539,8 +1541,8 @@ ENTRY(aesni_gcm_enc)
12487 #
12488 sub $VARIABLE_OFFSET, %rsp
12489 and $~63, %rsp
12490- mov %arg6, %r12
12491- movdqu (%r12), %xmm13
12492+ mov %arg6, %r15
12493+ movdqu (%r15), %xmm13
12494 movdqa SHUF_MASK(%rip), %xmm2
12495 PSHUFB_XMM %xmm2, %xmm13
12496
12497@@ -1564,13 +1566,13 @@ ENTRY(aesni_gcm_enc)
12498 movdqa %xmm13, HashKey(%rsp)
12499 mov %arg4, %r13 # %xmm13 holds HashKey<<1 (mod poly)
12500 and $-16, %r13
12501- mov %r13, %r12
12502+ mov %r13, %r15
12503
12504 # Encrypt first few blocks
12505
12506- and $(3<<4), %r12
12507+ and $(3<<4), %r15
12508 jz _initial_num_blocks_is_0_encrypt
12509- cmp $(2<<4), %r12
12510+ cmp $(2<<4), %r15
12511 jb _initial_num_blocks_is_1_encrypt
12512 je _initial_num_blocks_is_2_encrypt
12513 _initial_num_blocks_is_3_encrypt:
12514@@ -1623,14 +1625,14 @@ _zero_cipher_left_encrypt:
12515 sub $16, %r11
12516 add %r13, %r11
12517 movdqu (%arg3,%r11,1), %xmm1 # receive the last <16 byte blocks
12518- lea SHIFT_MASK+16(%rip), %r12
12519- sub %r13, %r12
12520+ lea SHIFT_MASK+16(%rip), %r15
12521+ sub %r13, %r15
12522 # adjust the shuffle mask pointer to be able to shift 16-r13 bytes
12523 # (%r13 is the number of bytes in plaintext mod 16)
12524- movdqu (%r12), %xmm2 # get the appropriate shuffle mask
12525+ movdqu (%r15), %xmm2 # get the appropriate shuffle mask
12526 PSHUFB_XMM %xmm2, %xmm1 # shift right 16-r13 byte
12527 pxor %xmm1, %xmm0 # Plaintext XOR Encrypt(K, Yn)
12528- movdqu ALL_F-SHIFT_MASK(%r12), %xmm1
12529+ movdqu ALL_F-SHIFT_MASK(%r15), %xmm1
12530 # get the appropriate mask to mask out top 16-r13 bytes of xmm0
12531 pand %xmm1, %xmm0 # mask out top 16-r13 bytes of xmm0
12532 movdqa SHUF_MASK(%rip), %xmm10
12533@@ -1663,9 +1665,9 @@ _less_than_8_bytes_left_encrypt:
12534 sub $1, %r13
12535 jne _less_than_8_bytes_left_encrypt
12536 _multiple_of_16_bytes_encrypt:
12537- mov arg8, %r12 # %r12 = addLen (number of bytes)
12538- shl $3, %r12
12539- movd %r12d, %xmm15 # len(A) in %xmm15
12540+ mov arg8, %r15 # %r15 = addLen (number of bytes)
12541+ shl $3, %r15
12542+ movd %r15d, %xmm15 # len(A) in %xmm15
12543 shl $3, %arg4 # len(C) in bits (*128)
12544 MOVQ_R64_XMM %arg4, %xmm1
12545 pslldq $8, %xmm15 # %xmm15 = len(A)||0x0000000000000000
12546@@ -1704,7 +1706,8 @@ _return_T_done_encrypt:
12547 mov %r14, %rsp
12548 pop %r14
12549 pop %r13
12550- pop %r12
12551+ pop %r15
12552+ pax_force_retaddr
12553 ret
12554 ENDPROC(aesni_gcm_enc)
12555
12556@@ -1722,6 +1725,7 @@ _key_expansion_256a:
12557 pxor %xmm1, %xmm0
12558 movaps %xmm0, (TKEYP)
12559 add $0x10, TKEYP
12560+ pax_force_retaddr
12561 ret
12562 ENDPROC(_key_expansion_128)
12563 ENDPROC(_key_expansion_256a)
12564@@ -1748,6 +1752,7 @@ _key_expansion_192a:
12565 shufps $0b01001110, %xmm2, %xmm1
12566 movaps %xmm1, 0x10(TKEYP)
12567 add $0x20, TKEYP
12568+ pax_force_retaddr
12569 ret
12570 ENDPROC(_key_expansion_192a)
12571
12572@@ -1768,6 +1773,7 @@ _key_expansion_192b:
12573
12574 movaps %xmm0, (TKEYP)
12575 add $0x10, TKEYP
12576+ pax_force_retaddr
12577 ret
12578 ENDPROC(_key_expansion_192b)
12579
12580@@ -1781,6 +1787,7 @@ _key_expansion_256b:
12581 pxor %xmm1, %xmm2
12582 movaps %xmm2, (TKEYP)
12583 add $0x10, TKEYP
12584+ pax_force_retaddr
12585 ret
12586 ENDPROC(_key_expansion_256b)
12587
12588@@ -1894,6 +1901,7 @@ ENTRY(aesni_set_key)
12589 #ifndef __x86_64__
12590 popl KEYP
12591 #endif
12592+ pax_force_retaddr
12593 ret
12594 ENDPROC(aesni_set_key)
12595
12596@@ -1916,6 +1924,7 @@ ENTRY(aesni_enc)
12597 popl KLEN
12598 popl KEYP
12599 #endif
12600+ pax_force_retaddr
12601 ret
12602 ENDPROC(aesni_enc)
12603
12604@@ -1974,6 +1983,7 @@ _aesni_enc1:
12605 AESENC KEY STATE
12606 movaps 0x70(TKEYP), KEY
12607 AESENCLAST KEY STATE
12608+ pax_force_retaddr
12609 ret
12610 ENDPROC(_aesni_enc1)
12611
12612@@ -2083,6 +2093,7 @@ _aesni_enc4:
12613 AESENCLAST KEY STATE2
12614 AESENCLAST KEY STATE3
12615 AESENCLAST KEY STATE4
12616+ pax_force_retaddr
12617 ret
12618 ENDPROC(_aesni_enc4)
12619
12620@@ -2106,6 +2117,7 @@ ENTRY(aesni_dec)
12621 popl KLEN
12622 popl KEYP
12623 #endif
12624+ pax_force_retaddr
12625 ret
12626 ENDPROC(aesni_dec)
12627
12628@@ -2164,6 +2176,7 @@ _aesni_dec1:
12629 AESDEC KEY STATE
12630 movaps 0x70(TKEYP), KEY
12631 AESDECLAST KEY STATE
12632+ pax_force_retaddr
12633 ret
12634 ENDPROC(_aesni_dec1)
12635
12636@@ -2273,6 +2286,7 @@ _aesni_dec4:
12637 AESDECLAST KEY STATE2
12638 AESDECLAST KEY STATE3
12639 AESDECLAST KEY STATE4
12640+ pax_force_retaddr
12641 ret
12642 ENDPROC(_aesni_dec4)
12643
12644@@ -2331,6 +2345,7 @@ ENTRY(aesni_ecb_enc)
12645 popl KEYP
12646 popl LEN
12647 #endif
12648+ pax_force_retaddr
12649 ret
12650 ENDPROC(aesni_ecb_enc)
12651
12652@@ -2390,6 +2405,7 @@ ENTRY(aesni_ecb_dec)
12653 popl KEYP
12654 popl LEN
12655 #endif
12656+ pax_force_retaddr
12657 ret
12658 ENDPROC(aesni_ecb_dec)
12659
12660@@ -2432,6 +2448,7 @@ ENTRY(aesni_cbc_enc)
12661 popl LEN
12662 popl IVP
12663 #endif
12664+ pax_force_retaddr
12665 ret
12666 ENDPROC(aesni_cbc_enc)
12667
12668@@ -2523,6 +2540,7 @@ ENTRY(aesni_cbc_dec)
12669 popl LEN
12670 popl IVP
12671 #endif
12672+ pax_force_retaddr
12673 ret
12674 ENDPROC(aesni_cbc_dec)
12675
12676@@ -2550,6 +2568,7 @@ _aesni_inc_init:
12677 mov $1, TCTR_LOW
12678 MOVQ_R64_XMM TCTR_LOW INC
12679 MOVQ_R64_XMM CTR TCTR_LOW
12680+ pax_force_retaddr
12681 ret
12682 ENDPROC(_aesni_inc_init)
12683
12684@@ -2579,6 +2598,7 @@ _aesni_inc:
12685 .Linc_low:
12686 movaps CTR, IV
12687 PSHUFB_XMM BSWAP_MASK IV
12688+ pax_force_retaddr
12689 ret
12690 ENDPROC(_aesni_inc)
12691
12692@@ -2640,6 +2660,7 @@ ENTRY(aesni_ctr_enc)
12693 .Lctr_enc_ret:
12694 movups IV, (IVP)
12695 .Lctr_enc_just_ret:
12696+ pax_force_retaddr
12697 ret
12698 ENDPROC(aesni_ctr_enc)
12699
12700@@ -2766,6 +2787,7 @@ ENTRY(aesni_xts_crypt8)
12701 pxor INC, STATE4
12702 movdqu STATE4, 0x70(OUTP)
12703
12704+ pax_force_retaddr
12705 ret
12706 ENDPROC(aesni_xts_crypt8)
12707
12708diff --git a/arch/x86/crypto/blowfish-x86_64-asm_64.S b/arch/x86/crypto/blowfish-x86_64-asm_64.S
12709index 246c670..466e2d6 100644
12710--- a/arch/x86/crypto/blowfish-x86_64-asm_64.S
12711+++ b/arch/x86/crypto/blowfish-x86_64-asm_64.S
12712@@ -21,6 +21,7 @@
12713 */
12714
12715 #include <linux/linkage.h>
12716+#include <asm/alternative-asm.h>
12717
12718 .file "blowfish-x86_64-asm.S"
12719 .text
12720@@ -149,9 +150,11 @@ ENTRY(__blowfish_enc_blk)
12721 jnz .L__enc_xor;
12722
12723 write_block();
12724+ pax_force_retaddr
12725 ret;
12726 .L__enc_xor:
12727 xor_block();
12728+ pax_force_retaddr
12729 ret;
12730 ENDPROC(__blowfish_enc_blk)
12731
12732@@ -183,6 +186,7 @@ ENTRY(blowfish_dec_blk)
12733
12734 movq %r11, %rbp;
12735
12736+ pax_force_retaddr
12737 ret;
12738 ENDPROC(blowfish_dec_blk)
12739
12740@@ -334,6 +338,7 @@ ENTRY(__blowfish_enc_blk_4way)
12741
12742 popq %rbx;
12743 popq %rbp;
12744+ pax_force_retaddr
12745 ret;
12746
12747 .L__enc_xor4:
12748@@ -341,6 +346,7 @@ ENTRY(__blowfish_enc_blk_4way)
12749
12750 popq %rbx;
12751 popq %rbp;
12752+ pax_force_retaddr
12753 ret;
12754 ENDPROC(__blowfish_enc_blk_4way)
12755
12756@@ -375,5 +381,6 @@ ENTRY(blowfish_dec_blk_4way)
12757 popq %rbx;
12758 popq %rbp;
12759
12760+ pax_force_retaddr
12761 ret;
12762 ENDPROC(blowfish_dec_blk_4way)
12763diff --git a/arch/x86/crypto/camellia-aesni-avx-asm_64.S b/arch/x86/crypto/camellia-aesni-avx-asm_64.S
12764index ce71f92..1dce7ec 100644
12765--- a/arch/x86/crypto/camellia-aesni-avx-asm_64.S
12766+++ b/arch/x86/crypto/camellia-aesni-avx-asm_64.S
12767@@ -16,6 +16,7 @@
12768 */
12769
12770 #include <linux/linkage.h>
12771+#include <asm/alternative-asm.h>
12772
12773 #define CAMELLIA_TABLE_BYTE_LEN 272
12774
12775@@ -191,6 +192,7 @@ roundsm16_x0_x1_x2_x3_x4_x5_x6_x7_y0_y1_y2_y3_y4_y5_y6_y7_cd:
12776 roundsm16(%xmm0, %xmm1, %xmm2, %xmm3, %xmm4, %xmm5, %xmm6, %xmm7,
12777 %xmm8, %xmm9, %xmm10, %xmm11, %xmm12, %xmm13, %xmm14, %xmm15,
12778 %rcx, (%r9));
12779+ pax_force_retaddr
12780 ret;
12781 ENDPROC(roundsm16_x0_x1_x2_x3_x4_x5_x6_x7_y0_y1_y2_y3_y4_y5_y6_y7_cd)
12782
12783@@ -199,6 +201,7 @@ roundsm16_x4_x5_x6_x7_x0_x1_x2_x3_y4_y5_y6_y7_y0_y1_y2_y3_ab:
12784 roundsm16(%xmm4, %xmm5, %xmm6, %xmm7, %xmm0, %xmm1, %xmm2, %xmm3,
12785 %xmm12, %xmm13, %xmm14, %xmm15, %xmm8, %xmm9, %xmm10, %xmm11,
12786 %rax, (%r9));
12787+ pax_force_retaddr
12788 ret;
12789 ENDPROC(roundsm16_x4_x5_x6_x7_x0_x1_x2_x3_y4_y5_y6_y7_y0_y1_y2_y3_ab)
12790
12791@@ -780,6 +783,7 @@ __camellia_enc_blk16:
12792 %xmm8, %xmm9, %xmm10, %xmm11, %xmm12, %xmm13, %xmm14,
12793 %xmm15, (key_table)(CTX, %r8, 8), (%rax), 1 * 16(%rax));
12794
12795+ pax_force_retaddr
12796 ret;
12797
12798 .align 8
12799@@ -865,6 +869,7 @@ __camellia_dec_blk16:
12800 %xmm8, %xmm9, %xmm10, %xmm11, %xmm12, %xmm13, %xmm14,
12801 %xmm15, (key_table)(CTX), (%rax), 1 * 16(%rax));
12802
12803+ pax_force_retaddr
12804 ret;
12805
12806 .align 8
12807@@ -904,6 +909,7 @@ ENTRY(camellia_ecb_enc_16way)
12808 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
12809 %xmm8, %rsi);
12810
12811+ pax_force_retaddr
12812 ret;
12813 ENDPROC(camellia_ecb_enc_16way)
12814
12815@@ -932,6 +938,7 @@ ENTRY(camellia_ecb_dec_16way)
12816 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
12817 %xmm8, %rsi);
12818
12819+ pax_force_retaddr
12820 ret;
12821 ENDPROC(camellia_ecb_dec_16way)
12822
12823@@ -981,6 +988,7 @@ ENTRY(camellia_cbc_dec_16way)
12824 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
12825 %xmm8, %rsi);
12826
12827+ pax_force_retaddr
12828 ret;
12829 ENDPROC(camellia_cbc_dec_16way)
12830
12831@@ -1092,6 +1100,7 @@ ENTRY(camellia_ctr_16way)
12832 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
12833 %xmm8, %rsi);
12834
12835+ pax_force_retaddr
12836 ret;
12837 ENDPROC(camellia_ctr_16way)
12838
12839@@ -1234,6 +1243,7 @@ camellia_xts_crypt_16way:
12840 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
12841 %xmm8, %rsi);
12842
12843+ pax_force_retaddr
12844 ret;
12845 ENDPROC(camellia_xts_crypt_16way)
12846
12847diff --git a/arch/x86/crypto/camellia-aesni-avx2-asm_64.S b/arch/x86/crypto/camellia-aesni-avx2-asm_64.S
12848index 0e0b886..5a3123c 100644
12849--- a/arch/x86/crypto/camellia-aesni-avx2-asm_64.S
12850+++ b/arch/x86/crypto/camellia-aesni-avx2-asm_64.S
12851@@ -11,6 +11,7 @@
12852 */
12853
12854 #include <linux/linkage.h>
12855+#include <asm/alternative-asm.h>
12856
12857 #define CAMELLIA_TABLE_BYTE_LEN 272
12858
12859@@ -230,6 +231,7 @@ roundsm32_x0_x1_x2_x3_x4_x5_x6_x7_y0_y1_y2_y3_y4_y5_y6_y7_cd:
12860 roundsm32(%ymm0, %ymm1, %ymm2, %ymm3, %ymm4, %ymm5, %ymm6, %ymm7,
12861 %ymm8, %ymm9, %ymm10, %ymm11, %ymm12, %ymm13, %ymm14, %ymm15,
12862 %rcx, (%r9));
12863+ pax_force_retaddr
12864 ret;
12865 ENDPROC(roundsm32_x0_x1_x2_x3_x4_x5_x6_x7_y0_y1_y2_y3_y4_y5_y6_y7_cd)
12866
12867@@ -238,6 +240,7 @@ roundsm32_x4_x5_x6_x7_x0_x1_x2_x3_y4_y5_y6_y7_y0_y1_y2_y3_ab:
12868 roundsm32(%ymm4, %ymm5, %ymm6, %ymm7, %ymm0, %ymm1, %ymm2, %ymm3,
12869 %ymm12, %ymm13, %ymm14, %ymm15, %ymm8, %ymm9, %ymm10, %ymm11,
12870 %rax, (%r9));
12871+ pax_force_retaddr
12872 ret;
12873 ENDPROC(roundsm32_x4_x5_x6_x7_x0_x1_x2_x3_y4_y5_y6_y7_y0_y1_y2_y3_ab)
12874
12875@@ -820,6 +823,7 @@ __camellia_enc_blk32:
12876 %ymm8, %ymm9, %ymm10, %ymm11, %ymm12, %ymm13, %ymm14,
12877 %ymm15, (key_table)(CTX, %r8, 8), (%rax), 1 * 32(%rax));
12878
12879+ pax_force_retaddr
12880 ret;
12881
12882 .align 8
12883@@ -905,6 +909,7 @@ __camellia_dec_blk32:
12884 %ymm8, %ymm9, %ymm10, %ymm11, %ymm12, %ymm13, %ymm14,
12885 %ymm15, (key_table)(CTX), (%rax), 1 * 32(%rax));
12886
12887+ pax_force_retaddr
12888 ret;
12889
12890 .align 8
12891@@ -948,6 +953,7 @@ ENTRY(camellia_ecb_enc_32way)
12892
12893 vzeroupper;
12894
12895+ pax_force_retaddr
12896 ret;
12897 ENDPROC(camellia_ecb_enc_32way)
12898
12899@@ -980,6 +986,7 @@ ENTRY(camellia_ecb_dec_32way)
12900
12901 vzeroupper;
12902
12903+ pax_force_retaddr
12904 ret;
12905 ENDPROC(camellia_ecb_dec_32way)
12906
12907@@ -1046,6 +1053,7 @@ ENTRY(camellia_cbc_dec_32way)
12908
12909 vzeroupper;
12910
12911+ pax_force_retaddr
12912 ret;
12913 ENDPROC(camellia_cbc_dec_32way)
12914
12915@@ -1184,6 +1192,7 @@ ENTRY(camellia_ctr_32way)
12916
12917 vzeroupper;
12918
12919+ pax_force_retaddr
12920 ret;
12921 ENDPROC(camellia_ctr_32way)
12922
12923@@ -1349,6 +1358,7 @@ camellia_xts_crypt_32way:
12924
12925 vzeroupper;
12926
12927+ pax_force_retaddr
12928 ret;
12929 ENDPROC(camellia_xts_crypt_32way)
12930
12931diff --git a/arch/x86/crypto/camellia-x86_64-asm_64.S b/arch/x86/crypto/camellia-x86_64-asm_64.S
12932index 310319c..db3d7b5 100644
12933--- a/arch/x86/crypto/camellia-x86_64-asm_64.S
12934+++ b/arch/x86/crypto/camellia-x86_64-asm_64.S
12935@@ -21,6 +21,7 @@
12936 */
12937
12938 #include <linux/linkage.h>
12939+#include <asm/alternative-asm.h>
12940
12941 .file "camellia-x86_64-asm_64.S"
12942 .text
12943@@ -228,12 +229,14 @@ ENTRY(__camellia_enc_blk)
12944 enc_outunpack(mov, RT1);
12945
12946 movq RRBP, %rbp;
12947+ pax_force_retaddr
12948 ret;
12949
12950 .L__enc_xor:
12951 enc_outunpack(xor, RT1);
12952
12953 movq RRBP, %rbp;
12954+ pax_force_retaddr
12955 ret;
12956 ENDPROC(__camellia_enc_blk)
12957
12958@@ -272,6 +275,7 @@ ENTRY(camellia_dec_blk)
12959 dec_outunpack();
12960
12961 movq RRBP, %rbp;
12962+ pax_force_retaddr
12963 ret;
12964 ENDPROC(camellia_dec_blk)
12965
12966@@ -463,6 +467,7 @@ ENTRY(__camellia_enc_blk_2way)
12967
12968 movq RRBP, %rbp;
12969 popq %rbx;
12970+ pax_force_retaddr
12971 ret;
12972
12973 .L__enc2_xor:
12974@@ -470,6 +475,7 @@ ENTRY(__camellia_enc_blk_2way)
12975
12976 movq RRBP, %rbp;
12977 popq %rbx;
12978+ pax_force_retaddr
12979 ret;
12980 ENDPROC(__camellia_enc_blk_2way)
12981
12982@@ -510,5 +516,6 @@ ENTRY(camellia_dec_blk_2way)
12983
12984 movq RRBP, %rbp;
12985 movq RXOR, %rbx;
12986+ pax_force_retaddr
12987 ret;
12988 ENDPROC(camellia_dec_blk_2way)
12989diff --git a/arch/x86/crypto/cast5-avx-x86_64-asm_64.S b/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
12990index c35fd5d..2d8c7db 100644
12991--- a/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
12992+++ b/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
12993@@ -24,6 +24,7 @@
12994 */
12995
12996 #include <linux/linkage.h>
12997+#include <asm/alternative-asm.h>
12998
12999 .file "cast5-avx-x86_64-asm_64.S"
13000
13001@@ -281,6 +282,7 @@ __cast5_enc_blk16:
13002 outunpack_blocks(RR3, RL3, RTMP, RX, RKM);
13003 outunpack_blocks(RR4, RL4, RTMP, RX, RKM);
13004
13005+ pax_force_retaddr
13006 ret;
13007 ENDPROC(__cast5_enc_blk16)
13008
13009@@ -352,6 +354,7 @@ __cast5_dec_blk16:
13010 outunpack_blocks(RR3, RL3, RTMP, RX, RKM);
13011 outunpack_blocks(RR4, RL4, RTMP, RX, RKM);
13012
13013+ pax_force_retaddr
13014 ret;
13015
13016 .L__skip_dec:
13017@@ -388,6 +391,7 @@ ENTRY(cast5_ecb_enc_16way)
13018 vmovdqu RR4, (6*4*4)(%r11);
13019 vmovdqu RL4, (7*4*4)(%r11);
13020
13021+ pax_force_retaddr
13022 ret;
13023 ENDPROC(cast5_ecb_enc_16way)
13024
13025@@ -420,6 +424,7 @@ ENTRY(cast5_ecb_dec_16way)
13026 vmovdqu RR4, (6*4*4)(%r11);
13027 vmovdqu RL4, (7*4*4)(%r11);
13028
13029+ pax_force_retaddr
13030 ret;
13031 ENDPROC(cast5_ecb_dec_16way)
13032
13033@@ -430,10 +435,10 @@ ENTRY(cast5_cbc_dec_16way)
13034 * %rdx: src
13035 */
13036
13037- pushq %r12;
13038+ pushq %r14;
13039
13040 movq %rsi, %r11;
13041- movq %rdx, %r12;
13042+ movq %rdx, %r14;
13043
13044 vmovdqu (0*16)(%rdx), RL1;
13045 vmovdqu (1*16)(%rdx), RR1;
13046@@ -447,16 +452,16 @@ ENTRY(cast5_cbc_dec_16way)
13047 call __cast5_dec_blk16;
13048
13049 /* xor with src */
13050- vmovq (%r12), RX;
13051+ vmovq (%r14), RX;
13052 vpshufd $0x4f, RX, RX;
13053 vpxor RX, RR1, RR1;
13054- vpxor 0*16+8(%r12), RL1, RL1;
13055- vpxor 1*16+8(%r12), RR2, RR2;
13056- vpxor 2*16+8(%r12), RL2, RL2;
13057- vpxor 3*16+8(%r12), RR3, RR3;
13058- vpxor 4*16+8(%r12), RL3, RL3;
13059- vpxor 5*16+8(%r12), RR4, RR4;
13060- vpxor 6*16+8(%r12), RL4, RL4;
13061+ vpxor 0*16+8(%r14), RL1, RL1;
13062+ vpxor 1*16+8(%r14), RR2, RR2;
13063+ vpxor 2*16+8(%r14), RL2, RL2;
13064+ vpxor 3*16+8(%r14), RR3, RR3;
13065+ vpxor 4*16+8(%r14), RL3, RL3;
13066+ vpxor 5*16+8(%r14), RR4, RR4;
13067+ vpxor 6*16+8(%r14), RL4, RL4;
13068
13069 vmovdqu RR1, (0*16)(%r11);
13070 vmovdqu RL1, (1*16)(%r11);
13071@@ -467,8 +472,9 @@ ENTRY(cast5_cbc_dec_16way)
13072 vmovdqu RR4, (6*16)(%r11);
13073 vmovdqu RL4, (7*16)(%r11);
13074
13075- popq %r12;
13076+ popq %r14;
13077
13078+ pax_force_retaddr
13079 ret;
13080 ENDPROC(cast5_cbc_dec_16way)
13081
13082@@ -480,10 +486,10 @@ ENTRY(cast5_ctr_16way)
13083 * %rcx: iv (big endian, 64bit)
13084 */
13085
13086- pushq %r12;
13087+ pushq %r14;
13088
13089 movq %rsi, %r11;
13090- movq %rdx, %r12;
13091+ movq %rdx, %r14;
13092
13093 vpcmpeqd RTMP, RTMP, RTMP;
13094 vpsrldq $8, RTMP, RTMP; /* low: -1, high: 0 */
13095@@ -523,14 +529,14 @@ ENTRY(cast5_ctr_16way)
13096 call __cast5_enc_blk16;
13097
13098 /* dst = src ^ iv */
13099- vpxor (0*16)(%r12), RR1, RR1;
13100- vpxor (1*16)(%r12), RL1, RL1;
13101- vpxor (2*16)(%r12), RR2, RR2;
13102- vpxor (3*16)(%r12), RL2, RL2;
13103- vpxor (4*16)(%r12), RR3, RR3;
13104- vpxor (5*16)(%r12), RL3, RL3;
13105- vpxor (6*16)(%r12), RR4, RR4;
13106- vpxor (7*16)(%r12), RL4, RL4;
13107+ vpxor (0*16)(%r14), RR1, RR1;
13108+ vpxor (1*16)(%r14), RL1, RL1;
13109+ vpxor (2*16)(%r14), RR2, RR2;
13110+ vpxor (3*16)(%r14), RL2, RL2;
13111+ vpxor (4*16)(%r14), RR3, RR3;
13112+ vpxor (5*16)(%r14), RL3, RL3;
13113+ vpxor (6*16)(%r14), RR4, RR4;
13114+ vpxor (7*16)(%r14), RL4, RL4;
13115 vmovdqu RR1, (0*16)(%r11);
13116 vmovdqu RL1, (1*16)(%r11);
13117 vmovdqu RR2, (2*16)(%r11);
13118@@ -540,7 +546,8 @@ ENTRY(cast5_ctr_16way)
13119 vmovdqu RR4, (6*16)(%r11);
13120 vmovdqu RL4, (7*16)(%r11);
13121
13122- popq %r12;
13123+ popq %r14;
13124
13125+ pax_force_retaddr
13126 ret;
13127 ENDPROC(cast5_ctr_16way)
13128diff --git a/arch/x86/crypto/cast6-avx-x86_64-asm_64.S b/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
13129index e3531f8..e123f35 100644
13130--- a/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
13131+++ b/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
13132@@ -24,6 +24,7 @@
13133 */
13134
13135 #include <linux/linkage.h>
13136+#include <asm/alternative-asm.h>
13137 #include "glue_helper-asm-avx.S"
13138
13139 .file "cast6-avx-x86_64-asm_64.S"
13140@@ -295,6 +296,7 @@ __cast6_enc_blk8:
13141 outunpack_blocks(RA1, RB1, RC1, RD1, RTMP, RX, RKRF, RKM);
13142 outunpack_blocks(RA2, RB2, RC2, RD2, RTMP, RX, RKRF, RKM);
13143
13144+ pax_force_retaddr
13145 ret;
13146 ENDPROC(__cast6_enc_blk8)
13147
13148@@ -340,6 +342,7 @@ __cast6_dec_blk8:
13149 outunpack_blocks(RA1, RB1, RC1, RD1, RTMP, RX, RKRF, RKM);
13150 outunpack_blocks(RA2, RB2, RC2, RD2, RTMP, RX, RKRF, RKM);
13151
13152+ pax_force_retaddr
13153 ret;
13154 ENDPROC(__cast6_dec_blk8)
13155
13156@@ -358,6 +361,7 @@ ENTRY(cast6_ecb_enc_8way)
13157
13158 store_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13159
13160+ pax_force_retaddr
13161 ret;
13162 ENDPROC(cast6_ecb_enc_8way)
13163
13164@@ -376,6 +380,7 @@ ENTRY(cast6_ecb_dec_8way)
13165
13166 store_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13167
13168+ pax_force_retaddr
13169 ret;
13170 ENDPROC(cast6_ecb_dec_8way)
13171
13172@@ -386,19 +391,20 @@ ENTRY(cast6_cbc_dec_8way)
13173 * %rdx: src
13174 */
13175
13176- pushq %r12;
13177+ pushq %r14;
13178
13179 movq %rsi, %r11;
13180- movq %rdx, %r12;
13181+ movq %rdx, %r14;
13182
13183 load_8way(%rdx, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13184
13185 call __cast6_dec_blk8;
13186
13187- store_cbc_8way(%r12, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13188+ store_cbc_8way(%r14, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13189
13190- popq %r12;
13191+ popq %r14;
13192
13193+ pax_force_retaddr
13194 ret;
13195 ENDPROC(cast6_cbc_dec_8way)
13196
13197@@ -410,20 +416,21 @@ ENTRY(cast6_ctr_8way)
13198 * %rcx: iv (little endian, 128bit)
13199 */
13200
13201- pushq %r12;
13202+ pushq %r14;
13203
13204 movq %rsi, %r11;
13205- movq %rdx, %r12;
13206+ movq %rdx, %r14;
13207
13208 load_ctr_8way(%rcx, .Lbswap128_mask, RA1, RB1, RC1, RD1, RA2, RB2, RC2,
13209 RD2, RX, RKR, RKM);
13210
13211 call __cast6_enc_blk8;
13212
13213- store_ctr_8way(%r12, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13214+ store_ctr_8way(%r14, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13215
13216- popq %r12;
13217+ popq %r14;
13218
13219+ pax_force_retaddr
13220 ret;
13221 ENDPROC(cast6_ctr_8way)
13222
13223@@ -446,6 +453,7 @@ ENTRY(cast6_xts_enc_8way)
13224 /* dst <= regs xor IVs(in dst) */
13225 store_xts_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13226
13227+ pax_force_retaddr
13228 ret;
13229 ENDPROC(cast6_xts_enc_8way)
13230
13231@@ -468,5 +476,6 @@ ENTRY(cast6_xts_dec_8way)
13232 /* dst <= regs xor IVs(in dst) */
13233 store_xts_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13234
13235+ pax_force_retaddr
13236 ret;
13237 ENDPROC(cast6_xts_dec_8way)
13238diff --git a/arch/x86/crypto/crc32c-pcl-intel-asm_64.S b/arch/x86/crypto/crc32c-pcl-intel-asm_64.S
13239index dbc4339..de6e120 100644
13240--- a/arch/x86/crypto/crc32c-pcl-intel-asm_64.S
13241+++ b/arch/x86/crypto/crc32c-pcl-intel-asm_64.S
13242@@ -45,6 +45,7 @@
13243
13244 #include <asm/inst.h>
13245 #include <linux/linkage.h>
13246+#include <asm/alternative-asm.h>
13247
13248 ## ISCSI CRC 32 Implementation with crc32 and pclmulqdq Instruction
13249
13250@@ -312,6 +313,7 @@ do_return:
13251 popq %rsi
13252 popq %rdi
13253 popq %rbx
13254+ pax_force_retaddr
13255 ret
13256
13257 ################################################################
13258diff --git a/arch/x86/crypto/ghash-clmulni-intel_asm.S b/arch/x86/crypto/ghash-clmulni-intel_asm.S
13259index 586f41a..d02851e 100644
13260--- a/arch/x86/crypto/ghash-clmulni-intel_asm.S
13261+++ b/arch/x86/crypto/ghash-clmulni-intel_asm.S
13262@@ -18,6 +18,7 @@
13263
13264 #include <linux/linkage.h>
13265 #include <asm/inst.h>
13266+#include <asm/alternative-asm.h>
13267
13268 .data
13269
13270@@ -93,6 +94,7 @@ __clmul_gf128mul_ble:
13271 psrlq $1, T2
13272 pxor T2, T1
13273 pxor T1, DATA
13274+ pax_force_retaddr
13275 ret
13276 ENDPROC(__clmul_gf128mul_ble)
13277
13278@@ -105,6 +107,7 @@ ENTRY(clmul_ghash_mul)
13279 call __clmul_gf128mul_ble
13280 PSHUFB_XMM BSWAP DATA
13281 movups DATA, (%rdi)
13282+ pax_force_retaddr
13283 ret
13284 ENDPROC(clmul_ghash_mul)
13285
13286@@ -132,6 +135,7 @@ ENTRY(clmul_ghash_update)
13287 PSHUFB_XMM BSWAP DATA
13288 movups DATA, (%rdi)
13289 .Lupdate_just_ret:
13290+ pax_force_retaddr
13291 ret
13292 ENDPROC(clmul_ghash_update)
13293
13294@@ -157,5 +161,6 @@ ENTRY(clmul_ghash_setkey)
13295 pand .Lpoly, %xmm1
13296 pxor %xmm1, %xmm0
13297 movups %xmm0, (%rdi)
13298+ pax_force_retaddr
13299 ret
13300 ENDPROC(clmul_ghash_setkey)
13301diff --git a/arch/x86/crypto/salsa20-x86_64-asm_64.S b/arch/x86/crypto/salsa20-x86_64-asm_64.S
13302index 9279e0b..c4b3d2c 100644
13303--- a/arch/x86/crypto/salsa20-x86_64-asm_64.S
13304+++ b/arch/x86/crypto/salsa20-x86_64-asm_64.S
13305@@ -1,4 +1,5 @@
13306 #include <linux/linkage.h>
13307+#include <asm/alternative-asm.h>
13308
13309 # enter salsa20_encrypt_bytes
13310 ENTRY(salsa20_encrypt_bytes)
13311@@ -789,6 +790,7 @@ ENTRY(salsa20_encrypt_bytes)
13312 add %r11,%rsp
13313 mov %rdi,%rax
13314 mov %rsi,%rdx
13315+ pax_force_retaddr
13316 ret
13317 # bytesatleast65:
13318 ._bytesatleast65:
13319@@ -889,6 +891,7 @@ ENTRY(salsa20_keysetup)
13320 add %r11,%rsp
13321 mov %rdi,%rax
13322 mov %rsi,%rdx
13323+ pax_force_retaddr
13324 ret
13325 ENDPROC(salsa20_keysetup)
13326
13327@@ -914,5 +917,6 @@ ENTRY(salsa20_ivsetup)
13328 add %r11,%rsp
13329 mov %rdi,%rax
13330 mov %rsi,%rdx
13331+ pax_force_retaddr
13332 ret
13333 ENDPROC(salsa20_ivsetup)
13334diff --git a/arch/x86/crypto/serpent-avx-x86_64-asm_64.S b/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
13335index 2f202f4..d9164d6 100644
13336--- a/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
13337+++ b/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
13338@@ -24,6 +24,7 @@
13339 */
13340
13341 #include <linux/linkage.h>
13342+#include <asm/alternative-asm.h>
13343 #include "glue_helper-asm-avx.S"
13344
13345 .file "serpent-avx-x86_64-asm_64.S"
13346@@ -618,6 +619,7 @@ __serpent_enc_blk8_avx:
13347 write_blocks(RA1, RB1, RC1, RD1, RK0, RK1, RK2);
13348 write_blocks(RA2, RB2, RC2, RD2, RK0, RK1, RK2);
13349
13350+ pax_force_retaddr
13351 ret;
13352 ENDPROC(__serpent_enc_blk8_avx)
13353
13354@@ -672,6 +674,7 @@ __serpent_dec_blk8_avx:
13355 write_blocks(RC1, RD1, RB1, RE1, RK0, RK1, RK2);
13356 write_blocks(RC2, RD2, RB2, RE2, RK0, RK1, RK2);
13357
13358+ pax_force_retaddr
13359 ret;
13360 ENDPROC(__serpent_dec_blk8_avx)
13361
13362@@ -688,6 +691,7 @@ ENTRY(serpent_ecb_enc_8way_avx)
13363
13364 store_8way(%rsi, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13365
13366+ pax_force_retaddr
13367 ret;
13368 ENDPROC(serpent_ecb_enc_8way_avx)
13369
13370@@ -704,6 +708,7 @@ ENTRY(serpent_ecb_dec_8way_avx)
13371
13372 store_8way(%rsi, RC1, RD1, RB1, RE1, RC2, RD2, RB2, RE2);
13373
13374+ pax_force_retaddr
13375 ret;
13376 ENDPROC(serpent_ecb_dec_8way_avx)
13377
13378@@ -720,6 +725,7 @@ ENTRY(serpent_cbc_dec_8way_avx)
13379
13380 store_cbc_8way(%rdx, %rsi, RC1, RD1, RB1, RE1, RC2, RD2, RB2, RE2);
13381
13382+ pax_force_retaddr
13383 ret;
13384 ENDPROC(serpent_cbc_dec_8way_avx)
13385
13386@@ -738,6 +744,7 @@ ENTRY(serpent_ctr_8way_avx)
13387
13388 store_ctr_8way(%rdx, %rsi, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13389
13390+ pax_force_retaddr
13391 ret;
13392 ENDPROC(serpent_ctr_8way_avx)
13393
13394@@ -758,6 +765,7 @@ ENTRY(serpent_xts_enc_8way_avx)
13395 /* dst <= regs xor IVs(in dst) */
13396 store_xts_8way(%rsi, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13397
13398+ pax_force_retaddr
13399 ret;
13400 ENDPROC(serpent_xts_enc_8way_avx)
13401
13402@@ -778,5 +786,6 @@ ENTRY(serpent_xts_dec_8way_avx)
13403 /* dst <= regs xor IVs(in dst) */
13404 store_xts_8way(%rsi, RC1, RD1, RB1, RE1, RC2, RD2, RB2, RE2);
13405
13406+ pax_force_retaddr
13407 ret;
13408 ENDPROC(serpent_xts_dec_8way_avx)
13409diff --git a/arch/x86/crypto/serpent-avx2-asm_64.S b/arch/x86/crypto/serpent-avx2-asm_64.S
13410index b222085..abd483c 100644
13411--- a/arch/x86/crypto/serpent-avx2-asm_64.S
13412+++ b/arch/x86/crypto/serpent-avx2-asm_64.S
13413@@ -15,6 +15,7 @@
13414 */
13415
13416 #include <linux/linkage.h>
13417+#include <asm/alternative-asm.h>
13418 #include "glue_helper-asm-avx2.S"
13419
13420 .file "serpent-avx2-asm_64.S"
13421@@ -610,6 +611,7 @@ __serpent_enc_blk16:
13422 write_blocks(RA1, RB1, RC1, RD1, RK0, RK1, RK2);
13423 write_blocks(RA2, RB2, RC2, RD2, RK0, RK1, RK2);
13424
13425+ pax_force_retaddr
13426 ret;
13427 ENDPROC(__serpent_enc_blk16)
13428
13429@@ -664,6 +666,7 @@ __serpent_dec_blk16:
13430 write_blocks(RC1, RD1, RB1, RE1, RK0, RK1, RK2);
13431 write_blocks(RC2, RD2, RB2, RE2, RK0, RK1, RK2);
13432
13433+ pax_force_retaddr
13434 ret;
13435 ENDPROC(__serpent_dec_blk16)
13436
13437@@ -684,6 +687,7 @@ ENTRY(serpent_ecb_enc_16way)
13438
13439 vzeroupper;
13440
13441+ pax_force_retaddr
13442 ret;
13443 ENDPROC(serpent_ecb_enc_16way)
13444
13445@@ -704,6 +708,7 @@ ENTRY(serpent_ecb_dec_16way)
13446
13447 vzeroupper;
13448
13449+ pax_force_retaddr
13450 ret;
13451 ENDPROC(serpent_ecb_dec_16way)
13452
13453@@ -725,6 +730,7 @@ ENTRY(serpent_cbc_dec_16way)
13454
13455 vzeroupper;
13456
13457+ pax_force_retaddr
13458 ret;
13459 ENDPROC(serpent_cbc_dec_16way)
13460
13461@@ -748,6 +754,7 @@ ENTRY(serpent_ctr_16way)
13462
13463 vzeroupper;
13464
13465+ pax_force_retaddr
13466 ret;
13467 ENDPROC(serpent_ctr_16way)
13468
13469@@ -772,6 +779,7 @@ ENTRY(serpent_xts_enc_16way)
13470
13471 vzeroupper;
13472
13473+ pax_force_retaddr
13474 ret;
13475 ENDPROC(serpent_xts_enc_16way)
13476
13477@@ -796,5 +804,6 @@ ENTRY(serpent_xts_dec_16way)
13478
13479 vzeroupper;
13480
13481+ pax_force_retaddr
13482 ret;
13483 ENDPROC(serpent_xts_dec_16way)
13484diff --git a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
13485index acc066c..1559cc4 100644
13486--- a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
13487+++ b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
13488@@ -25,6 +25,7 @@
13489 */
13490
13491 #include <linux/linkage.h>
13492+#include <asm/alternative-asm.h>
13493
13494 .file "serpent-sse2-x86_64-asm_64.S"
13495 .text
13496@@ -690,12 +691,14 @@ ENTRY(__serpent_enc_blk_8way)
13497 write_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
13498 write_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
13499
13500+ pax_force_retaddr
13501 ret;
13502
13503 .L__enc_xor8:
13504 xor_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
13505 xor_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
13506
13507+ pax_force_retaddr
13508 ret;
13509 ENDPROC(__serpent_enc_blk_8way)
13510
13511@@ -750,5 +753,6 @@ ENTRY(serpent_dec_blk_8way)
13512 write_blocks(%rsi, RC1, RD1, RB1, RE1, RK0, RK1, RK2);
13513 write_blocks(%rax, RC2, RD2, RB2, RE2, RK0, RK1, RK2);
13514
13515+ pax_force_retaddr
13516 ret;
13517 ENDPROC(serpent_dec_blk_8way)
13518diff --git a/arch/x86/crypto/sha1_ssse3_asm.S b/arch/x86/crypto/sha1_ssse3_asm.S
13519index a410950..9dfe7ad 100644
13520--- a/arch/x86/crypto/sha1_ssse3_asm.S
13521+++ b/arch/x86/crypto/sha1_ssse3_asm.S
13522@@ -29,6 +29,7 @@
13523 */
13524
13525 #include <linux/linkage.h>
13526+#include <asm/alternative-asm.h>
13527
13528 #define CTX %rdi // arg1
13529 #define BUF %rsi // arg2
13530@@ -75,9 +76,9 @@
13531
13532 push %rbx
13533 push %rbp
13534- push %r12
13535+ push %r14
13536
13537- mov %rsp, %r12
13538+ mov %rsp, %r14
13539 sub $64, %rsp # allocate workspace
13540 and $~15, %rsp # align stack
13541
13542@@ -99,11 +100,12 @@
13543 xor %rax, %rax
13544 rep stosq
13545
13546- mov %r12, %rsp # deallocate workspace
13547+ mov %r14, %rsp # deallocate workspace
13548
13549- pop %r12
13550+ pop %r14
13551 pop %rbp
13552 pop %rbx
13553+ pax_force_retaddr
13554 ret
13555
13556 ENDPROC(\name)
13557diff --git a/arch/x86/crypto/sha256-avx-asm.S b/arch/x86/crypto/sha256-avx-asm.S
13558index 642f156..51a513c 100644
13559--- a/arch/x86/crypto/sha256-avx-asm.S
13560+++ b/arch/x86/crypto/sha256-avx-asm.S
13561@@ -49,6 +49,7 @@
13562
13563 #ifdef CONFIG_AS_AVX
13564 #include <linux/linkage.h>
13565+#include <asm/alternative-asm.h>
13566
13567 ## assume buffers not aligned
13568 #define VMOVDQ vmovdqu
13569@@ -460,6 +461,7 @@ done_hash:
13570 popq %r13
13571 popq %rbp
13572 popq %rbx
13573+ pax_force_retaddr
13574 ret
13575 ENDPROC(sha256_transform_avx)
13576
13577diff --git a/arch/x86/crypto/sha256-avx2-asm.S b/arch/x86/crypto/sha256-avx2-asm.S
13578index 9e86944..3795e6a 100644
13579--- a/arch/x86/crypto/sha256-avx2-asm.S
13580+++ b/arch/x86/crypto/sha256-avx2-asm.S
13581@@ -50,6 +50,7 @@
13582
13583 #ifdef CONFIG_AS_AVX2
13584 #include <linux/linkage.h>
13585+#include <asm/alternative-asm.h>
13586
13587 ## assume buffers not aligned
13588 #define VMOVDQ vmovdqu
13589@@ -720,6 +721,7 @@ done_hash:
13590 popq %r12
13591 popq %rbp
13592 popq %rbx
13593+ pax_force_retaddr
13594 ret
13595 ENDPROC(sha256_transform_rorx)
13596
13597diff --git a/arch/x86/crypto/sha256-ssse3-asm.S b/arch/x86/crypto/sha256-ssse3-asm.S
13598index f833b74..8c62a9e 100644
13599--- a/arch/x86/crypto/sha256-ssse3-asm.S
13600+++ b/arch/x86/crypto/sha256-ssse3-asm.S
13601@@ -47,6 +47,7 @@
13602 ########################################################################
13603
13604 #include <linux/linkage.h>
13605+#include <asm/alternative-asm.h>
13606
13607 ## assume buffers not aligned
13608 #define MOVDQ movdqu
13609@@ -471,6 +472,7 @@ done_hash:
13610 popq %rbp
13611 popq %rbx
13612
13613+ pax_force_retaddr
13614 ret
13615 ENDPROC(sha256_transform_ssse3)
13616
13617diff --git a/arch/x86/crypto/sha512-avx-asm.S b/arch/x86/crypto/sha512-avx-asm.S
13618index 974dde9..a823ff9 100644
13619--- a/arch/x86/crypto/sha512-avx-asm.S
13620+++ b/arch/x86/crypto/sha512-avx-asm.S
13621@@ -49,6 +49,7 @@
13622
13623 #ifdef CONFIG_AS_AVX
13624 #include <linux/linkage.h>
13625+#include <asm/alternative-asm.h>
13626
13627 .text
13628
13629@@ -364,6 +365,7 @@ updateblock:
13630 mov frame_RSPSAVE(%rsp), %rsp
13631
13632 nowork:
13633+ pax_force_retaddr
13634 ret
13635 ENDPROC(sha512_transform_avx)
13636
13637diff --git a/arch/x86/crypto/sha512-avx2-asm.S b/arch/x86/crypto/sha512-avx2-asm.S
13638index 568b961..ed20c37 100644
13639--- a/arch/x86/crypto/sha512-avx2-asm.S
13640+++ b/arch/x86/crypto/sha512-avx2-asm.S
13641@@ -51,6 +51,7 @@
13642
13643 #ifdef CONFIG_AS_AVX2
13644 #include <linux/linkage.h>
13645+#include <asm/alternative-asm.h>
13646
13647 .text
13648
13649@@ -678,6 +679,7 @@ done_hash:
13650
13651 # Restore Stack Pointer
13652 mov frame_RSPSAVE(%rsp), %rsp
13653+ pax_force_retaddr
13654 ret
13655 ENDPROC(sha512_transform_rorx)
13656
13657diff --git a/arch/x86/crypto/sha512-ssse3-asm.S b/arch/x86/crypto/sha512-ssse3-asm.S
13658index fb56855..6edd768 100644
13659--- a/arch/x86/crypto/sha512-ssse3-asm.S
13660+++ b/arch/x86/crypto/sha512-ssse3-asm.S
13661@@ -48,6 +48,7 @@
13662 ########################################################################
13663
13664 #include <linux/linkage.h>
13665+#include <asm/alternative-asm.h>
13666
13667 .text
13668
13669@@ -363,6 +364,7 @@ updateblock:
13670 mov frame_RSPSAVE(%rsp), %rsp
13671
13672 nowork:
13673+ pax_force_retaddr
13674 ret
13675 ENDPROC(sha512_transform_ssse3)
13676
13677diff --git a/arch/x86/crypto/twofish-avx-x86_64-asm_64.S b/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
13678index 0505813..b067311 100644
13679--- a/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
13680+++ b/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
13681@@ -24,6 +24,7 @@
13682 */
13683
13684 #include <linux/linkage.h>
13685+#include <asm/alternative-asm.h>
13686 #include "glue_helper-asm-avx.S"
13687
13688 .file "twofish-avx-x86_64-asm_64.S"
13689@@ -284,6 +285,7 @@ __twofish_enc_blk8:
13690 outunpack_blocks(RC1, RD1, RA1, RB1, RK1, RX0, RY0, RK2);
13691 outunpack_blocks(RC2, RD2, RA2, RB2, RK1, RX0, RY0, RK2);
13692
13693+ pax_force_retaddr
13694 ret;
13695 ENDPROC(__twofish_enc_blk8)
13696
13697@@ -324,6 +326,7 @@ __twofish_dec_blk8:
13698 outunpack_blocks(RA1, RB1, RC1, RD1, RK1, RX0, RY0, RK2);
13699 outunpack_blocks(RA2, RB2, RC2, RD2, RK1, RX0, RY0, RK2);
13700
13701+ pax_force_retaddr
13702 ret;
13703 ENDPROC(__twofish_dec_blk8)
13704
13705@@ -342,6 +345,7 @@ ENTRY(twofish_ecb_enc_8way)
13706
13707 store_8way(%r11, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
13708
13709+ pax_force_retaddr
13710 ret;
13711 ENDPROC(twofish_ecb_enc_8way)
13712
13713@@ -360,6 +364,7 @@ ENTRY(twofish_ecb_dec_8way)
13714
13715 store_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13716
13717+ pax_force_retaddr
13718 ret;
13719 ENDPROC(twofish_ecb_dec_8way)
13720
13721@@ -370,19 +375,20 @@ ENTRY(twofish_cbc_dec_8way)
13722 * %rdx: src
13723 */
13724
13725- pushq %r12;
13726+ pushq %r14;
13727
13728 movq %rsi, %r11;
13729- movq %rdx, %r12;
13730+ movq %rdx, %r14;
13731
13732 load_8way(%rdx, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
13733
13734 call __twofish_dec_blk8;
13735
13736- store_cbc_8way(%r12, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13737+ store_cbc_8way(%r14, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13738
13739- popq %r12;
13740+ popq %r14;
13741
13742+ pax_force_retaddr
13743 ret;
13744 ENDPROC(twofish_cbc_dec_8way)
13745
13746@@ -394,20 +400,21 @@ ENTRY(twofish_ctr_8way)
13747 * %rcx: iv (little endian, 128bit)
13748 */
13749
13750- pushq %r12;
13751+ pushq %r14;
13752
13753 movq %rsi, %r11;
13754- movq %rdx, %r12;
13755+ movq %rdx, %r14;
13756
13757 load_ctr_8way(%rcx, .Lbswap128_mask, RA1, RB1, RC1, RD1, RA2, RB2, RC2,
13758 RD2, RX0, RX1, RY0);
13759
13760 call __twofish_enc_blk8;
13761
13762- store_ctr_8way(%r12, %r11, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
13763+ store_ctr_8way(%r14, %r11, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
13764
13765- popq %r12;
13766+ popq %r14;
13767
13768+ pax_force_retaddr
13769 ret;
13770 ENDPROC(twofish_ctr_8way)
13771
13772@@ -430,6 +437,7 @@ ENTRY(twofish_xts_enc_8way)
13773 /* dst <= regs xor IVs(in dst) */
13774 store_xts_8way(%r11, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
13775
13776+ pax_force_retaddr
13777 ret;
13778 ENDPROC(twofish_xts_enc_8way)
13779
13780@@ -452,5 +460,6 @@ ENTRY(twofish_xts_dec_8way)
13781 /* dst <= regs xor IVs(in dst) */
13782 store_xts_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13783
13784+ pax_force_retaddr
13785 ret;
13786 ENDPROC(twofish_xts_dec_8way)
13787diff --git a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
13788index 1c3b7ce..02f578d 100644
13789--- a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
13790+++ b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
13791@@ -21,6 +21,7 @@
13792 */
13793
13794 #include <linux/linkage.h>
13795+#include <asm/alternative-asm.h>
13796
13797 .file "twofish-x86_64-asm-3way.S"
13798 .text
13799@@ -258,6 +259,7 @@ ENTRY(__twofish_enc_blk_3way)
13800 popq %r13;
13801 popq %r14;
13802 popq %r15;
13803+ pax_force_retaddr
13804 ret;
13805
13806 .L__enc_xor3:
13807@@ -269,6 +271,7 @@ ENTRY(__twofish_enc_blk_3way)
13808 popq %r13;
13809 popq %r14;
13810 popq %r15;
13811+ pax_force_retaddr
13812 ret;
13813 ENDPROC(__twofish_enc_blk_3way)
13814
13815@@ -308,5 +311,6 @@ ENTRY(twofish_dec_blk_3way)
13816 popq %r13;
13817 popq %r14;
13818 popq %r15;
13819+ pax_force_retaddr
13820 ret;
13821 ENDPROC(twofish_dec_blk_3way)
13822diff --git a/arch/x86/crypto/twofish-x86_64-asm_64.S b/arch/x86/crypto/twofish-x86_64-asm_64.S
13823index a039d21..524b8b2 100644
13824--- a/arch/x86/crypto/twofish-x86_64-asm_64.S
13825+++ b/arch/x86/crypto/twofish-x86_64-asm_64.S
13826@@ -22,6 +22,7 @@
13827
13828 #include <linux/linkage.h>
13829 #include <asm/asm-offsets.h>
13830+#include <asm/alternative-asm.h>
13831
13832 #define a_offset 0
13833 #define b_offset 4
13834@@ -265,6 +266,7 @@ ENTRY(twofish_enc_blk)
13835
13836 popq R1
13837 movq $1,%rax
13838+ pax_force_retaddr
13839 ret
13840 ENDPROC(twofish_enc_blk)
13841
13842@@ -317,5 +319,6 @@ ENTRY(twofish_dec_blk)
13843
13844 popq R1
13845 movq $1,%rax
13846+ pax_force_retaddr
13847 ret
13848 ENDPROC(twofish_dec_blk)
13849diff --git a/arch/x86/ia32/ia32_aout.c b/arch/x86/ia32/ia32_aout.c
13850index bae3aba..c1788c1 100644
13851--- a/arch/x86/ia32/ia32_aout.c
13852+++ b/arch/x86/ia32/ia32_aout.c
13853@@ -159,6 +159,8 @@ static int aout_core_dump(long signr, struct pt_regs *regs, struct file *file,
13854 unsigned long dump_start, dump_size;
13855 struct user32 dump;
13856
13857+ memset(&dump, 0, sizeof(dump));
13858+
13859 fs = get_fs();
13860 set_fs(KERNEL_DS);
13861 has_dumped = 1;
13862diff --git a/arch/x86/ia32/ia32_signal.c b/arch/x86/ia32/ia32_signal.c
13863index 665a730..8e7a67a 100644
13864--- a/arch/x86/ia32/ia32_signal.c
13865+++ b/arch/x86/ia32/ia32_signal.c
13866@@ -338,7 +338,7 @@ static void __user *get_sigframe(struct ksignal *ksig, struct pt_regs *regs,
13867 sp -= frame_size;
13868 /* Align the stack pointer according to the i386 ABI,
13869 * i.e. so that on function entry ((sp + 4) & 15) == 0. */
13870- sp = ((sp + 4) & -16ul) - 4;
13871+ sp = ((sp - 12) & -16ul) - 4;
13872 return (void __user *) sp;
13873 }
13874
13875@@ -396,7 +396,7 @@ int ia32_setup_frame(int sig, struct ksignal *ksig,
13876 * These are actually not used anymore, but left because some
13877 * gdb versions depend on them as a marker.
13878 */
13879- put_user_ex(*((u64 *)&code), (u64 __user *)frame->retcode);
13880+ put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
13881 } put_user_catch(err);
13882
13883 if (err)
13884@@ -438,7 +438,7 @@ int ia32_setup_rt_frame(int sig, struct ksignal *ksig,
13885 0xb8,
13886 __NR_ia32_rt_sigreturn,
13887 0x80cd,
13888- 0,
13889+ 0
13890 };
13891
13892 frame = get_sigframe(ksig, regs, sizeof(*frame), &fpstate);
13893@@ -461,16 +461,18 @@ int ia32_setup_rt_frame(int sig, struct ksignal *ksig,
13894
13895 if (ksig->ka.sa.sa_flags & SA_RESTORER)
13896 restorer = ksig->ka.sa.sa_restorer;
13897+ else if (current->mm->context.vdso)
13898+ /* Return stub is in 32bit vsyscall page */
13899+ restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
13900 else
13901- restorer = VDSO32_SYMBOL(current->mm->context.vdso,
13902- rt_sigreturn);
13903+ restorer = &frame->retcode;
13904 put_user_ex(ptr_to_compat(restorer), &frame->pretcode);
13905
13906 /*
13907 * Not actually used anymore, but left because some gdb
13908 * versions need it.
13909 */
13910- put_user_ex(*((u64 *)&code), (u64 __user *)frame->retcode);
13911+ put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
13912 } put_user_catch(err);
13913
13914 err |= copy_siginfo_to_user32(&frame->info, &ksig->info);
13915diff --git a/arch/x86/ia32/ia32entry.S b/arch/x86/ia32/ia32entry.S
13916index 4299eb0..c0687a7 100644
13917--- a/arch/x86/ia32/ia32entry.S
13918+++ b/arch/x86/ia32/ia32entry.S
13919@@ -15,8 +15,10 @@
13920 #include <asm/irqflags.h>
13921 #include <asm/asm.h>
13922 #include <asm/smap.h>
13923+#include <asm/pgtable.h>
13924 #include <linux/linkage.h>
13925 #include <linux/err.h>
13926+#include <asm/alternative-asm.h>
13927
13928 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
13929 #include <linux/elf-em.h>
13930@@ -62,12 +64,12 @@
13931 */
13932 .macro LOAD_ARGS32 offset, _r9=0
13933 .if \_r9
13934- movl \offset+16(%rsp),%r9d
13935+ movl \offset+R9(%rsp),%r9d
13936 .endif
13937- movl \offset+40(%rsp),%ecx
13938- movl \offset+48(%rsp),%edx
13939- movl \offset+56(%rsp),%esi
13940- movl \offset+64(%rsp),%edi
13941+ movl \offset+RCX(%rsp),%ecx
13942+ movl \offset+RDX(%rsp),%edx
13943+ movl \offset+RSI(%rsp),%esi
13944+ movl \offset+RDI(%rsp),%edi
13945 movl %eax,%eax /* zero extension */
13946 .endm
13947
13948@@ -96,6 +98,32 @@ ENTRY(native_irq_enable_sysexit)
13949 ENDPROC(native_irq_enable_sysexit)
13950 #endif
13951
13952+ .macro pax_enter_kernel_user
13953+ pax_set_fptr_mask
13954+#ifdef CONFIG_PAX_MEMORY_UDEREF
13955+ call pax_enter_kernel_user
13956+#endif
13957+ .endm
13958+
13959+ .macro pax_exit_kernel_user
13960+#ifdef CONFIG_PAX_MEMORY_UDEREF
13961+ call pax_exit_kernel_user
13962+#endif
13963+#ifdef CONFIG_PAX_RANDKSTACK
13964+ pushq %rax
13965+ pushq %r11
13966+ call pax_randomize_kstack
13967+ popq %r11
13968+ popq %rax
13969+#endif
13970+ .endm
13971+
13972+ .macro pax_erase_kstack
13973+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
13974+ call pax_erase_kstack
13975+#endif
13976+ .endm
13977+
13978 /*
13979 * 32bit SYSENTER instruction entry.
13980 *
13981@@ -122,12 +150,6 @@ ENTRY(ia32_sysenter_target)
13982 CFI_REGISTER rsp,rbp
13983 SWAPGS_UNSAFE_STACK
13984 movq PER_CPU_VAR(kernel_stack), %rsp
13985- addq $(KERNEL_STACK_OFFSET),%rsp
13986- /*
13987- * No need to follow this irqs on/off section: the syscall
13988- * disabled irqs, here we enable it straight after entry:
13989- */
13990- ENABLE_INTERRUPTS(CLBR_NONE)
13991 movl %ebp,%ebp /* zero extension */
13992 pushq_cfi $__USER32_DS
13993 /*CFI_REL_OFFSET ss,0*/
13994@@ -135,24 +157,49 @@ ENTRY(ia32_sysenter_target)
13995 CFI_REL_OFFSET rsp,0
13996 pushfq_cfi
13997 /*CFI_REL_OFFSET rflags,0*/
13998- movl TI_sysenter_return+THREAD_INFO(%rsp,3*8-KERNEL_STACK_OFFSET),%r10d
13999- CFI_REGISTER rip,r10
14000+ orl $X86_EFLAGS_IF,(%rsp)
14001+ GET_THREAD_INFO(%r11)
14002+ movl TI_sysenter_return(%r11), %r11d
14003+ CFI_REGISTER rip,r11
14004 pushq_cfi $__USER32_CS
14005 /*CFI_REL_OFFSET cs,0*/
14006 movl %eax, %eax
14007- pushq_cfi %r10
14008+ pushq_cfi %r11
14009 CFI_REL_OFFSET rip,0
14010 pushq_cfi %rax
14011 cld
14012 SAVE_ARGS 0,1,0
14013+ pax_enter_kernel_user
14014+
14015+#ifdef CONFIG_PAX_RANDKSTACK
14016+ pax_erase_kstack
14017+#endif
14018+
14019+ /*
14020+ * No need to follow this irqs on/off section: the syscall
14021+ * disabled irqs, here we enable it straight after entry:
14022+ */
14023+ ENABLE_INTERRUPTS(CLBR_NONE)
14024 /* no need to do an access_ok check here because rbp has been
14025 32bit zero extended */
14026+
14027+#ifdef CONFIG_PAX_MEMORY_UDEREF
14028+ addq pax_user_shadow_base,%rbp
14029+ ASM_PAX_OPEN_USERLAND
14030+#endif
14031+
14032 ASM_STAC
14033 1: movl (%rbp),%ebp
14034 _ASM_EXTABLE(1b,ia32_badarg)
14035 ASM_CLAC
14036- orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14037- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14038+
14039+#ifdef CONFIG_PAX_MEMORY_UDEREF
14040+ ASM_PAX_CLOSE_USERLAND
14041+#endif
14042+
14043+ GET_THREAD_INFO(%r11)
14044+ orl $TS_COMPAT,TI_status(%r11)
14045+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
14046 CFI_REMEMBER_STATE
14047 jnz sysenter_tracesys
14048 cmpq $(IA32_NR_syscalls-1),%rax
14049@@ -162,15 +209,18 @@ sysenter_do_call:
14050 sysenter_dispatch:
14051 call *ia32_sys_call_table(,%rax,8)
14052 movq %rax,RAX-ARGOFFSET(%rsp)
14053+ GET_THREAD_INFO(%r11)
14054 DISABLE_INTERRUPTS(CLBR_NONE)
14055 TRACE_IRQS_OFF
14056- testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14057+ testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
14058 jnz sysexit_audit
14059 sysexit_from_sys_call:
14060- andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14061+ pax_exit_kernel_user
14062+ pax_erase_kstack
14063+ andl $~TS_COMPAT,TI_status(%r11)
14064 /* clear IF, that popfq doesn't enable interrupts early */
14065- andl $~0x200,EFLAGS-R11(%rsp)
14066- movl RIP-R11(%rsp),%edx /* User %eip */
14067+ andl $~X86_EFLAGS_IF,EFLAGS(%rsp)
14068+ movl RIP(%rsp),%edx /* User %eip */
14069 CFI_REGISTER rip,rdx
14070 RESTORE_ARGS 0,24,0,0,0,0
14071 xorq %r8,%r8
14072@@ -193,6 +243,9 @@ sysexit_from_sys_call:
14073 movl %eax,%esi /* 2nd arg: syscall number */
14074 movl $AUDIT_ARCH_I386,%edi /* 1st arg: audit arch */
14075 call __audit_syscall_entry
14076+
14077+ pax_erase_kstack
14078+
14079 movl RAX-ARGOFFSET(%rsp),%eax /* reload syscall number */
14080 cmpq $(IA32_NR_syscalls-1),%rax
14081 ja ia32_badsys
14082@@ -204,7 +257,7 @@ sysexit_from_sys_call:
14083 .endm
14084
14085 .macro auditsys_exit exit
14086- testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14087+ testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
14088 jnz ia32_ret_from_sys_call
14089 TRACE_IRQS_ON
14090 ENABLE_INTERRUPTS(CLBR_NONE)
14091@@ -215,11 +268,12 @@ sysexit_from_sys_call:
14092 1: setbe %al /* 1 if error, 0 if not */
14093 movzbl %al,%edi /* zero-extend that into %edi */
14094 call __audit_syscall_exit
14095+ GET_THREAD_INFO(%r11)
14096 movq RAX-ARGOFFSET(%rsp),%rax /* reload syscall return value */
14097 movl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),%edi
14098 DISABLE_INTERRUPTS(CLBR_NONE)
14099 TRACE_IRQS_OFF
14100- testl %edi,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14101+ testl %edi,TI_flags(%r11)
14102 jz \exit
14103 CLEAR_RREGS -ARGOFFSET
14104 jmp int_with_check
14105@@ -237,7 +291,7 @@ sysexit_audit:
14106
14107 sysenter_tracesys:
14108 #ifdef CONFIG_AUDITSYSCALL
14109- testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14110+ testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
14111 jz sysenter_auditsys
14112 #endif
14113 SAVE_REST
14114@@ -249,6 +303,9 @@ sysenter_tracesys:
14115 RESTORE_REST
14116 cmpq $(IA32_NR_syscalls-1),%rax
14117 ja int_ret_from_sys_call /* sysenter_tracesys has set RAX(%rsp) */
14118+
14119+ pax_erase_kstack
14120+
14121 jmp sysenter_do_call
14122 CFI_ENDPROC
14123 ENDPROC(ia32_sysenter_target)
14124@@ -276,19 +333,25 @@ ENDPROC(ia32_sysenter_target)
14125 ENTRY(ia32_cstar_target)
14126 CFI_STARTPROC32 simple
14127 CFI_SIGNAL_FRAME
14128- CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
14129+ CFI_DEF_CFA rsp,0
14130 CFI_REGISTER rip,rcx
14131 /*CFI_REGISTER rflags,r11*/
14132 SWAPGS_UNSAFE_STACK
14133 movl %esp,%r8d
14134 CFI_REGISTER rsp,r8
14135 movq PER_CPU_VAR(kernel_stack),%rsp
14136+ SAVE_ARGS 8*6,0,0
14137+ pax_enter_kernel_user
14138+
14139+#ifdef CONFIG_PAX_RANDKSTACK
14140+ pax_erase_kstack
14141+#endif
14142+
14143 /*
14144 * No need to follow this irqs on/off section: the syscall
14145 * disabled irqs and here we enable it straight after entry:
14146 */
14147 ENABLE_INTERRUPTS(CLBR_NONE)
14148- SAVE_ARGS 8,0,0
14149 movl %eax,%eax /* zero extension */
14150 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
14151 movq %rcx,RIP-ARGOFFSET(%rsp)
14152@@ -304,12 +367,25 @@ ENTRY(ia32_cstar_target)
14153 /* no need to do an access_ok check here because r8 has been
14154 32bit zero extended */
14155 /* hardware stack frame is complete now */
14156+
14157+#ifdef CONFIG_PAX_MEMORY_UDEREF
14158+ ASM_PAX_OPEN_USERLAND
14159+ movq pax_user_shadow_base,%r8
14160+ addq RSP-ARGOFFSET(%rsp),%r8
14161+#endif
14162+
14163 ASM_STAC
14164 1: movl (%r8),%r9d
14165 _ASM_EXTABLE(1b,ia32_badarg)
14166 ASM_CLAC
14167- orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14168- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14169+
14170+#ifdef CONFIG_PAX_MEMORY_UDEREF
14171+ ASM_PAX_CLOSE_USERLAND
14172+#endif
14173+
14174+ GET_THREAD_INFO(%r11)
14175+ orl $TS_COMPAT,TI_status(%r11)
14176+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
14177 CFI_REMEMBER_STATE
14178 jnz cstar_tracesys
14179 cmpq $IA32_NR_syscalls-1,%rax
14180@@ -319,13 +395,16 @@ cstar_do_call:
14181 cstar_dispatch:
14182 call *ia32_sys_call_table(,%rax,8)
14183 movq %rax,RAX-ARGOFFSET(%rsp)
14184+ GET_THREAD_INFO(%r11)
14185 DISABLE_INTERRUPTS(CLBR_NONE)
14186 TRACE_IRQS_OFF
14187- testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14188+ testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
14189 jnz sysretl_audit
14190 sysretl_from_sys_call:
14191- andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14192- RESTORE_ARGS 0,-ARG_SKIP,0,0,0
14193+ pax_exit_kernel_user
14194+ pax_erase_kstack
14195+ andl $~TS_COMPAT,TI_status(%r11)
14196+ RESTORE_ARGS 0,-ORIG_RAX,0,0,0
14197 movl RIP-ARGOFFSET(%rsp),%ecx
14198 CFI_REGISTER rip,rcx
14199 movl EFLAGS-ARGOFFSET(%rsp),%r11d
14200@@ -352,7 +431,7 @@ sysretl_audit:
14201
14202 cstar_tracesys:
14203 #ifdef CONFIG_AUDITSYSCALL
14204- testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14205+ testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
14206 jz cstar_auditsys
14207 #endif
14208 xchgl %r9d,%ebp
14209@@ -366,11 +445,19 @@ cstar_tracesys:
14210 xchgl %ebp,%r9d
14211 cmpq $(IA32_NR_syscalls-1),%rax
14212 ja int_ret_from_sys_call /* cstar_tracesys has set RAX(%rsp) */
14213+
14214+ pax_erase_kstack
14215+
14216 jmp cstar_do_call
14217 END(ia32_cstar_target)
14218
14219 ia32_badarg:
14220 ASM_CLAC
14221+
14222+#ifdef CONFIG_PAX_MEMORY_UDEREF
14223+ ASM_PAX_CLOSE_USERLAND
14224+#endif
14225+
14226 movq $-EFAULT,%rax
14227 jmp ia32_sysret
14228 CFI_ENDPROC
14229@@ -407,19 +494,26 @@ ENTRY(ia32_syscall)
14230 CFI_REL_OFFSET rip,RIP-RIP
14231 PARAVIRT_ADJUST_EXCEPTION_FRAME
14232 SWAPGS
14233- /*
14234- * No need to follow this irqs on/off section: the syscall
14235- * disabled irqs and here we enable it straight after entry:
14236- */
14237- ENABLE_INTERRUPTS(CLBR_NONE)
14238 movl %eax,%eax
14239 pushq_cfi %rax
14240 cld
14241 /* note the registers are not zero extended to the sf.
14242 this could be a problem. */
14243 SAVE_ARGS 0,1,0
14244- orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14245- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14246+ pax_enter_kernel_user
14247+
14248+#ifdef CONFIG_PAX_RANDKSTACK
14249+ pax_erase_kstack
14250+#endif
14251+
14252+ /*
14253+ * No need to follow this irqs on/off section: the syscall
14254+ * disabled irqs and here we enable it straight after entry:
14255+ */
14256+ ENABLE_INTERRUPTS(CLBR_NONE)
14257+ GET_THREAD_INFO(%r11)
14258+ orl $TS_COMPAT,TI_status(%r11)
14259+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
14260 jnz ia32_tracesys
14261 cmpq $(IA32_NR_syscalls-1),%rax
14262 ja ia32_badsys
14263@@ -442,6 +536,9 @@ ia32_tracesys:
14264 RESTORE_REST
14265 cmpq $(IA32_NR_syscalls-1),%rax
14266 ja int_ret_from_sys_call /* ia32_tracesys has set RAX(%rsp) */
14267+
14268+ pax_erase_kstack
14269+
14270 jmp ia32_do_call
14271 END(ia32_syscall)
14272
14273diff --git a/arch/x86/ia32/sys_ia32.c b/arch/x86/ia32/sys_ia32.c
14274index 8e0ceec..af13504 100644
14275--- a/arch/x86/ia32/sys_ia32.c
14276+++ b/arch/x86/ia32/sys_ia32.c
14277@@ -69,8 +69,8 @@ asmlinkage long sys32_ftruncate64(unsigned int fd, unsigned long offset_low,
14278 */
14279 static int cp_stat64(struct stat64 __user *ubuf, struct kstat *stat)
14280 {
14281- typeof(ubuf->st_uid) uid = 0;
14282- typeof(ubuf->st_gid) gid = 0;
14283+ typeof(((struct stat64 *)0)->st_uid) uid = 0;
14284+ typeof(((struct stat64 *)0)->st_gid) gid = 0;
14285 SET_UID(uid, from_kuid_munged(current_user_ns(), stat->uid));
14286 SET_GID(gid, from_kgid_munged(current_user_ns(), stat->gid));
14287 if (!access_ok(VERIFY_WRITE, ubuf, sizeof(struct stat64)) ||
14288diff --git a/arch/x86/include/asm/alternative-asm.h b/arch/x86/include/asm/alternative-asm.h
14289index 372231c..51b537d 100644
14290--- a/arch/x86/include/asm/alternative-asm.h
14291+++ b/arch/x86/include/asm/alternative-asm.h
14292@@ -18,6 +18,45 @@
14293 .endm
14294 #endif
14295
14296+#ifdef KERNEXEC_PLUGIN
14297+ .macro pax_force_retaddr_bts rip=0
14298+ btsq $63,\rip(%rsp)
14299+ .endm
14300+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
14301+ .macro pax_force_retaddr rip=0, reload=0
14302+ btsq $63,\rip(%rsp)
14303+ .endm
14304+ .macro pax_force_fptr ptr
14305+ btsq $63,\ptr
14306+ .endm
14307+ .macro pax_set_fptr_mask
14308+ .endm
14309+#endif
14310+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
14311+ .macro pax_force_retaddr rip=0, reload=0
14312+ .if \reload
14313+ pax_set_fptr_mask
14314+ .endif
14315+ orq %r12,\rip(%rsp)
14316+ .endm
14317+ .macro pax_force_fptr ptr
14318+ orq %r12,\ptr
14319+ .endm
14320+ .macro pax_set_fptr_mask
14321+ movabs $0x8000000000000000,%r12
14322+ .endm
14323+#endif
14324+#else
14325+ .macro pax_force_retaddr rip=0, reload=0
14326+ .endm
14327+ .macro pax_force_fptr ptr
14328+ .endm
14329+ .macro pax_force_retaddr_bts rip=0
14330+ .endm
14331+ .macro pax_set_fptr_mask
14332+ .endm
14333+#endif
14334+
14335 .macro altinstruction_entry orig alt feature orig_len alt_len
14336 .long \orig - .
14337 .long \alt - .
14338diff --git a/arch/x86/include/asm/alternative.h b/arch/x86/include/asm/alternative.h
14339index 0a3f9c9..c9d081d 100644
14340--- a/arch/x86/include/asm/alternative.h
14341+++ b/arch/x86/include/asm/alternative.h
14342@@ -106,7 +106,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
14343 ".pushsection .discard,\"aw\",@progbits\n" \
14344 DISCARD_ENTRY(1) \
14345 ".popsection\n" \
14346- ".pushsection .altinstr_replacement, \"ax\"\n" \
14347+ ".pushsection .altinstr_replacement, \"a\"\n" \
14348 ALTINSTR_REPLACEMENT(newinstr, feature, 1) \
14349 ".popsection"
14350
14351@@ -120,7 +120,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
14352 DISCARD_ENTRY(1) \
14353 DISCARD_ENTRY(2) \
14354 ".popsection\n" \
14355- ".pushsection .altinstr_replacement, \"ax\"\n" \
14356+ ".pushsection .altinstr_replacement, \"a\"\n" \
14357 ALTINSTR_REPLACEMENT(newinstr1, feature1, 1) \
14358 ALTINSTR_REPLACEMENT(newinstr2, feature2, 2) \
14359 ".popsection"
14360diff --git a/arch/x86/include/asm/apic.h b/arch/x86/include/asm/apic.h
14361index 1d2091a..f5074c1 100644
14362--- a/arch/x86/include/asm/apic.h
14363+++ b/arch/x86/include/asm/apic.h
14364@@ -45,7 +45,7 @@ static inline void generic_apic_probe(void)
14365
14366 #ifdef CONFIG_X86_LOCAL_APIC
14367
14368-extern unsigned int apic_verbosity;
14369+extern int apic_verbosity;
14370 extern int local_apic_timer_c2_ok;
14371
14372 extern int disable_apic;
14373diff --git a/arch/x86/include/asm/apm.h b/arch/x86/include/asm/apm.h
14374index 20370c6..a2eb9b0 100644
14375--- a/arch/x86/include/asm/apm.h
14376+++ b/arch/x86/include/asm/apm.h
14377@@ -34,7 +34,7 @@ static inline void apm_bios_call_asm(u32 func, u32 ebx_in, u32 ecx_in,
14378 __asm__ __volatile__(APM_DO_ZERO_SEGS
14379 "pushl %%edi\n\t"
14380 "pushl %%ebp\n\t"
14381- "lcall *%%cs:apm_bios_entry\n\t"
14382+ "lcall *%%ss:apm_bios_entry\n\t"
14383 "setc %%al\n\t"
14384 "popl %%ebp\n\t"
14385 "popl %%edi\n\t"
14386@@ -58,7 +58,7 @@ static inline u8 apm_bios_call_simple_asm(u32 func, u32 ebx_in,
14387 __asm__ __volatile__(APM_DO_ZERO_SEGS
14388 "pushl %%edi\n\t"
14389 "pushl %%ebp\n\t"
14390- "lcall *%%cs:apm_bios_entry\n\t"
14391+ "lcall *%%ss:apm_bios_entry\n\t"
14392 "setc %%bl\n\t"
14393 "popl %%ebp\n\t"
14394 "popl %%edi\n\t"
14395diff --git a/arch/x86/include/asm/atomic.h b/arch/x86/include/asm/atomic.h
14396index 722aa3b..c392d85 100644
14397--- a/arch/x86/include/asm/atomic.h
14398+++ b/arch/x86/include/asm/atomic.h
14399@@ -22,7 +22,18 @@
14400 */
14401 static inline int atomic_read(const atomic_t *v)
14402 {
14403- return (*(volatile int *)&(v)->counter);
14404+ return (*(volatile const int *)&(v)->counter);
14405+}
14406+
14407+/**
14408+ * atomic_read_unchecked - read atomic variable
14409+ * @v: pointer of type atomic_unchecked_t
14410+ *
14411+ * Atomically reads the value of @v.
14412+ */
14413+static inline int __intentional_overflow(-1) atomic_read_unchecked(const atomic_unchecked_t *v)
14414+{
14415+ return (*(volatile const int *)&(v)->counter);
14416 }
14417
14418 /**
14419@@ -38,6 +49,18 @@ static inline void atomic_set(atomic_t *v, int i)
14420 }
14421
14422 /**
14423+ * atomic_set_unchecked - set atomic variable
14424+ * @v: pointer of type atomic_unchecked_t
14425+ * @i: required value
14426+ *
14427+ * Atomically sets the value of @v to @i.
14428+ */
14429+static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
14430+{
14431+ v->counter = i;
14432+}
14433+
14434+/**
14435 * atomic_add - add integer to atomic variable
14436 * @i: integer value to add
14437 * @v: pointer of type atomic_t
14438@@ -46,7 +69,29 @@ static inline void atomic_set(atomic_t *v, int i)
14439 */
14440 static inline void atomic_add(int i, atomic_t *v)
14441 {
14442- asm volatile(LOCK_PREFIX "addl %1,%0"
14443+ asm volatile(LOCK_PREFIX "addl %1,%0\n"
14444+
14445+#ifdef CONFIG_PAX_REFCOUNT
14446+ "jno 0f\n"
14447+ LOCK_PREFIX "subl %1,%0\n"
14448+ "int $4\n0:\n"
14449+ _ASM_EXTABLE(0b, 0b)
14450+#endif
14451+
14452+ : "+m" (v->counter)
14453+ : "ir" (i));
14454+}
14455+
14456+/**
14457+ * atomic_add_unchecked - add integer to atomic variable
14458+ * @i: integer value to add
14459+ * @v: pointer of type atomic_unchecked_t
14460+ *
14461+ * Atomically adds @i to @v.
14462+ */
14463+static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
14464+{
14465+ asm volatile(LOCK_PREFIX "addl %1,%0\n"
14466 : "+m" (v->counter)
14467 : "ir" (i));
14468 }
14469@@ -60,7 +105,29 @@ static inline void atomic_add(int i, atomic_t *v)
14470 */
14471 static inline void atomic_sub(int i, atomic_t *v)
14472 {
14473- asm volatile(LOCK_PREFIX "subl %1,%0"
14474+ asm volatile(LOCK_PREFIX "subl %1,%0\n"
14475+
14476+#ifdef CONFIG_PAX_REFCOUNT
14477+ "jno 0f\n"
14478+ LOCK_PREFIX "addl %1,%0\n"
14479+ "int $4\n0:\n"
14480+ _ASM_EXTABLE(0b, 0b)
14481+#endif
14482+
14483+ : "+m" (v->counter)
14484+ : "ir" (i));
14485+}
14486+
14487+/**
14488+ * atomic_sub_unchecked - subtract integer from atomic variable
14489+ * @i: integer value to subtract
14490+ * @v: pointer of type atomic_unchecked_t
14491+ *
14492+ * Atomically subtracts @i from @v.
14493+ */
14494+static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
14495+{
14496+ asm volatile(LOCK_PREFIX "subl %1,%0\n"
14497 : "+m" (v->counter)
14498 : "ir" (i));
14499 }
14500@@ -78,7 +145,16 @@ static inline int atomic_sub_and_test(int i, atomic_t *v)
14501 {
14502 unsigned char c;
14503
14504- asm volatile(LOCK_PREFIX "subl %2,%0; sete %1"
14505+ asm volatile(LOCK_PREFIX "subl %2,%0\n"
14506+
14507+#ifdef CONFIG_PAX_REFCOUNT
14508+ "jno 0f\n"
14509+ LOCK_PREFIX "addl %2,%0\n"
14510+ "int $4\n0:\n"
14511+ _ASM_EXTABLE(0b, 0b)
14512+#endif
14513+
14514+ "sete %1\n"
14515 : "+m" (v->counter), "=qm" (c)
14516 : "ir" (i) : "memory");
14517 return c;
14518@@ -92,7 +168,27 @@ static inline int atomic_sub_and_test(int i, atomic_t *v)
14519 */
14520 static inline void atomic_inc(atomic_t *v)
14521 {
14522- asm volatile(LOCK_PREFIX "incl %0"
14523+ asm volatile(LOCK_PREFIX "incl %0\n"
14524+
14525+#ifdef CONFIG_PAX_REFCOUNT
14526+ "jno 0f\n"
14527+ LOCK_PREFIX "decl %0\n"
14528+ "int $4\n0:\n"
14529+ _ASM_EXTABLE(0b, 0b)
14530+#endif
14531+
14532+ : "+m" (v->counter));
14533+}
14534+
14535+/**
14536+ * atomic_inc_unchecked - increment atomic variable
14537+ * @v: pointer of type atomic_unchecked_t
14538+ *
14539+ * Atomically increments @v by 1.
14540+ */
14541+static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
14542+{
14543+ asm volatile(LOCK_PREFIX "incl %0\n"
14544 : "+m" (v->counter));
14545 }
14546
14547@@ -104,7 +200,27 @@ static inline void atomic_inc(atomic_t *v)
14548 */
14549 static inline void atomic_dec(atomic_t *v)
14550 {
14551- asm volatile(LOCK_PREFIX "decl %0"
14552+ asm volatile(LOCK_PREFIX "decl %0\n"
14553+
14554+#ifdef CONFIG_PAX_REFCOUNT
14555+ "jno 0f\n"
14556+ LOCK_PREFIX "incl %0\n"
14557+ "int $4\n0:\n"
14558+ _ASM_EXTABLE(0b, 0b)
14559+#endif
14560+
14561+ : "+m" (v->counter));
14562+}
14563+
14564+/**
14565+ * atomic_dec_unchecked - decrement atomic variable
14566+ * @v: pointer of type atomic_unchecked_t
14567+ *
14568+ * Atomically decrements @v by 1.
14569+ */
14570+static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
14571+{
14572+ asm volatile(LOCK_PREFIX "decl %0\n"
14573 : "+m" (v->counter));
14574 }
14575
14576@@ -120,7 +236,16 @@ static inline int atomic_dec_and_test(atomic_t *v)
14577 {
14578 unsigned char c;
14579
14580- asm volatile(LOCK_PREFIX "decl %0; sete %1"
14581+ asm volatile(LOCK_PREFIX "decl %0\n"
14582+
14583+#ifdef CONFIG_PAX_REFCOUNT
14584+ "jno 0f\n"
14585+ LOCK_PREFIX "incl %0\n"
14586+ "int $4\n0:\n"
14587+ _ASM_EXTABLE(0b, 0b)
14588+#endif
14589+
14590+ "sete %1\n"
14591 : "+m" (v->counter), "=qm" (c)
14592 : : "memory");
14593 return c != 0;
14594@@ -138,7 +263,35 @@ static inline int atomic_inc_and_test(atomic_t *v)
14595 {
14596 unsigned char c;
14597
14598- asm volatile(LOCK_PREFIX "incl %0; sete %1"
14599+ asm volatile(LOCK_PREFIX "incl %0\n"
14600+
14601+#ifdef CONFIG_PAX_REFCOUNT
14602+ "jno 0f\n"
14603+ LOCK_PREFIX "decl %0\n"
14604+ "int $4\n0:\n"
14605+ _ASM_EXTABLE(0b, 0b)
14606+#endif
14607+
14608+ "sete %1\n"
14609+ : "+m" (v->counter), "=qm" (c)
14610+ : : "memory");
14611+ return c != 0;
14612+}
14613+
14614+/**
14615+ * atomic_inc_and_test_unchecked - increment and test
14616+ * @v: pointer of type atomic_unchecked_t
14617+ *
14618+ * Atomically increments @v by 1
14619+ * and returns true if the result is zero, or false for all
14620+ * other cases.
14621+ */
14622+static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
14623+{
14624+ unsigned char c;
14625+
14626+ asm volatile(LOCK_PREFIX "incl %0\n"
14627+ "sete %1\n"
14628 : "+m" (v->counter), "=qm" (c)
14629 : : "memory");
14630 return c != 0;
14631@@ -157,7 +310,16 @@ static inline int atomic_add_negative(int i, atomic_t *v)
14632 {
14633 unsigned char c;
14634
14635- asm volatile(LOCK_PREFIX "addl %2,%0; sets %1"
14636+ asm volatile(LOCK_PREFIX "addl %2,%0\n"
14637+
14638+#ifdef CONFIG_PAX_REFCOUNT
14639+ "jno 0f\n"
14640+ LOCK_PREFIX "subl %2,%0\n"
14641+ "int $4\n0:\n"
14642+ _ASM_EXTABLE(0b, 0b)
14643+#endif
14644+
14645+ "sets %1\n"
14646 : "+m" (v->counter), "=qm" (c)
14647 : "ir" (i) : "memory");
14648 return c;
14649@@ -172,6 +334,18 @@ static inline int atomic_add_negative(int i, atomic_t *v)
14650 */
14651 static inline int atomic_add_return(int i, atomic_t *v)
14652 {
14653+ return i + xadd_check_overflow(&v->counter, i);
14654+}
14655+
14656+/**
14657+ * atomic_add_return_unchecked - add integer and return
14658+ * @i: integer value to add
14659+ * @v: pointer of type atomic_unchecked_t
14660+ *
14661+ * Atomically adds @i to @v and returns @i + @v
14662+ */
14663+static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
14664+{
14665 return i + xadd(&v->counter, i);
14666 }
14667
14668@@ -188,9 +362,18 @@ static inline int atomic_sub_return(int i, atomic_t *v)
14669 }
14670
14671 #define atomic_inc_return(v) (atomic_add_return(1, v))
14672+static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
14673+{
14674+ return atomic_add_return_unchecked(1, v);
14675+}
14676 #define atomic_dec_return(v) (atomic_sub_return(1, v))
14677
14678-static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
14679+static inline int __intentional_overflow(-1) atomic_cmpxchg(atomic_t *v, int old, int new)
14680+{
14681+ return cmpxchg(&v->counter, old, new);
14682+}
14683+
14684+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
14685 {
14686 return cmpxchg(&v->counter, old, new);
14687 }
14688@@ -200,6 +383,11 @@ static inline int atomic_xchg(atomic_t *v, int new)
14689 return xchg(&v->counter, new);
14690 }
14691
14692+static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
14693+{
14694+ return xchg(&v->counter, new);
14695+}
14696+
14697 /**
14698 * __atomic_add_unless - add unless the number is already a given value
14699 * @v: pointer of type atomic_t
14700@@ -209,14 +397,27 @@ static inline int atomic_xchg(atomic_t *v, int new)
14701 * Atomically adds @a to @v, so long as @v was not already @u.
14702 * Returns the old value of @v.
14703 */
14704-static inline int __atomic_add_unless(atomic_t *v, int a, int u)
14705+static inline int __intentional_overflow(-1) __atomic_add_unless(atomic_t *v, int a, int u)
14706 {
14707- int c, old;
14708+ int c, old, new;
14709 c = atomic_read(v);
14710 for (;;) {
14711- if (unlikely(c == (u)))
14712+ if (unlikely(c == u))
14713 break;
14714- old = atomic_cmpxchg((v), c, c + (a));
14715+
14716+ asm volatile("addl %2,%0\n"
14717+
14718+#ifdef CONFIG_PAX_REFCOUNT
14719+ "jno 0f\n"
14720+ "subl %2,%0\n"
14721+ "int $4\n0:\n"
14722+ _ASM_EXTABLE(0b, 0b)
14723+#endif
14724+
14725+ : "=r" (new)
14726+ : "0" (c), "ir" (a));
14727+
14728+ old = atomic_cmpxchg(v, c, new);
14729 if (likely(old == c))
14730 break;
14731 c = old;
14732@@ -225,6 +426,49 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
14733 }
14734
14735 /**
14736+ * atomic_inc_not_zero_hint - increment if not null
14737+ * @v: pointer of type atomic_t
14738+ * @hint: probable value of the atomic before the increment
14739+ *
14740+ * This version of atomic_inc_not_zero() gives a hint of probable
14741+ * value of the atomic. This helps processor to not read the memory
14742+ * before doing the atomic read/modify/write cycle, lowering
14743+ * number of bus transactions on some arches.
14744+ *
14745+ * Returns: 0 if increment was not done, 1 otherwise.
14746+ */
14747+#define atomic_inc_not_zero_hint atomic_inc_not_zero_hint
14748+static inline int atomic_inc_not_zero_hint(atomic_t *v, int hint)
14749+{
14750+ int val, c = hint, new;
14751+
14752+ /* sanity test, should be removed by compiler if hint is a constant */
14753+ if (!hint)
14754+ return __atomic_add_unless(v, 1, 0);
14755+
14756+ do {
14757+ asm volatile("incl %0\n"
14758+
14759+#ifdef CONFIG_PAX_REFCOUNT
14760+ "jno 0f\n"
14761+ "decl %0\n"
14762+ "int $4\n0:\n"
14763+ _ASM_EXTABLE(0b, 0b)
14764+#endif
14765+
14766+ : "=r" (new)
14767+ : "0" (c));
14768+
14769+ val = atomic_cmpxchg(v, c, new);
14770+ if (val == c)
14771+ return 1;
14772+ c = val;
14773+ } while (c);
14774+
14775+ return 0;
14776+}
14777+
14778+/**
14779 * atomic_inc_short - increment of a short integer
14780 * @v: pointer to type int
14781 *
14782@@ -253,14 +497,37 @@ static inline void atomic_or_long(unsigned long *v1, unsigned long v2)
14783 #endif
14784
14785 /* These are x86-specific, used by some header files */
14786-#define atomic_clear_mask(mask, addr) \
14787- asm volatile(LOCK_PREFIX "andl %0,%1" \
14788- : : "r" (~(mask)), "m" (*(addr)) : "memory")
14789+static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
14790+{
14791+ asm volatile(LOCK_PREFIX "andl %1,%0"
14792+ : "+m" (v->counter)
14793+ : "r" (~(mask))
14794+ : "memory");
14795+}
14796
14797-#define atomic_set_mask(mask, addr) \
14798- asm volatile(LOCK_PREFIX "orl %0,%1" \
14799- : : "r" ((unsigned)(mask)), "m" (*(addr)) \
14800- : "memory")
14801+static inline void atomic_clear_mask_unchecked(unsigned int mask, atomic_unchecked_t *v)
14802+{
14803+ asm volatile(LOCK_PREFIX "andl %1,%0"
14804+ : "+m" (v->counter)
14805+ : "r" (~(mask))
14806+ : "memory");
14807+}
14808+
14809+static inline void atomic_set_mask(unsigned int mask, atomic_t *v)
14810+{
14811+ asm volatile(LOCK_PREFIX "orl %1,%0"
14812+ : "+m" (v->counter)
14813+ : "r" (mask)
14814+ : "memory");
14815+}
14816+
14817+static inline void atomic_set_mask_unchecked(unsigned int mask, atomic_unchecked_t *v)
14818+{
14819+ asm volatile(LOCK_PREFIX "orl %1,%0"
14820+ : "+m" (v->counter)
14821+ : "r" (mask)
14822+ : "memory");
14823+}
14824
14825 /* Atomic operations are already serializing on x86 */
14826 #define smp_mb__before_atomic_dec() barrier()
14827diff --git a/arch/x86/include/asm/atomic64_32.h b/arch/x86/include/asm/atomic64_32.h
14828index b154de7..bf18a5a 100644
14829--- a/arch/x86/include/asm/atomic64_32.h
14830+++ b/arch/x86/include/asm/atomic64_32.h
14831@@ -12,6 +12,14 @@ typedef struct {
14832 u64 __aligned(8) counter;
14833 } atomic64_t;
14834
14835+#ifdef CONFIG_PAX_REFCOUNT
14836+typedef struct {
14837+ u64 __aligned(8) counter;
14838+} atomic64_unchecked_t;
14839+#else
14840+typedef atomic64_t atomic64_unchecked_t;
14841+#endif
14842+
14843 #define ATOMIC64_INIT(val) { (val) }
14844
14845 #define __ATOMIC64_DECL(sym) void atomic64_##sym(atomic64_t *, ...)
14846@@ -37,21 +45,31 @@ typedef struct {
14847 ATOMIC64_DECL_ONE(sym##_386)
14848
14849 ATOMIC64_DECL_ONE(add_386);
14850+ATOMIC64_DECL_ONE(add_unchecked_386);
14851 ATOMIC64_DECL_ONE(sub_386);
14852+ATOMIC64_DECL_ONE(sub_unchecked_386);
14853 ATOMIC64_DECL_ONE(inc_386);
14854+ATOMIC64_DECL_ONE(inc_unchecked_386);
14855 ATOMIC64_DECL_ONE(dec_386);
14856+ATOMIC64_DECL_ONE(dec_unchecked_386);
14857 #endif
14858
14859 #define alternative_atomic64(f, out, in...) \
14860 __alternative_atomic64(f, f, ASM_OUTPUT2(out), ## in)
14861
14862 ATOMIC64_DECL(read);
14863+ATOMIC64_DECL(read_unchecked);
14864 ATOMIC64_DECL(set);
14865+ATOMIC64_DECL(set_unchecked);
14866 ATOMIC64_DECL(xchg);
14867 ATOMIC64_DECL(add_return);
14868+ATOMIC64_DECL(add_return_unchecked);
14869 ATOMIC64_DECL(sub_return);
14870+ATOMIC64_DECL(sub_return_unchecked);
14871 ATOMIC64_DECL(inc_return);
14872+ATOMIC64_DECL(inc_return_unchecked);
14873 ATOMIC64_DECL(dec_return);
14874+ATOMIC64_DECL(dec_return_unchecked);
14875 ATOMIC64_DECL(dec_if_positive);
14876 ATOMIC64_DECL(inc_not_zero);
14877 ATOMIC64_DECL(add_unless);
14878@@ -77,6 +95,21 @@ static inline long long atomic64_cmpxchg(atomic64_t *v, long long o, long long n
14879 }
14880
14881 /**
14882+ * atomic64_cmpxchg_unchecked - cmpxchg atomic64 variable
14883+ * @p: pointer to type atomic64_unchecked_t
14884+ * @o: expected value
14885+ * @n: new value
14886+ *
14887+ * Atomically sets @v to @n if it was equal to @o and returns
14888+ * the old value.
14889+ */
14890+
14891+static inline long long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long long o, long long n)
14892+{
14893+ return cmpxchg64(&v->counter, o, n);
14894+}
14895+
14896+/**
14897 * atomic64_xchg - xchg atomic64 variable
14898 * @v: pointer to type atomic64_t
14899 * @n: value to assign
14900@@ -112,6 +145,22 @@ static inline void atomic64_set(atomic64_t *v, long long i)
14901 }
14902
14903 /**
14904+ * atomic64_set_unchecked - set atomic64 variable
14905+ * @v: pointer to type atomic64_unchecked_t
14906+ * @n: value to assign
14907+ *
14908+ * Atomically sets the value of @v to @n.
14909+ */
14910+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long long i)
14911+{
14912+ unsigned high = (unsigned)(i >> 32);
14913+ unsigned low = (unsigned)i;
14914+ alternative_atomic64(set, /* no output */,
14915+ "S" (v), "b" (low), "c" (high)
14916+ : "eax", "edx", "memory");
14917+}
14918+
14919+/**
14920 * atomic64_read - read atomic64 variable
14921 * @v: pointer to type atomic64_t
14922 *
14923@@ -125,6 +174,19 @@ static inline long long atomic64_read(const atomic64_t *v)
14924 }
14925
14926 /**
14927+ * atomic64_read_unchecked - read atomic64 variable
14928+ * @v: pointer to type atomic64_unchecked_t
14929+ *
14930+ * Atomically reads the value of @v and returns it.
14931+ */
14932+static inline long long __intentional_overflow(-1) atomic64_read_unchecked(atomic64_unchecked_t *v)
14933+{
14934+ long long r;
14935+ alternative_atomic64(read, "=&A" (r), "c" (v) : "memory");
14936+ return r;
14937+ }
14938+
14939+/**
14940 * atomic64_add_return - add and return
14941 * @i: integer value to add
14942 * @v: pointer to type atomic64_t
14943@@ -139,6 +201,21 @@ static inline long long atomic64_add_return(long long i, atomic64_t *v)
14944 return i;
14945 }
14946
14947+/**
14948+ * atomic64_add_return_unchecked - add and return
14949+ * @i: integer value to add
14950+ * @v: pointer to type atomic64_unchecked_t
14951+ *
14952+ * Atomically adds @i to @v and returns @i + *@v
14953+ */
14954+static inline long long atomic64_add_return_unchecked(long long i, atomic64_unchecked_t *v)
14955+{
14956+ alternative_atomic64(add_return_unchecked,
14957+ ASM_OUTPUT2("+A" (i), "+c" (v)),
14958+ ASM_NO_INPUT_CLOBBER("memory"));
14959+ return i;
14960+}
14961+
14962 /*
14963 * Other variants with different arithmetic operators:
14964 */
14965@@ -158,6 +235,14 @@ static inline long long atomic64_inc_return(atomic64_t *v)
14966 return a;
14967 }
14968
14969+static inline long long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
14970+{
14971+ long long a;
14972+ alternative_atomic64(inc_return_unchecked, "=&A" (a),
14973+ "S" (v) : "memory", "ecx");
14974+ return a;
14975+}
14976+
14977 static inline long long atomic64_dec_return(atomic64_t *v)
14978 {
14979 long long a;
14980@@ -182,6 +267,21 @@ static inline long long atomic64_add(long long i, atomic64_t *v)
14981 }
14982
14983 /**
14984+ * atomic64_add_unchecked - add integer to atomic64 variable
14985+ * @i: integer value to add
14986+ * @v: pointer to type atomic64_unchecked_t
14987+ *
14988+ * Atomically adds @i to @v.
14989+ */
14990+static inline long long atomic64_add_unchecked(long long i, atomic64_unchecked_t *v)
14991+{
14992+ __alternative_atomic64(add_unchecked, add_return_unchecked,
14993+ ASM_OUTPUT2("+A" (i), "+c" (v)),
14994+ ASM_NO_INPUT_CLOBBER("memory"));
14995+ return i;
14996+}
14997+
14998+/**
14999 * atomic64_sub - subtract the atomic64 variable
15000 * @i: integer value to subtract
15001 * @v: pointer to type atomic64_t
15002diff --git a/arch/x86/include/asm/atomic64_64.h b/arch/x86/include/asm/atomic64_64.h
15003index 0e1cbfc..a891fc7 100644
15004--- a/arch/x86/include/asm/atomic64_64.h
15005+++ b/arch/x86/include/asm/atomic64_64.h
15006@@ -18,7 +18,19 @@
15007 */
15008 static inline long atomic64_read(const atomic64_t *v)
15009 {
15010- return (*(volatile long *)&(v)->counter);
15011+ return (*(volatile const long *)&(v)->counter);
15012+}
15013+
15014+/**
15015+ * atomic64_read_unchecked - read atomic64 variable
15016+ * @v: pointer of type atomic64_unchecked_t
15017+ *
15018+ * Atomically reads the value of @v.
15019+ * Doesn't imply a read memory barrier.
15020+ */
15021+static inline long __intentional_overflow(-1) atomic64_read_unchecked(const atomic64_unchecked_t *v)
15022+{
15023+ return (*(volatile const long *)&(v)->counter);
15024 }
15025
15026 /**
15027@@ -34,6 +46,18 @@ static inline void atomic64_set(atomic64_t *v, long i)
15028 }
15029
15030 /**
15031+ * atomic64_set_unchecked - set atomic64 variable
15032+ * @v: pointer to type atomic64_unchecked_t
15033+ * @i: required value
15034+ *
15035+ * Atomically sets the value of @v to @i.
15036+ */
15037+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
15038+{
15039+ v->counter = i;
15040+}
15041+
15042+/**
15043 * atomic64_add - add integer to atomic64 variable
15044 * @i: integer value to add
15045 * @v: pointer to type atomic64_t
15046@@ -42,6 +66,28 @@ static inline void atomic64_set(atomic64_t *v, long i)
15047 */
15048 static inline void atomic64_add(long i, atomic64_t *v)
15049 {
15050+ asm volatile(LOCK_PREFIX "addq %1,%0\n"
15051+
15052+#ifdef CONFIG_PAX_REFCOUNT
15053+ "jno 0f\n"
15054+ LOCK_PREFIX "subq %1,%0\n"
15055+ "int $4\n0:\n"
15056+ _ASM_EXTABLE(0b, 0b)
15057+#endif
15058+
15059+ : "=m" (v->counter)
15060+ : "er" (i), "m" (v->counter));
15061+}
15062+
15063+/**
15064+ * atomic64_add_unchecked - add integer to atomic64 variable
15065+ * @i: integer value to add
15066+ * @v: pointer to type atomic64_unchecked_t
15067+ *
15068+ * Atomically adds @i to @v.
15069+ */
15070+static inline void atomic64_add_unchecked(long i, atomic64_unchecked_t *v)
15071+{
15072 asm volatile(LOCK_PREFIX "addq %1,%0"
15073 : "=m" (v->counter)
15074 : "er" (i), "m" (v->counter));
15075@@ -56,7 +102,29 @@ static inline void atomic64_add(long i, atomic64_t *v)
15076 */
15077 static inline void atomic64_sub(long i, atomic64_t *v)
15078 {
15079- asm volatile(LOCK_PREFIX "subq %1,%0"
15080+ asm volatile(LOCK_PREFIX "subq %1,%0\n"
15081+
15082+#ifdef CONFIG_PAX_REFCOUNT
15083+ "jno 0f\n"
15084+ LOCK_PREFIX "addq %1,%0\n"
15085+ "int $4\n0:\n"
15086+ _ASM_EXTABLE(0b, 0b)
15087+#endif
15088+
15089+ : "=m" (v->counter)
15090+ : "er" (i), "m" (v->counter));
15091+}
15092+
15093+/**
15094+ * atomic64_sub_unchecked - subtract the atomic64 variable
15095+ * @i: integer value to subtract
15096+ * @v: pointer to type atomic64_unchecked_t
15097+ *
15098+ * Atomically subtracts @i from @v.
15099+ */
15100+static inline void atomic64_sub_unchecked(long i, atomic64_unchecked_t *v)
15101+{
15102+ asm volatile(LOCK_PREFIX "subq %1,%0\n"
15103 : "=m" (v->counter)
15104 : "er" (i), "m" (v->counter));
15105 }
15106@@ -74,7 +142,16 @@ static inline int atomic64_sub_and_test(long i, atomic64_t *v)
15107 {
15108 unsigned char c;
15109
15110- asm volatile(LOCK_PREFIX "subq %2,%0; sete %1"
15111+ asm volatile(LOCK_PREFIX "subq %2,%0\n"
15112+
15113+#ifdef CONFIG_PAX_REFCOUNT
15114+ "jno 0f\n"
15115+ LOCK_PREFIX "addq %2,%0\n"
15116+ "int $4\n0:\n"
15117+ _ASM_EXTABLE(0b, 0b)
15118+#endif
15119+
15120+ "sete %1\n"
15121 : "=m" (v->counter), "=qm" (c)
15122 : "er" (i), "m" (v->counter) : "memory");
15123 return c;
15124@@ -88,6 +165,27 @@ static inline int atomic64_sub_and_test(long i, atomic64_t *v)
15125 */
15126 static inline void atomic64_inc(atomic64_t *v)
15127 {
15128+ asm volatile(LOCK_PREFIX "incq %0\n"
15129+
15130+#ifdef CONFIG_PAX_REFCOUNT
15131+ "jno 0f\n"
15132+ LOCK_PREFIX "decq %0\n"
15133+ "int $4\n0:\n"
15134+ _ASM_EXTABLE(0b, 0b)
15135+#endif
15136+
15137+ : "=m" (v->counter)
15138+ : "m" (v->counter));
15139+}
15140+
15141+/**
15142+ * atomic64_inc_unchecked - increment atomic64 variable
15143+ * @v: pointer to type atomic64_unchecked_t
15144+ *
15145+ * Atomically increments @v by 1.
15146+ */
15147+static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
15148+{
15149 asm volatile(LOCK_PREFIX "incq %0"
15150 : "=m" (v->counter)
15151 : "m" (v->counter));
15152@@ -101,7 +199,28 @@ static inline void atomic64_inc(atomic64_t *v)
15153 */
15154 static inline void atomic64_dec(atomic64_t *v)
15155 {
15156- asm volatile(LOCK_PREFIX "decq %0"
15157+ asm volatile(LOCK_PREFIX "decq %0\n"
15158+
15159+#ifdef CONFIG_PAX_REFCOUNT
15160+ "jno 0f\n"
15161+ LOCK_PREFIX "incq %0\n"
15162+ "int $4\n0:\n"
15163+ _ASM_EXTABLE(0b, 0b)
15164+#endif
15165+
15166+ : "=m" (v->counter)
15167+ : "m" (v->counter));
15168+}
15169+
15170+/**
15171+ * atomic64_dec_unchecked - decrement atomic64 variable
15172+ * @v: pointer to type atomic64_t
15173+ *
15174+ * Atomically decrements @v by 1.
15175+ */
15176+static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
15177+{
15178+ asm volatile(LOCK_PREFIX "decq %0\n"
15179 : "=m" (v->counter)
15180 : "m" (v->counter));
15181 }
15182@@ -118,7 +237,16 @@ static inline int atomic64_dec_and_test(atomic64_t *v)
15183 {
15184 unsigned char c;
15185
15186- asm volatile(LOCK_PREFIX "decq %0; sete %1"
15187+ asm volatile(LOCK_PREFIX "decq %0\n"
15188+
15189+#ifdef CONFIG_PAX_REFCOUNT
15190+ "jno 0f\n"
15191+ LOCK_PREFIX "incq %0\n"
15192+ "int $4\n0:\n"
15193+ _ASM_EXTABLE(0b, 0b)
15194+#endif
15195+
15196+ "sete %1\n"
15197 : "=m" (v->counter), "=qm" (c)
15198 : "m" (v->counter) : "memory");
15199 return c != 0;
15200@@ -136,7 +264,16 @@ static inline int atomic64_inc_and_test(atomic64_t *v)
15201 {
15202 unsigned char c;
15203
15204- asm volatile(LOCK_PREFIX "incq %0; sete %1"
15205+ asm volatile(LOCK_PREFIX "incq %0\n"
15206+
15207+#ifdef CONFIG_PAX_REFCOUNT
15208+ "jno 0f\n"
15209+ LOCK_PREFIX "decq %0\n"
15210+ "int $4\n0:\n"
15211+ _ASM_EXTABLE(0b, 0b)
15212+#endif
15213+
15214+ "sete %1\n"
15215 : "=m" (v->counter), "=qm" (c)
15216 : "m" (v->counter) : "memory");
15217 return c != 0;
15218@@ -155,7 +292,16 @@ static inline int atomic64_add_negative(long i, atomic64_t *v)
15219 {
15220 unsigned char c;
15221
15222- asm volatile(LOCK_PREFIX "addq %2,%0; sets %1"
15223+ asm volatile(LOCK_PREFIX "addq %2,%0\n"
15224+
15225+#ifdef CONFIG_PAX_REFCOUNT
15226+ "jno 0f\n"
15227+ LOCK_PREFIX "subq %2,%0\n"
15228+ "int $4\n0:\n"
15229+ _ASM_EXTABLE(0b, 0b)
15230+#endif
15231+
15232+ "sets %1\n"
15233 : "=m" (v->counter), "=qm" (c)
15234 : "er" (i), "m" (v->counter) : "memory");
15235 return c;
15236@@ -170,6 +316,18 @@ static inline int atomic64_add_negative(long i, atomic64_t *v)
15237 */
15238 static inline long atomic64_add_return(long i, atomic64_t *v)
15239 {
15240+ return i + xadd_check_overflow(&v->counter, i);
15241+}
15242+
15243+/**
15244+ * atomic64_add_return_unchecked - add and return
15245+ * @i: integer value to add
15246+ * @v: pointer to type atomic64_unchecked_t
15247+ *
15248+ * Atomically adds @i to @v and returns @i + @v
15249+ */
15250+static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
15251+{
15252 return i + xadd(&v->counter, i);
15253 }
15254
15255@@ -179,6 +337,10 @@ static inline long atomic64_sub_return(long i, atomic64_t *v)
15256 }
15257
15258 #define atomic64_inc_return(v) (atomic64_add_return(1, (v)))
15259+static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
15260+{
15261+ return atomic64_add_return_unchecked(1, v);
15262+}
15263 #define atomic64_dec_return(v) (atomic64_sub_return(1, (v)))
15264
15265 static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
15266@@ -186,6 +348,11 @@ static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
15267 return cmpxchg(&v->counter, old, new);
15268 }
15269
15270+static inline long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long old, long new)
15271+{
15272+ return cmpxchg(&v->counter, old, new);
15273+}
15274+
15275 static inline long atomic64_xchg(atomic64_t *v, long new)
15276 {
15277 return xchg(&v->counter, new);
15278@@ -202,17 +369,30 @@ static inline long atomic64_xchg(atomic64_t *v, long new)
15279 */
15280 static inline int atomic64_add_unless(atomic64_t *v, long a, long u)
15281 {
15282- long c, old;
15283+ long c, old, new;
15284 c = atomic64_read(v);
15285 for (;;) {
15286- if (unlikely(c == (u)))
15287+ if (unlikely(c == u))
15288 break;
15289- old = atomic64_cmpxchg((v), c, c + (a));
15290+
15291+ asm volatile("add %2,%0\n"
15292+
15293+#ifdef CONFIG_PAX_REFCOUNT
15294+ "jno 0f\n"
15295+ "sub %2,%0\n"
15296+ "int $4\n0:\n"
15297+ _ASM_EXTABLE(0b, 0b)
15298+#endif
15299+
15300+ : "=r" (new)
15301+ : "0" (c), "ir" (a));
15302+
15303+ old = atomic64_cmpxchg(v, c, new);
15304 if (likely(old == c))
15305 break;
15306 c = old;
15307 }
15308- return c != (u);
15309+ return c != u;
15310 }
15311
15312 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
15313diff --git a/arch/x86/include/asm/bitops.h b/arch/x86/include/asm/bitops.h
15314index 41639ce..ebce552 100644
15315--- a/arch/x86/include/asm/bitops.h
15316+++ b/arch/x86/include/asm/bitops.h
15317@@ -48,7 +48,7 @@
15318 * a mask operation on a byte.
15319 */
15320 #define IS_IMMEDIATE(nr) (__builtin_constant_p(nr))
15321-#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((void *)(addr) + ((nr)>>3))
15322+#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((volatile void *)(addr) + ((nr)>>3))
15323 #define CONST_MASK(nr) (1 << ((nr) & 7))
15324
15325 /**
15326@@ -361,7 +361,7 @@ static int test_bit(int nr, const volatile unsigned long *addr);
15327 *
15328 * Undefined if no bit exists, so code should check against 0 first.
15329 */
15330-static inline unsigned long __ffs(unsigned long word)
15331+static inline unsigned long __intentional_overflow(-1) __ffs(unsigned long word)
15332 {
15333 asm("rep; bsf %1,%0"
15334 : "=r" (word)
15335@@ -375,7 +375,7 @@ static inline unsigned long __ffs(unsigned long word)
15336 *
15337 * Undefined if no zero exists, so code should check against ~0UL first.
15338 */
15339-static inline unsigned long ffz(unsigned long word)
15340+static inline unsigned long __intentional_overflow(-1) ffz(unsigned long word)
15341 {
15342 asm("rep; bsf %1,%0"
15343 : "=r" (word)
15344@@ -389,7 +389,7 @@ static inline unsigned long ffz(unsigned long word)
15345 *
15346 * Undefined if no set bit exists, so code should check against 0 first.
15347 */
15348-static inline unsigned long __fls(unsigned long word)
15349+static inline unsigned long __intentional_overflow(-1) __fls(unsigned long word)
15350 {
15351 asm("bsr %1,%0"
15352 : "=r" (word)
15353@@ -452,7 +452,7 @@ static inline int ffs(int x)
15354 * set bit if value is nonzero. The last (most significant) bit is
15355 * at position 32.
15356 */
15357-static inline int fls(int x)
15358+static inline int __intentional_overflow(-1) fls(int x)
15359 {
15360 int r;
15361
15362@@ -494,7 +494,7 @@ static inline int fls(int x)
15363 * at position 64.
15364 */
15365 #ifdef CONFIG_X86_64
15366-static __always_inline int fls64(__u64 x)
15367+static __always_inline long fls64(__u64 x)
15368 {
15369 int bitpos = -1;
15370 /*
15371diff --git a/arch/x86/include/asm/boot.h b/arch/x86/include/asm/boot.h
15372index 4fa687a..60f2d39 100644
15373--- a/arch/x86/include/asm/boot.h
15374+++ b/arch/x86/include/asm/boot.h
15375@@ -6,10 +6,15 @@
15376 #include <uapi/asm/boot.h>
15377
15378 /* Physical address where kernel should be loaded. */
15379-#define LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
15380+#define ____LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
15381 + (CONFIG_PHYSICAL_ALIGN - 1)) \
15382 & ~(CONFIG_PHYSICAL_ALIGN - 1))
15383
15384+#ifndef __ASSEMBLY__
15385+extern unsigned char __LOAD_PHYSICAL_ADDR[];
15386+#define LOAD_PHYSICAL_ADDR ((unsigned long)__LOAD_PHYSICAL_ADDR)
15387+#endif
15388+
15389 /* Minimum kernel alignment, as a power of two */
15390 #ifdef CONFIG_X86_64
15391 #define MIN_KERNEL_ALIGN_LG2 PMD_SHIFT
15392diff --git a/arch/x86/include/asm/cache.h b/arch/x86/include/asm/cache.h
15393index 48f99f1..d78ebf9 100644
15394--- a/arch/x86/include/asm/cache.h
15395+++ b/arch/x86/include/asm/cache.h
15396@@ -5,12 +5,13 @@
15397
15398 /* L1 cache line size */
15399 #define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
15400-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
15401+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
15402
15403 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
15404+#define __read_only __attribute__((__section__(".data..read_only")))
15405
15406 #define INTERNODE_CACHE_SHIFT CONFIG_X86_INTERNODE_CACHE_SHIFT
15407-#define INTERNODE_CACHE_BYTES (1 << INTERNODE_CACHE_SHIFT)
15408+#define INTERNODE_CACHE_BYTES (_AC(1,UL) << INTERNODE_CACHE_SHIFT)
15409
15410 #ifdef CONFIG_X86_VSMP
15411 #ifdef CONFIG_SMP
15412diff --git a/arch/x86/include/asm/cacheflush.h b/arch/x86/include/asm/cacheflush.h
15413index 9863ee3..4a1f8e1 100644
15414--- a/arch/x86/include/asm/cacheflush.h
15415+++ b/arch/x86/include/asm/cacheflush.h
15416@@ -27,7 +27,7 @@ static inline unsigned long get_page_memtype(struct page *pg)
15417 unsigned long pg_flags = pg->flags & _PGMT_MASK;
15418
15419 if (pg_flags == _PGMT_DEFAULT)
15420- return -1;
15421+ return ~0UL;
15422 else if (pg_flags == _PGMT_WC)
15423 return _PAGE_CACHE_WC;
15424 else if (pg_flags == _PGMT_UC_MINUS)
15425diff --git a/arch/x86/include/asm/calling.h b/arch/x86/include/asm/calling.h
15426index 0fa6750..cb7b2c3 100644
15427--- a/arch/x86/include/asm/calling.h
15428+++ b/arch/x86/include/asm/calling.h
15429@@ -80,103 +80,113 @@ For 32-bit we have the following conventions - kernel is built with
15430 #define RSP 152
15431 #define SS 160
15432
15433-#define ARGOFFSET R11
15434-#define SWFRAME ORIG_RAX
15435+#define ARGOFFSET R15
15436
15437 .macro SAVE_ARGS addskip=0, save_rcx=1, save_r891011=1
15438- subq $9*8+\addskip, %rsp
15439- CFI_ADJUST_CFA_OFFSET 9*8+\addskip
15440- movq_cfi rdi, 8*8
15441- movq_cfi rsi, 7*8
15442- movq_cfi rdx, 6*8
15443+ subq $ORIG_RAX-ARGOFFSET+\addskip, %rsp
15444+ CFI_ADJUST_CFA_OFFSET ORIG_RAX-ARGOFFSET+\addskip
15445+ movq_cfi rdi, RDI
15446+ movq_cfi rsi, RSI
15447+ movq_cfi rdx, RDX
15448
15449 .if \save_rcx
15450- movq_cfi rcx, 5*8
15451+ movq_cfi rcx, RCX
15452 .endif
15453
15454- movq_cfi rax, 4*8
15455+ movq_cfi rax, RAX
15456
15457 .if \save_r891011
15458- movq_cfi r8, 3*8
15459- movq_cfi r9, 2*8
15460- movq_cfi r10, 1*8
15461- movq_cfi r11, 0*8
15462+ movq_cfi r8, R8
15463+ movq_cfi r9, R9
15464+ movq_cfi r10, R10
15465+ movq_cfi r11, R11
15466 .endif
15467
15468+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
15469+ movq_cfi r12, R12
15470+#endif
15471+
15472 .endm
15473
15474-#define ARG_SKIP (9*8)
15475+#define ARG_SKIP ORIG_RAX
15476
15477 .macro RESTORE_ARGS rstor_rax=1, addskip=0, rstor_rcx=1, rstor_r11=1, \
15478 rstor_r8910=1, rstor_rdx=1
15479+
15480+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
15481+ movq_cfi_restore R12, r12
15482+#endif
15483+
15484 .if \rstor_r11
15485- movq_cfi_restore 0*8, r11
15486+ movq_cfi_restore R11, r11
15487 .endif
15488
15489 .if \rstor_r8910
15490- movq_cfi_restore 1*8, r10
15491- movq_cfi_restore 2*8, r9
15492- movq_cfi_restore 3*8, r8
15493+ movq_cfi_restore R10, r10
15494+ movq_cfi_restore R9, r9
15495+ movq_cfi_restore R8, r8
15496 .endif
15497
15498 .if \rstor_rax
15499- movq_cfi_restore 4*8, rax
15500+ movq_cfi_restore RAX, rax
15501 .endif
15502
15503 .if \rstor_rcx
15504- movq_cfi_restore 5*8, rcx
15505+ movq_cfi_restore RCX, rcx
15506 .endif
15507
15508 .if \rstor_rdx
15509- movq_cfi_restore 6*8, rdx
15510+ movq_cfi_restore RDX, rdx
15511 .endif
15512
15513- movq_cfi_restore 7*8, rsi
15514- movq_cfi_restore 8*8, rdi
15515+ movq_cfi_restore RSI, rsi
15516+ movq_cfi_restore RDI, rdi
15517
15518- .if ARG_SKIP+\addskip > 0
15519- addq $ARG_SKIP+\addskip, %rsp
15520- CFI_ADJUST_CFA_OFFSET -(ARG_SKIP+\addskip)
15521+ .if ORIG_RAX+\addskip > 0
15522+ addq $ORIG_RAX+\addskip, %rsp
15523+ CFI_ADJUST_CFA_OFFSET -(ORIG_RAX+\addskip)
15524 .endif
15525 .endm
15526
15527- .macro LOAD_ARGS offset, skiprax=0
15528- movq \offset(%rsp), %r11
15529- movq \offset+8(%rsp), %r10
15530- movq \offset+16(%rsp), %r9
15531- movq \offset+24(%rsp), %r8
15532- movq \offset+40(%rsp), %rcx
15533- movq \offset+48(%rsp), %rdx
15534- movq \offset+56(%rsp), %rsi
15535- movq \offset+64(%rsp), %rdi
15536+ .macro LOAD_ARGS skiprax=0
15537+ movq R11(%rsp), %r11
15538+ movq R10(%rsp), %r10
15539+ movq R9(%rsp), %r9
15540+ movq R8(%rsp), %r8
15541+ movq RCX(%rsp), %rcx
15542+ movq RDX(%rsp), %rdx
15543+ movq RSI(%rsp), %rsi
15544+ movq RDI(%rsp), %rdi
15545 .if \skiprax
15546 .else
15547- movq \offset+72(%rsp), %rax
15548+ movq RAX(%rsp), %rax
15549 .endif
15550 .endm
15551
15552-#define REST_SKIP (6*8)
15553-
15554 .macro SAVE_REST
15555- subq $REST_SKIP, %rsp
15556- CFI_ADJUST_CFA_OFFSET REST_SKIP
15557- movq_cfi rbx, 5*8
15558- movq_cfi rbp, 4*8
15559- movq_cfi r12, 3*8
15560- movq_cfi r13, 2*8
15561- movq_cfi r14, 1*8
15562- movq_cfi r15, 0*8
15563+ movq_cfi rbx, RBX
15564+ movq_cfi rbp, RBP
15565+
15566+#ifndef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
15567+ movq_cfi r12, R12
15568+#endif
15569+
15570+ movq_cfi r13, R13
15571+ movq_cfi r14, R14
15572+ movq_cfi r15, R15
15573 .endm
15574
15575 .macro RESTORE_REST
15576- movq_cfi_restore 0*8, r15
15577- movq_cfi_restore 1*8, r14
15578- movq_cfi_restore 2*8, r13
15579- movq_cfi_restore 3*8, r12
15580- movq_cfi_restore 4*8, rbp
15581- movq_cfi_restore 5*8, rbx
15582- addq $REST_SKIP, %rsp
15583- CFI_ADJUST_CFA_OFFSET -(REST_SKIP)
15584+ movq_cfi_restore R15, r15
15585+ movq_cfi_restore R14, r14
15586+ movq_cfi_restore R13, r13
15587+
15588+#ifndef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
15589+ movq_cfi_restore R12, r12
15590+#endif
15591+
15592+ movq_cfi_restore RBP, rbp
15593+ movq_cfi_restore RBX, rbx
15594 .endm
15595
15596 .macro SAVE_ALL
15597diff --git a/arch/x86/include/asm/checksum_32.h b/arch/x86/include/asm/checksum_32.h
15598index f50de69..2b0a458 100644
15599--- a/arch/x86/include/asm/checksum_32.h
15600+++ b/arch/x86/include/asm/checksum_32.h
15601@@ -31,6 +31,14 @@ asmlinkage __wsum csum_partial_copy_generic(const void *src, void *dst,
15602 int len, __wsum sum,
15603 int *src_err_ptr, int *dst_err_ptr);
15604
15605+asmlinkage __wsum csum_partial_copy_generic_to_user(const void *src, void *dst,
15606+ int len, __wsum sum,
15607+ int *src_err_ptr, int *dst_err_ptr);
15608+
15609+asmlinkage __wsum csum_partial_copy_generic_from_user(const void *src, void *dst,
15610+ int len, __wsum sum,
15611+ int *src_err_ptr, int *dst_err_ptr);
15612+
15613 /*
15614 * Note: when you get a NULL pointer exception here this means someone
15615 * passed in an incorrect kernel address to one of these functions.
15616@@ -53,7 +61,7 @@ static inline __wsum csum_partial_copy_from_user(const void __user *src,
15617
15618 might_sleep();
15619 stac();
15620- ret = csum_partial_copy_generic((__force void *)src, dst,
15621+ ret = csum_partial_copy_generic_from_user((__force void *)src, dst,
15622 len, sum, err_ptr, NULL);
15623 clac();
15624
15625@@ -187,7 +195,7 @@ static inline __wsum csum_and_copy_to_user(const void *src,
15626 might_sleep();
15627 if (access_ok(VERIFY_WRITE, dst, len)) {
15628 stac();
15629- ret = csum_partial_copy_generic(src, (__force void *)dst,
15630+ ret = csum_partial_copy_generic_to_user(src, (__force void *)dst,
15631 len, sum, NULL, err_ptr);
15632 clac();
15633 return ret;
15634diff --git a/arch/x86/include/asm/cmpxchg.h b/arch/x86/include/asm/cmpxchg.h
15635index d47786a..ce1b05d 100644
15636--- a/arch/x86/include/asm/cmpxchg.h
15637+++ b/arch/x86/include/asm/cmpxchg.h
15638@@ -14,8 +14,12 @@ extern void __cmpxchg_wrong_size(void)
15639 __compiletime_error("Bad argument size for cmpxchg");
15640 extern void __xadd_wrong_size(void)
15641 __compiletime_error("Bad argument size for xadd");
15642+extern void __xadd_check_overflow_wrong_size(void)
15643+ __compiletime_error("Bad argument size for xadd_check_overflow");
15644 extern void __add_wrong_size(void)
15645 __compiletime_error("Bad argument size for add");
15646+extern void __add_check_overflow_wrong_size(void)
15647+ __compiletime_error("Bad argument size for add_check_overflow");
15648
15649 /*
15650 * Constants for operation sizes. On 32-bit, the 64-bit size it set to
15651@@ -67,6 +71,34 @@ extern void __add_wrong_size(void)
15652 __ret; \
15653 })
15654
15655+#define __xchg_op_check_overflow(ptr, arg, op, lock) \
15656+ ({ \
15657+ __typeof__ (*(ptr)) __ret = (arg); \
15658+ switch (sizeof(*(ptr))) { \
15659+ case __X86_CASE_L: \
15660+ asm volatile (lock #op "l %0, %1\n" \
15661+ "jno 0f\n" \
15662+ "mov %0,%1\n" \
15663+ "int $4\n0:\n" \
15664+ _ASM_EXTABLE(0b, 0b) \
15665+ : "+r" (__ret), "+m" (*(ptr)) \
15666+ : : "memory", "cc"); \
15667+ break; \
15668+ case __X86_CASE_Q: \
15669+ asm volatile (lock #op "q %q0, %1\n" \
15670+ "jno 0f\n" \
15671+ "mov %0,%1\n" \
15672+ "int $4\n0:\n" \
15673+ _ASM_EXTABLE(0b, 0b) \
15674+ : "+r" (__ret), "+m" (*(ptr)) \
15675+ : : "memory", "cc"); \
15676+ break; \
15677+ default: \
15678+ __ ## op ## _check_overflow_wrong_size(); \
15679+ } \
15680+ __ret; \
15681+ })
15682+
15683 /*
15684 * Note: no "lock" prefix even on SMP: xchg always implies lock anyway.
15685 * Since this is generally used to protect other memory information, we
15686@@ -167,6 +199,9 @@ extern void __add_wrong_size(void)
15687 #define xadd_sync(ptr, inc) __xadd((ptr), (inc), "lock; ")
15688 #define xadd_local(ptr, inc) __xadd((ptr), (inc), "")
15689
15690+#define __xadd_check_overflow(ptr, inc, lock) __xchg_op_check_overflow((ptr), (inc), xadd, lock)
15691+#define xadd_check_overflow(ptr, inc) __xadd_check_overflow((ptr), (inc), LOCK_PREFIX)
15692+
15693 #define __add(ptr, inc, lock) \
15694 ({ \
15695 __typeof__ (*(ptr)) __ret = (inc); \
15696diff --git a/arch/x86/include/asm/compat.h b/arch/x86/include/asm/compat.h
15697index 59c6c40..5e0b22c 100644
15698--- a/arch/x86/include/asm/compat.h
15699+++ b/arch/x86/include/asm/compat.h
15700@@ -41,7 +41,7 @@ typedef s64 __attribute__((aligned(4))) compat_s64;
15701 typedef u32 compat_uint_t;
15702 typedef u32 compat_ulong_t;
15703 typedef u64 __attribute__((aligned(4))) compat_u64;
15704-typedef u32 compat_uptr_t;
15705+typedef u32 __user compat_uptr_t;
15706
15707 struct compat_timespec {
15708 compat_time_t tv_sec;
15709diff --git a/arch/x86/include/asm/cpufeature.h b/arch/x86/include/asm/cpufeature.h
15710index 89270b4..f0abf8e 100644
15711--- a/arch/x86/include/asm/cpufeature.h
15712+++ b/arch/x86/include/asm/cpufeature.h
15713@@ -203,7 +203,7 @@
15714 #define X86_FEATURE_DECODEASSISTS (8*32+12) /* AMD Decode Assists support */
15715 #define X86_FEATURE_PAUSEFILTER (8*32+13) /* AMD filtered pause intercept */
15716 #define X86_FEATURE_PFTHRESHOLD (8*32+14) /* AMD pause filter threshold */
15717-
15718+#define X86_FEATURE_STRONGUDEREF (8*32+31) /* PaX PCID based strong UDEREF */
15719
15720 /* Intel-defined CPU features, CPUID level 0x00000007:0 (ebx), word 9 */
15721 #define X86_FEATURE_FSGSBASE (9*32+ 0) /* {RD/WR}{FS/GS}BASE instructions*/
15722@@ -211,7 +211,7 @@
15723 #define X86_FEATURE_BMI1 (9*32+ 3) /* 1st group bit manipulation extensions */
15724 #define X86_FEATURE_HLE (9*32+ 4) /* Hardware Lock Elision */
15725 #define X86_FEATURE_AVX2 (9*32+ 5) /* AVX2 instructions */
15726-#define X86_FEATURE_SMEP (9*32+ 7) /* Supervisor Mode Execution Protection */
15727+#define X86_FEATURE_SMEP (9*32+ 7) /* Supervisor Mode Execution Prevention */
15728 #define X86_FEATURE_BMI2 (9*32+ 8) /* 2nd group bit manipulation extensions */
15729 #define X86_FEATURE_ERMS (9*32+ 9) /* Enhanced REP MOVSB/STOSB */
15730 #define X86_FEATURE_INVPCID (9*32+10) /* Invalidate Processor Context ID */
15731@@ -353,6 +353,7 @@ extern const char * const x86_power_flags[32];
15732 #undef cpu_has_centaur_mcr
15733 #define cpu_has_centaur_mcr 0
15734
15735+#define cpu_has_pcid boot_cpu_has(X86_FEATURE_PCID)
15736 #endif /* CONFIG_X86_64 */
15737
15738 #if __GNUC__ >= 4
15739@@ -405,7 +406,8 @@ static __always_inline __pure bool __static_cpu_has(u16 bit)
15740
15741 #ifdef CONFIG_X86_DEBUG_STATIC_CPU_HAS
15742 t_warn:
15743- warn_pre_alternatives();
15744+ if (bit != X86_FEATURE_PCID && bit != X86_FEATURE_INVPCID)
15745+ warn_pre_alternatives();
15746 return false;
15747 #endif
15748
15749@@ -425,7 +427,7 @@ static __always_inline __pure bool __static_cpu_has(u16 bit)
15750 ".section .discard,\"aw\",@progbits\n"
15751 " .byte 0xff + (4f-3f) - (2b-1b)\n" /* size check */
15752 ".previous\n"
15753- ".section .altinstr_replacement,\"ax\"\n"
15754+ ".section .altinstr_replacement,\"a\"\n"
15755 "3: movb $1,%0\n"
15756 "4:\n"
15757 ".previous\n"
15758@@ -462,7 +464,7 @@ static __always_inline __pure bool _static_cpu_has_safe(u16 bit)
15759 " .byte 2b - 1b\n" /* src len */
15760 " .byte 4f - 3f\n" /* repl len */
15761 ".previous\n"
15762- ".section .altinstr_replacement,\"ax\"\n"
15763+ ".section .altinstr_replacement,\"a\"\n"
15764 "3: .byte 0xe9\n .long %l[t_no] - 2b\n"
15765 "4:\n"
15766 ".previous\n"
15767@@ -495,7 +497,7 @@ static __always_inline __pure bool _static_cpu_has_safe(u16 bit)
15768 ".section .discard,\"aw\",@progbits\n"
15769 " .byte 0xff + (4f-3f) - (2b-1b)\n" /* size check */
15770 ".previous\n"
15771- ".section .altinstr_replacement,\"ax\"\n"
15772+ ".section .altinstr_replacement,\"a\"\n"
15773 "3: movb $0,%0\n"
15774 "4:\n"
15775 ".previous\n"
15776@@ -509,7 +511,7 @@ static __always_inline __pure bool _static_cpu_has_safe(u16 bit)
15777 ".section .discard,\"aw\",@progbits\n"
15778 " .byte 0xff + (6f-5f) - (4b-3b)\n" /* size check */
15779 ".previous\n"
15780- ".section .altinstr_replacement,\"ax\"\n"
15781+ ".section .altinstr_replacement,\"a\"\n"
15782 "5: movb $1,%0\n"
15783 "6:\n"
15784 ".previous\n"
15785diff --git a/arch/x86/include/asm/desc.h b/arch/x86/include/asm/desc.h
15786index b90e5df..b462c91 100644
15787--- a/arch/x86/include/asm/desc.h
15788+++ b/arch/x86/include/asm/desc.h
15789@@ -4,6 +4,7 @@
15790 #include <asm/desc_defs.h>
15791 #include <asm/ldt.h>
15792 #include <asm/mmu.h>
15793+#include <asm/pgtable.h>
15794
15795 #include <linux/smp.h>
15796 #include <linux/percpu.h>
15797@@ -17,6 +18,7 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
15798
15799 desc->type = (info->read_exec_only ^ 1) << 1;
15800 desc->type |= info->contents << 2;
15801+ desc->type |= info->seg_not_present ^ 1;
15802
15803 desc->s = 1;
15804 desc->dpl = 0x3;
15805@@ -35,19 +37,14 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
15806 }
15807
15808 extern struct desc_ptr idt_descr;
15809-extern gate_desc idt_table[];
15810-extern struct desc_ptr debug_idt_descr;
15811-extern gate_desc debug_idt_table[];
15812-
15813-struct gdt_page {
15814- struct desc_struct gdt[GDT_ENTRIES];
15815-} __attribute__((aligned(PAGE_SIZE)));
15816-
15817-DECLARE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page);
15818+extern gate_desc idt_table[IDT_ENTRIES];
15819+extern const struct desc_ptr debug_idt_descr;
15820+extern gate_desc debug_idt_table[IDT_ENTRIES];
15821
15822+extern struct desc_struct cpu_gdt_table[NR_CPUS][PAGE_SIZE / sizeof(struct desc_struct)];
15823 static inline struct desc_struct *get_cpu_gdt_table(unsigned int cpu)
15824 {
15825- return per_cpu(gdt_page, cpu).gdt;
15826+ return cpu_gdt_table[cpu];
15827 }
15828
15829 #ifdef CONFIG_X86_64
15830@@ -72,8 +69,14 @@ static inline void pack_gate(gate_desc *gate, unsigned char type,
15831 unsigned long base, unsigned dpl, unsigned flags,
15832 unsigned short seg)
15833 {
15834- gate->a = (seg << 16) | (base & 0xffff);
15835- gate->b = (base & 0xffff0000) | (((0x80 | type | (dpl << 5)) & 0xff) << 8);
15836+ gate->gate.offset_low = base;
15837+ gate->gate.seg = seg;
15838+ gate->gate.reserved = 0;
15839+ gate->gate.type = type;
15840+ gate->gate.s = 0;
15841+ gate->gate.dpl = dpl;
15842+ gate->gate.p = 1;
15843+ gate->gate.offset_high = base >> 16;
15844 }
15845
15846 #endif
15847@@ -118,12 +121,16 @@ static inline void paravirt_free_ldt(struct desc_struct *ldt, unsigned entries)
15848
15849 static inline void native_write_idt_entry(gate_desc *idt, int entry, const gate_desc *gate)
15850 {
15851+ pax_open_kernel();
15852 memcpy(&idt[entry], gate, sizeof(*gate));
15853+ pax_close_kernel();
15854 }
15855
15856 static inline void native_write_ldt_entry(struct desc_struct *ldt, int entry, const void *desc)
15857 {
15858+ pax_open_kernel();
15859 memcpy(&ldt[entry], desc, 8);
15860+ pax_close_kernel();
15861 }
15862
15863 static inline void
15864@@ -137,7 +144,9 @@ native_write_gdt_entry(struct desc_struct *gdt, int entry, const void *desc, int
15865 default: size = sizeof(*gdt); break;
15866 }
15867
15868+ pax_open_kernel();
15869 memcpy(&gdt[entry], desc, size);
15870+ pax_close_kernel();
15871 }
15872
15873 static inline void pack_descriptor(struct desc_struct *desc, unsigned long base,
15874@@ -210,7 +219,9 @@ static inline void native_set_ldt(const void *addr, unsigned int entries)
15875
15876 static inline void native_load_tr_desc(void)
15877 {
15878+ pax_open_kernel();
15879 asm volatile("ltr %w0"::"q" (GDT_ENTRY_TSS*8));
15880+ pax_close_kernel();
15881 }
15882
15883 static inline void native_load_gdt(const struct desc_ptr *dtr)
15884@@ -247,8 +258,10 @@ static inline void native_load_tls(struct thread_struct *t, unsigned int cpu)
15885 struct desc_struct *gdt = get_cpu_gdt_table(cpu);
15886 unsigned int i;
15887
15888+ pax_open_kernel();
15889 for (i = 0; i < GDT_ENTRY_TLS_ENTRIES; i++)
15890 gdt[GDT_ENTRY_TLS_MIN + i] = t->tls_array[i];
15891+ pax_close_kernel();
15892 }
15893
15894 #define _LDT_empty(info) \
15895@@ -287,7 +300,7 @@ static inline void load_LDT(mm_context_t *pc)
15896 preempt_enable();
15897 }
15898
15899-static inline unsigned long get_desc_base(const struct desc_struct *desc)
15900+static inline unsigned long __intentional_overflow(-1) get_desc_base(const struct desc_struct *desc)
15901 {
15902 return (unsigned)(desc->base0 | ((desc->base1) << 16) | ((desc->base2) << 24));
15903 }
15904@@ -311,7 +324,7 @@ static inline void set_desc_limit(struct desc_struct *desc, unsigned long limit)
15905 }
15906
15907 #ifdef CONFIG_X86_64
15908-static inline void set_nmi_gate(int gate, void *addr)
15909+static inline void set_nmi_gate(int gate, const void *addr)
15910 {
15911 gate_desc s;
15912
15913@@ -321,8 +334,8 @@ static inline void set_nmi_gate(int gate, void *addr)
15914 #endif
15915
15916 #ifdef CONFIG_TRACING
15917-extern struct desc_ptr trace_idt_descr;
15918-extern gate_desc trace_idt_table[];
15919+extern const struct desc_ptr trace_idt_descr;
15920+extern gate_desc trace_idt_table[IDT_ENTRIES];
15921 static inline void write_trace_idt_entry(int entry, const gate_desc *gate)
15922 {
15923 write_idt_entry(trace_idt_table, entry, gate);
15924@@ -333,7 +346,7 @@ static inline void write_trace_idt_entry(int entry, const gate_desc *gate)
15925 }
15926 #endif
15927
15928-static inline void _set_gate(int gate, unsigned type, void *addr,
15929+static inline void _set_gate(int gate, unsigned type, const void *addr,
15930 unsigned dpl, unsigned ist, unsigned seg)
15931 {
15932 gate_desc s;
15933@@ -353,7 +366,7 @@ static inline void _set_gate(int gate, unsigned type, void *addr,
15934 * Pentium F0 0F bugfix can have resulted in the mapped
15935 * IDT being write-protected.
15936 */
15937-static inline void set_intr_gate(unsigned int n, void *addr)
15938+static inline void set_intr_gate(unsigned int n, const void *addr)
15939 {
15940 BUG_ON((unsigned)n > 0xFF);
15941 _set_gate(n, GATE_INTERRUPT, addr, 0, 0, __KERNEL_CS);
15942@@ -410,19 +423,19 @@ static inline void __alloc_intr_gate(unsigned int n, void *addr)
15943 /*
15944 * This routine sets up an interrupt gate at directory privilege level 3.
15945 */
15946-static inline void set_system_intr_gate(unsigned int n, void *addr)
15947+static inline void set_system_intr_gate(unsigned int n, const void *addr)
15948 {
15949 BUG_ON((unsigned)n > 0xFF);
15950 _set_gate(n, GATE_INTERRUPT, addr, 0x3, 0, __KERNEL_CS);
15951 }
15952
15953-static inline void set_system_trap_gate(unsigned int n, void *addr)
15954+static inline void set_system_trap_gate(unsigned int n, const void *addr)
15955 {
15956 BUG_ON((unsigned)n > 0xFF);
15957 _set_gate(n, GATE_TRAP, addr, 0x3, 0, __KERNEL_CS);
15958 }
15959
15960-static inline void set_trap_gate(unsigned int n, void *addr)
15961+static inline void set_trap_gate(unsigned int n, const void *addr)
15962 {
15963 BUG_ON((unsigned)n > 0xFF);
15964 _set_gate(n, GATE_TRAP, addr, 0, 0, __KERNEL_CS);
15965@@ -431,16 +444,16 @@ static inline void set_trap_gate(unsigned int n, void *addr)
15966 static inline void set_task_gate(unsigned int n, unsigned int gdt_entry)
15967 {
15968 BUG_ON((unsigned)n > 0xFF);
15969- _set_gate(n, GATE_TASK, (void *)0, 0, 0, (gdt_entry<<3));
15970+ _set_gate(n, GATE_TASK, (const void *)0, 0, 0, (gdt_entry<<3));
15971 }
15972
15973-static inline void set_intr_gate_ist(int n, void *addr, unsigned ist)
15974+static inline void set_intr_gate_ist(int n, const void *addr, unsigned ist)
15975 {
15976 BUG_ON((unsigned)n > 0xFF);
15977 _set_gate(n, GATE_INTERRUPT, addr, 0, ist, __KERNEL_CS);
15978 }
15979
15980-static inline void set_system_intr_gate_ist(int n, void *addr, unsigned ist)
15981+static inline void set_system_intr_gate_ist(int n, const void *addr, unsigned ist)
15982 {
15983 BUG_ON((unsigned)n > 0xFF);
15984 _set_gate(n, GATE_INTERRUPT, addr, 0x3, ist, __KERNEL_CS);
15985@@ -512,4 +525,17 @@ static inline void load_current_idt(void)
15986 else
15987 load_idt((const struct desc_ptr *)&idt_descr);
15988 }
15989+
15990+#ifdef CONFIG_X86_32
15991+static inline void set_user_cs(unsigned long base, unsigned long limit, int cpu)
15992+{
15993+ struct desc_struct d;
15994+
15995+ if (likely(limit))
15996+ limit = (limit - 1UL) >> PAGE_SHIFT;
15997+ pack_descriptor(&d, base, limit, 0xFB, 0xC);
15998+ write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_DEFAULT_USER_CS, &d, DESCTYPE_S);
15999+}
16000+#endif
16001+
16002 #endif /* _ASM_X86_DESC_H */
16003diff --git a/arch/x86/include/asm/desc_defs.h b/arch/x86/include/asm/desc_defs.h
16004index 278441f..b95a174 100644
16005--- a/arch/x86/include/asm/desc_defs.h
16006+++ b/arch/x86/include/asm/desc_defs.h
16007@@ -31,6 +31,12 @@ struct desc_struct {
16008 unsigned base1: 8, type: 4, s: 1, dpl: 2, p: 1;
16009 unsigned limit: 4, avl: 1, l: 1, d: 1, g: 1, base2: 8;
16010 };
16011+ struct {
16012+ u16 offset_low;
16013+ u16 seg;
16014+ unsigned reserved: 8, type: 4, s: 1, dpl: 2, p: 1;
16015+ unsigned offset_high: 16;
16016+ } gate;
16017 };
16018 } __attribute__((packed));
16019
16020diff --git a/arch/x86/include/asm/div64.h b/arch/x86/include/asm/div64.h
16021index ced283a..ffe04cc 100644
16022--- a/arch/x86/include/asm/div64.h
16023+++ b/arch/x86/include/asm/div64.h
16024@@ -39,7 +39,7 @@
16025 __mod; \
16026 })
16027
16028-static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
16029+static inline u64 __intentional_overflow(-1) div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
16030 {
16031 union {
16032 u64 v64;
16033diff --git a/arch/x86/include/asm/elf.h b/arch/x86/include/asm/elf.h
16034index 9c999c1..3860cb8 100644
16035--- a/arch/x86/include/asm/elf.h
16036+++ b/arch/x86/include/asm/elf.h
16037@@ -243,7 +243,25 @@ extern int force_personality32;
16038 the loader. We need to make sure that it is out of the way of the program
16039 that it will "exec", and that there is sufficient room for the brk. */
16040
16041+#ifdef CONFIG_PAX_SEGMEXEC
16042+#define ELF_ET_DYN_BASE ((current->mm->pax_flags & MF_PAX_SEGMEXEC) ? SEGMEXEC_TASK_SIZE/3*2 : TASK_SIZE/3*2)
16043+#else
16044 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
16045+#endif
16046+
16047+#ifdef CONFIG_PAX_ASLR
16048+#ifdef CONFIG_X86_32
16049+#define PAX_ELF_ET_DYN_BASE 0x10000000UL
16050+
16051+#define PAX_DELTA_MMAP_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
16052+#define PAX_DELTA_STACK_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
16053+#else
16054+#define PAX_ELF_ET_DYN_BASE 0x400000UL
16055+
16056+#define PAX_DELTA_MMAP_LEN ((test_thread_flag(TIF_ADDR32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
16057+#define PAX_DELTA_STACK_LEN ((test_thread_flag(TIF_ADDR32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
16058+#endif
16059+#endif
16060
16061 /* This yields a mask that user programs can use to figure out what
16062 instruction set this CPU supports. This could be done in user space,
16063@@ -296,16 +314,12 @@ do { \
16064
16065 #define ARCH_DLINFO \
16066 do { \
16067- if (vdso_enabled) \
16068- NEW_AUX_ENT(AT_SYSINFO_EHDR, \
16069- (unsigned long)current->mm->context.vdso); \
16070+ NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
16071 } while (0)
16072
16073 #define ARCH_DLINFO_X32 \
16074 do { \
16075- if (vdso_enabled) \
16076- NEW_AUX_ENT(AT_SYSINFO_EHDR, \
16077- (unsigned long)current->mm->context.vdso); \
16078+ NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
16079 } while (0)
16080
16081 #define AT_SYSINFO 32
16082@@ -320,7 +334,7 @@ else \
16083
16084 #endif /* !CONFIG_X86_32 */
16085
16086-#define VDSO_CURRENT_BASE ((unsigned long)current->mm->context.vdso)
16087+#define VDSO_CURRENT_BASE (current->mm->context.vdso)
16088
16089 #define VDSO_ENTRY \
16090 ((unsigned long)VDSO32_SYMBOL(VDSO_CURRENT_BASE, vsyscall))
16091@@ -336,9 +350,6 @@ extern int x32_setup_additional_pages(struct linux_binprm *bprm,
16092 extern int syscall32_setup_pages(struct linux_binprm *, int exstack);
16093 #define compat_arch_setup_additional_pages syscall32_setup_pages
16094
16095-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
16096-#define arch_randomize_brk arch_randomize_brk
16097-
16098 /*
16099 * True on X86_32 or when emulating IA32 on X86_64
16100 */
16101diff --git a/arch/x86/include/asm/emergency-restart.h b/arch/x86/include/asm/emergency-restart.h
16102index 77a99ac..39ff7f5 100644
16103--- a/arch/x86/include/asm/emergency-restart.h
16104+++ b/arch/x86/include/asm/emergency-restart.h
16105@@ -1,6 +1,6 @@
16106 #ifndef _ASM_X86_EMERGENCY_RESTART_H
16107 #define _ASM_X86_EMERGENCY_RESTART_H
16108
16109-extern void machine_emergency_restart(void);
16110+extern void machine_emergency_restart(void) __noreturn;
16111
16112 #endif /* _ASM_X86_EMERGENCY_RESTART_H */
16113diff --git a/arch/x86/include/asm/floppy.h b/arch/x86/include/asm/floppy.h
16114index d3d7469..677ef72 100644
16115--- a/arch/x86/include/asm/floppy.h
16116+++ b/arch/x86/include/asm/floppy.h
16117@@ -229,18 +229,18 @@ static struct fd_routine_l {
16118 int (*_dma_setup)(char *addr, unsigned long size, int mode, int io);
16119 } fd_routine[] = {
16120 {
16121- request_dma,
16122- free_dma,
16123- get_dma_residue,
16124- dma_mem_alloc,
16125- hard_dma_setup
16126+ ._request_dma = request_dma,
16127+ ._free_dma = free_dma,
16128+ ._get_dma_residue = get_dma_residue,
16129+ ._dma_mem_alloc = dma_mem_alloc,
16130+ ._dma_setup = hard_dma_setup
16131 },
16132 {
16133- vdma_request_dma,
16134- vdma_nop,
16135- vdma_get_dma_residue,
16136- vdma_mem_alloc,
16137- vdma_dma_setup
16138+ ._request_dma = vdma_request_dma,
16139+ ._free_dma = vdma_nop,
16140+ ._get_dma_residue = vdma_get_dma_residue,
16141+ ._dma_mem_alloc = vdma_mem_alloc,
16142+ ._dma_setup = vdma_dma_setup
16143 }
16144 };
16145
16146diff --git a/arch/x86/include/asm/fpu-internal.h b/arch/x86/include/asm/fpu-internal.h
16147index 5be9f87..0320912 100644
16148--- a/arch/x86/include/asm/fpu-internal.h
16149+++ b/arch/x86/include/asm/fpu-internal.h
16150@@ -124,8 +124,11 @@ static inline void sanitize_i387_state(struct task_struct *tsk)
16151 #define user_insn(insn, output, input...) \
16152 ({ \
16153 int err; \
16154+ pax_open_userland(); \
16155 asm volatile(ASM_STAC "\n" \
16156- "1:" #insn "\n\t" \
16157+ "1:" \
16158+ __copyuser_seg \
16159+ #insn "\n\t" \
16160 "2: " ASM_CLAC "\n" \
16161 ".section .fixup,\"ax\"\n" \
16162 "3: movl $-1,%[err]\n" \
16163@@ -134,6 +137,7 @@ static inline void sanitize_i387_state(struct task_struct *tsk)
16164 _ASM_EXTABLE(1b, 3b) \
16165 : [err] "=r" (err), output \
16166 : "0"(0), input); \
16167+ pax_close_userland(); \
16168 err; \
16169 })
16170
16171@@ -298,7 +302,7 @@ static inline int restore_fpu_checking(struct task_struct *tsk)
16172 "fnclex\n\t"
16173 "emms\n\t"
16174 "fildl %P[addr]" /* set F?P to defined value */
16175- : : [addr] "m" (tsk->thread.fpu.has_fpu));
16176+ : : [addr] "m" (init_tss[raw_smp_processor_id()].x86_tss.sp0));
16177 }
16178
16179 return fpu_restore_checking(&tsk->thread.fpu);
16180diff --git a/arch/x86/include/asm/futex.h b/arch/x86/include/asm/futex.h
16181index be27ba1..04a8801 100644
16182--- a/arch/x86/include/asm/futex.h
16183+++ b/arch/x86/include/asm/futex.h
16184@@ -12,6 +12,7 @@
16185 #include <asm/smap.h>
16186
16187 #define __futex_atomic_op1(insn, ret, oldval, uaddr, oparg) \
16188+ typecheck(u32 __user *, uaddr); \
16189 asm volatile("\t" ASM_STAC "\n" \
16190 "1:\t" insn "\n" \
16191 "2:\t" ASM_CLAC "\n" \
16192@@ -20,15 +21,16 @@
16193 "\tjmp\t2b\n" \
16194 "\t.previous\n" \
16195 _ASM_EXTABLE(1b, 3b) \
16196- : "=r" (oldval), "=r" (ret), "+m" (*uaddr) \
16197+ : "=r" (oldval), "=r" (ret), "+m" (*(u32 __user *)____m(uaddr)) \
16198 : "i" (-EFAULT), "0" (oparg), "1" (0))
16199
16200 #define __futex_atomic_op2(insn, ret, oldval, uaddr, oparg) \
16201+ typecheck(u32 __user *, uaddr); \
16202 asm volatile("\t" ASM_STAC "\n" \
16203 "1:\tmovl %2, %0\n" \
16204 "\tmovl\t%0, %3\n" \
16205 "\t" insn "\n" \
16206- "2:\t" LOCK_PREFIX "cmpxchgl %3, %2\n" \
16207+ "2:\t" LOCK_PREFIX __copyuser_seg"cmpxchgl %3, %2\n" \
16208 "\tjnz\t1b\n" \
16209 "3:\t" ASM_CLAC "\n" \
16210 "\t.section .fixup,\"ax\"\n" \
16211@@ -38,7 +40,7 @@
16212 _ASM_EXTABLE(1b, 4b) \
16213 _ASM_EXTABLE(2b, 4b) \
16214 : "=&a" (oldval), "=&r" (ret), \
16215- "+m" (*uaddr), "=&r" (tem) \
16216+ "+m" (*(u32 __user *)____m(uaddr)), "=&r" (tem) \
16217 : "r" (oparg), "i" (-EFAULT), "1" (0))
16218
16219 static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
16220@@ -57,12 +59,13 @@ static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
16221
16222 pagefault_disable();
16223
16224+ pax_open_userland();
16225 switch (op) {
16226 case FUTEX_OP_SET:
16227- __futex_atomic_op1("xchgl %0, %2", ret, oldval, uaddr, oparg);
16228+ __futex_atomic_op1(__copyuser_seg"xchgl %0, %2", ret, oldval, uaddr, oparg);
16229 break;
16230 case FUTEX_OP_ADD:
16231- __futex_atomic_op1(LOCK_PREFIX "xaddl %0, %2", ret, oldval,
16232+ __futex_atomic_op1(LOCK_PREFIX __copyuser_seg"xaddl %0, %2", ret, oldval,
16233 uaddr, oparg);
16234 break;
16235 case FUTEX_OP_OR:
16236@@ -77,6 +80,7 @@ static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
16237 default:
16238 ret = -ENOSYS;
16239 }
16240+ pax_close_userland();
16241
16242 pagefault_enable();
16243
16244@@ -115,18 +119,20 @@ static inline int futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
16245 if (!access_ok(VERIFY_WRITE, uaddr, sizeof(u32)))
16246 return -EFAULT;
16247
16248+ pax_open_userland();
16249 asm volatile("\t" ASM_STAC "\n"
16250- "1:\t" LOCK_PREFIX "cmpxchgl %4, %2\n"
16251+ "1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgl %4, %2\n"
16252 "2:\t" ASM_CLAC "\n"
16253 "\t.section .fixup, \"ax\"\n"
16254 "3:\tmov %3, %0\n"
16255 "\tjmp 2b\n"
16256 "\t.previous\n"
16257 _ASM_EXTABLE(1b, 3b)
16258- : "+r" (ret), "=a" (oldval), "+m" (*uaddr)
16259+ : "+r" (ret), "=a" (oldval), "+m" (*(u32 __user *)____m(uaddr))
16260 : "i" (-EFAULT), "r" (newval), "1" (oldval)
16261 : "memory"
16262 );
16263+ pax_close_userland();
16264
16265 *uval = oldval;
16266 return ret;
16267diff --git a/arch/x86/include/asm/hw_irq.h b/arch/x86/include/asm/hw_irq.h
16268index 92b3bae..3866449 100644
16269--- a/arch/x86/include/asm/hw_irq.h
16270+++ b/arch/x86/include/asm/hw_irq.h
16271@@ -165,8 +165,8 @@ extern void setup_ioapic_dest(void);
16272 extern void enable_IO_APIC(void);
16273
16274 /* Statistics */
16275-extern atomic_t irq_err_count;
16276-extern atomic_t irq_mis_count;
16277+extern atomic_unchecked_t irq_err_count;
16278+extern atomic_unchecked_t irq_mis_count;
16279
16280 /* EISA */
16281 extern void eisa_set_level_irq(unsigned int irq);
16282diff --git a/arch/x86/include/asm/i8259.h b/arch/x86/include/asm/i8259.h
16283index a203659..9889f1c 100644
16284--- a/arch/x86/include/asm/i8259.h
16285+++ b/arch/x86/include/asm/i8259.h
16286@@ -62,7 +62,7 @@ struct legacy_pic {
16287 void (*init)(int auto_eoi);
16288 int (*irq_pending)(unsigned int irq);
16289 void (*make_irq)(unsigned int irq);
16290-};
16291+} __do_const;
16292
16293 extern struct legacy_pic *legacy_pic;
16294 extern struct legacy_pic null_legacy_pic;
16295diff --git a/arch/x86/include/asm/io.h b/arch/x86/include/asm/io.h
16296index 34f69cb..6d95446 100644
16297--- a/arch/x86/include/asm/io.h
16298+++ b/arch/x86/include/asm/io.h
16299@@ -51,12 +51,12 @@ static inline void name(type val, volatile void __iomem *addr) \
16300 "m" (*(volatile type __force *)addr) barrier); }
16301
16302 build_mmio_read(readb, "b", unsigned char, "=q", :"memory")
16303-build_mmio_read(readw, "w", unsigned short, "=r", :"memory")
16304-build_mmio_read(readl, "l", unsigned int, "=r", :"memory")
16305+build_mmio_read(__intentional_overflow(-1) readw, "w", unsigned short, "=r", :"memory")
16306+build_mmio_read(__intentional_overflow(-1) readl, "l", unsigned int, "=r", :"memory")
16307
16308 build_mmio_read(__readb, "b", unsigned char, "=q", )
16309-build_mmio_read(__readw, "w", unsigned short, "=r", )
16310-build_mmio_read(__readl, "l", unsigned int, "=r", )
16311+build_mmio_read(__intentional_overflow(-1) __readw, "w", unsigned short, "=r", )
16312+build_mmio_read(__intentional_overflow(-1) __readl, "l", unsigned int, "=r", )
16313
16314 build_mmio_write(writeb, "b", unsigned char, "q", :"memory")
16315 build_mmio_write(writew, "w", unsigned short, "r", :"memory")
16316@@ -184,7 +184,7 @@ static inline void __iomem *ioremap(resource_size_t offset, unsigned long size)
16317 return ioremap_nocache(offset, size);
16318 }
16319
16320-extern void iounmap(volatile void __iomem *addr);
16321+extern void iounmap(const volatile void __iomem *addr);
16322
16323 extern void set_iounmap_nonlazy(void);
16324
16325@@ -194,6 +194,17 @@ extern void set_iounmap_nonlazy(void);
16326
16327 #include <linux/vmalloc.h>
16328
16329+#define ARCH_HAS_VALID_PHYS_ADDR_RANGE
16330+static inline int valid_phys_addr_range(unsigned long addr, size_t count)
16331+{
16332+ return ((addr + count + PAGE_SIZE - 1) >> PAGE_SHIFT) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
16333+}
16334+
16335+static inline int valid_mmap_phys_addr_range(unsigned long pfn, size_t count)
16336+{
16337+ return (pfn + (count >> PAGE_SHIFT)) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
16338+}
16339+
16340 /*
16341 * Convert a virtual cached pointer to an uncached pointer
16342 */
16343diff --git a/arch/x86/include/asm/irqflags.h b/arch/x86/include/asm/irqflags.h
16344index bba3cf8..06bc8da 100644
16345--- a/arch/x86/include/asm/irqflags.h
16346+++ b/arch/x86/include/asm/irqflags.h
16347@@ -141,6 +141,11 @@ static inline notrace unsigned long arch_local_irq_save(void)
16348 sti; \
16349 sysexit
16350
16351+#define GET_CR0_INTO_RDI mov %cr0, %rdi
16352+#define SET_RDI_INTO_CR0 mov %rdi, %cr0
16353+#define GET_CR3_INTO_RDI mov %cr3, %rdi
16354+#define SET_RDI_INTO_CR3 mov %rdi, %cr3
16355+
16356 #else
16357 #define INTERRUPT_RETURN iret
16358 #define ENABLE_INTERRUPTS_SYSEXIT sti; sysexit
16359diff --git a/arch/x86/include/asm/kprobes.h b/arch/x86/include/asm/kprobes.h
16360index 9454c16..e4100e3 100644
16361--- a/arch/x86/include/asm/kprobes.h
16362+++ b/arch/x86/include/asm/kprobes.h
16363@@ -38,13 +38,8 @@ typedef u8 kprobe_opcode_t;
16364 #define RELATIVEJUMP_SIZE 5
16365 #define RELATIVECALL_OPCODE 0xe8
16366 #define RELATIVE_ADDR_SIZE 4
16367-#define MAX_STACK_SIZE 64
16368-#define MIN_STACK_SIZE(ADDR) \
16369- (((MAX_STACK_SIZE) < (((unsigned long)current_thread_info()) + \
16370- THREAD_SIZE - (unsigned long)(ADDR))) \
16371- ? (MAX_STACK_SIZE) \
16372- : (((unsigned long)current_thread_info()) + \
16373- THREAD_SIZE - (unsigned long)(ADDR)))
16374+#define MAX_STACK_SIZE 64UL
16375+#define MIN_STACK_SIZE(ADDR) min(MAX_STACK_SIZE, current->thread.sp0 - (unsigned long)(ADDR))
16376
16377 #define flush_insn_slot(p) do { } while (0)
16378
16379diff --git a/arch/x86/include/asm/local.h b/arch/x86/include/asm/local.h
16380index 2d89e39..baee879 100644
16381--- a/arch/x86/include/asm/local.h
16382+++ b/arch/x86/include/asm/local.h
16383@@ -10,33 +10,97 @@ typedef struct {
16384 atomic_long_t a;
16385 } local_t;
16386
16387+typedef struct {
16388+ atomic_long_unchecked_t a;
16389+} local_unchecked_t;
16390+
16391 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
16392
16393 #define local_read(l) atomic_long_read(&(l)->a)
16394+#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
16395 #define local_set(l, i) atomic_long_set(&(l)->a, (i))
16396+#define local_set_unchecked(l, i) atomic_long_set_unchecked(&(l)->a, (i))
16397
16398 static inline void local_inc(local_t *l)
16399 {
16400- asm volatile(_ASM_INC "%0"
16401+ asm volatile(_ASM_INC "%0\n"
16402+
16403+#ifdef CONFIG_PAX_REFCOUNT
16404+ "jno 0f\n"
16405+ _ASM_DEC "%0\n"
16406+ "int $4\n0:\n"
16407+ _ASM_EXTABLE(0b, 0b)
16408+#endif
16409+
16410+ : "+m" (l->a.counter));
16411+}
16412+
16413+static inline void local_inc_unchecked(local_unchecked_t *l)
16414+{
16415+ asm volatile(_ASM_INC "%0\n"
16416 : "+m" (l->a.counter));
16417 }
16418
16419 static inline void local_dec(local_t *l)
16420 {
16421- asm volatile(_ASM_DEC "%0"
16422+ asm volatile(_ASM_DEC "%0\n"
16423+
16424+#ifdef CONFIG_PAX_REFCOUNT
16425+ "jno 0f\n"
16426+ _ASM_INC "%0\n"
16427+ "int $4\n0:\n"
16428+ _ASM_EXTABLE(0b, 0b)
16429+#endif
16430+
16431+ : "+m" (l->a.counter));
16432+}
16433+
16434+static inline void local_dec_unchecked(local_unchecked_t *l)
16435+{
16436+ asm volatile(_ASM_DEC "%0\n"
16437 : "+m" (l->a.counter));
16438 }
16439
16440 static inline void local_add(long i, local_t *l)
16441 {
16442- asm volatile(_ASM_ADD "%1,%0"
16443+ asm volatile(_ASM_ADD "%1,%0\n"
16444+
16445+#ifdef CONFIG_PAX_REFCOUNT
16446+ "jno 0f\n"
16447+ _ASM_SUB "%1,%0\n"
16448+ "int $4\n0:\n"
16449+ _ASM_EXTABLE(0b, 0b)
16450+#endif
16451+
16452+ : "+m" (l->a.counter)
16453+ : "ir" (i));
16454+}
16455+
16456+static inline void local_add_unchecked(long i, local_unchecked_t *l)
16457+{
16458+ asm volatile(_ASM_ADD "%1,%0\n"
16459 : "+m" (l->a.counter)
16460 : "ir" (i));
16461 }
16462
16463 static inline void local_sub(long i, local_t *l)
16464 {
16465- asm volatile(_ASM_SUB "%1,%0"
16466+ asm volatile(_ASM_SUB "%1,%0\n"
16467+
16468+#ifdef CONFIG_PAX_REFCOUNT
16469+ "jno 0f\n"
16470+ _ASM_ADD "%1,%0\n"
16471+ "int $4\n0:\n"
16472+ _ASM_EXTABLE(0b, 0b)
16473+#endif
16474+
16475+ : "+m" (l->a.counter)
16476+ : "ir" (i));
16477+}
16478+
16479+static inline void local_sub_unchecked(long i, local_unchecked_t *l)
16480+{
16481+ asm volatile(_ASM_SUB "%1,%0\n"
16482 : "+m" (l->a.counter)
16483 : "ir" (i));
16484 }
16485@@ -54,7 +118,16 @@ static inline int local_sub_and_test(long i, local_t *l)
16486 {
16487 unsigned char c;
16488
16489- asm volatile(_ASM_SUB "%2,%0; sete %1"
16490+ asm volatile(_ASM_SUB "%2,%0\n"
16491+
16492+#ifdef CONFIG_PAX_REFCOUNT
16493+ "jno 0f\n"
16494+ _ASM_ADD "%2,%0\n"
16495+ "int $4\n0:\n"
16496+ _ASM_EXTABLE(0b, 0b)
16497+#endif
16498+
16499+ "sete %1\n"
16500 : "+m" (l->a.counter), "=qm" (c)
16501 : "ir" (i) : "memory");
16502 return c;
16503@@ -72,7 +145,16 @@ static inline int local_dec_and_test(local_t *l)
16504 {
16505 unsigned char c;
16506
16507- asm volatile(_ASM_DEC "%0; sete %1"
16508+ asm volatile(_ASM_DEC "%0\n"
16509+
16510+#ifdef CONFIG_PAX_REFCOUNT
16511+ "jno 0f\n"
16512+ _ASM_INC "%0\n"
16513+ "int $4\n0:\n"
16514+ _ASM_EXTABLE(0b, 0b)
16515+#endif
16516+
16517+ "sete %1\n"
16518 : "+m" (l->a.counter), "=qm" (c)
16519 : : "memory");
16520 return c != 0;
16521@@ -90,7 +172,16 @@ static inline int local_inc_and_test(local_t *l)
16522 {
16523 unsigned char c;
16524
16525- asm volatile(_ASM_INC "%0; sete %1"
16526+ asm volatile(_ASM_INC "%0\n"
16527+
16528+#ifdef CONFIG_PAX_REFCOUNT
16529+ "jno 0f\n"
16530+ _ASM_DEC "%0\n"
16531+ "int $4\n0:\n"
16532+ _ASM_EXTABLE(0b, 0b)
16533+#endif
16534+
16535+ "sete %1\n"
16536 : "+m" (l->a.counter), "=qm" (c)
16537 : : "memory");
16538 return c != 0;
16539@@ -109,7 +200,16 @@ static inline int local_add_negative(long i, local_t *l)
16540 {
16541 unsigned char c;
16542
16543- asm volatile(_ASM_ADD "%2,%0; sets %1"
16544+ asm volatile(_ASM_ADD "%2,%0\n"
16545+
16546+#ifdef CONFIG_PAX_REFCOUNT
16547+ "jno 0f\n"
16548+ _ASM_SUB "%2,%0\n"
16549+ "int $4\n0:\n"
16550+ _ASM_EXTABLE(0b, 0b)
16551+#endif
16552+
16553+ "sets %1\n"
16554 : "+m" (l->a.counter), "=qm" (c)
16555 : "ir" (i) : "memory");
16556 return c;
16557@@ -125,6 +225,30 @@ static inline int local_add_negative(long i, local_t *l)
16558 static inline long local_add_return(long i, local_t *l)
16559 {
16560 long __i = i;
16561+ asm volatile(_ASM_XADD "%0, %1\n"
16562+
16563+#ifdef CONFIG_PAX_REFCOUNT
16564+ "jno 0f\n"
16565+ _ASM_MOV "%0,%1\n"
16566+ "int $4\n0:\n"
16567+ _ASM_EXTABLE(0b, 0b)
16568+#endif
16569+
16570+ : "+r" (i), "+m" (l->a.counter)
16571+ : : "memory");
16572+ return i + __i;
16573+}
16574+
16575+/**
16576+ * local_add_return_unchecked - add and return
16577+ * @i: integer value to add
16578+ * @l: pointer to type local_unchecked_t
16579+ *
16580+ * Atomically adds @i to @l and returns @i + @l
16581+ */
16582+static inline long local_add_return_unchecked(long i, local_unchecked_t *l)
16583+{
16584+ long __i = i;
16585 asm volatile(_ASM_XADD "%0, %1;"
16586 : "+r" (i), "+m" (l->a.counter)
16587 : : "memory");
16588@@ -141,6 +265,8 @@ static inline long local_sub_return(long i, local_t *l)
16589
16590 #define local_cmpxchg(l, o, n) \
16591 (cmpxchg_local(&((l)->a.counter), (o), (n)))
16592+#define local_cmpxchg_unchecked(l, o, n) \
16593+ (cmpxchg_local(&((l)->a.counter), (o), (n)))
16594 /* Always has a lock prefix */
16595 #define local_xchg(l, n) (xchg(&((l)->a.counter), (n)))
16596
16597diff --git a/arch/x86/include/asm/mman.h b/arch/x86/include/asm/mman.h
16598new file mode 100644
16599index 0000000..2bfd3ba
16600--- /dev/null
16601+++ b/arch/x86/include/asm/mman.h
16602@@ -0,0 +1,15 @@
16603+#ifndef _X86_MMAN_H
16604+#define _X86_MMAN_H
16605+
16606+#include <uapi/asm/mman.h>
16607+
16608+#ifdef __KERNEL__
16609+#ifndef __ASSEMBLY__
16610+#ifdef CONFIG_X86_32
16611+#define arch_mmap_check i386_mmap_check
16612+int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags);
16613+#endif
16614+#endif
16615+#endif
16616+
16617+#endif /* X86_MMAN_H */
16618diff --git a/arch/x86/include/asm/mmu.h b/arch/x86/include/asm/mmu.h
16619index 5f55e69..e20bfb1 100644
16620--- a/arch/x86/include/asm/mmu.h
16621+++ b/arch/x86/include/asm/mmu.h
16622@@ -9,7 +9,7 @@
16623 * we put the segment information here.
16624 */
16625 typedef struct {
16626- void *ldt;
16627+ struct desc_struct *ldt;
16628 int size;
16629
16630 #ifdef CONFIG_X86_64
16631@@ -18,7 +18,19 @@ typedef struct {
16632 #endif
16633
16634 struct mutex lock;
16635- void *vdso;
16636+ unsigned long vdso;
16637+
16638+#ifdef CONFIG_X86_32
16639+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
16640+ unsigned long user_cs_base;
16641+ unsigned long user_cs_limit;
16642+
16643+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
16644+ cpumask_t cpu_user_cs_mask;
16645+#endif
16646+
16647+#endif
16648+#endif
16649 } mm_context_t;
16650
16651 #ifdef CONFIG_SMP
16652diff --git a/arch/x86/include/asm/mmu_context.h b/arch/x86/include/asm/mmu_context.h
16653index be12c53..4d24039 100644
16654--- a/arch/x86/include/asm/mmu_context.h
16655+++ b/arch/x86/include/asm/mmu_context.h
16656@@ -24,6 +24,20 @@ void destroy_context(struct mm_struct *mm);
16657
16658 static inline void enter_lazy_tlb(struct mm_struct *mm, struct task_struct *tsk)
16659 {
16660+
16661+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
16662+ if (!(static_cpu_has(X86_FEATURE_PCID))) {
16663+ unsigned int i;
16664+ pgd_t *pgd;
16665+
16666+ pax_open_kernel();
16667+ pgd = get_cpu_pgd(smp_processor_id(), kernel);
16668+ for (i = USER_PGD_PTRS; i < 2 * USER_PGD_PTRS; ++i)
16669+ set_pgd_batched(pgd+i, native_make_pgd(0));
16670+ pax_close_kernel();
16671+ }
16672+#endif
16673+
16674 #ifdef CONFIG_SMP
16675 if (this_cpu_read(cpu_tlbstate.state) == TLBSTATE_OK)
16676 this_cpu_write(cpu_tlbstate.state, TLBSTATE_LAZY);
16677@@ -34,16 +48,59 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
16678 struct task_struct *tsk)
16679 {
16680 unsigned cpu = smp_processor_id();
16681+#if defined(CONFIG_X86_32) && defined(CONFIG_SMP) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
16682+ int tlbstate = TLBSTATE_OK;
16683+#endif
16684
16685 if (likely(prev != next)) {
16686 #ifdef CONFIG_SMP
16687+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
16688+ tlbstate = this_cpu_read(cpu_tlbstate.state);
16689+#endif
16690 this_cpu_write(cpu_tlbstate.state, TLBSTATE_OK);
16691 this_cpu_write(cpu_tlbstate.active_mm, next);
16692 #endif
16693 cpumask_set_cpu(cpu, mm_cpumask(next));
16694
16695 /* Re-load page tables */
16696+#ifdef CONFIG_PAX_PER_CPU_PGD
16697+ pax_open_kernel();
16698+
16699+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
16700+ if (static_cpu_has(X86_FEATURE_PCID))
16701+ __clone_user_pgds(get_cpu_pgd(cpu, user), next->pgd);
16702+ else
16703+#endif
16704+
16705+ __clone_user_pgds(get_cpu_pgd(cpu, kernel), next->pgd);
16706+ __shadow_user_pgds(get_cpu_pgd(cpu, kernel) + USER_PGD_PTRS, next->pgd);
16707+ pax_close_kernel();
16708+ BUG_ON((__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL) != (read_cr3() & __PHYSICAL_MASK) && (__pa(get_cpu_pgd(cpu, user)) | PCID_USER) != (read_cr3() & __PHYSICAL_MASK));
16709+
16710+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
16711+ if (static_cpu_has(X86_FEATURE_PCID)) {
16712+ if (static_cpu_has(X86_FEATURE_INVPCID)) {
16713+ u64 descriptor[2];
16714+ descriptor[0] = PCID_USER;
16715+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_CONTEXT) : "memory");
16716+ if (!static_cpu_has(X86_FEATURE_STRONGUDEREF)) {
16717+ descriptor[0] = PCID_KERNEL;
16718+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_CONTEXT) : "memory");
16719+ }
16720+ } else {
16721+ write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER);
16722+ if (static_cpu_has(X86_FEATURE_STRONGUDEREF))
16723+ write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL | PCID_NOFLUSH);
16724+ else
16725+ write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL);
16726+ }
16727+ } else
16728+#endif
16729+
16730+ load_cr3(get_cpu_pgd(cpu, kernel));
16731+#else
16732 load_cr3(next->pgd);
16733+#endif
16734
16735 /* Stop flush ipis for the previous mm */
16736 cpumask_clear_cpu(cpu, mm_cpumask(prev));
16737@@ -51,9 +108,67 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
16738 /* Load the LDT, if the LDT is different: */
16739 if (unlikely(prev->context.ldt != next->context.ldt))
16740 load_LDT_nolock(&next->context);
16741+
16742+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
16743+ if (!(__supported_pte_mask & _PAGE_NX)) {
16744+ smp_mb__before_clear_bit();
16745+ cpu_clear(cpu, prev->context.cpu_user_cs_mask);
16746+ smp_mb__after_clear_bit();
16747+ cpu_set(cpu, next->context.cpu_user_cs_mask);
16748+ }
16749+#endif
16750+
16751+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
16752+ if (unlikely(prev->context.user_cs_base != next->context.user_cs_base ||
16753+ prev->context.user_cs_limit != next->context.user_cs_limit))
16754+ set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
16755+#ifdef CONFIG_SMP
16756+ else if (unlikely(tlbstate != TLBSTATE_OK))
16757+ set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
16758+#endif
16759+#endif
16760+
16761 }
16762+ else {
16763+
16764+#ifdef CONFIG_PAX_PER_CPU_PGD
16765+ pax_open_kernel();
16766+
16767+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
16768+ if (static_cpu_has(X86_FEATURE_PCID))
16769+ __clone_user_pgds(get_cpu_pgd(cpu, user), next->pgd);
16770+ else
16771+#endif
16772+
16773+ __clone_user_pgds(get_cpu_pgd(cpu, kernel), next->pgd);
16774+ __shadow_user_pgds(get_cpu_pgd(cpu, kernel) + USER_PGD_PTRS, next->pgd);
16775+ pax_close_kernel();
16776+ BUG_ON((__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL) != (read_cr3() & __PHYSICAL_MASK) && (__pa(get_cpu_pgd(cpu, user)) | PCID_USER) != (read_cr3() & __PHYSICAL_MASK));
16777+
16778+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
16779+ if (static_cpu_has(X86_FEATURE_PCID)) {
16780+ if (static_cpu_has(X86_FEATURE_INVPCID)) {
16781+ u64 descriptor[2];
16782+ descriptor[0] = PCID_USER;
16783+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_CONTEXT) : "memory");
16784+ if (!static_cpu_has(X86_FEATURE_STRONGUDEREF)) {
16785+ descriptor[0] = PCID_KERNEL;
16786+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_CONTEXT) : "memory");
16787+ }
16788+ } else {
16789+ write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER);
16790+ if (static_cpu_has(X86_FEATURE_STRONGUDEREF))
16791+ write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL | PCID_NOFLUSH);
16792+ else
16793+ write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL);
16794+ }
16795+ } else
16796+#endif
16797+
16798+ load_cr3(get_cpu_pgd(cpu, kernel));
16799+#endif
16800+
16801 #ifdef CONFIG_SMP
16802- else {
16803 this_cpu_write(cpu_tlbstate.state, TLBSTATE_OK);
16804 BUG_ON(this_cpu_read(cpu_tlbstate.active_mm) != next);
16805
16806@@ -70,11 +185,28 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
16807 * tlb flush IPI delivery. We must reload CR3
16808 * to make sure to use no freed page tables.
16809 */
16810+
16811+#ifndef CONFIG_PAX_PER_CPU_PGD
16812 load_cr3(next->pgd);
16813+#endif
16814+
16815 load_LDT_nolock(&next->context);
16816+
16817+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
16818+ if (!(__supported_pte_mask & _PAGE_NX))
16819+ cpu_set(cpu, next->context.cpu_user_cs_mask);
16820+#endif
16821+
16822+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
16823+#ifdef CONFIG_PAX_PAGEEXEC
16824+ if (!((next->pax_flags & MF_PAX_PAGEEXEC) && (__supported_pte_mask & _PAGE_NX)))
16825+#endif
16826+ set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
16827+#endif
16828+
16829 }
16830+#endif
16831 }
16832-#endif
16833 }
16834
16835 #define activate_mm(prev, next) \
16836diff --git a/arch/x86/include/asm/module.h b/arch/x86/include/asm/module.h
16837index e3b7819..b257c64 100644
16838--- a/arch/x86/include/asm/module.h
16839+++ b/arch/x86/include/asm/module.h
16840@@ -5,6 +5,7 @@
16841
16842 #ifdef CONFIG_X86_64
16843 /* X86_64 does not define MODULE_PROC_FAMILY */
16844+#define MODULE_PROC_FAMILY ""
16845 #elif defined CONFIG_M486
16846 #define MODULE_PROC_FAMILY "486 "
16847 #elif defined CONFIG_M586
16848@@ -57,8 +58,20 @@
16849 #error unknown processor family
16850 #endif
16851
16852-#ifdef CONFIG_X86_32
16853-# define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY
16854+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
16855+#define MODULE_PAX_KERNEXEC "KERNEXEC_BTS "
16856+#elif defined(CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR)
16857+#define MODULE_PAX_KERNEXEC "KERNEXEC_OR "
16858+#else
16859+#define MODULE_PAX_KERNEXEC ""
16860 #endif
16861
16862+#ifdef CONFIG_PAX_MEMORY_UDEREF
16863+#define MODULE_PAX_UDEREF "UDEREF "
16864+#else
16865+#define MODULE_PAX_UDEREF ""
16866+#endif
16867+
16868+#define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY MODULE_PAX_KERNEXEC MODULE_PAX_UDEREF
16869+
16870 #endif /* _ASM_X86_MODULE_H */
16871diff --git a/arch/x86/include/asm/nmi.h b/arch/x86/include/asm/nmi.h
16872index 86f9301..b365cda 100644
16873--- a/arch/x86/include/asm/nmi.h
16874+++ b/arch/x86/include/asm/nmi.h
16875@@ -40,11 +40,11 @@ struct nmiaction {
16876 nmi_handler_t handler;
16877 unsigned long flags;
16878 const char *name;
16879-};
16880+} __do_const;
16881
16882 #define register_nmi_handler(t, fn, fg, n, init...) \
16883 ({ \
16884- static struct nmiaction init fn##_na = { \
16885+ static const struct nmiaction init fn##_na = { \
16886 .handler = (fn), \
16887 .name = (n), \
16888 .flags = (fg), \
16889@@ -52,7 +52,7 @@ struct nmiaction {
16890 __register_nmi_handler((t), &fn##_na); \
16891 })
16892
16893-int __register_nmi_handler(unsigned int, struct nmiaction *);
16894+int __register_nmi_handler(unsigned int, const struct nmiaction *);
16895
16896 void unregister_nmi_handler(unsigned int, const char *);
16897
16898diff --git a/arch/x86/include/asm/page.h b/arch/x86/include/asm/page.h
16899index c878924..21f4889 100644
16900--- a/arch/x86/include/asm/page.h
16901+++ b/arch/x86/include/asm/page.h
16902@@ -52,6 +52,7 @@ static inline void copy_user_page(void *to, void *from, unsigned long vaddr,
16903 __phys_addr_symbol(__phys_reloc_hide((unsigned long)(x)))
16904
16905 #define __va(x) ((void *)((unsigned long)(x)+PAGE_OFFSET))
16906+#define __early_va(x) ((void *)((unsigned long)(x)+__START_KERNEL_map - phys_base))
16907
16908 #define __boot_va(x) __va(x)
16909 #define __boot_pa(x) __pa(x)
16910diff --git a/arch/x86/include/asm/page_64.h b/arch/x86/include/asm/page_64.h
16911index 0f1ddee..e2fc3d1 100644
16912--- a/arch/x86/include/asm/page_64.h
16913+++ b/arch/x86/include/asm/page_64.h
16914@@ -7,9 +7,9 @@
16915
16916 /* duplicated to the one in bootmem.h */
16917 extern unsigned long max_pfn;
16918-extern unsigned long phys_base;
16919+extern const unsigned long phys_base;
16920
16921-static inline unsigned long __phys_addr_nodebug(unsigned long x)
16922+static inline unsigned long __intentional_overflow(-1) __phys_addr_nodebug(unsigned long x)
16923 {
16924 unsigned long y = x - __START_KERNEL_map;
16925
16926diff --git a/arch/x86/include/asm/paravirt.h b/arch/x86/include/asm/paravirt.h
16927index 401f350..dee5d13 100644
16928--- a/arch/x86/include/asm/paravirt.h
16929+++ b/arch/x86/include/asm/paravirt.h
16930@@ -560,7 +560,7 @@ static inline pmd_t __pmd(pmdval_t val)
16931 return (pmd_t) { ret };
16932 }
16933
16934-static inline pmdval_t pmd_val(pmd_t pmd)
16935+static inline __intentional_overflow(-1) pmdval_t pmd_val(pmd_t pmd)
16936 {
16937 pmdval_t ret;
16938
16939@@ -626,6 +626,18 @@ static inline void set_pgd(pgd_t *pgdp, pgd_t pgd)
16940 val);
16941 }
16942
16943+static inline void set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
16944+{
16945+ pgdval_t val = native_pgd_val(pgd);
16946+
16947+ if (sizeof(pgdval_t) > sizeof(long))
16948+ PVOP_VCALL3(pv_mmu_ops.set_pgd_batched, pgdp,
16949+ val, (u64)val >> 32);
16950+ else
16951+ PVOP_VCALL2(pv_mmu_ops.set_pgd_batched, pgdp,
16952+ val);
16953+}
16954+
16955 static inline void pgd_clear(pgd_t *pgdp)
16956 {
16957 set_pgd(pgdp, __pgd(0));
16958@@ -710,6 +722,21 @@ static inline void __set_fixmap(unsigned /* enum fixed_addresses */ idx,
16959 pv_mmu_ops.set_fixmap(idx, phys, flags);
16960 }
16961
16962+#ifdef CONFIG_PAX_KERNEXEC
16963+static inline unsigned long pax_open_kernel(void)
16964+{
16965+ return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_open_kernel);
16966+}
16967+
16968+static inline unsigned long pax_close_kernel(void)
16969+{
16970+ return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_close_kernel);
16971+}
16972+#else
16973+static inline unsigned long pax_open_kernel(void) { return 0; }
16974+static inline unsigned long pax_close_kernel(void) { return 0; }
16975+#endif
16976+
16977 #if defined(CONFIG_SMP) && defined(CONFIG_PARAVIRT_SPINLOCKS)
16978
16979 static __always_inline void __ticket_lock_spinning(struct arch_spinlock *lock,
16980@@ -906,7 +933,7 @@ extern void default_banner(void);
16981
16982 #define PARA_PATCH(struct, off) ((PARAVIRT_PATCH_##struct + (off)) / 4)
16983 #define PARA_SITE(ptype, clobbers, ops) _PVSITE(ptype, clobbers, ops, .long, 4)
16984-#define PARA_INDIRECT(addr) *%cs:addr
16985+#define PARA_INDIRECT(addr) *%ss:addr
16986 #endif
16987
16988 #define INTERRUPT_RETURN \
16989@@ -981,6 +1008,21 @@ extern void default_banner(void);
16990 PARA_SITE(PARA_PATCH(pv_cpu_ops, PV_CPU_irq_enable_sysexit), \
16991 CLBR_NONE, \
16992 jmp PARA_INDIRECT(pv_cpu_ops+PV_CPU_irq_enable_sysexit))
16993+
16994+#define GET_CR0_INTO_RDI \
16995+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0); \
16996+ mov %rax,%rdi
16997+
16998+#define SET_RDI_INTO_CR0 \
16999+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
17000+
17001+#define GET_CR3_INTO_RDI \
17002+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_read_cr3); \
17003+ mov %rax,%rdi
17004+
17005+#define SET_RDI_INTO_CR3 \
17006+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_write_cr3)
17007+
17008 #endif /* CONFIG_X86_32 */
17009
17010 #endif /* __ASSEMBLY__ */
17011diff --git a/arch/x86/include/asm/paravirt_types.h b/arch/x86/include/asm/paravirt_types.h
17012index aab8f67..0fb0ee4 100644
17013--- a/arch/x86/include/asm/paravirt_types.h
17014+++ b/arch/x86/include/asm/paravirt_types.h
17015@@ -84,7 +84,7 @@ struct pv_init_ops {
17016 */
17017 unsigned (*patch)(u8 type, u16 clobber, void *insnbuf,
17018 unsigned long addr, unsigned len);
17019-};
17020+} __no_const __no_randomize_layout;
17021
17022
17023 struct pv_lazy_ops {
17024@@ -92,13 +92,13 @@ struct pv_lazy_ops {
17025 void (*enter)(void);
17026 void (*leave)(void);
17027 void (*flush)(void);
17028-};
17029+} __no_randomize_layout;
17030
17031 struct pv_time_ops {
17032 unsigned long long (*sched_clock)(void);
17033 unsigned long long (*steal_clock)(int cpu);
17034 unsigned long (*get_tsc_khz)(void);
17035-};
17036+} __no_const __no_randomize_layout;
17037
17038 struct pv_cpu_ops {
17039 /* hooks for various privileged instructions */
17040@@ -192,7 +192,7 @@ struct pv_cpu_ops {
17041
17042 void (*start_context_switch)(struct task_struct *prev);
17043 void (*end_context_switch)(struct task_struct *next);
17044-};
17045+} __no_const __no_randomize_layout;
17046
17047 struct pv_irq_ops {
17048 /*
17049@@ -215,7 +215,7 @@ struct pv_irq_ops {
17050 #ifdef CONFIG_X86_64
17051 void (*adjust_exception_frame)(void);
17052 #endif
17053-};
17054+} __no_randomize_layout;
17055
17056 struct pv_apic_ops {
17057 #ifdef CONFIG_X86_LOCAL_APIC
17058@@ -223,7 +223,7 @@ struct pv_apic_ops {
17059 unsigned long start_eip,
17060 unsigned long start_esp);
17061 #endif
17062-};
17063+} __no_const __no_randomize_layout;
17064
17065 struct pv_mmu_ops {
17066 unsigned long (*read_cr2)(void);
17067@@ -313,6 +313,7 @@ struct pv_mmu_ops {
17068 struct paravirt_callee_save make_pud;
17069
17070 void (*set_pgd)(pgd_t *pudp, pgd_t pgdval);
17071+ void (*set_pgd_batched)(pgd_t *pudp, pgd_t pgdval);
17072 #endif /* PAGETABLE_LEVELS == 4 */
17073 #endif /* PAGETABLE_LEVELS >= 3 */
17074
17075@@ -324,7 +325,13 @@ struct pv_mmu_ops {
17076 an mfn. We can tell which is which from the index. */
17077 void (*set_fixmap)(unsigned /* enum fixed_addresses */ idx,
17078 phys_addr_t phys, pgprot_t flags);
17079-};
17080+
17081+#ifdef CONFIG_PAX_KERNEXEC
17082+ unsigned long (*pax_open_kernel)(void);
17083+ unsigned long (*pax_close_kernel)(void);
17084+#endif
17085+
17086+} __no_randomize_layout;
17087
17088 struct arch_spinlock;
17089 #ifdef CONFIG_SMP
17090@@ -336,11 +343,14 @@ typedef u16 __ticket_t;
17091 struct pv_lock_ops {
17092 struct paravirt_callee_save lock_spinning;
17093 void (*unlock_kick)(struct arch_spinlock *lock, __ticket_t ticket);
17094-};
17095+} __no_randomize_layout;
17096
17097 /* This contains all the paravirt structures: we get a convenient
17098 * number for each function using the offset which we use to indicate
17099- * what to patch. */
17100+ * what to patch.
17101+ * shouldn't be randomized due to the "NEAT TRICK" in paravirt.c
17102+ */
17103+
17104 struct paravirt_patch_template {
17105 struct pv_init_ops pv_init_ops;
17106 struct pv_time_ops pv_time_ops;
17107@@ -349,7 +359,7 @@ struct paravirt_patch_template {
17108 struct pv_apic_ops pv_apic_ops;
17109 struct pv_mmu_ops pv_mmu_ops;
17110 struct pv_lock_ops pv_lock_ops;
17111-};
17112+} __no_randomize_layout;
17113
17114 extern struct pv_info pv_info;
17115 extern struct pv_init_ops pv_init_ops;
17116diff --git a/arch/x86/include/asm/pgalloc.h b/arch/x86/include/asm/pgalloc.h
17117index b4389a4..7024269 100644
17118--- a/arch/x86/include/asm/pgalloc.h
17119+++ b/arch/x86/include/asm/pgalloc.h
17120@@ -63,6 +63,13 @@ static inline void pmd_populate_kernel(struct mm_struct *mm,
17121 pmd_t *pmd, pte_t *pte)
17122 {
17123 paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
17124+ set_pmd(pmd, __pmd(__pa(pte) | _KERNPG_TABLE));
17125+}
17126+
17127+static inline void pmd_populate_user(struct mm_struct *mm,
17128+ pmd_t *pmd, pte_t *pte)
17129+{
17130+ paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
17131 set_pmd(pmd, __pmd(__pa(pte) | _PAGE_TABLE));
17132 }
17133
17134@@ -99,12 +106,22 @@ static inline void __pmd_free_tlb(struct mmu_gather *tlb, pmd_t *pmd,
17135
17136 #ifdef CONFIG_X86_PAE
17137 extern void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd);
17138+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
17139+{
17140+ pud_populate(mm, pudp, pmd);
17141+}
17142 #else /* !CONFIG_X86_PAE */
17143 static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
17144 {
17145 paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
17146 set_pud(pud, __pud(_PAGE_TABLE | __pa(pmd)));
17147 }
17148+
17149+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
17150+{
17151+ paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
17152+ set_pud(pud, __pud(_KERNPG_TABLE | __pa(pmd)));
17153+}
17154 #endif /* CONFIG_X86_PAE */
17155
17156 #if PAGETABLE_LEVELS > 3
17157@@ -114,6 +131,12 @@ static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
17158 set_pgd(pgd, __pgd(_PAGE_TABLE | __pa(pud)));
17159 }
17160
17161+static inline void pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
17162+{
17163+ paravirt_alloc_pud(mm, __pa(pud) >> PAGE_SHIFT);
17164+ set_pgd(pgd, __pgd(_KERNPG_TABLE | __pa(pud)));
17165+}
17166+
17167 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
17168 {
17169 return (pud_t *)get_zeroed_page(GFP_KERNEL|__GFP_REPEAT);
17170diff --git a/arch/x86/include/asm/pgtable-2level.h b/arch/x86/include/asm/pgtable-2level.h
17171index 3bf2dd0..23d2a9f 100644
17172--- a/arch/x86/include/asm/pgtable-2level.h
17173+++ b/arch/x86/include/asm/pgtable-2level.h
17174@@ -18,7 +18,9 @@ static inline void native_set_pte(pte_t *ptep , pte_t pte)
17175
17176 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
17177 {
17178+ pax_open_kernel();
17179 *pmdp = pmd;
17180+ pax_close_kernel();
17181 }
17182
17183 static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
17184diff --git a/arch/x86/include/asm/pgtable-3level.h b/arch/x86/include/asm/pgtable-3level.h
17185index 81bb91b..9392125 100644
17186--- a/arch/x86/include/asm/pgtable-3level.h
17187+++ b/arch/x86/include/asm/pgtable-3level.h
17188@@ -92,12 +92,16 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
17189
17190 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
17191 {
17192+ pax_open_kernel();
17193 set_64bit((unsigned long long *)(pmdp), native_pmd_val(pmd));
17194+ pax_close_kernel();
17195 }
17196
17197 static inline void native_set_pud(pud_t *pudp, pud_t pud)
17198 {
17199+ pax_open_kernel();
17200 set_64bit((unsigned long long *)(pudp), native_pud_val(pud));
17201+ pax_close_kernel();
17202 }
17203
17204 /*
17205diff --git a/arch/x86/include/asm/pgtable.h b/arch/x86/include/asm/pgtable.h
17206index bbc8b12..f228861 100644
17207--- a/arch/x86/include/asm/pgtable.h
17208+++ b/arch/x86/include/asm/pgtable.h
17209@@ -45,6 +45,7 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
17210
17211 #ifndef __PAGETABLE_PUD_FOLDED
17212 #define set_pgd(pgdp, pgd) native_set_pgd(pgdp, pgd)
17213+#define set_pgd_batched(pgdp, pgd) native_set_pgd_batched(pgdp, pgd)
17214 #define pgd_clear(pgd) native_pgd_clear(pgd)
17215 #endif
17216
17217@@ -82,12 +83,51 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
17218
17219 #define arch_end_context_switch(prev) do {} while(0)
17220
17221+#define pax_open_kernel() native_pax_open_kernel()
17222+#define pax_close_kernel() native_pax_close_kernel()
17223 #endif /* CONFIG_PARAVIRT */
17224
17225+#define __HAVE_ARCH_PAX_OPEN_KERNEL
17226+#define __HAVE_ARCH_PAX_CLOSE_KERNEL
17227+
17228+#ifdef CONFIG_PAX_KERNEXEC
17229+static inline unsigned long native_pax_open_kernel(void)
17230+{
17231+ unsigned long cr0;
17232+
17233+ preempt_disable();
17234+ barrier();
17235+ cr0 = read_cr0() ^ X86_CR0_WP;
17236+ BUG_ON(cr0 & X86_CR0_WP);
17237+ write_cr0(cr0);
17238+ return cr0 ^ X86_CR0_WP;
17239+}
17240+
17241+static inline unsigned long native_pax_close_kernel(void)
17242+{
17243+ unsigned long cr0;
17244+
17245+ cr0 = read_cr0() ^ X86_CR0_WP;
17246+ BUG_ON(!(cr0 & X86_CR0_WP));
17247+ write_cr0(cr0);
17248+ barrier();
17249+ preempt_enable_no_resched();
17250+ return cr0 ^ X86_CR0_WP;
17251+}
17252+#else
17253+static inline unsigned long native_pax_open_kernel(void) { return 0; }
17254+static inline unsigned long native_pax_close_kernel(void) { return 0; }
17255+#endif
17256+
17257 /*
17258 * The following only work if pte_present() is true.
17259 * Undefined behaviour if not..
17260 */
17261+static inline int pte_user(pte_t pte)
17262+{
17263+ return pte_val(pte) & _PAGE_USER;
17264+}
17265+
17266 static inline int pte_dirty(pte_t pte)
17267 {
17268 return pte_flags(pte) & _PAGE_DIRTY;
17269@@ -148,6 +188,11 @@ static inline unsigned long pud_pfn(pud_t pud)
17270 return (pud_val(pud) & PTE_PFN_MASK) >> PAGE_SHIFT;
17271 }
17272
17273+static inline unsigned long pgd_pfn(pgd_t pgd)
17274+{
17275+ return (pgd_val(pgd) & PTE_PFN_MASK) >> PAGE_SHIFT;
17276+}
17277+
17278 #define pte_page(pte) pfn_to_page(pte_pfn(pte))
17279
17280 static inline int pmd_large(pmd_t pte)
17281@@ -201,9 +246,29 @@ static inline pte_t pte_wrprotect(pte_t pte)
17282 return pte_clear_flags(pte, _PAGE_RW);
17283 }
17284
17285+static inline pte_t pte_mkread(pte_t pte)
17286+{
17287+ return __pte(pte_val(pte) | _PAGE_USER);
17288+}
17289+
17290 static inline pte_t pte_mkexec(pte_t pte)
17291 {
17292- return pte_clear_flags(pte, _PAGE_NX);
17293+#ifdef CONFIG_X86_PAE
17294+ if (__supported_pte_mask & _PAGE_NX)
17295+ return pte_clear_flags(pte, _PAGE_NX);
17296+ else
17297+#endif
17298+ return pte_set_flags(pte, _PAGE_USER);
17299+}
17300+
17301+static inline pte_t pte_exprotect(pte_t pte)
17302+{
17303+#ifdef CONFIG_X86_PAE
17304+ if (__supported_pte_mask & _PAGE_NX)
17305+ return pte_set_flags(pte, _PAGE_NX);
17306+ else
17307+#endif
17308+ return pte_clear_flags(pte, _PAGE_USER);
17309 }
17310
17311 static inline pte_t pte_mkdirty(pte_t pte)
17312@@ -430,6 +495,16 @@ pte_t *populate_extra_pte(unsigned long vaddr);
17313 #endif
17314
17315 #ifndef __ASSEMBLY__
17316+
17317+#ifdef CONFIG_PAX_PER_CPU_PGD
17318+extern pgd_t cpu_pgd[NR_CPUS][2][PTRS_PER_PGD];
17319+enum cpu_pgd_type {kernel = 0, user = 1};
17320+static inline pgd_t *get_cpu_pgd(unsigned int cpu, enum cpu_pgd_type type)
17321+{
17322+ return cpu_pgd[cpu][type];
17323+}
17324+#endif
17325+
17326 #include <linux/mm_types.h>
17327 #include <linux/mmdebug.h>
17328 #include <linux/log2.h>
17329@@ -570,7 +645,7 @@ static inline unsigned long pud_page_vaddr(pud_t pud)
17330 * Currently stuck as a macro due to indirect forward reference to
17331 * linux/mmzone.h's __section_mem_map_addr() definition:
17332 */
17333-#define pud_page(pud) pfn_to_page(pud_val(pud) >> PAGE_SHIFT)
17334+#define pud_page(pud) pfn_to_page((pud_val(pud) & PTE_PFN_MASK) >> PAGE_SHIFT)
17335
17336 /* Find an entry in the second-level page table.. */
17337 static inline pmd_t *pmd_offset(pud_t *pud, unsigned long address)
17338@@ -610,7 +685,7 @@ static inline unsigned long pgd_page_vaddr(pgd_t pgd)
17339 * Currently stuck as a macro due to indirect forward reference to
17340 * linux/mmzone.h's __section_mem_map_addr() definition:
17341 */
17342-#define pgd_page(pgd) pfn_to_page(pgd_val(pgd) >> PAGE_SHIFT)
17343+#define pgd_page(pgd) pfn_to_page((pgd_val(pgd) & PTE_PFN_MASK) >> PAGE_SHIFT)
17344
17345 /* to find an entry in a page-table-directory. */
17346 static inline unsigned long pud_index(unsigned long address)
17347@@ -625,7 +700,7 @@ static inline pud_t *pud_offset(pgd_t *pgd, unsigned long address)
17348
17349 static inline int pgd_bad(pgd_t pgd)
17350 {
17351- return (pgd_flags(pgd) & ~_PAGE_USER) != _KERNPG_TABLE;
17352+ return (pgd_flags(pgd) & ~(_PAGE_USER | _PAGE_NX)) != _KERNPG_TABLE;
17353 }
17354
17355 static inline int pgd_none(pgd_t pgd)
17356@@ -648,7 +723,12 @@ static inline int pgd_none(pgd_t pgd)
17357 * pgd_offset() returns a (pgd_t *)
17358 * pgd_index() is used get the offset into the pgd page's array of pgd_t's;
17359 */
17360-#define pgd_offset(mm, address) ((mm)->pgd + pgd_index((address)))
17361+#define pgd_offset(mm, address) ((mm)->pgd + pgd_index(address))
17362+
17363+#ifdef CONFIG_PAX_PER_CPU_PGD
17364+#define pgd_offset_cpu(cpu, type, address) (get_cpu_pgd(cpu, type) + pgd_index(address))
17365+#endif
17366+
17367 /*
17368 * a shortcut which implies the use of the kernel's pgd, instead
17369 * of a process's
17370@@ -659,6 +739,23 @@ static inline int pgd_none(pgd_t pgd)
17371 #define KERNEL_PGD_BOUNDARY pgd_index(PAGE_OFFSET)
17372 #define KERNEL_PGD_PTRS (PTRS_PER_PGD - KERNEL_PGD_BOUNDARY)
17373
17374+#ifdef CONFIG_X86_32
17375+#define USER_PGD_PTRS KERNEL_PGD_BOUNDARY
17376+#else
17377+#define TASK_SIZE_MAX_SHIFT CONFIG_TASK_SIZE_MAX_SHIFT
17378+#define USER_PGD_PTRS (_AC(1,UL) << (TASK_SIZE_MAX_SHIFT - PGDIR_SHIFT))
17379+
17380+#ifdef CONFIG_PAX_MEMORY_UDEREF
17381+#ifdef __ASSEMBLY__
17382+#define pax_user_shadow_base pax_user_shadow_base(%rip)
17383+#else
17384+extern unsigned long pax_user_shadow_base;
17385+extern pgdval_t clone_pgd_mask;
17386+#endif
17387+#endif
17388+
17389+#endif
17390+
17391 #ifndef __ASSEMBLY__
17392
17393 extern int direct_gbpages;
17394@@ -825,11 +922,24 @@ static inline void pmdp_set_wrprotect(struct mm_struct *mm,
17395 * dst and src can be on the same page, but the range must not overlap,
17396 * and must not cross a page boundary.
17397 */
17398-static inline void clone_pgd_range(pgd_t *dst, pgd_t *src, int count)
17399+static inline void clone_pgd_range(pgd_t *dst, const pgd_t *src, int count)
17400 {
17401- memcpy(dst, src, count * sizeof(pgd_t));
17402+ pax_open_kernel();
17403+ while (count--)
17404+ *dst++ = *src++;
17405+ pax_close_kernel();
17406 }
17407
17408+#ifdef CONFIG_PAX_PER_CPU_PGD
17409+extern void __clone_user_pgds(pgd_t *dst, const pgd_t *src);
17410+#endif
17411+
17412+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17413+extern void __shadow_user_pgds(pgd_t *dst, const pgd_t *src);
17414+#else
17415+static inline void __shadow_user_pgds(pgd_t *dst, const pgd_t *src) {}
17416+#endif
17417+
17418 #define PTE_SHIFT ilog2(PTRS_PER_PTE)
17419 static inline int page_level_shift(enum pg_level level)
17420 {
17421diff --git a/arch/x86/include/asm/pgtable_32.h b/arch/x86/include/asm/pgtable_32.h
17422index 9ee3221..b979c6b 100644
17423--- a/arch/x86/include/asm/pgtable_32.h
17424+++ b/arch/x86/include/asm/pgtable_32.h
17425@@ -25,9 +25,6 @@
17426 struct mm_struct;
17427 struct vm_area_struct;
17428
17429-extern pgd_t swapper_pg_dir[1024];
17430-extern pgd_t initial_page_table[1024];
17431-
17432 static inline void pgtable_cache_init(void) { }
17433 static inline void check_pgt_cache(void) { }
17434 void paging_init(void);
17435@@ -48,6 +45,12 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
17436 # include <asm/pgtable-2level.h>
17437 #endif
17438
17439+extern pgd_t swapper_pg_dir[PTRS_PER_PGD];
17440+extern pgd_t initial_page_table[PTRS_PER_PGD];
17441+#ifdef CONFIG_X86_PAE
17442+extern pmd_t swapper_pm_dir[PTRS_PER_PGD][PTRS_PER_PMD];
17443+#endif
17444+
17445 #if defined(CONFIG_HIGHPTE)
17446 #define pte_offset_map(dir, address) \
17447 ((pte_t *)kmap_atomic(pmd_page(*(dir))) + \
17448@@ -62,12 +65,17 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
17449 /* Clear a kernel PTE and flush it from the TLB */
17450 #define kpte_clear_flush(ptep, vaddr) \
17451 do { \
17452+ pax_open_kernel(); \
17453 pte_clear(&init_mm, (vaddr), (ptep)); \
17454+ pax_close_kernel(); \
17455 __flush_tlb_one((vaddr)); \
17456 } while (0)
17457
17458 #endif /* !__ASSEMBLY__ */
17459
17460+#define HAVE_ARCH_UNMAPPED_AREA
17461+#define HAVE_ARCH_UNMAPPED_AREA_TOPDOWN
17462+
17463 /*
17464 * kern_addr_valid() is (1) for FLATMEM and (0) for
17465 * SPARSEMEM and DISCONTIGMEM
17466diff --git a/arch/x86/include/asm/pgtable_32_types.h b/arch/x86/include/asm/pgtable_32_types.h
17467index ed5903b..c7fe163 100644
17468--- a/arch/x86/include/asm/pgtable_32_types.h
17469+++ b/arch/x86/include/asm/pgtable_32_types.h
17470@@ -8,7 +8,7 @@
17471 */
17472 #ifdef CONFIG_X86_PAE
17473 # include <asm/pgtable-3level_types.h>
17474-# define PMD_SIZE (1UL << PMD_SHIFT)
17475+# define PMD_SIZE (_AC(1, UL) << PMD_SHIFT)
17476 # define PMD_MASK (~(PMD_SIZE - 1))
17477 #else
17478 # include <asm/pgtable-2level_types.h>
17479@@ -46,6 +46,19 @@ extern bool __vmalloc_start_set; /* set once high_memory is set */
17480 # define VMALLOC_END (FIXADDR_START - 2 * PAGE_SIZE)
17481 #endif
17482
17483+#ifdef CONFIG_PAX_KERNEXEC
17484+#ifndef __ASSEMBLY__
17485+extern unsigned char MODULES_EXEC_VADDR[];
17486+extern unsigned char MODULES_EXEC_END[];
17487+#endif
17488+#include <asm/boot.h>
17489+#define ktla_ktva(addr) (addr + LOAD_PHYSICAL_ADDR + PAGE_OFFSET)
17490+#define ktva_ktla(addr) (addr - LOAD_PHYSICAL_ADDR - PAGE_OFFSET)
17491+#else
17492+#define ktla_ktva(addr) (addr)
17493+#define ktva_ktla(addr) (addr)
17494+#endif
17495+
17496 #define MODULES_VADDR VMALLOC_START
17497 #define MODULES_END VMALLOC_END
17498 #define MODULES_LEN (MODULES_VADDR - MODULES_END)
17499diff --git a/arch/x86/include/asm/pgtable_64.h b/arch/x86/include/asm/pgtable_64.h
17500index e22c1db..23a625a 100644
17501--- a/arch/x86/include/asm/pgtable_64.h
17502+++ b/arch/x86/include/asm/pgtable_64.h
17503@@ -16,10 +16,14 @@
17504
17505 extern pud_t level3_kernel_pgt[512];
17506 extern pud_t level3_ident_pgt[512];
17507+extern pud_t level3_vmalloc_start_pgt[512];
17508+extern pud_t level3_vmalloc_end_pgt[512];
17509+extern pud_t level3_vmemmap_pgt[512];
17510+extern pud_t level2_vmemmap_pgt[512];
17511 extern pmd_t level2_kernel_pgt[512];
17512 extern pmd_t level2_fixmap_pgt[512];
17513-extern pmd_t level2_ident_pgt[512];
17514-extern pgd_t init_level4_pgt[];
17515+extern pmd_t level2_ident_pgt[512*2];
17516+extern pgd_t init_level4_pgt[512];
17517
17518 #define swapper_pg_dir init_level4_pgt
17519
17520@@ -61,7 +65,9 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
17521
17522 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
17523 {
17524+ pax_open_kernel();
17525 *pmdp = pmd;
17526+ pax_close_kernel();
17527 }
17528
17529 static inline void native_pmd_clear(pmd_t *pmd)
17530@@ -97,7 +103,9 @@ static inline pmd_t native_pmdp_get_and_clear(pmd_t *xp)
17531
17532 static inline void native_set_pud(pud_t *pudp, pud_t pud)
17533 {
17534+ pax_open_kernel();
17535 *pudp = pud;
17536+ pax_close_kernel();
17537 }
17538
17539 static inline void native_pud_clear(pud_t *pud)
17540@@ -107,6 +115,13 @@ static inline void native_pud_clear(pud_t *pud)
17541
17542 static inline void native_set_pgd(pgd_t *pgdp, pgd_t pgd)
17543 {
17544+ pax_open_kernel();
17545+ *pgdp = pgd;
17546+ pax_close_kernel();
17547+}
17548+
17549+static inline void native_set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
17550+{
17551 *pgdp = pgd;
17552 }
17553
17554diff --git a/arch/x86/include/asm/pgtable_64_types.h b/arch/x86/include/asm/pgtable_64_types.h
17555index 2d88344..4679fc3 100644
17556--- a/arch/x86/include/asm/pgtable_64_types.h
17557+++ b/arch/x86/include/asm/pgtable_64_types.h
17558@@ -61,6 +61,11 @@ typedef struct { pteval_t pte; } pte_t;
17559 #define MODULES_VADDR _AC(0xffffffffa0000000, UL)
17560 #define MODULES_END _AC(0xffffffffff000000, UL)
17561 #define MODULES_LEN (MODULES_END - MODULES_VADDR)
17562+#define MODULES_EXEC_VADDR MODULES_VADDR
17563+#define MODULES_EXEC_END MODULES_END
17564+
17565+#define ktla_ktva(addr) (addr)
17566+#define ktva_ktla(addr) (addr)
17567
17568 #define EARLY_DYNAMIC_PAGE_TABLES 64
17569
17570diff --git a/arch/x86/include/asm/pgtable_types.h b/arch/x86/include/asm/pgtable_types.h
17571index 0ecac25..306c276 100644
17572--- a/arch/x86/include/asm/pgtable_types.h
17573+++ b/arch/x86/include/asm/pgtable_types.h
17574@@ -16,13 +16,12 @@
17575 #define _PAGE_BIT_PSE 7 /* 4 MB (or 2MB) page */
17576 #define _PAGE_BIT_PAT 7 /* on 4KB pages */
17577 #define _PAGE_BIT_GLOBAL 8 /* Global TLB entry PPro+ */
17578-#define _PAGE_BIT_UNUSED1 9 /* available for programmer */
17579+#define _PAGE_BIT_SPECIAL 9 /* special mappings, no associated struct page */
17580 #define _PAGE_BIT_IOMAP 10 /* flag used to indicate IO mapping */
17581 #define _PAGE_BIT_HIDDEN 11 /* hidden by kmemcheck */
17582 #define _PAGE_BIT_PAT_LARGE 12 /* On 2MB or 1GB pages */
17583-#define _PAGE_BIT_SPECIAL _PAGE_BIT_UNUSED1
17584-#define _PAGE_BIT_CPA_TEST _PAGE_BIT_UNUSED1
17585-#define _PAGE_BIT_SPLITTING _PAGE_BIT_UNUSED1 /* only valid on a PSE pmd */
17586+#define _PAGE_BIT_CPA_TEST _PAGE_BIT_SPECIAL
17587+#define _PAGE_BIT_SPLITTING _PAGE_BIT_SPECIAL /* only valid on a PSE pmd */
17588 #define _PAGE_BIT_NX 63 /* No execute: only valid after cpuid check */
17589
17590 /* If _PAGE_BIT_PRESENT is clear, we use these: */
17591@@ -40,7 +39,6 @@
17592 #define _PAGE_DIRTY (_AT(pteval_t, 1) << _PAGE_BIT_DIRTY)
17593 #define _PAGE_PSE (_AT(pteval_t, 1) << _PAGE_BIT_PSE)
17594 #define _PAGE_GLOBAL (_AT(pteval_t, 1) << _PAGE_BIT_GLOBAL)
17595-#define _PAGE_UNUSED1 (_AT(pteval_t, 1) << _PAGE_BIT_UNUSED1)
17596 #define _PAGE_IOMAP (_AT(pteval_t, 1) << _PAGE_BIT_IOMAP)
17597 #define _PAGE_PAT (_AT(pteval_t, 1) << _PAGE_BIT_PAT)
17598 #define _PAGE_PAT_LARGE (_AT(pteval_t, 1) << _PAGE_BIT_PAT_LARGE)
17599@@ -87,8 +85,10 @@
17600
17601 #if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
17602 #define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_NX)
17603-#else
17604+#elif defined(CONFIG_KMEMCHECK)
17605 #define _PAGE_NX (_AT(pteval_t, 0))
17606+#else
17607+#define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_HIDDEN)
17608 #endif
17609
17610 #define _PAGE_FILE (_AT(pteval_t, 1) << _PAGE_BIT_FILE)
17611@@ -146,6 +146,9 @@
17612 #define PAGE_READONLY_EXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | \
17613 _PAGE_ACCESSED)
17614
17615+#define PAGE_READONLY_NOEXEC PAGE_READONLY
17616+#define PAGE_SHARED_NOEXEC PAGE_SHARED
17617+
17618 #define __PAGE_KERNEL_EXEC \
17619 (_PAGE_PRESENT | _PAGE_RW | _PAGE_DIRTY | _PAGE_ACCESSED | _PAGE_GLOBAL)
17620 #define __PAGE_KERNEL (__PAGE_KERNEL_EXEC | _PAGE_NX)
17621@@ -156,7 +159,7 @@
17622 #define __PAGE_KERNEL_WC (__PAGE_KERNEL | _PAGE_CACHE_WC)
17623 #define __PAGE_KERNEL_NOCACHE (__PAGE_KERNEL | _PAGE_PCD | _PAGE_PWT)
17624 #define __PAGE_KERNEL_UC_MINUS (__PAGE_KERNEL | _PAGE_PCD)
17625-#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RX | _PAGE_USER)
17626+#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RO | _PAGE_USER)
17627 #define __PAGE_KERNEL_VVAR (__PAGE_KERNEL_RO | _PAGE_USER)
17628 #define __PAGE_KERNEL_VVAR_NOCACHE (__PAGE_KERNEL_VVAR | _PAGE_PCD | _PAGE_PWT)
17629 #define __PAGE_KERNEL_LARGE (__PAGE_KERNEL | _PAGE_PSE)
17630@@ -218,8 +221,8 @@
17631 * bits are combined, this will alow user to access the high address mapped
17632 * VDSO in the presence of CONFIG_COMPAT_VDSO
17633 */
17634-#define PTE_IDENT_ATTR 0x003 /* PRESENT+RW */
17635-#define PDE_IDENT_ATTR 0x067 /* PRESENT+RW+USER+DIRTY+ACCESSED */
17636+#define PTE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
17637+#define PDE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
17638 #define PGD_IDENT_ATTR 0x001 /* PRESENT (no other attributes) */
17639 #endif
17640
17641@@ -257,7 +260,17 @@ static inline pgdval_t pgd_flags(pgd_t pgd)
17642 {
17643 return native_pgd_val(pgd) & PTE_FLAGS_MASK;
17644 }
17645+#endif
17646
17647+#if PAGETABLE_LEVELS == 3
17648+#include <asm-generic/pgtable-nopud.h>
17649+#endif
17650+
17651+#if PAGETABLE_LEVELS == 2
17652+#include <asm-generic/pgtable-nopmd.h>
17653+#endif
17654+
17655+#ifndef __ASSEMBLY__
17656 #if PAGETABLE_LEVELS > 3
17657 typedef struct { pudval_t pud; } pud_t;
17658
17659@@ -271,8 +284,6 @@ static inline pudval_t native_pud_val(pud_t pud)
17660 return pud.pud;
17661 }
17662 #else
17663-#include <asm-generic/pgtable-nopud.h>
17664-
17665 static inline pudval_t native_pud_val(pud_t pud)
17666 {
17667 return native_pgd_val(pud.pgd);
17668@@ -292,8 +303,6 @@ static inline pmdval_t native_pmd_val(pmd_t pmd)
17669 return pmd.pmd;
17670 }
17671 #else
17672-#include <asm-generic/pgtable-nopmd.h>
17673-
17674 static inline pmdval_t native_pmd_val(pmd_t pmd)
17675 {
17676 return native_pgd_val(pmd.pud.pgd);
17677@@ -333,7 +342,6 @@ typedef struct page *pgtable_t;
17678
17679 extern pteval_t __supported_pte_mask;
17680 extern void set_nx(void);
17681-extern int nx_enabled;
17682
17683 #define pgprot_writecombine pgprot_writecombine
17684 extern pgprot_t pgprot_writecombine(pgprot_t prot);
17685diff --git a/arch/x86/include/asm/processor.h b/arch/x86/include/asm/processor.h
17686index 987c75e..c7bd172 100644
17687--- a/arch/x86/include/asm/processor.h
17688+++ b/arch/x86/include/asm/processor.h
17689@@ -128,7 +128,7 @@ struct cpuinfo_x86 {
17690 /* Index into per_cpu list: */
17691 u16 cpu_index;
17692 u32 microcode;
17693-} __attribute__((__aligned__(SMP_CACHE_BYTES)));
17694+} __attribute__((__aligned__(SMP_CACHE_BYTES))) __randomize_layout;
17695
17696 #define X86_VENDOR_INTEL 0
17697 #define X86_VENDOR_CYRIX 1
17698@@ -199,9 +199,21 @@ static inline void native_cpuid(unsigned int *eax, unsigned int *ebx,
17699 : "memory");
17700 }
17701
17702+/* invpcid (%rdx),%rax */
17703+#define __ASM_INVPCID ".byte 0x66,0x0f,0x38,0x82,0x02"
17704+
17705+#define INVPCID_SINGLE_ADDRESS 0UL
17706+#define INVPCID_SINGLE_CONTEXT 1UL
17707+#define INVPCID_ALL_GLOBAL 2UL
17708+#define INVPCID_ALL_MONGLOBAL 3UL
17709+
17710+#define PCID_KERNEL 0UL
17711+#define PCID_USER 1UL
17712+#define PCID_NOFLUSH (1UL << 63)
17713+
17714 static inline void load_cr3(pgd_t *pgdir)
17715 {
17716- write_cr3(__pa(pgdir));
17717+ write_cr3(__pa(pgdir) | PCID_KERNEL);
17718 }
17719
17720 #ifdef CONFIG_X86_32
17721@@ -283,7 +295,7 @@ struct tss_struct {
17722
17723 } ____cacheline_aligned;
17724
17725-DECLARE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss);
17726+extern struct tss_struct init_tss[NR_CPUS];
17727
17728 /*
17729 * Save the original ist values for checking stack pointers during debugging
17730@@ -453,6 +465,7 @@ struct thread_struct {
17731 unsigned short ds;
17732 unsigned short fsindex;
17733 unsigned short gsindex;
17734+ unsigned short ss;
17735 #endif
17736 #ifdef CONFIG_X86_32
17737 unsigned long ip;
17738@@ -553,29 +566,8 @@ static inline void load_sp0(struct tss_struct *tss,
17739 extern unsigned long mmu_cr4_features;
17740 extern u32 *trampoline_cr4_features;
17741
17742-static inline void set_in_cr4(unsigned long mask)
17743-{
17744- unsigned long cr4;
17745-
17746- mmu_cr4_features |= mask;
17747- if (trampoline_cr4_features)
17748- *trampoline_cr4_features = mmu_cr4_features;
17749- cr4 = read_cr4();
17750- cr4 |= mask;
17751- write_cr4(cr4);
17752-}
17753-
17754-static inline void clear_in_cr4(unsigned long mask)
17755-{
17756- unsigned long cr4;
17757-
17758- mmu_cr4_features &= ~mask;
17759- if (trampoline_cr4_features)
17760- *trampoline_cr4_features = mmu_cr4_features;
17761- cr4 = read_cr4();
17762- cr4 &= ~mask;
17763- write_cr4(cr4);
17764-}
17765+extern void set_in_cr4(unsigned long mask);
17766+extern void clear_in_cr4(unsigned long mask);
17767
17768 typedef struct {
17769 unsigned long seg;
17770@@ -824,11 +816,18 @@ static inline void spin_lock_prefetch(const void *x)
17771 */
17772 #define TASK_SIZE PAGE_OFFSET
17773 #define TASK_SIZE_MAX TASK_SIZE
17774+
17775+#ifdef CONFIG_PAX_SEGMEXEC
17776+#define SEGMEXEC_TASK_SIZE (TASK_SIZE / 2)
17777+#define STACK_TOP ((current->mm->pax_flags & MF_PAX_SEGMEXEC)?SEGMEXEC_TASK_SIZE:TASK_SIZE)
17778+#else
17779 #define STACK_TOP TASK_SIZE
17780-#define STACK_TOP_MAX STACK_TOP
17781+#endif
17782+
17783+#define STACK_TOP_MAX TASK_SIZE
17784
17785 #define INIT_THREAD { \
17786- .sp0 = sizeof(init_stack) + (long)&init_stack, \
17787+ .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
17788 .vm86_info = NULL, \
17789 .sysenter_cs = __KERNEL_CS, \
17790 .io_bitmap_ptr = NULL, \
17791@@ -842,7 +841,7 @@ static inline void spin_lock_prefetch(const void *x)
17792 */
17793 #define INIT_TSS { \
17794 .x86_tss = { \
17795- .sp0 = sizeof(init_stack) + (long)&init_stack, \
17796+ .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
17797 .ss0 = __KERNEL_DS, \
17798 .ss1 = __KERNEL_CS, \
17799 .io_bitmap_base = INVALID_IO_BITMAP_OFFSET, \
17800@@ -853,11 +852,7 @@ static inline void spin_lock_prefetch(const void *x)
17801 extern unsigned long thread_saved_pc(struct task_struct *tsk);
17802
17803 #define THREAD_SIZE_LONGS (THREAD_SIZE/sizeof(unsigned long))
17804-#define KSTK_TOP(info) \
17805-({ \
17806- unsigned long *__ptr = (unsigned long *)(info); \
17807- (unsigned long)(&__ptr[THREAD_SIZE_LONGS]); \
17808-})
17809+#define KSTK_TOP(info) ((container_of(info, struct task_struct, tinfo))->thread.sp0)
17810
17811 /*
17812 * The below -8 is to reserve 8 bytes on top of the ring0 stack.
17813@@ -872,7 +867,7 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
17814 #define task_pt_regs(task) \
17815 ({ \
17816 struct pt_regs *__regs__; \
17817- __regs__ = (struct pt_regs *)(KSTK_TOP(task_stack_page(task))-8); \
17818+ __regs__ = (struct pt_regs *)((task)->thread.sp0); \
17819 __regs__ - 1; \
17820 })
17821
17822@@ -882,13 +877,13 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
17823 /*
17824 * User space process size. 47bits minus one guard page.
17825 */
17826-#define TASK_SIZE_MAX ((1UL << 47) - PAGE_SIZE)
17827+#define TASK_SIZE_MAX ((1UL << TASK_SIZE_MAX_SHIFT) - PAGE_SIZE)
17828
17829 /* This decides where the kernel will search for a free chunk of vm
17830 * space during mmap's.
17831 */
17832 #define IA32_PAGE_OFFSET ((current->personality & ADDR_LIMIT_3GB) ? \
17833- 0xc0000000 : 0xFFFFe000)
17834+ 0xc0000000 : 0xFFFFf000)
17835
17836 #define TASK_SIZE (test_thread_flag(TIF_ADDR32) ? \
17837 IA32_PAGE_OFFSET : TASK_SIZE_MAX)
17838@@ -899,11 +894,11 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
17839 #define STACK_TOP_MAX TASK_SIZE_MAX
17840
17841 #define INIT_THREAD { \
17842- .sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
17843+ .sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
17844 }
17845
17846 #define INIT_TSS { \
17847- .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
17848+ .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
17849 }
17850
17851 /*
17852@@ -931,6 +926,10 @@ extern void start_thread(struct pt_regs *regs, unsigned long new_ip,
17853 */
17854 #define TASK_UNMAPPED_BASE (PAGE_ALIGN(TASK_SIZE / 3))
17855
17856+#ifdef CONFIG_PAX_SEGMEXEC
17857+#define SEGMEXEC_TASK_UNMAPPED_BASE (PAGE_ALIGN(SEGMEXEC_TASK_SIZE / 3))
17858+#endif
17859+
17860 #define KSTK_EIP(task) (task_pt_regs(task)->ip)
17861
17862 /* Get/set a process' ability to use the timestamp counter instruction */
17863@@ -957,7 +956,7 @@ static inline uint32_t hypervisor_cpuid_base(const char *sig, uint32_t leaves)
17864 return 0;
17865 }
17866
17867-extern unsigned long arch_align_stack(unsigned long sp);
17868+#define arch_align_stack(x) ((x) & ~0xfUL)
17869 extern void free_init_pages(char *what, unsigned long begin, unsigned long end);
17870
17871 void default_idle(void);
17872@@ -967,6 +966,6 @@ bool xen_set_default_idle(void);
17873 #define xen_set_default_idle 0
17874 #endif
17875
17876-void stop_this_cpu(void *dummy);
17877+void stop_this_cpu(void *dummy) __noreturn;
17878 void df_debug(struct pt_regs *regs, long error_code);
17879 #endif /* _ASM_X86_PROCESSOR_H */
17880diff --git a/arch/x86/include/asm/ptrace.h b/arch/x86/include/asm/ptrace.h
17881index 942a086..6c26446 100644
17882--- a/arch/x86/include/asm/ptrace.h
17883+++ b/arch/x86/include/asm/ptrace.h
17884@@ -85,28 +85,29 @@ static inline unsigned long regs_return_value(struct pt_regs *regs)
17885 }
17886
17887 /*
17888- * user_mode_vm(regs) determines whether a register set came from user mode.
17889+ * user_mode(regs) determines whether a register set came from user mode.
17890 * This is true if V8086 mode was enabled OR if the register set was from
17891 * protected mode with RPL-3 CS value. This tricky test checks that with
17892 * one comparison. Many places in the kernel can bypass this full check
17893- * if they have already ruled out V8086 mode, so user_mode(regs) can be used.
17894+ * if they have already ruled out V8086 mode, so user_mode_novm(regs) can
17895+ * be used.
17896 */
17897-static inline int user_mode(struct pt_regs *regs)
17898+static inline int user_mode_novm(struct pt_regs *regs)
17899 {
17900 #ifdef CONFIG_X86_32
17901 return (regs->cs & SEGMENT_RPL_MASK) == USER_RPL;
17902 #else
17903- return !!(regs->cs & 3);
17904+ return !!(regs->cs & SEGMENT_RPL_MASK);
17905 #endif
17906 }
17907
17908-static inline int user_mode_vm(struct pt_regs *regs)
17909+static inline int user_mode(struct pt_regs *regs)
17910 {
17911 #ifdef CONFIG_X86_32
17912 return ((regs->cs & SEGMENT_RPL_MASK) | (regs->flags & X86_VM_MASK)) >=
17913 USER_RPL;
17914 #else
17915- return user_mode(regs);
17916+ return user_mode_novm(regs);
17917 #endif
17918 }
17919
17920@@ -122,15 +123,16 @@ static inline int v8086_mode(struct pt_regs *regs)
17921 #ifdef CONFIG_X86_64
17922 static inline bool user_64bit_mode(struct pt_regs *regs)
17923 {
17924+ unsigned long cs = regs->cs & 0xffff;
17925 #ifndef CONFIG_PARAVIRT
17926 /*
17927 * On non-paravirt systems, this is the only long mode CPL 3
17928 * selector. We do not allow long mode selectors in the LDT.
17929 */
17930- return regs->cs == __USER_CS;
17931+ return cs == __USER_CS;
17932 #else
17933 /* Headers are too twisted for this to go in paravirt.h. */
17934- return regs->cs == __USER_CS || regs->cs == pv_info.extra_user_64bit_cs;
17935+ return cs == __USER_CS || cs == pv_info.extra_user_64bit_cs;
17936 #endif
17937 }
17938
17939@@ -181,9 +183,11 @@ static inline unsigned long regs_get_register(struct pt_regs *regs,
17940 * Traps from the kernel do not save sp and ss.
17941 * Use the helper function to retrieve sp.
17942 */
17943- if (offset == offsetof(struct pt_regs, sp) &&
17944- regs->cs == __KERNEL_CS)
17945- return kernel_stack_pointer(regs);
17946+ if (offset == offsetof(struct pt_regs, sp)) {
17947+ unsigned long cs = regs->cs & 0xffff;
17948+ if (cs == __KERNEL_CS || cs == __KERNEXEC_KERNEL_CS)
17949+ return kernel_stack_pointer(regs);
17950+ }
17951 #endif
17952 return *(unsigned long *)((unsigned long)regs + offset);
17953 }
17954diff --git a/arch/x86/include/asm/realmode.h b/arch/x86/include/asm/realmode.h
17955index 9c6b890..5305f53 100644
17956--- a/arch/x86/include/asm/realmode.h
17957+++ b/arch/x86/include/asm/realmode.h
17958@@ -22,16 +22,14 @@ struct real_mode_header {
17959 #endif
17960 /* APM/BIOS reboot */
17961 u32 machine_real_restart_asm;
17962-#ifdef CONFIG_X86_64
17963 u32 machine_real_restart_seg;
17964-#endif
17965 };
17966
17967 /* This must match data at trampoline_32/64.S */
17968 struct trampoline_header {
17969 #ifdef CONFIG_X86_32
17970 u32 start;
17971- u16 gdt_pad;
17972+ u16 boot_cs;
17973 u16 gdt_limit;
17974 u32 gdt_base;
17975 #else
17976diff --git a/arch/x86/include/asm/reboot.h b/arch/x86/include/asm/reboot.h
17977index a82c4f1..ac45053 100644
17978--- a/arch/x86/include/asm/reboot.h
17979+++ b/arch/x86/include/asm/reboot.h
17980@@ -6,13 +6,13 @@
17981 struct pt_regs;
17982
17983 struct machine_ops {
17984- void (*restart)(char *cmd);
17985- void (*halt)(void);
17986- void (*power_off)(void);
17987+ void (* __noreturn restart)(char *cmd);
17988+ void (* __noreturn halt)(void);
17989+ void (* __noreturn power_off)(void);
17990 void (*shutdown)(void);
17991 void (*crash_shutdown)(struct pt_regs *);
17992- void (*emergency_restart)(void);
17993-};
17994+ void (* __noreturn emergency_restart)(void);
17995+} __no_const;
17996
17997 extern struct machine_ops machine_ops;
17998
17999diff --git a/arch/x86/include/asm/rwsem.h b/arch/x86/include/asm/rwsem.h
18000index cad82c9..2e5c5c1 100644
18001--- a/arch/x86/include/asm/rwsem.h
18002+++ b/arch/x86/include/asm/rwsem.h
18003@@ -64,6 +64,14 @@ static inline void __down_read(struct rw_semaphore *sem)
18004 {
18005 asm volatile("# beginning down_read\n\t"
18006 LOCK_PREFIX _ASM_INC "(%1)\n\t"
18007+
18008+#ifdef CONFIG_PAX_REFCOUNT
18009+ "jno 0f\n"
18010+ LOCK_PREFIX _ASM_DEC "(%1)\n"
18011+ "int $4\n0:\n"
18012+ _ASM_EXTABLE(0b, 0b)
18013+#endif
18014+
18015 /* adds 0x00000001 */
18016 " jns 1f\n"
18017 " call call_rwsem_down_read_failed\n"
18018@@ -85,6 +93,14 @@ static inline int __down_read_trylock(struct rw_semaphore *sem)
18019 "1:\n\t"
18020 " mov %1,%2\n\t"
18021 " add %3,%2\n\t"
18022+
18023+#ifdef CONFIG_PAX_REFCOUNT
18024+ "jno 0f\n"
18025+ "sub %3,%2\n"
18026+ "int $4\n0:\n"
18027+ _ASM_EXTABLE(0b, 0b)
18028+#endif
18029+
18030 " jle 2f\n\t"
18031 LOCK_PREFIX " cmpxchg %2,%0\n\t"
18032 " jnz 1b\n\t"
18033@@ -104,6 +120,14 @@ static inline void __down_write_nested(struct rw_semaphore *sem, int subclass)
18034 long tmp;
18035 asm volatile("# beginning down_write\n\t"
18036 LOCK_PREFIX " xadd %1,(%2)\n\t"
18037+
18038+#ifdef CONFIG_PAX_REFCOUNT
18039+ "jno 0f\n"
18040+ "mov %1,(%2)\n"
18041+ "int $4\n0:\n"
18042+ _ASM_EXTABLE(0b, 0b)
18043+#endif
18044+
18045 /* adds 0xffff0001, returns the old value */
18046 " test " __ASM_SEL(%w1,%k1) "," __ASM_SEL(%w1,%k1) "\n\t"
18047 /* was the active mask 0 before? */
18048@@ -155,6 +179,14 @@ static inline void __up_read(struct rw_semaphore *sem)
18049 long tmp;
18050 asm volatile("# beginning __up_read\n\t"
18051 LOCK_PREFIX " xadd %1,(%2)\n\t"
18052+
18053+#ifdef CONFIG_PAX_REFCOUNT
18054+ "jno 0f\n"
18055+ "mov %1,(%2)\n"
18056+ "int $4\n0:\n"
18057+ _ASM_EXTABLE(0b, 0b)
18058+#endif
18059+
18060 /* subtracts 1, returns the old value */
18061 " jns 1f\n\t"
18062 " call call_rwsem_wake\n" /* expects old value in %edx */
18063@@ -173,6 +205,14 @@ static inline void __up_write(struct rw_semaphore *sem)
18064 long tmp;
18065 asm volatile("# beginning __up_write\n\t"
18066 LOCK_PREFIX " xadd %1,(%2)\n\t"
18067+
18068+#ifdef CONFIG_PAX_REFCOUNT
18069+ "jno 0f\n"
18070+ "mov %1,(%2)\n"
18071+ "int $4\n0:\n"
18072+ _ASM_EXTABLE(0b, 0b)
18073+#endif
18074+
18075 /* subtracts 0xffff0001, returns the old value */
18076 " jns 1f\n\t"
18077 " call call_rwsem_wake\n" /* expects old value in %edx */
18078@@ -190,6 +230,14 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
18079 {
18080 asm volatile("# beginning __downgrade_write\n\t"
18081 LOCK_PREFIX _ASM_ADD "%2,(%1)\n\t"
18082+
18083+#ifdef CONFIG_PAX_REFCOUNT
18084+ "jno 0f\n"
18085+ LOCK_PREFIX _ASM_SUB "%2,(%1)\n"
18086+ "int $4\n0:\n"
18087+ _ASM_EXTABLE(0b, 0b)
18088+#endif
18089+
18090 /*
18091 * transitions 0xZZZZ0001 -> 0xYYYY0001 (i386)
18092 * 0xZZZZZZZZ00000001 -> 0xYYYYYYYY00000001 (x86_64)
18093@@ -208,7 +256,15 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
18094 */
18095 static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
18096 {
18097- asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0"
18098+ asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0\n"
18099+
18100+#ifdef CONFIG_PAX_REFCOUNT
18101+ "jno 0f\n"
18102+ LOCK_PREFIX _ASM_SUB "%1,%0\n"
18103+ "int $4\n0:\n"
18104+ _ASM_EXTABLE(0b, 0b)
18105+#endif
18106+
18107 : "+m" (sem->count)
18108 : "er" (delta));
18109 }
18110@@ -218,7 +274,7 @@ static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
18111 */
18112 static inline long rwsem_atomic_update(long delta, struct rw_semaphore *sem)
18113 {
18114- return delta + xadd(&sem->count, delta);
18115+ return delta + xadd_check_overflow(&sem->count, delta);
18116 }
18117
18118 #endif /* __KERNEL__ */
18119diff --git a/arch/x86/include/asm/segment.h b/arch/x86/include/asm/segment.h
18120index c48a950..bc40804 100644
18121--- a/arch/x86/include/asm/segment.h
18122+++ b/arch/x86/include/asm/segment.h
18123@@ -64,10 +64,15 @@
18124 * 26 - ESPFIX small SS
18125 * 27 - per-cpu [ offset to per-cpu data area ]
18126 * 28 - stack_canary-20 [ for stack protector ]
18127- * 29 - unused
18128- * 30 - unused
18129+ * 29 - PCI BIOS CS
18130+ * 30 - PCI BIOS DS
18131 * 31 - TSS for double fault handler
18132 */
18133+#define GDT_ENTRY_KERNEXEC_EFI_CS (1)
18134+#define GDT_ENTRY_KERNEXEC_EFI_DS (2)
18135+#define __KERNEXEC_EFI_CS (GDT_ENTRY_KERNEXEC_EFI_CS*8)
18136+#define __KERNEXEC_EFI_DS (GDT_ENTRY_KERNEXEC_EFI_DS*8)
18137+
18138 #define GDT_ENTRY_TLS_MIN 6
18139 #define GDT_ENTRY_TLS_MAX (GDT_ENTRY_TLS_MIN + GDT_ENTRY_TLS_ENTRIES - 1)
18140
18141@@ -79,6 +84,8 @@
18142
18143 #define GDT_ENTRY_KERNEL_CS (GDT_ENTRY_KERNEL_BASE+0)
18144
18145+#define GDT_ENTRY_KERNEXEC_KERNEL_CS (4)
18146+
18147 #define GDT_ENTRY_KERNEL_DS (GDT_ENTRY_KERNEL_BASE+1)
18148
18149 #define GDT_ENTRY_TSS (GDT_ENTRY_KERNEL_BASE+4)
18150@@ -104,6 +111,12 @@
18151 #define __KERNEL_STACK_CANARY 0
18152 #endif
18153
18154+#define GDT_ENTRY_PCIBIOS_CS (GDT_ENTRY_KERNEL_BASE+17)
18155+#define __PCIBIOS_CS (GDT_ENTRY_PCIBIOS_CS * 8)
18156+
18157+#define GDT_ENTRY_PCIBIOS_DS (GDT_ENTRY_KERNEL_BASE+18)
18158+#define __PCIBIOS_DS (GDT_ENTRY_PCIBIOS_DS * 8)
18159+
18160 #define GDT_ENTRY_DOUBLEFAULT_TSS 31
18161
18162 /*
18163@@ -141,7 +154,7 @@
18164 */
18165
18166 /* Matches PNP_CS32 and PNP_CS16 (they must be consecutive) */
18167-#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xf4) == GDT_ENTRY_PNPBIOS_BASE * 8)
18168+#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xFFFCU) == PNP_CS32 || ((x) & 0xFFFCU) == PNP_CS16)
18169
18170
18171 #else
18172@@ -165,6 +178,8 @@
18173 #define __USER32_CS (GDT_ENTRY_DEFAULT_USER32_CS*8+3)
18174 #define __USER32_DS __USER_DS
18175
18176+#define GDT_ENTRY_KERNEXEC_KERNEL_CS 7
18177+
18178 #define GDT_ENTRY_TSS 8 /* needs two entries */
18179 #define GDT_ENTRY_LDT 10 /* needs two entries */
18180 #define GDT_ENTRY_TLS_MIN 12
18181@@ -173,6 +188,8 @@
18182 #define GDT_ENTRY_PER_CPU 15 /* Abused to load per CPU data from limit */
18183 #define __PER_CPU_SEG (GDT_ENTRY_PER_CPU * 8 + 3)
18184
18185+#define GDT_ENTRY_UDEREF_KERNEL_DS 16
18186+
18187 /* TLS indexes for 64bit - hardcoded in arch_prctl */
18188 #define FS_TLS 0
18189 #define GS_TLS 1
18190@@ -180,12 +197,14 @@
18191 #define GS_TLS_SEL ((GDT_ENTRY_TLS_MIN+GS_TLS)*8 + 3)
18192 #define FS_TLS_SEL ((GDT_ENTRY_TLS_MIN+FS_TLS)*8 + 3)
18193
18194-#define GDT_ENTRIES 16
18195+#define GDT_ENTRIES 17
18196
18197 #endif
18198
18199 #define __KERNEL_CS (GDT_ENTRY_KERNEL_CS*8)
18200+#define __KERNEXEC_KERNEL_CS (GDT_ENTRY_KERNEXEC_KERNEL_CS*8)
18201 #define __KERNEL_DS (GDT_ENTRY_KERNEL_DS*8)
18202+#define __UDEREF_KERNEL_DS (GDT_ENTRY_UDEREF_KERNEL_DS*8)
18203 #define __USER_DS (GDT_ENTRY_DEFAULT_USER_DS*8+3)
18204 #define __USER_CS (GDT_ENTRY_DEFAULT_USER_CS*8+3)
18205 #ifndef CONFIG_PARAVIRT
18206@@ -265,7 +284,7 @@ static inline unsigned long get_limit(unsigned long segment)
18207 {
18208 unsigned long __limit;
18209 asm("lsll %1,%0" : "=r" (__limit) : "r" (segment));
18210- return __limit + 1;
18211+ return __limit;
18212 }
18213
18214 #endif /* !__ASSEMBLY__ */
18215diff --git a/arch/x86/include/asm/smap.h b/arch/x86/include/asm/smap.h
18216index 8d3120f..352b440 100644
18217--- a/arch/x86/include/asm/smap.h
18218+++ b/arch/x86/include/asm/smap.h
18219@@ -25,11 +25,40 @@
18220
18221 #include <asm/alternative-asm.h>
18222
18223+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
18224+#define ASM_PAX_OPEN_USERLAND \
18225+ 661: jmp 663f; \
18226+ .pushsection .altinstr_replacement, "a" ; \
18227+ 662: pushq %rax; nop; \
18228+ .popsection ; \
18229+ .pushsection .altinstructions, "a" ; \
18230+ altinstruction_entry 661b, 662b, X86_FEATURE_STRONGUDEREF, 2, 2;\
18231+ .popsection ; \
18232+ call __pax_open_userland; \
18233+ popq %rax; \
18234+ 663:
18235+
18236+#define ASM_PAX_CLOSE_USERLAND \
18237+ 661: jmp 663f; \
18238+ .pushsection .altinstr_replacement, "a" ; \
18239+ 662: pushq %rax; nop; \
18240+ .popsection; \
18241+ .pushsection .altinstructions, "a" ; \
18242+ altinstruction_entry 661b, 662b, X86_FEATURE_STRONGUDEREF, 2, 2;\
18243+ .popsection; \
18244+ call __pax_close_userland; \
18245+ popq %rax; \
18246+ 663:
18247+#else
18248+#define ASM_PAX_OPEN_USERLAND
18249+#define ASM_PAX_CLOSE_USERLAND
18250+#endif
18251+
18252 #ifdef CONFIG_X86_SMAP
18253
18254 #define ASM_CLAC \
18255 661: ASM_NOP3 ; \
18256- .pushsection .altinstr_replacement, "ax" ; \
18257+ .pushsection .altinstr_replacement, "a" ; \
18258 662: __ASM_CLAC ; \
18259 .popsection ; \
18260 .pushsection .altinstructions, "a" ; \
18261@@ -38,7 +67,7 @@
18262
18263 #define ASM_STAC \
18264 661: ASM_NOP3 ; \
18265- .pushsection .altinstr_replacement, "ax" ; \
18266+ .pushsection .altinstr_replacement, "a" ; \
18267 662: __ASM_STAC ; \
18268 .popsection ; \
18269 .pushsection .altinstructions, "a" ; \
18270@@ -56,6 +85,37 @@
18271
18272 #include <asm/alternative.h>
18273
18274+#define __HAVE_ARCH_PAX_OPEN_USERLAND
18275+#define __HAVE_ARCH_PAX_CLOSE_USERLAND
18276+
18277+extern void __pax_open_userland(void);
18278+static __always_inline unsigned long pax_open_userland(void)
18279+{
18280+
18281+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
18282+ asm volatile(ALTERNATIVE(ASM_NOP5, "call %P[open]", X86_FEATURE_STRONGUDEREF)
18283+ :
18284+ : [open] "i" (__pax_open_userland)
18285+ : "memory", "rax");
18286+#endif
18287+
18288+ return 0;
18289+}
18290+
18291+extern void __pax_close_userland(void);
18292+static __always_inline unsigned long pax_close_userland(void)
18293+{
18294+
18295+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
18296+ asm volatile(ALTERNATIVE(ASM_NOP5, "call %P[close]", X86_FEATURE_STRONGUDEREF)
18297+ :
18298+ : [close] "i" (__pax_close_userland)
18299+ : "memory", "rax");
18300+#endif
18301+
18302+ return 0;
18303+}
18304+
18305 #ifdef CONFIG_X86_SMAP
18306
18307 static __always_inline void clac(void)
18308diff --git a/arch/x86/include/asm/smp.h b/arch/x86/include/asm/smp.h
18309index 4137890..03fa172 100644
18310--- a/arch/x86/include/asm/smp.h
18311+++ b/arch/x86/include/asm/smp.h
18312@@ -36,7 +36,7 @@ DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_core_map);
18313 /* cpus sharing the last level cache: */
18314 DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_llc_shared_map);
18315 DECLARE_PER_CPU_READ_MOSTLY(u16, cpu_llc_id);
18316-DECLARE_PER_CPU_READ_MOSTLY(int, cpu_number);
18317+DECLARE_PER_CPU_READ_MOSTLY(unsigned int, cpu_number);
18318
18319 static inline struct cpumask *cpu_sibling_mask(int cpu)
18320 {
18321@@ -79,7 +79,7 @@ struct smp_ops {
18322
18323 void (*send_call_func_ipi)(const struct cpumask *mask);
18324 void (*send_call_func_single_ipi)(int cpu);
18325-};
18326+} __no_const;
18327
18328 /* Globals due to paravirt */
18329 extern void set_cpu_sibling_map(int cpu);
18330@@ -191,14 +191,8 @@ extern unsigned disabled_cpus;
18331 extern int safe_smp_processor_id(void);
18332
18333 #elif defined(CONFIG_X86_64_SMP)
18334-#define raw_smp_processor_id() (this_cpu_read(cpu_number))
18335-
18336-#define stack_smp_processor_id() \
18337-({ \
18338- struct thread_info *ti; \
18339- __asm__("andq %%rsp,%0; ":"=r" (ti) : "0" (CURRENT_MASK)); \
18340- ti->cpu; \
18341-})
18342+#define raw_smp_processor_id() (this_cpu_read(cpu_number))
18343+#define stack_smp_processor_id() raw_smp_processor_id()
18344 #define safe_smp_processor_id() smp_processor_id()
18345
18346 #endif
18347diff --git a/arch/x86/include/asm/spinlock.h b/arch/x86/include/asm/spinlock.h
18348index bf156de..1a782ab 100644
18349--- a/arch/x86/include/asm/spinlock.h
18350+++ b/arch/x86/include/asm/spinlock.h
18351@@ -223,6 +223,14 @@ static inline int arch_write_can_lock(arch_rwlock_t *lock)
18352 static inline void arch_read_lock(arch_rwlock_t *rw)
18353 {
18354 asm volatile(LOCK_PREFIX READ_LOCK_SIZE(dec) " (%0)\n\t"
18355+
18356+#ifdef CONFIG_PAX_REFCOUNT
18357+ "jno 0f\n"
18358+ LOCK_PREFIX READ_LOCK_SIZE(inc) " (%0)\n"
18359+ "int $4\n0:\n"
18360+ _ASM_EXTABLE(0b, 0b)
18361+#endif
18362+
18363 "jns 1f\n"
18364 "call __read_lock_failed\n\t"
18365 "1:\n"
18366@@ -232,6 +240,14 @@ static inline void arch_read_lock(arch_rwlock_t *rw)
18367 static inline void arch_write_lock(arch_rwlock_t *rw)
18368 {
18369 asm volatile(LOCK_PREFIX WRITE_LOCK_SUB(%1) "(%0)\n\t"
18370+
18371+#ifdef CONFIG_PAX_REFCOUNT
18372+ "jno 0f\n"
18373+ LOCK_PREFIX WRITE_LOCK_ADD(%1) "(%0)\n"
18374+ "int $4\n0:\n"
18375+ _ASM_EXTABLE(0b, 0b)
18376+#endif
18377+
18378 "jz 1f\n"
18379 "call __write_lock_failed\n\t"
18380 "1:\n"
18381@@ -261,13 +277,29 @@ static inline int arch_write_trylock(arch_rwlock_t *lock)
18382
18383 static inline void arch_read_unlock(arch_rwlock_t *rw)
18384 {
18385- asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0"
18386+ asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0\n"
18387+
18388+#ifdef CONFIG_PAX_REFCOUNT
18389+ "jno 0f\n"
18390+ LOCK_PREFIX READ_LOCK_SIZE(dec) " %0\n"
18391+ "int $4\n0:\n"
18392+ _ASM_EXTABLE(0b, 0b)
18393+#endif
18394+
18395 :"+m" (rw->lock) : : "memory");
18396 }
18397
18398 static inline void arch_write_unlock(arch_rwlock_t *rw)
18399 {
18400- asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0"
18401+ asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0\n"
18402+
18403+#ifdef CONFIG_PAX_REFCOUNT
18404+ "jno 0f\n"
18405+ LOCK_PREFIX WRITE_LOCK_SUB(%1) "%0\n"
18406+ "int $4\n0:\n"
18407+ _ASM_EXTABLE(0b, 0b)
18408+#endif
18409+
18410 : "+m" (rw->write) : "i" (RW_LOCK_BIAS) : "memory");
18411 }
18412
18413diff --git a/arch/x86/include/asm/stackprotector.h b/arch/x86/include/asm/stackprotector.h
18414index 6a99859..03cb807 100644
18415--- a/arch/x86/include/asm/stackprotector.h
18416+++ b/arch/x86/include/asm/stackprotector.h
18417@@ -47,7 +47,7 @@
18418 * head_32 for boot CPU and setup_per_cpu_areas() for others.
18419 */
18420 #define GDT_STACK_CANARY_INIT \
18421- [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x18),
18422+ [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x17),
18423
18424 /*
18425 * Initialize the stackprotector canary value.
18426@@ -112,7 +112,7 @@ static inline void setup_stack_canary_segment(int cpu)
18427
18428 static inline void load_stack_canary_segment(void)
18429 {
18430-#ifdef CONFIG_X86_32
18431+#if defined(CONFIG_X86_32) && !defined(CONFIG_PAX_MEMORY_UDEREF)
18432 asm volatile ("mov %0, %%gs" : : "r" (0));
18433 #endif
18434 }
18435diff --git a/arch/x86/include/asm/stacktrace.h b/arch/x86/include/asm/stacktrace.h
18436index 70bbe39..4ae2bd4 100644
18437--- a/arch/x86/include/asm/stacktrace.h
18438+++ b/arch/x86/include/asm/stacktrace.h
18439@@ -11,28 +11,20 @@
18440
18441 extern int kstack_depth_to_print;
18442
18443-struct thread_info;
18444+struct task_struct;
18445 struct stacktrace_ops;
18446
18447-typedef unsigned long (*walk_stack_t)(struct thread_info *tinfo,
18448- unsigned long *stack,
18449- unsigned long bp,
18450- const struct stacktrace_ops *ops,
18451- void *data,
18452- unsigned long *end,
18453- int *graph);
18454+typedef unsigned long walk_stack_t(struct task_struct *task,
18455+ void *stack_start,
18456+ unsigned long *stack,
18457+ unsigned long bp,
18458+ const struct stacktrace_ops *ops,
18459+ void *data,
18460+ unsigned long *end,
18461+ int *graph);
18462
18463-extern unsigned long
18464-print_context_stack(struct thread_info *tinfo,
18465- unsigned long *stack, unsigned long bp,
18466- const struct stacktrace_ops *ops, void *data,
18467- unsigned long *end, int *graph);
18468-
18469-extern unsigned long
18470-print_context_stack_bp(struct thread_info *tinfo,
18471- unsigned long *stack, unsigned long bp,
18472- const struct stacktrace_ops *ops, void *data,
18473- unsigned long *end, int *graph);
18474+extern walk_stack_t print_context_stack;
18475+extern walk_stack_t print_context_stack_bp;
18476
18477 /* Generic stack tracer with callbacks */
18478
18479@@ -40,7 +32,7 @@ struct stacktrace_ops {
18480 void (*address)(void *data, unsigned long address, int reliable);
18481 /* On negative return stop dumping */
18482 int (*stack)(void *data, char *name);
18483- walk_stack_t walk_stack;
18484+ walk_stack_t *walk_stack;
18485 };
18486
18487 void dump_trace(struct task_struct *tsk, struct pt_regs *regs,
18488diff --git a/arch/x86/include/asm/switch_to.h b/arch/x86/include/asm/switch_to.h
18489index d7f3b3b..3cc39f1 100644
18490--- a/arch/x86/include/asm/switch_to.h
18491+++ b/arch/x86/include/asm/switch_to.h
18492@@ -108,7 +108,7 @@ do { \
18493 "call __switch_to\n\t" \
18494 "movq "__percpu_arg([current_task])",%%rsi\n\t" \
18495 __switch_canary \
18496- "movq %P[thread_info](%%rsi),%%r8\n\t" \
18497+ "movq "__percpu_arg([thread_info])",%%r8\n\t" \
18498 "movq %%rax,%%rdi\n\t" \
18499 "testl %[_tif_fork],%P[ti_flags](%%r8)\n\t" \
18500 "jnz ret_from_fork\n\t" \
18501@@ -119,7 +119,7 @@ do { \
18502 [threadrsp] "i" (offsetof(struct task_struct, thread.sp)), \
18503 [ti_flags] "i" (offsetof(struct thread_info, flags)), \
18504 [_tif_fork] "i" (_TIF_FORK), \
18505- [thread_info] "i" (offsetof(struct task_struct, stack)), \
18506+ [thread_info] "m" (current_tinfo), \
18507 [current_task] "m" (current_task) \
18508 __switch_canary_iparam \
18509 : "memory", "cc" __EXTRA_CLOBBER)
18510diff --git a/arch/x86/include/asm/thread_info.h b/arch/x86/include/asm/thread_info.h
18511index 2781119..618b59b 100644
18512--- a/arch/x86/include/asm/thread_info.h
18513+++ b/arch/x86/include/asm/thread_info.h
18514@@ -10,6 +10,7 @@
18515 #include <linux/compiler.h>
18516 #include <asm/page.h>
18517 #include <asm/types.h>
18518+#include <asm/percpu.h>
18519
18520 /*
18521 * low level task data that entry.S needs immediate access to
18522@@ -23,7 +24,6 @@ struct exec_domain;
18523 #include <linux/atomic.h>
18524
18525 struct thread_info {
18526- struct task_struct *task; /* main task structure */
18527 struct exec_domain *exec_domain; /* execution domain */
18528 __u32 flags; /* low level flags */
18529 __u32 status; /* thread synchronous flags */
18530@@ -33,19 +33,13 @@ struct thread_info {
18531 mm_segment_t addr_limit;
18532 struct restart_block restart_block;
18533 void __user *sysenter_return;
18534-#ifdef CONFIG_X86_32
18535- unsigned long previous_esp; /* ESP of the previous stack in
18536- case of nested (IRQ) stacks
18537- */
18538- __u8 supervisor_stack[0];
18539-#endif
18540+ unsigned long lowest_stack;
18541 unsigned int sig_on_uaccess_error:1;
18542 unsigned int uaccess_err:1; /* uaccess failed */
18543 };
18544
18545-#define INIT_THREAD_INFO(tsk) \
18546+#define INIT_THREAD_INFO \
18547 { \
18548- .task = &tsk, \
18549 .exec_domain = &default_exec_domain, \
18550 .flags = 0, \
18551 .cpu = 0, \
18552@@ -56,7 +50,7 @@ struct thread_info {
18553 }, \
18554 }
18555
18556-#define init_thread_info (init_thread_union.thread_info)
18557+#define init_thread_info (init_thread_union.stack)
18558 #define init_stack (init_thread_union.stack)
18559
18560 #else /* !__ASSEMBLY__ */
18561@@ -96,6 +90,7 @@ struct thread_info {
18562 #define TIF_SYSCALL_TRACEPOINT 28 /* syscall tracepoint instrumentation */
18563 #define TIF_ADDR32 29 /* 32-bit address space on 64 bits */
18564 #define TIF_X32 30 /* 32-bit native x86-64 binary */
18565+#define TIF_GRSEC_SETXID 31 /* update credentials on syscall entry/exit */
18566
18567 #define _TIF_SYSCALL_TRACE (1 << TIF_SYSCALL_TRACE)
18568 #define _TIF_NOTIFY_RESUME (1 << TIF_NOTIFY_RESUME)
18569@@ -119,17 +114,18 @@ struct thread_info {
18570 #define _TIF_SYSCALL_TRACEPOINT (1 << TIF_SYSCALL_TRACEPOINT)
18571 #define _TIF_ADDR32 (1 << TIF_ADDR32)
18572 #define _TIF_X32 (1 << TIF_X32)
18573+#define _TIF_GRSEC_SETXID (1 << TIF_GRSEC_SETXID)
18574
18575 /* work to do in syscall_trace_enter() */
18576 #define _TIF_WORK_SYSCALL_ENTRY \
18577 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_EMU | _TIF_SYSCALL_AUDIT | \
18578 _TIF_SECCOMP | _TIF_SINGLESTEP | _TIF_SYSCALL_TRACEPOINT | \
18579- _TIF_NOHZ)
18580+ _TIF_NOHZ | _TIF_GRSEC_SETXID)
18581
18582 /* work to do in syscall_trace_leave() */
18583 #define _TIF_WORK_SYSCALL_EXIT \
18584 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_SINGLESTEP | \
18585- _TIF_SYSCALL_TRACEPOINT | _TIF_NOHZ)
18586+ _TIF_SYSCALL_TRACEPOINT | _TIF_NOHZ | _TIF_GRSEC_SETXID)
18587
18588 /* work to do on interrupt/exception return */
18589 #define _TIF_WORK_MASK \
18590@@ -140,7 +136,7 @@ struct thread_info {
18591 /* work to do on any return to user space */
18592 #define _TIF_ALLWORK_MASK \
18593 ((0x0000FFFF & ~_TIF_SECCOMP) | _TIF_SYSCALL_TRACEPOINT | \
18594- _TIF_NOHZ)
18595+ _TIF_NOHZ | _TIF_GRSEC_SETXID)
18596
18597 /* Only used for 64 bit */
18598 #define _TIF_DO_NOTIFY_MASK \
18599@@ -156,45 +152,40 @@ struct thread_info {
18600
18601 #define PREEMPT_ACTIVE 0x10000000
18602
18603-#ifdef CONFIG_X86_32
18604-
18605-#define STACK_WARN (THREAD_SIZE/8)
18606-/*
18607- * macros/functions for gaining access to the thread information structure
18608- *
18609- * preempt_count needs to be 1 initially, until the scheduler is functional.
18610- */
18611-#ifndef __ASSEMBLY__
18612-
18613-
18614-/* how to get the current stack pointer from C */
18615-register unsigned long current_stack_pointer asm("esp") __used;
18616-
18617-/* how to get the thread information struct from C */
18618-static inline struct thread_info *current_thread_info(void)
18619-{
18620- return (struct thread_info *)
18621- (current_stack_pointer & ~(THREAD_SIZE - 1));
18622-}
18623-
18624-#else /* !__ASSEMBLY__ */
18625-
18626+#ifdef __ASSEMBLY__
18627 /* how to get the thread information struct from ASM */
18628 #define GET_THREAD_INFO(reg) \
18629- movl $-THREAD_SIZE, reg; \
18630- andl %esp, reg
18631+ mov PER_CPU_VAR(current_tinfo), reg
18632
18633 /* use this one if reg already contains %esp */
18634-#define GET_THREAD_INFO_WITH_ESP(reg) \
18635- andl $-THREAD_SIZE, reg
18636+#define GET_THREAD_INFO_WITH_ESP(reg) GET_THREAD_INFO(reg)
18637+#else
18638+/* how to get the thread information struct from C */
18639+DECLARE_PER_CPU(struct thread_info *, current_tinfo);
18640+
18641+static __always_inline struct thread_info *current_thread_info(void)
18642+{
18643+ return this_cpu_read_stable(current_tinfo);
18644+}
18645+#endif
18646+
18647+#ifdef CONFIG_X86_32
18648+
18649+#define STACK_WARN (THREAD_SIZE/8)
18650+/*
18651+ * macros/functions for gaining access to the thread information structure
18652+ *
18653+ * preempt_count needs to be 1 initially, until the scheduler is functional.
18654+ */
18655+#ifndef __ASSEMBLY__
18656+
18657+/* how to get the current stack pointer from C */
18658+register unsigned long current_stack_pointer asm("esp") __used;
18659
18660 #endif
18661
18662 #else /* X86_32 */
18663
18664-#include <asm/percpu.h>
18665-#define KERNEL_STACK_OFFSET (5*8)
18666-
18667 /*
18668 * macros/functions for gaining access to the thread information structure
18669 * preempt_count needs to be 1 initially, until the scheduler is functional.
18670@@ -202,27 +193,8 @@ static inline struct thread_info *current_thread_info(void)
18671 #ifndef __ASSEMBLY__
18672 DECLARE_PER_CPU(unsigned long, kernel_stack);
18673
18674-static inline struct thread_info *current_thread_info(void)
18675-{
18676- struct thread_info *ti;
18677- ti = (void *)(this_cpu_read_stable(kernel_stack) +
18678- KERNEL_STACK_OFFSET - THREAD_SIZE);
18679- return ti;
18680-}
18681-
18682-#else /* !__ASSEMBLY__ */
18683-
18684-/* how to get the thread information struct from ASM */
18685-#define GET_THREAD_INFO(reg) \
18686- movq PER_CPU_VAR(kernel_stack),reg ; \
18687- subq $(THREAD_SIZE-KERNEL_STACK_OFFSET),reg
18688-
18689-/*
18690- * Same if PER_CPU_VAR(kernel_stack) is, perhaps with some offset, already in
18691- * a certain register (to be used in assembler memory operands).
18692- */
18693-#define THREAD_INFO(reg, off) KERNEL_STACK_OFFSET+(off)-THREAD_SIZE(reg)
18694-
18695+/* how to get the current stack pointer from C */
18696+register unsigned long current_stack_pointer asm("rsp") __used;
18697 #endif
18698
18699 #endif /* !X86_32 */
18700@@ -281,5 +253,12 @@ static inline bool is_ia32_task(void)
18701 extern void arch_task_cache_init(void);
18702 extern int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src);
18703 extern void arch_release_task_struct(struct task_struct *tsk);
18704+
18705+#define __HAVE_THREAD_FUNCTIONS
18706+#define task_thread_info(task) (&(task)->tinfo)
18707+#define task_stack_page(task) ((task)->stack)
18708+#define setup_thread_stack(p, org) do {} while (0)
18709+#define end_of_stack(p) ((unsigned long *)task_stack_page(p) + 1)
18710+
18711 #endif
18712 #endif /* _ASM_X86_THREAD_INFO_H */
18713diff --git a/arch/x86/include/asm/tlbflush.h b/arch/x86/include/asm/tlbflush.h
18714index e6d90ba..0897f44 100644
18715--- a/arch/x86/include/asm/tlbflush.h
18716+++ b/arch/x86/include/asm/tlbflush.h
18717@@ -17,18 +17,44 @@
18718
18719 static inline void __native_flush_tlb(void)
18720 {
18721+ if (static_cpu_has(X86_FEATURE_INVPCID)) {
18722+ u64 descriptor[2];
18723+
18724+ descriptor[0] = PCID_KERNEL;
18725+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_ALL_MONGLOBAL) : "memory");
18726+ return;
18727+ }
18728+
18729+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
18730+ if (static_cpu_has(X86_FEATURE_PCID)) {
18731+ unsigned int cpu = raw_get_cpu();
18732+
18733+ native_write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER);
18734+ native_write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL);
18735+ raw_put_cpu_no_resched();
18736+ return;
18737+ }
18738+#endif
18739+
18740 native_write_cr3(native_read_cr3());
18741 }
18742
18743 static inline void __native_flush_tlb_global_irq_disabled(void)
18744 {
18745- unsigned long cr4;
18746+ if (static_cpu_has(X86_FEATURE_INVPCID)) {
18747+ u64 descriptor[2];
18748
18749- cr4 = native_read_cr4();
18750- /* clear PGE */
18751- native_write_cr4(cr4 & ~X86_CR4_PGE);
18752- /* write old PGE again and flush TLBs */
18753- native_write_cr4(cr4);
18754+ descriptor[0] = PCID_KERNEL;
18755+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_ALL_GLOBAL) : "memory");
18756+ } else {
18757+ unsigned long cr4;
18758+
18759+ cr4 = native_read_cr4();
18760+ /* clear PGE */
18761+ native_write_cr4(cr4 & ~X86_CR4_PGE);
18762+ /* write old PGE again and flush TLBs */
18763+ native_write_cr4(cr4);
18764+ }
18765 }
18766
18767 static inline void __native_flush_tlb_global(void)
18768@@ -49,6 +75,42 @@ static inline void __native_flush_tlb_global(void)
18769
18770 static inline void __native_flush_tlb_single(unsigned long addr)
18771 {
18772+
18773+ if (static_cpu_has(X86_FEATURE_INVPCID)) {
18774+ u64 descriptor[2];
18775+
18776+ descriptor[0] = PCID_KERNEL;
18777+ descriptor[1] = addr;
18778+
18779+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
18780+ if (!static_cpu_has(X86_FEATURE_STRONGUDEREF) || addr >= TASK_SIZE_MAX) {
18781+ if (addr < TASK_SIZE_MAX)
18782+ descriptor[1] += pax_user_shadow_base;
18783+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_ADDRESS) : "memory");
18784+ }
18785+
18786+ descriptor[0] = PCID_USER;
18787+ descriptor[1] = addr;
18788+#endif
18789+
18790+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_ADDRESS) : "memory");
18791+ return;
18792+ }
18793+
18794+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
18795+ if (static_cpu_has(X86_FEATURE_PCID)) {
18796+ unsigned int cpu = raw_get_cpu();
18797+
18798+ native_write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER | PCID_NOFLUSH);
18799+ asm volatile("invlpg (%0)" ::"r" (addr) : "memory");
18800+ native_write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL | PCID_NOFLUSH);
18801+ raw_put_cpu_no_resched();
18802+
18803+ if (!static_cpu_has(X86_FEATURE_STRONGUDEREF) && addr < TASK_SIZE_MAX)
18804+ addr += pax_user_shadow_base;
18805+ }
18806+#endif
18807+
18808 asm volatile("invlpg (%0)" ::"r" (addr) : "memory");
18809 }
18810
18811diff --git a/arch/x86/include/asm/uaccess.h b/arch/x86/include/asm/uaccess.h
18812index 5838fa9..f7ae572 100644
18813--- a/arch/x86/include/asm/uaccess.h
18814+++ b/arch/x86/include/asm/uaccess.h
18815@@ -7,6 +7,7 @@
18816 #include <linux/compiler.h>
18817 #include <linux/thread_info.h>
18818 #include <linux/string.h>
18819+#include <linux/sched.h>
18820 #include <asm/asm.h>
18821 #include <asm/page.h>
18822 #include <asm/smap.h>
18823@@ -29,7 +30,12 @@
18824
18825 #define get_ds() (KERNEL_DS)
18826 #define get_fs() (current_thread_info()->addr_limit)
18827+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
18828+void __set_fs(mm_segment_t x);
18829+void set_fs(mm_segment_t x);
18830+#else
18831 #define set_fs(x) (current_thread_info()->addr_limit = (x))
18832+#endif
18833
18834 #define segment_eq(a, b) ((a).seg == (b).seg)
18835
18836@@ -77,8 +83,33 @@
18837 * checks that the pointer is in the user space range - after calling
18838 * this function, memory access functions may still return -EFAULT.
18839 */
18840-#define access_ok(type, addr, size) \
18841- (likely(__range_not_ok(addr, size, user_addr_max()) == 0))
18842+#define __access_ok(type, addr, size) (likely(__range_not_ok(addr, size, user_addr_max()) == 0))
18843+#define access_ok(type, addr, size) \
18844+({ \
18845+ long __size = size; \
18846+ unsigned long __addr = (unsigned long)addr; \
18847+ unsigned long __addr_ao = __addr & PAGE_MASK; \
18848+ unsigned long __end_ao = __addr + __size - 1; \
18849+ bool __ret_ao = __range_not_ok(__addr, __size, user_addr_max()) == 0;\
18850+ if (__ret_ao && unlikely((__end_ao ^ __addr_ao) & PAGE_MASK)) { \
18851+ while(__addr_ao <= __end_ao) { \
18852+ char __c_ao; \
18853+ __addr_ao += PAGE_SIZE; \
18854+ if (__size > PAGE_SIZE) \
18855+ cond_resched(); \
18856+ if (__get_user(__c_ao, (char __user *)__addr)) \
18857+ break; \
18858+ if (type != VERIFY_WRITE) { \
18859+ __addr = __addr_ao; \
18860+ continue; \
18861+ } \
18862+ if (__put_user(__c_ao, (char __user *)__addr)) \
18863+ break; \
18864+ __addr = __addr_ao; \
18865+ } \
18866+ } \
18867+ __ret_ao; \
18868+})
18869
18870 /*
18871 * The exception table consists of pairs of addresses relative to the
18872@@ -168,10 +199,12 @@ __typeof__(__builtin_choose_expr(sizeof(x) > sizeof(0UL), 0ULL, 0UL))
18873 register __inttype(*(ptr)) __val_gu asm("%"_ASM_DX); \
18874 __chk_user_ptr(ptr); \
18875 might_fault(); \
18876+ pax_open_userland(); \
18877 asm volatile("call __get_user_%P3" \
18878 : "=a" (__ret_gu), "=r" (__val_gu) \
18879 : "0" (ptr), "i" (sizeof(*(ptr)))); \
18880 (x) = (__typeof__(*(ptr))) __val_gu; \
18881+ pax_close_userland(); \
18882 __ret_gu; \
18883 })
18884
18885@@ -179,13 +212,21 @@ __typeof__(__builtin_choose_expr(sizeof(x) > sizeof(0UL), 0ULL, 0UL))
18886 asm volatile("call __put_user_" #size : "=a" (__ret_pu) \
18887 : "0" ((typeof(*(ptr)))(x)), "c" (ptr) : "ebx")
18888
18889-
18890+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
18891+#define __copyuser_seg "gs;"
18892+#define __COPYUSER_SET_ES "pushl %%gs; popl %%es\n"
18893+#define __COPYUSER_RESTORE_ES "pushl %%ss; popl %%es\n"
18894+#else
18895+#define __copyuser_seg
18896+#define __COPYUSER_SET_ES
18897+#define __COPYUSER_RESTORE_ES
18898+#endif
18899
18900 #ifdef CONFIG_X86_32
18901 #define __put_user_asm_u64(x, addr, err, errret) \
18902 asm volatile(ASM_STAC "\n" \
18903- "1: movl %%eax,0(%2)\n" \
18904- "2: movl %%edx,4(%2)\n" \
18905+ "1: "__copyuser_seg"movl %%eax,0(%2)\n" \
18906+ "2: "__copyuser_seg"movl %%edx,4(%2)\n" \
18907 "3: " ASM_CLAC "\n" \
18908 ".section .fixup,\"ax\"\n" \
18909 "4: movl %3,%0\n" \
18910@@ -198,8 +239,8 @@ __typeof__(__builtin_choose_expr(sizeof(x) > sizeof(0UL), 0ULL, 0UL))
18911
18912 #define __put_user_asm_ex_u64(x, addr) \
18913 asm volatile(ASM_STAC "\n" \
18914- "1: movl %%eax,0(%1)\n" \
18915- "2: movl %%edx,4(%1)\n" \
18916+ "1: "__copyuser_seg"movl %%eax,0(%1)\n" \
18917+ "2: "__copyuser_seg"movl %%edx,4(%1)\n" \
18918 "3: " ASM_CLAC "\n" \
18919 _ASM_EXTABLE_EX(1b, 2b) \
18920 _ASM_EXTABLE_EX(2b, 3b) \
18921@@ -249,7 +290,8 @@ extern void __put_user_8(void);
18922 __typeof__(*(ptr)) __pu_val; \
18923 __chk_user_ptr(ptr); \
18924 might_fault(); \
18925- __pu_val = x; \
18926+ __pu_val = (x); \
18927+ pax_open_userland(); \
18928 switch (sizeof(*(ptr))) { \
18929 case 1: \
18930 __put_user_x(1, __pu_val, ptr, __ret_pu); \
18931@@ -267,6 +309,7 @@ extern void __put_user_8(void);
18932 __put_user_x(X, __pu_val, ptr, __ret_pu); \
18933 break; \
18934 } \
18935+ pax_close_userland(); \
18936 __ret_pu; \
18937 })
18938
18939@@ -347,8 +390,10 @@ do { \
18940 } while (0)
18941
18942 #define __get_user_asm(x, addr, err, itype, rtype, ltype, errret) \
18943+do { \
18944+ pax_open_userland(); \
18945 asm volatile(ASM_STAC "\n" \
18946- "1: mov"itype" %2,%"rtype"1\n" \
18947+ "1: "__copyuser_seg"mov"itype" %2,%"rtype"1\n"\
18948 "2: " ASM_CLAC "\n" \
18949 ".section .fixup,\"ax\"\n" \
18950 "3: mov %3,%0\n" \
18951@@ -356,8 +401,10 @@ do { \
18952 " jmp 2b\n" \
18953 ".previous\n" \
18954 _ASM_EXTABLE(1b, 3b) \
18955- : "=r" (err), ltype(x) \
18956- : "m" (__m(addr)), "i" (errret), "0" (err))
18957+ : "=r" (err), ltype (x) \
18958+ : "m" (__m(addr)), "i" (errret), "0" (err)); \
18959+ pax_close_userland(); \
18960+} while (0)
18961
18962 #define __get_user_size_ex(x, ptr, size) \
18963 do { \
18964@@ -381,7 +428,7 @@ do { \
18965 } while (0)
18966
18967 #define __get_user_asm_ex(x, addr, itype, rtype, ltype) \
18968- asm volatile("1: mov"itype" %1,%"rtype"0\n" \
18969+ asm volatile("1: "__copyuser_seg"mov"itype" %1,%"rtype"0\n"\
18970 "2:\n" \
18971 _ASM_EXTABLE_EX(1b, 2b) \
18972 : ltype(x) : "m" (__m(addr)))
18973@@ -398,13 +445,24 @@ do { \
18974 int __gu_err; \
18975 unsigned long __gu_val; \
18976 __get_user_size(__gu_val, (ptr), (size), __gu_err, -EFAULT); \
18977- (x) = (__force __typeof__(*(ptr)))__gu_val; \
18978+ (x) = (__typeof__(*(ptr)))__gu_val; \
18979 __gu_err; \
18980 })
18981
18982 /* FIXME: this hack is definitely wrong -AK */
18983 struct __large_struct { unsigned long buf[100]; };
18984-#define __m(x) (*(struct __large_struct __user *)(x))
18985+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
18986+#define ____m(x) \
18987+({ \
18988+ unsigned long ____x = (unsigned long)(x); \
18989+ if (____x < pax_user_shadow_base) \
18990+ ____x += pax_user_shadow_base; \
18991+ (typeof(x))____x; \
18992+})
18993+#else
18994+#define ____m(x) (x)
18995+#endif
18996+#define __m(x) (*(struct __large_struct __user *)____m(x))
18997
18998 /*
18999 * Tell gcc we read from memory instead of writing: this is because
19000@@ -412,8 +470,10 @@ struct __large_struct { unsigned long buf[100]; };
19001 * aliasing issues.
19002 */
19003 #define __put_user_asm(x, addr, err, itype, rtype, ltype, errret) \
19004+do { \
19005+ pax_open_userland(); \
19006 asm volatile(ASM_STAC "\n" \
19007- "1: mov"itype" %"rtype"1,%2\n" \
19008+ "1: "__copyuser_seg"mov"itype" %"rtype"1,%2\n"\
19009 "2: " ASM_CLAC "\n" \
19010 ".section .fixup,\"ax\"\n" \
19011 "3: mov %3,%0\n" \
19012@@ -421,10 +481,12 @@ struct __large_struct { unsigned long buf[100]; };
19013 ".previous\n" \
19014 _ASM_EXTABLE(1b, 3b) \
19015 : "=r"(err) \
19016- : ltype(x), "m" (__m(addr)), "i" (errret), "0" (err))
19017+ : ltype (x), "m" (__m(addr)), "i" (errret), "0" (err));\
19018+ pax_close_userland(); \
19019+} while (0)
19020
19021 #define __put_user_asm_ex(x, addr, itype, rtype, ltype) \
19022- asm volatile("1: mov"itype" %"rtype"0,%1\n" \
19023+ asm volatile("1: "__copyuser_seg"mov"itype" %"rtype"0,%1\n"\
19024 "2:\n" \
19025 _ASM_EXTABLE_EX(1b, 2b) \
19026 : : ltype(x), "m" (__m(addr)))
19027@@ -434,11 +496,13 @@ struct __large_struct { unsigned long buf[100]; };
19028 */
19029 #define uaccess_try do { \
19030 current_thread_info()->uaccess_err = 0; \
19031+ pax_open_userland(); \
19032 stac(); \
19033 barrier();
19034
19035 #define uaccess_catch(err) \
19036 clac(); \
19037+ pax_close_userland(); \
19038 (err) |= (current_thread_info()->uaccess_err ? -EFAULT : 0); \
19039 } while (0)
19040
19041@@ -463,8 +527,12 @@ struct __large_struct { unsigned long buf[100]; };
19042 * On error, the variable @x is set to zero.
19043 */
19044
19045+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19046+#define __get_user(x, ptr) get_user((x), (ptr))
19047+#else
19048 #define __get_user(x, ptr) \
19049 __get_user_nocheck((x), (ptr), sizeof(*(ptr)))
19050+#endif
19051
19052 /**
19053 * __put_user: - Write a simple value into user space, with less checking.
19054@@ -486,8 +554,12 @@ struct __large_struct { unsigned long buf[100]; };
19055 * Returns zero on success, or -EFAULT on error.
19056 */
19057
19058+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19059+#define __put_user(x, ptr) put_user((x), (ptr))
19060+#else
19061 #define __put_user(x, ptr) \
19062 __put_user_nocheck((__typeof__(*(ptr)))(x), (ptr), sizeof(*(ptr)))
19063+#endif
19064
19065 #define __get_user_unaligned __get_user
19066 #define __put_user_unaligned __put_user
19067@@ -505,7 +577,7 @@ struct __large_struct { unsigned long buf[100]; };
19068 #define get_user_ex(x, ptr) do { \
19069 unsigned long __gue_val; \
19070 __get_user_size_ex((__gue_val), (ptr), (sizeof(*(ptr)))); \
19071- (x) = (__force __typeof__(*(ptr)))__gue_val; \
19072+ (x) = (__typeof__(*(ptr)))__gue_val; \
19073 } while (0)
19074
19075 #define put_user_try uaccess_try
19076diff --git a/arch/x86/include/asm/uaccess_32.h b/arch/x86/include/asm/uaccess_32.h
19077index 7f760a9..b596b9a 100644
19078--- a/arch/x86/include/asm/uaccess_32.h
19079+++ b/arch/x86/include/asm/uaccess_32.h
19080@@ -43,6 +43,11 @@ unsigned long __must_check __copy_from_user_ll_nocache_nozero
19081 static __always_inline unsigned long __must_check
19082 __copy_to_user_inatomic(void __user *to, const void *from, unsigned long n)
19083 {
19084+ if ((long)n < 0)
19085+ return n;
19086+
19087+ check_object_size(from, n, true);
19088+
19089 if (__builtin_constant_p(n)) {
19090 unsigned long ret;
19091
19092@@ -82,12 +87,16 @@ static __always_inline unsigned long __must_check
19093 __copy_to_user(void __user *to, const void *from, unsigned long n)
19094 {
19095 might_fault();
19096+
19097 return __copy_to_user_inatomic(to, from, n);
19098 }
19099
19100 static __always_inline unsigned long
19101 __copy_from_user_inatomic(void *to, const void __user *from, unsigned long n)
19102 {
19103+ if ((long)n < 0)
19104+ return n;
19105+
19106 /* Avoid zeroing the tail if the copy fails..
19107 * If 'n' is constant and 1, 2, or 4, we do still zero on a failure,
19108 * but as the zeroing behaviour is only significant when n is not
19109@@ -137,6 +146,12 @@ static __always_inline unsigned long
19110 __copy_from_user(void *to, const void __user *from, unsigned long n)
19111 {
19112 might_fault();
19113+
19114+ if ((long)n < 0)
19115+ return n;
19116+
19117+ check_object_size(to, n, false);
19118+
19119 if (__builtin_constant_p(n)) {
19120 unsigned long ret;
19121
19122@@ -159,6 +174,10 @@ static __always_inline unsigned long __copy_from_user_nocache(void *to,
19123 const void __user *from, unsigned long n)
19124 {
19125 might_fault();
19126+
19127+ if ((long)n < 0)
19128+ return n;
19129+
19130 if (__builtin_constant_p(n)) {
19131 unsigned long ret;
19132
19133@@ -181,15 +200,19 @@ static __always_inline unsigned long
19134 __copy_from_user_inatomic_nocache(void *to, const void __user *from,
19135 unsigned long n)
19136 {
19137- return __copy_from_user_ll_nocache_nozero(to, from, n);
19138+ if ((long)n < 0)
19139+ return n;
19140+
19141+ return __copy_from_user_ll_nocache_nozero(to, from, n);
19142 }
19143
19144-unsigned long __must_check copy_to_user(void __user *to,
19145- const void *from, unsigned long n);
19146-unsigned long __must_check _copy_from_user(void *to,
19147- const void __user *from,
19148- unsigned long n);
19149-
19150+extern void copy_to_user_overflow(void)
19151+#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
19152+ __compiletime_error("copy_to_user() buffer size is not provably correct")
19153+#else
19154+ __compiletime_warning("copy_to_user() buffer size is not provably correct")
19155+#endif
19156+;
19157
19158 extern void copy_from_user_overflow(void)
19159 #ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
19160@@ -199,17 +222,60 @@ extern void copy_from_user_overflow(void)
19161 #endif
19162 ;
19163
19164-static inline unsigned long __must_check copy_from_user(void *to,
19165- const void __user *from,
19166- unsigned long n)
19167+/**
19168+ * copy_to_user: - Copy a block of data into user space.
19169+ * @to: Destination address, in user space.
19170+ * @from: Source address, in kernel space.
19171+ * @n: Number of bytes to copy.
19172+ *
19173+ * Context: User context only. This function may sleep.
19174+ *
19175+ * Copy data from kernel space to user space.
19176+ *
19177+ * Returns number of bytes that could not be copied.
19178+ * On success, this will be zero.
19179+ */
19180+static inline unsigned long __must_check
19181+copy_to_user(void __user *to, const void *from, unsigned long n)
19182 {
19183- int sz = __compiletime_object_size(to);
19184+ size_t sz = __compiletime_object_size(from);
19185
19186- if (likely(sz == -1 || sz >= n))
19187- n = _copy_from_user(to, from, n);
19188- else
19189+ if (unlikely(sz != (size_t)-1 && sz < n))
19190+ copy_to_user_overflow();
19191+ else if (access_ok(VERIFY_WRITE, to, n))
19192+ n = __copy_to_user(to, from, n);
19193+ return n;
19194+}
19195+
19196+/**
19197+ * copy_from_user: - Copy a block of data from user space.
19198+ * @to: Destination address, in kernel space.
19199+ * @from: Source address, in user space.
19200+ * @n: Number of bytes to copy.
19201+ *
19202+ * Context: User context only. This function may sleep.
19203+ *
19204+ * Copy data from user space to kernel space.
19205+ *
19206+ * Returns number of bytes that could not be copied.
19207+ * On success, this will be zero.
19208+ *
19209+ * If some data could not be copied, this function will pad the copied
19210+ * data to the requested size using zero bytes.
19211+ */
19212+static inline unsigned long __must_check
19213+copy_from_user(void *to, const void __user *from, unsigned long n)
19214+{
19215+ size_t sz = __compiletime_object_size(to);
19216+
19217+ check_object_size(to, n, false);
19218+
19219+ if (unlikely(sz != (size_t)-1 && sz < n))
19220 copy_from_user_overflow();
19221-
19222+ else if (access_ok(VERIFY_READ, from, n))
19223+ n = __copy_from_user(to, from, n);
19224+ else if ((long)n > 0)
19225+ memset(to, 0, n);
19226 return n;
19227 }
19228
19229diff --git a/arch/x86/include/asm/uaccess_64.h b/arch/x86/include/asm/uaccess_64.h
19230index 4f7923d..201b58d 100644
19231--- a/arch/x86/include/asm/uaccess_64.h
19232+++ b/arch/x86/include/asm/uaccess_64.h
19233@@ -10,6 +10,9 @@
19234 #include <asm/alternative.h>
19235 #include <asm/cpufeature.h>
19236 #include <asm/page.h>
19237+#include <asm/pgtable.h>
19238+
19239+#define set_fs(x) (current_thread_info()->addr_limit = (x))
19240
19241 /*
19242 * Copy To/From Userspace
19243@@ -17,14 +20,14 @@
19244
19245 /* Handles exceptions in both to and from, but doesn't do access_ok */
19246 __must_check unsigned long
19247-copy_user_enhanced_fast_string(void *to, const void *from, unsigned len);
19248+copy_user_enhanced_fast_string(void *to, const void *from, unsigned len) __size_overflow(3);
19249 __must_check unsigned long
19250-copy_user_generic_string(void *to, const void *from, unsigned len);
19251+copy_user_generic_string(void *to, const void *from, unsigned len) __size_overflow(3);
19252 __must_check unsigned long
19253-copy_user_generic_unrolled(void *to, const void *from, unsigned len);
19254+copy_user_generic_unrolled(void *to, const void *from, unsigned len) __size_overflow(3);
19255
19256-static __always_inline __must_check unsigned long
19257-copy_user_generic(void *to, const void *from, unsigned len)
19258+static __always_inline __must_check unsigned long
19259+copy_user_generic(void *to, const void *from, unsigned long len)
19260 {
19261 unsigned ret;
19262
19263@@ -45,138 +48,200 @@ copy_user_generic(void *to, const void *from, unsigned len)
19264 return ret;
19265 }
19266
19267+static __always_inline __must_check unsigned long
19268+__copy_to_user(void __user *to, const void *from, unsigned long len);
19269+static __always_inline __must_check unsigned long
19270+__copy_from_user(void *to, const void __user *from, unsigned long len);
19271 __must_check unsigned long
19272-_copy_to_user(void __user *to, const void *from, unsigned len);
19273-__must_check unsigned long
19274-_copy_from_user(void *to, const void __user *from, unsigned len);
19275-__must_check unsigned long
19276-copy_in_user(void __user *to, const void __user *from, unsigned len);
19277+copy_in_user(void __user *to, const void __user *from, unsigned long len);
19278+
19279+extern void copy_to_user_overflow(void)
19280+#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
19281+ __compiletime_error("copy_to_user() buffer size is not provably correct")
19282+#else
19283+ __compiletime_warning("copy_to_user() buffer size is not provably correct")
19284+#endif
19285+;
19286+
19287+extern void copy_from_user_overflow(void)
19288+#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
19289+ __compiletime_error("copy_from_user() buffer size is not provably correct")
19290+#else
19291+ __compiletime_warning("copy_from_user() buffer size is not provably correct")
19292+#endif
19293+;
19294
19295 static inline unsigned long __must_check copy_from_user(void *to,
19296 const void __user *from,
19297 unsigned long n)
19298 {
19299- int sz = __compiletime_object_size(to);
19300-
19301 might_fault();
19302- if (likely(sz == -1 || sz >= n))
19303- n = _copy_from_user(to, from, n);
19304-#ifdef CONFIG_DEBUG_VM
19305- else
19306- WARN(1, "Buffer overflow detected!\n");
19307-#endif
19308+
19309+ check_object_size(to, n, false);
19310+
19311+ if (access_ok(VERIFY_READ, from, n))
19312+ n = __copy_from_user(to, from, n);
19313+ else if (n < INT_MAX)
19314+ memset(to, 0, n);
19315 return n;
19316 }
19317
19318 static __always_inline __must_check
19319-int copy_to_user(void __user *dst, const void *src, unsigned size)
19320+int copy_to_user(void __user *dst, const void *src, unsigned long size)
19321 {
19322 might_fault();
19323
19324- return _copy_to_user(dst, src, size);
19325+ if (access_ok(VERIFY_WRITE, dst, size))
19326+ size = __copy_to_user(dst, src, size);
19327+ return size;
19328 }
19329
19330 static __always_inline __must_check
19331-int __copy_from_user(void *dst, const void __user *src, unsigned size)
19332+unsigned long __copy_from_user(void *dst, const void __user *src, unsigned long size)
19333 {
19334- int ret = 0;
19335+ size_t sz = __compiletime_object_size(dst);
19336+ unsigned ret = 0;
19337
19338 might_fault();
19339+
19340+ if (size > INT_MAX)
19341+ return size;
19342+
19343+ check_object_size(dst, size, false);
19344+
19345+#ifdef CONFIG_PAX_MEMORY_UDEREF
19346+ if (!__access_ok(VERIFY_READ, src, size))
19347+ return size;
19348+#endif
19349+
19350+ if (unlikely(sz != (size_t)-1 && sz < size)) {
19351+ copy_from_user_overflow();
19352+ return size;
19353+ }
19354+
19355 if (!__builtin_constant_p(size))
19356- return copy_user_generic(dst, (__force void *)src, size);
19357+ return copy_user_generic(dst, (__force_kernel const void *)____m(src), size);
19358 switch (size) {
19359- case 1:__get_user_asm(*(u8 *)dst, (u8 __user *)src,
19360+ case 1:__get_user_asm(*(u8 *)dst, (const u8 __user *)src,
19361 ret, "b", "b", "=q", 1);
19362 return ret;
19363- case 2:__get_user_asm(*(u16 *)dst, (u16 __user *)src,
19364+ case 2:__get_user_asm(*(u16 *)dst, (const u16 __user *)src,
19365 ret, "w", "w", "=r", 2);
19366 return ret;
19367- case 4:__get_user_asm(*(u32 *)dst, (u32 __user *)src,
19368+ case 4:__get_user_asm(*(u32 *)dst, (const u32 __user *)src,
19369 ret, "l", "k", "=r", 4);
19370 return ret;
19371- case 8:__get_user_asm(*(u64 *)dst, (u64 __user *)src,
19372+ case 8:__get_user_asm(*(u64 *)dst, (const u64 __user *)src,
19373 ret, "q", "", "=r", 8);
19374 return ret;
19375 case 10:
19376- __get_user_asm(*(u64 *)dst, (u64 __user *)src,
19377+ __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
19378 ret, "q", "", "=r", 10);
19379 if (unlikely(ret))
19380 return ret;
19381 __get_user_asm(*(u16 *)(8 + (char *)dst),
19382- (u16 __user *)(8 + (char __user *)src),
19383+ (const u16 __user *)(8 + (const char __user *)src),
19384 ret, "w", "w", "=r", 2);
19385 return ret;
19386 case 16:
19387- __get_user_asm(*(u64 *)dst, (u64 __user *)src,
19388+ __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
19389 ret, "q", "", "=r", 16);
19390 if (unlikely(ret))
19391 return ret;
19392 __get_user_asm(*(u64 *)(8 + (char *)dst),
19393- (u64 __user *)(8 + (char __user *)src),
19394+ (const u64 __user *)(8 + (const char __user *)src),
19395 ret, "q", "", "=r", 8);
19396 return ret;
19397 default:
19398- return copy_user_generic(dst, (__force void *)src, size);
19399+ return copy_user_generic(dst, (__force_kernel const void *)____m(src), size);
19400 }
19401 }
19402
19403 static __always_inline __must_check
19404-int __copy_to_user(void __user *dst, const void *src, unsigned size)
19405+unsigned long __copy_to_user(void __user *dst, const void *src, unsigned long size)
19406 {
19407- int ret = 0;
19408+ size_t sz = __compiletime_object_size(src);
19409+ unsigned ret = 0;
19410
19411 might_fault();
19412+
19413+ if (size > INT_MAX)
19414+ return size;
19415+
19416+ check_object_size(src, size, true);
19417+
19418+#ifdef CONFIG_PAX_MEMORY_UDEREF
19419+ if (!__access_ok(VERIFY_WRITE, dst, size))
19420+ return size;
19421+#endif
19422+
19423+ if (unlikely(sz != (size_t)-1 && sz < size)) {
19424+ copy_to_user_overflow();
19425+ return size;
19426+ }
19427+
19428 if (!__builtin_constant_p(size))
19429- return copy_user_generic((__force void *)dst, src, size);
19430+ return copy_user_generic((__force_kernel void *)____m(dst), src, size);
19431 switch (size) {
19432- case 1:__put_user_asm(*(u8 *)src, (u8 __user *)dst,
19433+ case 1:__put_user_asm(*(const u8 *)src, (u8 __user *)dst,
19434 ret, "b", "b", "iq", 1);
19435 return ret;
19436- case 2:__put_user_asm(*(u16 *)src, (u16 __user *)dst,
19437+ case 2:__put_user_asm(*(const u16 *)src, (u16 __user *)dst,
19438 ret, "w", "w", "ir", 2);
19439 return ret;
19440- case 4:__put_user_asm(*(u32 *)src, (u32 __user *)dst,
19441+ case 4:__put_user_asm(*(const u32 *)src, (u32 __user *)dst,
19442 ret, "l", "k", "ir", 4);
19443 return ret;
19444- case 8:__put_user_asm(*(u64 *)src, (u64 __user *)dst,
19445+ case 8:__put_user_asm(*(const u64 *)src, (u64 __user *)dst,
19446 ret, "q", "", "er", 8);
19447 return ret;
19448 case 10:
19449- __put_user_asm(*(u64 *)src, (u64 __user *)dst,
19450+ __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
19451 ret, "q", "", "er", 10);
19452 if (unlikely(ret))
19453 return ret;
19454 asm("":::"memory");
19455- __put_user_asm(4[(u16 *)src], 4 + (u16 __user *)dst,
19456+ __put_user_asm(4[(const u16 *)src], 4 + (u16 __user *)dst,
19457 ret, "w", "w", "ir", 2);
19458 return ret;
19459 case 16:
19460- __put_user_asm(*(u64 *)src, (u64 __user *)dst,
19461+ __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
19462 ret, "q", "", "er", 16);
19463 if (unlikely(ret))
19464 return ret;
19465 asm("":::"memory");
19466- __put_user_asm(1[(u64 *)src], 1 + (u64 __user *)dst,
19467+ __put_user_asm(1[(const u64 *)src], 1 + (u64 __user *)dst,
19468 ret, "q", "", "er", 8);
19469 return ret;
19470 default:
19471- return copy_user_generic((__force void *)dst, src, size);
19472+ return copy_user_generic((__force_kernel void *)____m(dst), src, size);
19473 }
19474 }
19475
19476 static __always_inline __must_check
19477-int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
19478+unsigned long __copy_in_user(void __user *dst, const void __user *src, unsigned long size)
19479 {
19480- int ret = 0;
19481+ unsigned ret = 0;
19482
19483 might_fault();
19484+
19485+ if (size > INT_MAX)
19486+ return size;
19487+
19488+#ifdef CONFIG_PAX_MEMORY_UDEREF
19489+ if (!__access_ok(VERIFY_READ, src, size))
19490+ return size;
19491+ if (!__access_ok(VERIFY_WRITE, dst, size))
19492+ return size;
19493+#endif
19494+
19495 if (!__builtin_constant_p(size))
19496- return copy_user_generic((__force void *)dst,
19497- (__force void *)src, size);
19498+ return copy_user_generic((__force_kernel void *)____m(dst),
19499+ (__force_kernel const void *)____m(src), size);
19500 switch (size) {
19501 case 1: {
19502 u8 tmp;
19503- __get_user_asm(tmp, (u8 __user *)src,
19504+ __get_user_asm(tmp, (const u8 __user *)src,
19505 ret, "b", "b", "=q", 1);
19506 if (likely(!ret))
19507 __put_user_asm(tmp, (u8 __user *)dst,
19508@@ -185,7 +250,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
19509 }
19510 case 2: {
19511 u16 tmp;
19512- __get_user_asm(tmp, (u16 __user *)src,
19513+ __get_user_asm(tmp, (const u16 __user *)src,
19514 ret, "w", "w", "=r", 2);
19515 if (likely(!ret))
19516 __put_user_asm(tmp, (u16 __user *)dst,
19517@@ -195,7 +260,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
19518
19519 case 4: {
19520 u32 tmp;
19521- __get_user_asm(tmp, (u32 __user *)src,
19522+ __get_user_asm(tmp, (const u32 __user *)src,
19523 ret, "l", "k", "=r", 4);
19524 if (likely(!ret))
19525 __put_user_asm(tmp, (u32 __user *)dst,
19526@@ -204,7 +269,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
19527 }
19528 case 8: {
19529 u64 tmp;
19530- __get_user_asm(tmp, (u64 __user *)src,
19531+ __get_user_asm(tmp, (const u64 __user *)src,
19532 ret, "q", "", "=r", 8);
19533 if (likely(!ret))
19534 __put_user_asm(tmp, (u64 __user *)dst,
19535@@ -212,41 +277,74 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
19536 return ret;
19537 }
19538 default:
19539- return copy_user_generic((__force void *)dst,
19540- (__force void *)src, size);
19541+ return copy_user_generic((__force_kernel void *)____m(dst),
19542+ (__force_kernel const void *)____m(src), size);
19543 }
19544 }
19545
19546-static __must_check __always_inline int
19547-__copy_from_user_inatomic(void *dst, const void __user *src, unsigned size)
19548+static __must_check __always_inline unsigned long
19549+__copy_from_user_inatomic(void *dst, const void __user *src, unsigned long size)
19550 {
19551- return copy_user_generic(dst, (__force const void *)src, size);
19552+ if (size > INT_MAX)
19553+ return size;
19554+
19555+#ifdef CONFIG_PAX_MEMORY_UDEREF
19556+ if (!__access_ok(VERIFY_READ, src, size))
19557+ return size;
19558+#endif
19559+
19560+ return copy_user_generic(dst, (__force_kernel const void *)____m(src), size);
19561 }
19562
19563-static __must_check __always_inline int
19564-__copy_to_user_inatomic(void __user *dst, const void *src, unsigned size)
19565+static __must_check __always_inline unsigned long
19566+__copy_to_user_inatomic(void __user *dst, const void *src, unsigned long size)
19567 {
19568- return copy_user_generic((__force void *)dst, src, size);
19569+ if (size > INT_MAX)
19570+ return size;
19571+
19572+#ifdef CONFIG_PAX_MEMORY_UDEREF
19573+ if (!__access_ok(VERIFY_WRITE, dst, size))
19574+ return size;
19575+#endif
19576+
19577+ return copy_user_generic((__force_kernel void *)____m(dst), src, size);
19578 }
19579
19580-extern long __copy_user_nocache(void *dst, const void __user *src,
19581- unsigned size, int zerorest);
19582+extern unsigned long __copy_user_nocache(void *dst, const void __user *src,
19583+ unsigned long size, int zerorest);
19584
19585-static inline int
19586-__copy_from_user_nocache(void *dst, const void __user *src, unsigned size)
19587+static inline unsigned long
19588+__copy_from_user_nocache(void *dst, const void __user *src, unsigned long size)
19589 {
19590 might_fault();
19591+
19592+ if (size > INT_MAX)
19593+ return size;
19594+
19595+#ifdef CONFIG_PAX_MEMORY_UDEREF
19596+ if (!__access_ok(VERIFY_READ, src, size))
19597+ return size;
19598+#endif
19599+
19600 return __copy_user_nocache(dst, src, size, 1);
19601 }
19602
19603-static inline int
19604+static inline unsigned long
19605 __copy_from_user_inatomic_nocache(void *dst, const void __user *src,
19606- unsigned size)
19607+ unsigned long size)
19608 {
19609+ if (size > INT_MAX)
19610+ return size;
19611+
19612+#ifdef CONFIG_PAX_MEMORY_UDEREF
19613+ if (!__access_ok(VERIFY_READ, src, size))
19614+ return size;
19615+#endif
19616+
19617 return __copy_user_nocache(dst, src, size, 0);
19618 }
19619
19620 unsigned long
19621-copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest);
19622+copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest) __size_overflow(3);
19623
19624 #endif /* _ASM_X86_UACCESS_64_H */
19625diff --git a/arch/x86/include/asm/word-at-a-time.h b/arch/x86/include/asm/word-at-a-time.h
19626index 5b238981..77fdd78 100644
19627--- a/arch/x86/include/asm/word-at-a-time.h
19628+++ b/arch/x86/include/asm/word-at-a-time.h
19629@@ -11,7 +11,7 @@
19630 * and shift, for example.
19631 */
19632 struct word_at_a_time {
19633- const unsigned long one_bits, high_bits;
19634+ unsigned long one_bits, high_bits;
19635 };
19636
19637 #define WORD_AT_A_TIME_CONSTANTS { REPEAT_BYTE(0x01), REPEAT_BYTE(0x80) }
19638diff --git a/arch/x86/include/asm/x86_init.h b/arch/x86/include/asm/x86_init.h
19639index 828a156..650e625 100644
19640--- a/arch/x86/include/asm/x86_init.h
19641+++ b/arch/x86/include/asm/x86_init.h
19642@@ -129,7 +129,7 @@ struct x86_init_ops {
19643 struct x86_init_timers timers;
19644 struct x86_init_iommu iommu;
19645 struct x86_init_pci pci;
19646-};
19647+} __no_const;
19648
19649 /**
19650 * struct x86_cpuinit_ops - platform specific cpu hotplug setups
19651@@ -140,7 +140,7 @@ struct x86_cpuinit_ops {
19652 void (*setup_percpu_clockev)(void);
19653 void (*early_percpu_clock_init)(void);
19654 void (*fixup_cpu_id)(struct cpuinfo_x86 *c, int node);
19655-};
19656+} __no_const;
19657
19658 struct timespec;
19659
19660@@ -168,7 +168,7 @@ struct x86_platform_ops {
19661 void (*save_sched_clock_state)(void);
19662 void (*restore_sched_clock_state)(void);
19663 void (*apic_post_init)(void);
19664-};
19665+} __no_const;
19666
19667 struct pci_dev;
19668 struct msi_msg;
19669@@ -182,7 +182,7 @@ struct x86_msi_ops {
19670 void (*teardown_msi_irqs)(struct pci_dev *dev);
19671 void (*restore_msi_irqs)(struct pci_dev *dev, int irq);
19672 int (*setup_hpet_msi)(unsigned int irq, unsigned int id);
19673-};
19674+} __no_const;
19675
19676 struct IO_APIC_route_entry;
19677 struct io_apic_irq_attr;
19678@@ -203,7 +203,7 @@ struct x86_io_apic_ops {
19679 unsigned int destination, int vector,
19680 struct io_apic_irq_attr *attr);
19681 void (*eoi_ioapic_pin)(int apic, int pin, int vector);
19682-};
19683+} __no_const;
19684
19685 extern struct x86_init_ops x86_init;
19686 extern struct x86_cpuinit_ops x86_cpuinit;
19687diff --git a/arch/x86/include/asm/xen/page.h b/arch/x86/include/asm/xen/page.h
19688index b913915..4f5a581 100644
19689--- a/arch/x86/include/asm/xen/page.h
19690+++ b/arch/x86/include/asm/xen/page.h
19691@@ -56,7 +56,7 @@ extern int m2p_remove_override(struct page *page,
19692 extern struct page *m2p_find_override(unsigned long mfn);
19693 extern unsigned long m2p_find_override_pfn(unsigned long mfn, unsigned long pfn);
19694
19695-static inline unsigned long pfn_to_mfn(unsigned long pfn)
19696+static inline unsigned long __intentional_overflow(-1) pfn_to_mfn(unsigned long pfn)
19697 {
19698 unsigned long mfn;
19699
19700diff --git a/arch/x86/include/asm/xsave.h b/arch/x86/include/asm/xsave.h
19701index 0415cda..3b22adc 100644
19702--- a/arch/x86/include/asm/xsave.h
19703+++ b/arch/x86/include/asm/xsave.h
19704@@ -70,8 +70,11 @@ static inline int xsave_user(struct xsave_struct __user *buf)
19705 if (unlikely(err))
19706 return -EFAULT;
19707
19708+ pax_open_userland();
19709 __asm__ __volatile__(ASM_STAC "\n"
19710- "1: .byte " REX_PREFIX "0x0f,0xae,0x27\n"
19711+ "1:"
19712+ __copyuser_seg
19713+ ".byte " REX_PREFIX "0x0f,0xae,0x27\n"
19714 "2: " ASM_CLAC "\n"
19715 ".section .fixup,\"ax\"\n"
19716 "3: movl $-1,%[err]\n"
19717@@ -81,18 +84,22 @@ static inline int xsave_user(struct xsave_struct __user *buf)
19718 : [err] "=r" (err)
19719 : "D" (buf), "a" (-1), "d" (-1), "0" (0)
19720 : "memory");
19721+ pax_close_userland();
19722 return err;
19723 }
19724
19725 static inline int xrestore_user(struct xsave_struct __user *buf, u64 mask)
19726 {
19727 int err;
19728- struct xsave_struct *xstate = ((__force struct xsave_struct *)buf);
19729+ struct xsave_struct *xstate = ((__force_kernel struct xsave_struct *)buf);
19730 u32 lmask = mask;
19731 u32 hmask = mask >> 32;
19732
19733+ pax_open_userland();
19734 __asm__ __volatile__(ASM_STAC "\n"
19735- "1: .byte " REX_PREFIX "0x0f,0xae,0x2f\n"
19736+ "1:"
19737+ __copyuser_seg
19738+ ".byte " REX_PREFIX "0x0f,0xae,0x2f\n"
19739 "2: " ASM_CLAC "\n"
19740 ".section .fixup,\"ax\"\n"
19741 "3: movl $-1,%[err]\n"
19742@@ -102,6 +109,7 @@ static inline int xrestore_user(struct xsave_struct __user *buf, u64 mask)
19743 : [err] "=r" (err)
19744 : "D" (xstate), "a" (lmask), "d" (hmask), "0" (0)
19745 : "memory"); /* memory required? */
19746+ pax_close_userland();
19747 return err;
19748 }
19749
19750diff --git a/arch/x86/include/uapi/asm/e820.h b/arch/x86/include/uapi/asm/e820.h
19751index bbae024..e1528f9 100644
19752--- a/arch/x86/include/uapi/asm/e820.h
19753+++ b/arch/x86/include/uapi/asm/e820.h
19754@@ -63,7 +63,7 @@ struct e820map {
19755 #define ISA_START_ADDRESS 0xa0000
19756 #define ISA_END_ADDRESS 0x100000
19757
19758-#define BIOS_BEGIN 0x000a0000
19759+#define BIOS_BEGIN 0x000c0000
19760 #define BIOS_END 0x00100000
19761
19762 #define BIOS_ROM_BASE 0xffe00000
19763diff --git a/arch/x86/include/uapi/asm/ptrace-abi.h b/arch/x86/include/uapi/asm/ptrace-abi.h
19764index 7b0a55a..ad115bf 100644
19765--- a/arch/x86/include/uapi/asm/ptrace-abi.h
19766+++ b/arch/x86/include/uapi/asm/ptrace-abi.h
19767@@ -49,7 +49,6 @@
19768 #define EFLAGS 144
19769 #define RSP 152
19770 #define SS 160
19771-#define ARGOFFSET R11
19772 #endif /* __ASSEMBLY__ */
19773
19774 /* top of stack page */
19775diff --git a/arch/x86/kernel/Makefile b/arch/x86/kernel/Makefile
19776index a5408b9..5133813 100644
19777--- a/arch/x86/kernel/Makefile
19778+++ b/arch/x86/kernel/Makefile
19779@@ -24,7 +24,7 @@ obj-y += time.o ioport.o ldt.o dumpstack.o nmi.o
19780 obj-y += setup.o x86_init.o i8259.o irqinit.o jump_label.o
19781 obj-$(CONFIG_IRQ_WORK) += irq_work.o
19782 obj-y += probe_roms.o
19783-obj-$(CONFIG_X86_32) += i386_ksyms_32.o
19784+obj-$(CONFIG_X86_32) += sys_i386_32.o i386_ksyms_32.o
19785 obj-$(CONFIG_X86_64) += sys_x86_64.o x8664_ksyms_64.o
19786 obj-y += syscall_$(BITS).o
19787 obj-$(CONFIG_X86_64) += vsyscall_64.o
19788diff --git a/arch/x86/kernel/acpi/boot.c b/arch/x86/kernel/acpi/boot.c
19789index 40c7660..f709f4b 100644
19790--- a/arch/x86/kernel/acpi/boot.c
19791+++ b/arch/x86/kernel/acpi/boot.c
19792@@ -1365,7 +1365,7 @@ static int __init dmi_ignore_irq0_timer_override(const struct dmi_system_id *d)
19793 * If your system is blacklisted here, but you find that acpi=force
19794 * works for you, please contact linux-acpi@vger.kernel.org
19795 */
19796-static struct dmi_system_id __initdata acpi_dmi_table[] = {
19797+static const struct dmi_system_id __initconst acpi_dmi_table[] = {
19798 /*
19799 * Boxes that need ACPI disabled
19800 */
19801@@ -1440,7 +1440,7 @@ static struct dmi_system_id __initdata acpi_dmi_table[] = {
19802 };
19803
19804 /* second table for DMI checks that should run after early-quirks */
19805-static struct dmi_system_id __initdata acpi_dmi_table_late[] = {
19806+static const struct dmi_system_id __initconst acpi_dmi_table_late[] = {
19807 /*
19808 * HP laptops which use a DSDT reporting as HP/SB400/10000,
19809 * which includes some code which overrides all temperature
19810diff --git a/arch/x86/kernel/acpi/sleep.c b/arch/x86/kernel/acpi/sleep.c
19811index 3312010..a65ca7b 100644
19812--- a/arch/x86/kernel/acpi/sleep.c
19813+++ b/arch/x86/kernel/acpi/sleep.c
19814@@ -88,8 +88,12 @@ int x86_acpi_suspend_lowlevel(void)
19815 #else /* CONFIG_64BIT */
19816 #ifdef CONFIG_SMP
19817 stack_start = (unsigned long)temp_stack + sizeof(temp_stack);
19818+
19819+ pax_open_kernel();
19820 early_gdt_descr.address =
19821 (unsigned long)get_cpu_gdt_table(smp_processor_id());
19822+ pax_close_kernel();
19823+
19824 initial_gs = per_cpu_offset(smp_processor_id());
19825 #endif
19826 initial_code = (unsigned long)wakeup_long64;
19827diff --git a/arch/x86/kernel/acpi/wakeup_32.S b/arch/x86/kernel/acpi/wakeup_32.S
19828index d1daa66..59fecba 100644
19829--- a/arch/x86/kernel/acpi/wakeup_32.S
19830+++ b/arch/x86/kernel/acpi/wakeup_32.S
19831@@ -29,13 +29,11 @@ wakeup_pmode_return:
19832 # and restore the stack ... but you need gdt for this to work
19833 movl saved_context_esp, %esp
19834
19835- movl %cs:saved_magic, %eax
19836- cmpl $0x12345678, %eax
19837+ cmpl $0x12345678, saved_magic
19838 jne bogus_magic
19839
19840 # jump to place where we left off
19841- movl saved_eip, %eax
19842- jmp *%eax
19843+ jmp *(saved_eip)
19844
19845 bogus_magic:
19846 jmp bogus_magic
19847diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c
19848index 15e8563..323cbe1 100644
19849--- a/arch/x86/kernel/alternative.c
19850+++ b/arch/x86/kernel/alternative.c
19851@@ -269,6 +269,13 @@ void __init_or_module apply_alternatives(struct alt_instr *start,
19852 */
19853 for (a = start; a < end; a++) {
19854 instr = (u8 *)&a->instr_offset + a->instr_offset;
19855+
19856+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
19857+ instr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
19858+ if (instr < (u8 *)_text || (u8 *)_einittext <= instr)
19859+ instr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
19860+#endif
19861+
19862 replacement = (u8 *)&a->repl_offset + a->repl_offset;
19863 BUG_ON(a->replacementlen > a->instrlen);
19864 BUG_ON(a->instrlen > sizeof(insnbuf));
19865@@ -300,10 +307,16 @@ static void alternatives_smp_lock(const s32 *start, const s32 *end,
19866 for (poff = start; poff < end; poff++) {
19867 u8 *ptr = (u8 *)poff + *poff;
19868
19869+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
19870+ ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
19871+ if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
19872+ ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
19873+#endif
19874+
19875 if (!*poff || ptr < text || ptr >= text_end)
19876 continue;
19877 /* turn DS segment override prefix into lock prefix */
19878- if (*ptr == 0x3e)
19879+ if (*ktla_ktva(ptr) == 0x3e)
19880 text_poke(ptr, ((unsigned char []){0xf0}), 1);
19881 }
19882 mutex_unlock(&text_mutex);
19883@@ -318,10 +331,16 @@ static void alternatives_smp_unlock(const s32 *start, const s32 *end,
19884 for (poff = start; poff < end; poff++) {
19885 u8 *ptr = (u8 *)poff + *poff;
19886
19887+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
19888+ ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
19889+ if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
19890+ ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
19891+#endif
19892+
19893 if (!*poff || ptr < text || ptr >= text_end)
19894 continue;
19895 /* turn lock prefix into DS segment override prefix */
19896- if (*ptr == 0xf0)
19897+ if (*ktla_ktva(ptr) == 0xf0)
19898 text_poke(ptr, ((unsigned char []){0x3E}), 1);
19899 }
19900 mutex_unlock(&text_mutex);
19901@@ -469,7 +488,7 @@ void __init_or_module apply_paravirt(struct paravirt_patch_site *start,
19902
19903 BUG_ON(p->len > MAX_PATCH_LEN);
19904 /* prep the buffer with the original instructions */
19905- memcpy(insnbuf, p->instr, p->len);
19906+ memcpy(insnbuf, ktla_ktva(p->instr), p->len);
19907 used = pv_init_ops.patch(p->instrtype, p->clobbers, insnbuf,
19908 (unsigned long)p->instr, p->len);
19909
19910@@ -516,7 +535,7 @@ void __init alternative_instructions(void)
19911 if (!uniproc_patched || num_possible_cpus() == 1)
19912 free_init_pages("SMP alternatives",
19913 (unsigned long)__smp_locks,
19914- (unsigned long)__smp_locks_end);
19915+ PAGE_ALIGN((unsigned long)__smp_locks_end));
19916 #endif
19917
19918 apply_paravirt(__parainstructions, __parainstructions_end);
19919@@ -536,13 +555,17 @@ void __init alternative_instructions(void)
19920 * instructions. And on the local CPU you need to be protected again NMI or MCE
19921 * handlers seeing an inconsistent instruction while you patch.
19922 */
19923-void *__init_or_module text_poke_early(void *addr, const void *opcode,
19924+void *__kprobes text_poke_early(void *addr, const void *opcode,
19925 size_t len)
19926 {
19927 unsigned long flags;
19928 local_irq_save(flags);
19929- memcpy(addr, opcode, len);
19930+
19931+ pax_open_kernel();
19932+ memcpy(ktla_ktva(addr), opcode, len);
19933 sync_core();
19934+ pax_close_kernel();
19935+
19936 local_irq_restore(flags);
19937 /* Could also do a CLFLUSH here to speed up CPU recovery; but
19938 that causes hangs on some VIA CPUs. */
19939@@ -564,36 +587,22 @@ void *__init_or_module text_poke_early(void *addr, const void *opcode,
19940 */
19941 void *__kprobes text_poke(void *addr, const void *opcode, size_t len)
19942 {
19943- unsigned long flags;
19944- char *vaddr;
19945+ unsigned char *vaddr = ktla_ktva(addr);
19946 struct page *pages[2];
19947- int i;
19948+ size_t i;
19949
19950 if (!core_kernel_text((unsigned long)addr)) {
19951- pages[0] = vmalloc_to_page(addr);
19952- pages[1] = vmalloc_to_page(addr + PAGE_SIZE);
19953+ pages[0] = vmalloc_to_page(vaddr);
19954+ pages[1] = vmalloc_to_page(vaddr + PAGE_SIZE);
19955 } else {
19956- pages[0] = virt_to_page(addr);
19957+ pages[0] = virt_to_page(vaddr);
19958 WARN_ON(!PageReserved(pages[0]));
19959- pages[1] = virt_to_page(addr + PAGE_SIZE);
19960+ pages[1] = virt_to_page(vaddr + PAGE_SIZE);
19961 }
19962 BUG_ON(!pages[0]);
19963- local_irq_save(flags);
19964- set_fixmap(FIX_TEXT_POKE0, page_to_phys(pages[0]));
19965- if (pages[1])
19966- set_fixmap(FIX_TEXT_POKE1, page_to_phys(pages[1]));
19967- vaddr = (char *)fix_to_virt(FIX_TEXT_POKE0);
19968- memcpy(&vaddr[(unsigned long)addr & ~PAGE_MASK], opcode, len);
19969- clear_fixmap(FIX_TEXT_POKE0);
19970- if (pages[1])
19971- clear_fixmap(FIX_TEXT_POKE1);
19972- local_flush_tlb();
19973- sync_core();
19974- /* Could also do a CLFLUSH here to speed up CPU recovery; but
19975- that causes hangs on some VIA CPUs. */
19976+ text_poke_early(addr, opcode, len);
19977 for (i = 0; i < len; i++)
19978- BUG_ON(((char *)addr)[i] != ((char *)opcode)[i]);
19979- local_irq_restore(flags);
19980+ BUG_ON((vaddr)[i] != ((const unsigned char *)opcode)[i]);
19981 return addr;
19982 }
19983
19984@@ -613,7 +622,7 @@ int poke_int3_handler(struct pt_regs *regs)
19985 if (likely(!bp_patching_in_progress))
19986 return 0;
19987
19988- if (user_mode_vm(regs) || regs->ip != (unsigned long)bp_int3_addr)
19989+ if (user_mode(regs) || regs->ip != (unsigned long)bp_int3_addr)
19990 return 0;
19991
19992 /* set up the specified breakpoint handler */
19993@@ -647,7 +656,7 @@ int poke_int3_handler(struct pt_regs *regs)
19994 */
19995 void *text_poke_bp(void *addr, const void *opcode, size_t len, void *handler)
19996 {
19997- unsigned char int3 = 0xcc;
19998+ const unsigned char int3 = 0xcc;
19999
20000 bp_int3_handler = handler;
20001 bp_int3_addr = (u8 *)addr + sizeof(int3);
20002diff --git a/arch/x86/kernel/apic/apic.c b/arch/x86/kernel/apic/apic.c
20003index a7eb82d..f6e52d4 100644
20004--- a/arch/x86/kernel/apic/apic.c
20005+++ b/arch/x86/kernel/apic/apic.c
20006@@ -190,7 +190,7 @@ int first_system_vector = 0xfe;
20007 /*
20008 * Debug level, exported for io_apic.c
20009 */
20010-unsigned int apic_verbosity;
20011+int apic_verbosity;
20012
20013 int pic_mode;
20014
20015@@ -1985,7 +1985,7 @@ static inline void __smp_error_interrupt(struct pt_regs *regs)
20016 apic_write(APIC_ESR, 0);
20017 v1 = apic_read(APIC_ESR);
20018 ack_APIC_irq();
20019- atomic_inc(&irq_err_count);
20020+ atomic_inc_unchecked(&irq_err_count);
20021
20022 apic_printk(APIC_DEBUG, KERN_DEBUG "APIC error on CPU%d: %02x(%02x)",
20023 smp_processor_id(), v0 , v1);
20024diff --git a/arch/x86/kernel/apic/apic_flat_64.c b/arch/x86/kernel/apic/apic_flat_64.c
20025index 00c77cf..2dc6a2d 100644
20026--- a/arch/x86/kernel/apic/apic_flat_64.c
20027+++ b/arch/x86/kernel/apic/apic_flat_64.c
20028@@ -157,7 +157,7 @@ static int flat_probe(void)
20029 return 1;
20030 }
20031
20032-static struct apic apic_flat = {
20033+static struct apic apic_flat __read_only = {
20034 .name = "flat",
20035 .probe = flat_probe,
20036 .acpi_madt_oem_check = flat_acpi_madt_oem_check,
20037@@ -271,7 +271,7 @@ static int physflat_probe(void)
20038 return 0;
20039 }
20040
20041-static struct apic apic_physflat = {
20042+static struct apic apic_physflat __read_only = {
20043
20044 .name = "physical flat",
20045 .probe = physflat_probe,
20046diff --git a/arch/x86/kernel/apic/apic_noop.c b/arch/x86/kernel/apic/apic_noop.c
20047index e145f28..2752888 100644
20048--- a/arch/x86/kernel/apic/apic_noop.c
20049+++ b/arch/x86/kernel/apic/apic_noop.c
20050@@ -119,7 +119,7 @@ static void noop_apic_write(u32 reg, u32 v)
20051 WARN_ON_ONCE(cpu_has_apic && !disable_apic);
20052 }
20053
20054-struct apic apic_noop = {
20055+struct apic apic_noop __read_only = {
20056 .name = "noop",
20057 .probe = noop_probe,
20058 .acpi_madt_oem_check = NULL,
20059diff --git a/arch/x86/kernel/apic/bigsmp_32.c b/arch/x86/kernel/apic/bigsmp_32.c
20060index d50e364..543bee3 100644
20061--- a/arch/x86/kernel/apic/bigsmp_32.c
20062+++ b/arch/x86/kernel/apic/bigsmp_32.c
20063@@ -152,7 +152,7 @@ static int probe_bigsmp(void)
20064 return dmi_bigsmp;
20065 }
20066
20067-static struct apic apic_bigsmp = {
20068+static struct apic apic_bigsmp __read_only = {
20069
20070 .name = "bigsmp",
20071 .probe = probe_bigsmp,
20072diff --git a/arch/x86/kernel/apic/es7000_32.c b/arch/x86/kernel/apic/es7000_32.c
20073index c552247..587a316 100644
20074--- a/arch/x86/kernel/apic/es7000_32.c
20075+++ b/arch/x86/kernel/apic/es7000_32.c
20076@@ -608,8 +608,7 @@ static int es7000_mps_oem_check_cluster(struct mpc_table *mpc, char *oem,
20077 return ret && es7000_apic_is_cluster();
20078 }
20079
20080-/* We've been warned by a false positive warning.Use __refdata to keep calm. */
20081-static struct apic __refdata apic_es7000_cluster = {
20082+static struct apic apic_es7000_cluster __read_only = {
20083
20084 .name = "es7000",
20085 .probe = probe_es7000,
20086@@ -675,7 +674,7 @@ static struct apic __refdata apic_es7000_cluster = {
20087 .x86_32_early_logical_apicid = es7000_early_logical_apicid,
20088 };
20089
20090-static struct apic __refdata apic_es7000 = {
20091+static struct apic apic_es7000 __read_only = {
20092
20093 .name = "es7000",
20094 .probe = probe_es7000,
20095diff --git a/arch/x86/kernel/apic/io_apic.c b/arch/x86/kernel/apic/io_apic.c
20096index e63a5bd..c0babf8 100644
20097--- a/arch/x86/kernel/apic/io_apic.c
20098+++ b/arch/x86/kernel/apic/io_apic.c
20099@@ -1060,7 +1060,7 @@ int IO_APIC_get_PCI_irq_vector(int bus, int slot, int pin,
20100 }
20101 EXPORT_SYMBOL(IO_APIC_get_PCI_irq_vector);
20102
20103-void lock_vector_lock(void)
20104+void lock_vector_lock(void) __acquires(vector_lock)
20105 {
20106 /* Used to the online set of cpus does not change
20107 * during assign_irq_vector.
20108@@ -1068,7 +1068,7 @@ void lock_vector_lock(void)
20109 raw_spin_lock(&vector_lock);
20110 }
20111
20112-void unlock_vector_lock(void)
20113+void unlock_vector_lock(void) __releases(vector_lock)
20114 {
20115 raw_spin_unlock(&vector_lock);
20116 }
20117@@ -2367,7 +2367,7 @@ static void ack_apic_edge(struct irq_data *data)
20118 ack_APIC_irq();
20119 }
20120
20121-atomic_t irq_mis_count;
20122+atomic_unchecked_t irq_mis_count;
20123
20124 #ifdef CONFIG_GENERIC_PENDING_IRQ
20125 static bool io_apic_level_ack_pending(struct irq_cfg *cfg)
20126@@ -2508,7 +2508,7 @@ static void ack_apic_level(struct irq_data *data)
20127 * at the cpu.
20128 */
20129 if (!(v & (1 << (i & 0x1f)))) {
20130- atomic_inc(&irq_mis_count);
20131+ atomic_inc_unchecked(&irq_mis_count);
20132
20133 eoi_ioapic_irq(irq, cfg);
20134 }
20135diff --git a/arch/x86/kernel/apic/numaq_32.c b/arch/x86/kernel/apic/numaq_32.c
20136index 1e42e8f..daacf44 100644
20137--- a/arch/x86/kernel/apic/numaq_32.c
20138+++ b/arch/x86/kernel/apic/numaq_32.c
20139@@ -455,8 +455,7 @@ static void numaq_setup_portio_remap(void)
20140 (u_long) xquad_portio, (u_long) num_quads*XQUAD_PORTIO_QUAD);
20141 }
20142
20143-/* Use __refdata to keep false positive warning calm. */
20144-static struct apic __refdata apic_numaq = {
20145+static struct apic apic_numaq __read_only = {
20146
20147 .name = "NUMAQ",
20148 .probe = probe_numaq,
20149diff --git a/arch/x86/kernel/apic/probe_32.c b/arch/x86/kernel/apic/probe_32.c
20150index eb35ef9..f184a21 100644
20151--- a/arch/x86/kernel/apic/probe_32.c
20152+++ b/arch/x86/kernel/apic/probe_32.c
20153@@ -72,7 +72,7 @@ static int probe_default(void)
20154 return 1;
20155 }
20156
20157-static struct apic apic_default = {
20158+static struct apic apic_default __read_only = {
20159
20160 .name = "default",
20161 .probe = probe_default,
20162diff --git a/arch/x86/kernel/apic/summit_32.c b/arch/x86/kernel/apic/summit_32.c
20163index 77c95c0..434f8a4 100644
20164--- a/arch/x86/kernel/apic/summit_32.c
20165+++ b/arch/x86/kernel/apic/summit_32.c
20166@@ -486,7 +486,7 @@ void setup_summit(void)
20167 }
20168 #endif
20169
20170-static struct apic apic_summit = {
20171+static struct apic apic_summit __read_only = {
20172
20173 .name = "summit",
20174 .probe = probe_summit,
20175diff --git a/arch/x86/kernel/apic/x2apic_cluster.c b/arch/x86/kernel/apic/x2apic_cluster.c
20176index 140e29d..d88bc95 100644
20177--- a/arch/x86/kernel/apic/x2apic_cluster.c
20178+++ b/arch/x86/kernel/apic/x2apic_cluster.c
20179@@ -183,7 +183,7 @@ update_clusterinfo(struct notifier_block *nfb, unsigned long action, void *hcpu)
20180 return notifier_from_errno(err);
20181 }
20182
20183-static struct notifier_block __refdata x2apic_cpu_notifier = {
20184+static struct notifier_block x2apic_cpu_notifier = {
20185 .notifier_call = update_clusterinfo,
20186 };
20187
20188@@ -235,7 +235,7 @@ static void cluster_vector_allocation_domain(int cpu, struct cpumask *retmask,
20189 cpumask_and(retmask, mask, per_cpu(cpus_in_cluster, cpu));
20190 }
20191
20192-static struct apic apic_x2apic_cluster = {
20193+static struct apic apic_x2apic_cluster __read_only = {
20194
20195 .name = "cluster x2apic",
20196 .probe = x2apic_cluster_probe,
20197diff --git a/arch/x86/kernel/apic/x2apic_phys.c b/arch/x86/kernel/apic/x2apic_phys.c
20198index 562a76d..a003c0f 100644
20199--- a/arch/x86/kernel/apic/x2apic_phys.c
20200+++ b/arch/x86/kernel/apic/x2apic_phys.c
20201@@ -89,7 +89,7 @@ static int x2apic_phys_probe(void)
20202 return apic == &apic_x2apic_phys;
20203 }
20204
20205-static struct apic apic_x2apic_phys = {
20206+static struct apic apic_x2apic_phys __read_only = {
20207
20208 .name = "physical x2apic",
20209 .probe = x2apic_phys_probe,
20210diff --git a/arch/x86/kernel/apic/x2apic_uv_x.c b/arch/x86/kernel/apic/x2apic_uv_x.c
20211index a419814..1dd34a0 100644
20212--- a/arch/x86/kernel/apic/x2apic_uv_x.c
20213+++ b/arch/x86/kernel/apic/x2apic_uv_x.c
20214@@ -357,7 +357,7 @@ static int uv_probe(void)
20215 return apic == &apic_x2apic_uv_x;
20216 }
20217
20218-static struct apic __refdata apic_x2apic_uv_x = {
20219+static struct apic apic_x2apic_uv_x __read_only = {
20220
20221 .name = "UV large system",
20222 .probe = uv_probe,
20223diff --git a/arch/x86/kernel/apm_32.c b/arch/x86/kernel/apm_32.c
20224index 3ab0343..814c4787 100644
20225--- a/arch/x86/kernel/apm_32.c
20226+++ b/arch/x86/kernel/apm_32.c
20227@@ -433,7 +433,7 @@ static DEFINE_MUTEX(apm_mutex);
20228 * This is for buggy BIOS's that refer to (real mode) segment 0x40
20229 * even though they are called in protected mode.
20230 */
20231-static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
20232+static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
20233 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
20234
20235 static const char driver_version[] = "1.16ac"; /* no spaces */
20236@@ -611,7 +611,10 @@ static long __apm_bios_call(void *_call)
20237 BUG_ON(cpu != 0);
20238 gdt = get_cpu_gdt_table(cpu);
20239 save_desc_40 = gdt[0x40 / 8];
20240+
20241+ pax_open_kernel();
20242 gdt[0x40 / 8] = bad_bios_desc;
20243+ pax_close_kernel();
20244
20245 apm_irq_save(flags);
20246 APM_DO_SAVE_SEGS;
20247@@ -620,7 +623,11 @@ static long __apm_bios_call(void *_call)
20248 &call->esi);
20249 APM_DO_RESTORE_SEGS;
20250 apm_irq_restore(flags);
20251+
20252+ pax_open_kernel();
20253 gdt[0x40 / 8] = save_desc_40;
20254+ pax_close_kernel();
20255+
20256 put_cpu();
20257
20258 return call->eax & 0xff;
20259@@ -687,7 +694,10 @@ static long __apm_bios_call_simple(void *_call)
20260 BUG_ON(cpu != 0);
20261 gdt = get_cpu_gdt_table(cpu);
20262 save_desc_40 = gdt[0x40 / 8];
20263+
20264+ pax_open_kernel();
20265 gdt[0x40 / 8] = bad_bios_desc;
20266+ pax_close_kernel();
20267
20268 apm_irq_save(flags);
20269 APM_DO_SAVE_SEGS;
20270@@ -695,7 +705,11 @@ static long __apm_bios_call_simple(void *_call)
20271 &call->eax);
20272 APM_DO_RESTORE_SEGS;
20273 apm_irq_restore(flags);
20274+
20275+ pax_open_kernel();
20276 gdt[0x40 / 8] = save_desc_40;
20277+ pax_close_kernel();
20278+
20279 put_cpu();
20280 return error;
20281 }
20282@@ -2362,12 +2376,15 @@ static int __init apm_init(void)
20283 * code to that CPU.
20284 */
20285 gdt = get_cpu_gdt_table(0);
20286+
20287+ pax_open_kernel();
20288 set_desc_base(&gdt[APM_CS >> 3],
20289 (unsigned long)__va((unsigned long)apm_info.bios.cseg << 4));
20290 set_desc_base(&gdt[APM_CS_16 >> 3],
20291 (unsigned long)__va((unsigned long)apm_info.bios.cseg_16 << 4));
20292 set_desc_base(&gdt[APM_DS >> 3],
20293 (unsigned long)__va((unsigned long)apm_info.bios.dseg << 4));
20294+ pax_close_kernel();
20295
20296 proc_create("apm", 0, NULL, &apm_file_ops);
20297
20298diff --git a/arch/x86/kernel/asm-offsets.c b/arch/x86/kernel/asm-offsets.c
20299index 2861082..6d4718e 100644
20300--- a/arch/x86/kernel/asm-offsets.c
20301+++ b/arch/x86/kernel/asm-offsets.c
20302@@ -33,6 +33,8 @@ void common(void) {
20303 OFFSET(TI_status, thread_info, status);
20304 OFFSET(TI_addr_limit, thread_info, addr_limit);
20305 OFFSET(TI_preempt_count, thread_info, preempt_count);
20306+ OFFSET(TI_lowest_stack, thread_info, lowest_stack);
20307+ DEFINE(TI_task_thread_sp0, offsetof(struct task_struct, thread.sp0) - offsetof(struct task_struct, tinfo));
20308
20309 BLANK();
20310 OFFSET(crypto_tfm_ctx_offset, crypto_tfm, __crt_ctx);
20311@@ -53,8 +55,26 @@ void common(void) {
20312 OFFSET(PV_CPU_irq_enable_sysexit, pv_cpu_ops, irq_enable_sysexit);
20313 OFFSET(PV_CPU_read_cr0, pv_cpu_ops, read_cr0);
20314 OFFSET(PV_MMU_read_cr2, pv_mmu_ops, read_cr2);
20315+
20316+#ifdef CONFIG_PAX_KERNEXEC
20317+ OFFSET(PV_CPU_write_cr0, pv_cpu_ops, write_cr0);
20318 #endif
20319
20320+#ifdef CONFIG_PAX_MEMORY_UDEREF
20321+ OFFSET(PV_MMU_read_cr3, pv_mmu_ops, read_cr3);
20322+ OFFSET(PV_MMU_write_cr3, pv_mmu_ops, write_cr3);
20323+#ifdef CONFIG_X86_64
20324+ OFFSET(PV_MMU_set_pgd_batched, pv_mmu_ops, set_pgd_batched);
20325+#endif
20326+#endif
20327+
20328+#endif
20329+
20330+ BLANK();
20331+ DEFINE(PAGE_SIZE_asm, PAGE_SIZE);
20332+ DEFINE(PAGE_SHIFT_asm, PAGE_SHIFT);
20333+ DEFINE(THREAD_SIZE_asm, THREAD_SIZE);
20334+
20335 #ifdef CONFIG_XEN
20336 BLANK();
20337 OFFSET(XEN_vcpu_info_mask, vcpu_info, evtchn_upcall_mask);
20338diff --git a/arch/x86/kernel/asm-offsets_64.c b/arch/x86/kernel/asm-offsets_64.c
20339index e7c798b..2b2019b 100644
20340--- a/arch/x86/kernel/asm-offsets_64.c
20341+++ b/arch/x86/kernel/asm-offsets_64.c
20342@@ -77,6 +77,7 @@ int main(void)
20343 BLANK();
20344 #undef ENTRY
20345
20346+ DEFINE(TSS_size, sizeof(struct tss_struct));
20347 OFFSET(TSS_ist, tss_struct, x86_tss.ist);
20348 BLANK();
20349
20350diff --git a/arch/x86/kernel/cpu/Makefile b/arch/x86/kernel/cpu/Makefile
20351index 47b56a7..efc2bc6 100644
20352--- a/arch/x86/kernel/cpu/Makefile
20353+++ b/arch/x86/kernel/cpu/Makefile
20354@@ -8,10 +8,6 @@ CFLAGS_REMOVE_common.o = -pg
20355 CFLAGS_REMOVE_perf_event.o = -pg
20356 endif
20357
20358-# Make sure load_percpu_segment has no stackprotector
20359-nostackp := $(call cc-option, -fno-stack-protector)
20360-CFLAGS_common.o := $(nostackp)
20361-
20362 obj-y := intel_cacheinfo.o scattered.o topology.o
20363 obj-y += proc.o capflags.o powerflags.o common.o
20364 obj-y += rdrand.o
20365diff --git a/arch/x86/kernel/cpu/amd.c b/arch/x86/kernel/cpu/amd.c
20366index 903a264..fc955f3 100644
20367--- a/arch/x86/kernel/cpu/amd.c
20368+++ b/arch/x86/kernel/cpu/amd.c
20369@@ -743,7 +743,7 @@ static void init_amd(struct cpuinfo_x86 *c)
20370 static unsigned int amd_size_cache(struct cpuinfo_x86 *c, unsigned int size)
20371 {
20372 /* AMD errata T13 (order #21922) */
20373- if ((c->x86 == 6)) {
20374+ if (c->x86 == 6) {
20375 /* Duron Rev A0 */
20376 if (c->x86_model == 3 && c->x86_mask == 0)
20377 size = 64;
20378diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c
20379index 2793d1f..b4f313a 100644
20380--- a/arch/x86/kernel/cpu/common.c
20381+++ b/arch/x86/kernel/cpu/common.c
20382@@ -88,60 +88,6 @@ static const struct cpu_dev default_cpu = {
20383
20384 static const struct cpu_dev *this_cpu = &default_cpu;
20385
20386-DEFINE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page) = { .gdt = {
20387-#ifdef CONFIG_X86_64
20388- /*
20389- * We need valid kernel segments for data and code in long mode too
20390- * IRET will check the segment types kkeil 2000/10/28
20391- * Also sysret mandates a special GDT layout
20392- *
20393- * TLS descriptors are currently at a different place compared to i386.
20394- * Hopefully nobody expects them at a fixed place (Wine?)
20395- */
20396- [GDT_ENTRY_KERNEL32_CS] = GDT_ENTRY_INIT(0xc09b, 0, 0xfffff),
20397- [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xa09b, 0, 0xfffff),
20398- [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc093, 0, 0xfffff),
20399- [GDT_ENTRY_DEFAULT_USER32_CS] = GDT_ENTRY_INIT(0xc0fb, 0, 0xfffff),
20400- [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f3, 0, 0xfffff),
20401- [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xa0fb, 0, 0xfffff),
20402-#else
20403- [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xc09a, 0, 0xfffff),
20404- [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
20405- [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xc0fa, 0, 0xfffff),
20406- [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f2, 0, 0xfffff),
20407- /*
20408- * Segments used for calling PnP BIOS have byte granularity.
20409- * They code segments and data segments have fixed 64k limits,
20410- * the transfer segment sizes are set at run time.
20411- */
20412- /* 32-bit code */
20413- [GDT_ENTRY_PNPBIOS_CS32] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
20414- /* 16-bit code */
20415- [GDT_ENTRY_PNPBIOS_CS16] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
20416- /* 16-bit data */
20417- [GDT_ENTRY_PNPBIOS_DS] = GDT_ENTRY_INIT(0x0092, 0, 0xffff),
20418- /* 16-bit data */
20419- [GDT_ENTRY_PNPBIOS_TS1] = GDT_ENTRY_INIT(0x0092, 0, 0),
20420- /* 16-bit data */
20421- [GDT_ENTRY_PNPBIOS_TS2] = GDT_ENTRY_INIT(0x0092, 0, 0),
20422- /*
20423- * The APM segments have byte granularity and their bases
20424- * are set at run time. All have 64k limits.
20425- */
20426- /* 32-bit code */
20427- [GDT_ENTRY_APMBIOS_BASE] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
20428- /* 16-bit code */
20429- [GDT_ENTRY_APMBIOS_BASE+1] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
20430- /* data */
20431- [GDT_ENTRY_APMBIOS_BASE+2] = GDT_ENTRY_INIT(0x4092, 0, 0xffff),
20432-
20433- [GDT_ENTRY_ESPFIX_SS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
20434- [GDT_ENTRY_PERCPU] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
20435- GDT_STACK_CANARY_INIT
20436-#endif
20437-} };
20438-EXPORT_PER_CPU_SYMBOL_GPL(gdt_page);
20439-
20440 static int __init x86_xsave_setup(char *s)
20441 {
20442 setup_clear_cpu_cap(X86_FEATURE_XSAVE);
20443@@ -288,6 +234,59 @@ static __always_inline void setup_smap(struct cpuinfo_x86 *c)
20444 set_in_cr4(X86_CR4_SMAP);
20445 }
20446
20447+#ifdef CONFIG_X86_64
20448+static __init int setup_disable_pcid(char *arg)
20449+{
20450+ setup_clear_cpu_cap(X86_FEATURE_PCID);
20451+ setup_clear_cpu_cap(X86_FEATURE_INVPCID);
20452+
20453+#ifdef CONFIG_PAX_MEMORY_UDEREF
20454+ if (clone_pgd_mask != ~(pgdval_t)0UL)
20455+ pax_user_shadow_base = 1UL << TASK_SIZE_MAX_SHIFT;
20456+#endif
20457+
20458+ return 1;
20459+}
20460+__setup("nopcid", setup_disable_pcid);
20461+
20462+static void setup_pcid(struct cpuinfo_x86 *c)
20463+{
20464+ if (!cpu_has(c, X86_FEATURE_PCID)) {
20465+ clear_cpu_cap(c, X86_FEATURE_INVPCID);
20466+
20467+#ifdef CONFIG_PAX_MEMORY_UDEREF
20468+ if (clone_pgd_mask != ~(pgdval_t)0UL) {
20469+ pax_open_kernel();
20470+ pax_user_shadow_base = 1UL << TASK_SIZE_MAX_SHIFT;
20471+ pax_close_kernel();
20472+ printk("PAX: slow and weak UDEREF enabled\n");
20473+ } else
20474+ printk("PAX: UDEREF disabled\n");
20475+#endif
20476+
20477+ return;
20478+ }
20479+
20480+ printk("PAX: PCID detected\n");
20481+ set_in_cr4(X86_CR4_PCIDE);
20482+
20483+#ifdef CONFIG_PAX_MEMORY_UDEREF
20484+ pax_open_kernel();
20485+ clone_pgd_mask = ~(pgdval_t)0UL;
20486+ pax_close_kernel();
20487+ if (pax_user_shadow_base)
20488+ printk("PAX: weak UDEREF enabled\n");
20489+ else {
20490+ set_cpu_cap(c, X86_FEATURE_STRONGUDEREF);
20491+ printk("PAX: strong UDEREF enabled\n");
20492+ }
20493+#endif
20494+
20495+ if (cpu_has(c, X86_FEATURE_INVPCID))
20496+ printk("PAX: INVPCID detected\n");
20497+}
20498+#endif
20499+
20500 /*
20501 * Some CPU features depend on higher CPUID levels, which may not always
20502 * be available due to CPUID level capping or broken virtualization
20503@@ -386,7 +385,7 @@ void switch_to_new_gdt(int cpu)
20504 {
20505 struct desc_ptr gdt_descr;
20506
20507- gdt_descr.address = (long)get_cpu_gdt_table(cpu);
20508+ gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
20509 gdt_descr.size = GDT_SIZE - 1;
20510 load_gdt(&gdt_descr);
20511 /* Reload the per-cpu base */
20512@@ -875,6 +874,10 @@ static void identify_cpu(struct cpuinfo_x86 *c)
20513 setup_smep(c);
20514 setup_smap(c);
20515
20516+#ifdef CONFIG_X86_64
20517+ setup_pcid(c);
20518+#endif
20519+
20520 /*
20521 * The vendor-specific functions might have changed features.
20522 * Now we do "generic changes."
20523@@ -883,6 +886,10 @@ static void identify_cpu(struct cpuinfo_x86 *c)
20524 /* Filter out anything that depends on CPUID levels we don't have */
20525 filter_cpuid_features(c, true);
20526
20527+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
20528+ setup_clear_cpu_cap(X86_FEATURE_SEP);
20529+#endif
20530+
20531 /* If the model name is still unset, do table lookup. */
20532 if (!c->x86_model_id[0]) {
20533 const char *p;
20534@@ -1070,10 +1077,12 @@ static __init int setup_disablecpuid(char *arg)
20535 }
20536 __setup("clearcpuid=", setup_disablecpuid);
20537
20538+DEFINE_PER_CPU(struct thread_info *, current_tinfo) = &init_task.tinfo;
20539+EXPORT_PER_CPU_SYMBOL(current_tinfo);
20540+
20541 #ifdef CONFIG_X86_64
20542-struct desc_ptr idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) idt_table };
20543-struct desc_ptr debug_idt_descr = { NR_VECTORS * 16 - 1,
20544- (unsigned long) debug_idt_table };
20545+struct desc_ptr idt_descr __read_only = { NR_VECTORS * 16 - 1, (unsigned long) idt_table };
20546+const struct desc_ptr debug_idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) debug_idt_table };
20547
20548 DEFINE_PER_CPU_FIRST(union irq_stack_union,
20549 irq_stack_union) __aligned(PAGE_SIZE) __visible;
20550@@ -1087,7 +1096,7 @@ DEFINE_PER_CPU(struct task_struct *, current_task) ____cacheline_aligned =
20551 EXPORT_PER_CPU_SYMBOL(current_task);
20552
20553 DEFINE_PER_CPU(unsigned long, kernel_stack) =
20554- (unsigned long)&init_thread_union - KERNEL_STACK_OFFSET + THREAD_SIZE;
20555+ (unsigned long)&init_thread_union - 16 + THREAD_SIZE;
20556 EXPORT_PER_CPU_SYMBOL(kernel_stack);
20557
20558 DEFINE_PER_CPU(char *, irq_stack_ptr) =
20559@@ -1232,7 +1241,7 @@ void cpu_init(void)
20560 load_ucode_ap();
20561
20562 cpu = stack_smp_processor_id();
20563- t = &per_cpu(init_tss, cpu);
20564+ t = init_tss + cpu;
20565 oist = &per_cpu(orig_ist, cpu);
20566
20567 #ifdef CONFIG_NUMA
20568@@ -1267,7 +1276,6 @@ void cpu_init(void)
20569 wrmsrl(MSR_KERNEL_GS_BASE, 0);
20570 barrier();
20571
20572- x86_configure_nx();
20573 enable_x2apic();
20574
20575 /*
20576@@ -1319,7 +1327,7 @@ void cpu_init(void)
20577 {
20578 int cpu = smp_processor_id();
20579 struct task_struct *curr = current;
20580- struct tss_struct *t = &per_cpu(init_tss, cpu);
20581+ struct tss_struct *t = init_tss + cpu;
20582 struct thread_struct *thread = &curr->thread;
20583
20584 show_ucode_info_early();
20585diff --git a/arch/x86/kernel/cpu/intel_cacheinfo.c b/arch/x86/kernel/cpu/intel_cacheinfo.c
20586index 1414c90..1159406 100644
20587--- a/arch/x86/kernel/cpu/intel_cacheinfo.c
20588+++ b/arch/x86/kernel/cpu/intel_cacheinfo.c
20589@@ -1014,6 +1014,22 @@ static struct attribute *default_attrs[] = {
20590 };
20591
20592 #ifdef CONFIG_AMD_NB
20593+static struct attribute *default_attrs_amd_nb[] = {
20594+ &type.attr,
20595+ &level.attr,
20596+ &coherency_line_size.attr,
20597+ &physical_line_partition.attr,
20598+ &ways_of_associativity.attr,
20599+ &number_of_sets.attr,
20600+ &size.attr,
20601+ &shared_cpu_map.attr,
20602+ &shared_cpu_list.attr,
20603+ NULL,
20604+ NULL,
20605+ NULL,
20606+ NULL
20607+};
20608+
20609 static struct attribute **amd_l3_attrs(void)
20610 {
20611 static struct attribute **attrs;
20612@@ -1024,18 +1040,7 @@ static struct attribute **amd_l3_attrs(void)
20613
20614 n = ARRAY_SIZE(default_attrs);
20615
20616- if (amd_nb_has_feature(AMD_NB_L3_INDEX_DISABLE))
20617- n += 2;
20618-
20619- if (amd_nb_has_feature(AMD_NB_L3_PARTITIONING))
20620- n += 1;
20621-
20622- attrs = kzalloc(n * sizeof (struct attribute *), GFP_KERNEL);
20623- if (attrs == NULL)
20624- return attrs = default_attrs;
20625-
20626- for (n = 0; default_attrs[n]; n++)
20627- attrs[n] = default_attrs[n];
20628+ attrs = default_attrs_amd_nb;
20629
20630 if (amd_nb_has_feature(AMD_NB_L3_INDEX_DISABLE)) {
20631 attrs[n++] = &cache_disable_0.attr;
20632@@ -1086,6 +1091,13 @@ static struct kobj_type ktype_cache = {
20633 .default_attrs = default_attrs,
20634 };
20635
20636+#ifdef CONFIG_AMD_NB
20637+static struct kobj_type ktype_cache_amd_nb = {
20638+ .sysfs_ops = &sysfs_ops,
20639+ .default_attrs = default_attrs_amd_nb,
20640+};
20641+#endif
20642+
20643 static struct kobj_type ktype_percpu_entry = {
20644 .sysfs_ops = &sysfs_ops,
20645 };
20646@@ -1151,20 +1163,26 @@ static int cache_add_dev(struct device *dev)
20647 return retval;
20648 }
20649
20650+#ifdef CONFIG_AMD_NB
20651+ amd_l3_attrs();
20652+#endif
20653+
20654 for (i = 0; i < num_cache_leaves; i++) {
20655+ struct kobj_type *ktype;
20656+
20657 this_object = INDEX_KOBJECT_PTR(cpu, i);
20658 this_object->cpu = cpu;
20659 this_object->index = i;
20660
20661 this_leaf = CPUID4_INFO_IDX(cpu, i);
20662
20663- ktype_cache.default_attrs = default_attrs;
20664+ ktype = &ktype_cache;
20665 #ifdef CONFIG_AMD_NB
20666 if (this_leaf->base.nb)
20667- ktype_cache.default_attrs = amd_l3_attrs();
20668+ ktype = &ktype_cache_amd_nb;
20669 #endif
20670 retval = kobject_init_and_add(&(this_object->kobj),
20671- &ktype_cache,
20672+ ktype,
20673 per_cpu(ici_cache_kobject, cpu),
20674 "index%1lu", i);
20675 if (unlikely(retval)) {
20676diff --git a/arch/x86/kernel/cpu/mcheck/mce.c b/arch/x86/kernel/cpu/mcheck/mce.c
20677index b3218cd..99a75de 100644
20678--- a/arch/x86/kernel/cpu/mcheck/mce.c
20679+++ b/arch/x86/kernel/cpu/mcheck/mce.c
20680@@ -45,6 +45,7 @@
20681 #include <asm/processor.h>
20682 #include <asm/mce.h>
20683 #include <asm/msr.h>
20684+#include <asm/local.h>
20685
20686 #include "mce-internal.h"
20687
20688@@ -258,7 +259,7 @@ static void print_mce(struct mce *m)
20689 !(m->mcgstatus & MCG_STATUS_EIPV) ? " !INEXACT!" : "",
20690 m->cs, m->ip);
20691
20692- if (m->cs == __KERNEL_CS)
20693+ if (m->cs == __KERNEL_CS || m->cs == __KERNEXEC_KERNEL_CS)
20694 print_symbol("{%s}", m->ip);
20695 pr_cont("\n");
20696 }
20697@@ -291,10 +292,10 @@ static void print_mce(struct mce *m)
20698
20699 #define PANIC_TIMEOUT 5 /* 5 seconds */
20700
20701-static atomic_t mce_paniced;
20702+static atomic_unchecked_t mce_paniced;
20703
20704 static int fake_panic;
20705-static atomic_t mce_fake_paniced;
20706+static atomic_unchecked_t mce_fake_paniced;
20707
20708 /* Panic in progress. Enable interrupts and wait for final IPI */
20709 static void wait_for_panic(void)
20710@@ -318,7 +319,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
20711 /*
20712 * Make sure only one CPU runs in machine check panic
20713 */
20714- if (atomic_inc_return(&mce_paniced) > 1)
20715+ if (atomic_inc_return_unchecked(&mce_paniced) > 1)
20716 wait_for_panic();
20717 barrier();
20718
20719@@ -326,7 +327,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
20720 console_verbose();
20721 } else {
20722 /* Don't log too much for fake panic */
20723- if (atomic_inc_return(&mce_fake_paniced) > 1)
20724+ if (atomic_inc_return_unchecked(&mce_fake_paniced) > 1)
20725 return;
20726 }
20727 /* First print corrected ones that are still unlogged */
20728@@ -365,7 +366,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
20729 if (!fake_panic) {
20730 if (panic_timeout == 0)
20731 panic_timeout = mca_cfg.panic_timeout;
20732- panic(msg);
20733+ panic("%s", msg);
20734 } else
20735 pr_emerg(HW_ERR "Fake kernel panic: %s\n", msg);
20736 }
20737@@ -695,7 +696,7 @@ static int mce_timed_out(u64 *t)
20738 * might have been modified by someone else.
20739 */
20740 rmb();
20741- if (atomic_read(&mce_paniced))
20742+ if (atomic_read_unchecked(&mce_paniced))
20743 wait_for_panic();
20744 if (!mca_cfg.monarch_timeout)
20745 goto out;
20746@@ -1666,7 +1667,7 @@ static void unexpected_machine_check(struct pt_regs *regs, long error_code)
20747 }
20748
20749 /* Call the installed machine check handler for this CPU setup. */
20750-void (*machine_check_vector)(struct pt_regs *, long error_code) =
20751+void (*machine_check_vector)(struct pt_regs *, long error_code) __read_only =
20752 unexpected_machine_check;
20753
20754 /*
20755@@ -1689,7 +1690,9 @@ void mcheck_cpu_init(struct cpuinfo_x86 *c)
20756 return;
20757 }
20758
20759+ pax_open_kernel();
20760 machine_check_vector = do_machine_check;
20761+ pax_close_kernel();
20762
20763 __mcheck_cpu_init_generic();
20764 __mcheck_cpu_init_vendor(c);
20765@@ -1703,7 +1706,7 @@ void mcheck_cpu_init(struct cpuinfo_x86 *c)
20766 */
20767
20768 static DEFINE_SPINLOCK(mce_chrdev_state_lock);
20769-static int mce_chrdev_open_count; /* #times opened */
20770+static local_t mce_chrdev_open_count; /* #times opened */
20771 static int mce_chrdev_open_exclu; /* already open exclusive? */
20772
20773 static int mce_chrdev_open(struct inode *inode, struct file *file)
20774@@ -1711,7 +1714,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
20775 spin_lock(&mce_chrdev_state_lock);
20776
20777 if (mce_chrdev_open_exclu ||
20778- (mce_chrdev_open_count && (file->f_flags & O_EXCL))) {
20779+ (local_read(&mce_chrdev_open_count) && (file->f_flags & O_EXCL))) {
20780 spin_unlock(&mce_chrdev_state_lock);
20781
20782 return -EBUSY;
20783@@ -1719,7 +1722,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
20784
20785 if (file->f_flags & O_EXCL)
20786 mce_chrdev_open_exclu = 1;
20787- mce_chrdev_open_count++;
20788+ local_inc(&mce_chrdev_open_count);
20789
20790 spin_unlock(&mce_chrdev_state_lock);
20791
20792@@ -1730,7 +1733,7 @@ static int mce_chrdev_release(struct inode *inode, struct file *file)
20793 {
20794 spin_lock(&mce_chrdev_state_lock);
20795
20796- mce_chrdev_open_count--;
20797+ local_dec(&mce_chrdev_open_count);
20798 mce_chrdev_open_exclu = 0;
20799
20800 spin_unlock(&mce_chrdev_state_lock);
20801@@ -2404,7 +2407,7 @@ static __init void mce_init_banks(void)
20802
20803 for (i = 0; i < mca_cfg.banks; i++) {
20804 struct mce_bank *b = &mce_banks[i];
20805- struct device_attribute *a = &b->attr;
20806+ device_attribute_no_const *a = &b->attr;
20807
20808 sysfs_attr_init(&a->attr);
20809 a->attr.name = b->attrname;
20810@@ -2472,7 +2475,7 @@ struct dentry *mce_get_debugfs_dir(void)
20811 static void mce_reset(void)
20812 {
20813 cpu_missing = 0;
20814- atomic_set(&mce_fake_paniced, 0);
20815+ atomic_set_unchecked(&mce_fake_paniced, 0);
20816 atomic_set(&mce_executing, 0);
20817 atomic_set(&mce_callin, 0);
20818 atomic_set(&global_nwo, 0);
20819diff --git a/arch/x86/kernel/cpu/mcheck/p5.c b/arch/x86/kernel/cpu/mcheck/p5.c
20820index 1c044b1..37a2a43 100644
20821--- a/arch/x86/kernel/cpu/mcheck/p5.c
20822+++ b/arch/x86/kernel/cpu/mcheck/p5.c
20823@@ -11,6 +11,7 @@
20824 #include <asm/processor.h>
20825 #include <asm/mce.h>
20826 #include <asm/msr.h>
20827+#include <asm/pgtable.h>
20828
20829 /* By default disabled */
20830 int mce_p5_enabled __read_mostly;
20831@@ -49,7 +50,9 @@ void intel_p5_mcheck_init(struct cpuinfo_x86 *c)
20832 if (!cpu_has(c, X86_FEATURE_MCE))
20833 return;
20834
20835+ pax_open_kernel();
20836 machine_check_vector = pentium_machine_check;
20837+ pax_close_kernel();
20838 /* Make sure the vector pointer is visible before we enable MCEs: */
20839 wmb();
20840
20841diff --git a/arch/x86/kernel/cpu/mcheck/winchip.c b/arch/x86/kernel/cpu/mcheck/winchip.c
20842index e9a701a..35317d6 100644
20843--- a/arch/x86/kernel/cpu/mcheck/winchip.c
20844+++ b/arch/x86/kernel/cpu/mcheck/winchip.c
20845@@ -10,6 +10,7 @@
20846 #include <asm/processor.h>
20847 #include <asm/mce.h>
20848 #include <asm/msr.h>
20849+#include <asm/pgtable.h>
20850
20851 /* Machine check handler for WinChip C6: */
20852 static void winchip_machine_check(struct pt_regs *regs, long error_code)
20853@@ -23,7 +24,9 @@ void winchip_mcheck_init(struct cpuinfo_x86 *c)
20854 {
20855 u32 lo, hi;
20856
20857+ pax_open_kernel();
20858 machine_check_vector = winchip_machine_check;
20859+ pax_close_kernel();
20860 /* Make sure the vector pointer is visible before we enable MCEs: */
20861 wmb();
20862
20863diff --git a/arch/x86/kernel/cpu/mtrr/main.c b/arch/x86/kernel/cpu/mtrr/main.c
20864index f961de9..8a9d332 100644
20865--- a/arch/x86/kernel/cpu/mtrr/main.c
20866+++ b/arch/x86/kernel/cpu/mtrr/main.c
20867@@ -66,7 +66,7 @@ static DEFINE_MUTEX(mtrr_mutex);
20868 u64 size_or_mask, size_and_mask;
20869 static bool mtrr_aps_delayed_init;
20870
20871-static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM];
20872+static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM] __read_only;
20873
20874 const struct mtrr_ops *mtrr_if;
20875
20876diff --git a/arch/x86/kernel/cpu/mtrr/mtrr.h b/arch/x86/kernel/cpu/mtrr/mtrr.h
20877index df5e41f..816c719 100644
20878--- a/arch/x86/kernel/cpu/mtrr/mtrr.h
20879+++ b/arch/x86/kernel/cpu/mtrr/mtrr.h
20880@@ -25,7 +25,7 @@ struct mtrr_ops {
20881 int (*validate_add_page)(unsigned long base, unsigned long size,
20882 unsigned int type);
20883 int (*have_wrcomb)(void);
20884-};
20885+} __do_const;
20886
20887 extern int generic_get_free_region(unsigned long base, unsigned long size,
20888 int replace_reg);
20889diff --git a/arch/x86/kernel/cpu/perf_event.c b/arch/x86/kernel/cpu/perf_event.c
20890index 8a87a32..682a22a 100644
20891--- a/arch/x86/kernel/cpu/perf_event.c
20892+++ b/arch/x86/kernel/cpu/perf_event.c
20893@@ -1348,7 +1348,7 @@ static void __init pmu_check_apic(void)
20894 pr_info("no hardware sampling interrupt available.\n");
20895 }
20896
20897-static struct attribute_group x86_pmu_format_group = {
20898+static attribute_group_no_const x86_pmu_format_group = {
20899 .name = "format",
20900 .attrs = NULL,
20901 };
20902@@ -1447,7 +1447,7 @@ static struct attribute *events_attr[] = {
20903 NULL,
20904 };
20905
20906-static struct attribute_group x86_pmu_events_group = {
20907+static attribute_group_no_const x86_pmu_events_group = {
20908 .name = "events",
20909 .attrs = events_attr,
20910 };
20911@@ -1958,7 +1958,7 @@ static unsigned long get_segment_base(unsigned int segment)
20912 if (idx > GDT_ENTRIES)
20913 return 0;
20914
20915- desc = __this_cpu_ptr(&gdt_page.gdt[0]);
20916+ desc = get_cpu_gdt_table(smp_processor_id());
20917 }
20918
20919 return get_desc_base(desc + idx);
20920@@ -2048,7 +2048,7 @@ perf_callchain_user(struct perf_callchain_entry *entry, struct pt_regs *regs)
20921 break;
20922
20923 perf_callchain_store(entry, frame.return_address);
20924- fp = frame.next_frame;
20925+ fp = (const void __force_user *)frame.next_frame;
20926 }
20927 }
20928
20929diff --git a/arch/x86/kernel/cpu/perf_event_amd_iommu.c b/arch/x86/kernel/cpu/perf_event_amd_iommu.c
20930index 639d128..e92d7e5 100644
20931--- a/arch/x86/kernel/cpu/perf_event_amd_iommu.c
20932+++ b/arch/x86/kernel/cpu/perf_event_amd_iommu.c
20933@@ -405,7 +405,7 @@ static void perf_iommu_del(struct perf_event *event, int flags)
20934 static __init int _init_events_attrs(struct perf_amd_iommu *perf_iommu)
20935 {
20936 struct attribute **attrs;
20937- struct attribute_group *attr_group;
20938+ attribute_group_no_const *attr_group;
20939 int i = 0, j;
20940
20941 while (amd_iommu_v2_event_descs[i].attr.attr.name)
20942diff --git a/arch/x86/kernel/cpu/perf_event_intel.c b/arch/x86/kernel/cpu/perf_event_intel.c
20943index f31a165..7b46cd8 100644
20944--- a/arch/x86/kernel/cpu/perf_event_intel.c
20945+++ b/arch/x86/kernel/cpu/perf_event_intel.c
20946@@ -2247,10 +2247,10 @@ __init int intel_pmu_init(void)
20947 * v2 and above have a perf capabilities MSR
20948 */
20949 if (version > 1) {
20950- u64 capabilities;
20951+ u64 capabilities = x86_pmu.intel_cap.capabilities;
20952
20953- rdmsrl(MSR_IA32_PERF_CAPABILITIES, capabilities);
20954- x86_pmu.intel_cap.capabilities = capabilities;
20955+ if (rdmsrl_safe(MSR_IA32_PERF_CAPABILITIES, &x86_pmu.intel_cap.capabilities))
20956+ x86_pmu.intel_cap.capabilities = capabilities;
20957 }
20958
20959 intel_ds_init();
20960diff --git a/arch/x86/kernel/cpu/perf_event_intel_uncore.c b/arch/x86/kernel/cpu/perf_event_intel_uncore.c
20961index 4118f9f..f91d0ab 100644
20962--- a/arch/x86/kernel/cpu/perf_event_intel_uncore.c
20963+++ b/arch/x86/kernel/cpu/perf_event_intel_uncore.c
20964@@ -3204,7 +3204,7 @@ static void __init uncore_types_exit(struct intel_uncore_type **types)
20965 static int __init uncore_type_init(struct intel_uncore_type *type)
20966 {
20967 struct intel_uncore_pmu *pmus;
20968- struct attribute_group *attr_group;
20969+ attribute_group_no_const *attr_group;
20970 struct attribute **attrs;
20971 int i, j;
20972
20973diff --git a/arch/x86/kernel/cpu/perf_event_intel_uncore.h b/arch/x86/kernel/cpu/perf_event_intel_uncore.h
20974index a80ab71..4089da5 100644
20975--- a/arch/x86/kernel/cpu/perf_event_intel_uncore.h
20976+++ b/arch/x86/kernel/cpu/perf_event_intel_uncore.h
20977@@ -498,7 +498,7 @@ struct intel_uncore_box {
20978 struct uncore_event_desc {
20979 struct kobj_attribute attr;
20980 const char *config;
20981-};
20982+} __do_const;
20983
20984 #define INTEL_UNCORE_EVENT_DESC(_name, _config) \
20985 { \
20986diff --git a/arch/x86/kernel/cpuid.c b/arch/x86/kernel/cpuid.c
20987index 7d9481c..99c7e4b 100644
20988--- a/arch/x86/kernel/cpuid.c
20989+++ b/arch/x86/kernel/cpuid.c
20990@@ -170,7 +170,7 @@ static int cpuid_class_cpu_callback(struct notifier_block *nfb,
20991 return notifier_from_errno(err);
20992 }
20993
20994-static struct notifier_block __refdata cpuid_class_cpu_notifier =
20995+static struct notifier_block cpuid_class_cpu_notifier =
20996 {
20997 .notifier_call = cpuid_class_cpu_callback,
20998 };
20999diff --git a/arch/x86/kernel/crash.c b/arch/x86/kernel/crash.c
21000index 18677a9..f67c45b 100644
21001--- a/arch/x86/kernel/crash.c
21002+++ b/arch/x86/kernel/crash.c
21003@@ -58,10 +58,8 @@ static void kdump_nmi_callback(int cpu, struct pt_regs *regs)
21004 {
21005 #ifdef CONFIG_X86_32
21006 struct pt_regs fixed_regs;
21007-#endif
21008
21009-#ifdef CONFIG_X86_32
21010- if (!user_mode_vm(regs)) {
21011+ if (!user_mode(regs)) {
21012 crash_fixup_ss_esp(&fixed_regs, regs);
21013 regs = &fixed_regs;
21014 }
21015diff --git a/arch/x86/kernel/crash_dump_64.c b/arch/x86/kernel/crash_dump_64.c
21016index afa64ad..dce67dd 100644
21017--- a/arch/x86/kernel/crash_dump_64.c
21018+++ b/arch/x86/kernel/crash_dump_64.c
21019@@ -36,7 +36,7 @@ ssize_t copy_oldmem_page(unsigned long pfn, char *buf,
21020 return -ENOMEM;
21021
21022 if (userbuf) {
21023- if (copy_to_user(buf, vaddr + offset, csize)) {
21024+ if (copy_to_user((char __force_user *)buf, vaddr + offset, csize)) {
21025 iounmap(vaddr);
21026 return -EFAULT;
21027 }
21028diff --git a/arch/x86/kernel/doublefault.c b/arch/x86/kernel/doublefault.c
21029index 5d3fe8d..02e1429 100644
21030--- a/arch/x86/kernel/doublefault.c
21031+++ b/arch/x86/kernel/doublefault.c
21032@@ -13,7 +13,7 @@
21033
21034 #define DOUBLEFAULT_STACKSIZE (1024)
21035 static unsigned long doublefault_stack[DOUBLEFAULT_STACKSIZE];
21036-#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE)
21037+#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE-2)
21038
21039 #define ptr_ok(x) ((x) > PAGE_OFFSET && (x) < PAGE_OFFSET + MAXMEM)
21040
21041@@ -23,7 +23,7 @@ static void doublefault_fn(void)
21042 unsigned long gdt, tss;
21043
21044 native_store_gdt(&gdt_desc);
21045- gdt = gdt_desc.address;
21046+ gdt = (unsigned long)gdt_desc.address;
21047
21048 printk(KERN_EMERG "PANIC: double fault, gdt at %08lx [%d bytes]\n", gdt, gdt_desc.size);
21049
21050@@ -60,10 +60,10 @@ struct tss_struct doublefault_tss __cacheline_aligned = {
21051 /* 0x2 bit is always set */
21052 .flags = X86_EFLAGS_SF | 0x2,
21053 .sp = STACK_START,
21054- .es = __USER_DS,
21055+ .es = __KERNEL_DS,
21056 .cs = __KERNEL_CS,
21057 .ss = __KERNEL_DS,
21058- .ds = __USER_DS,
21059+ .ds = __KERNEL_DS,
21060 .fs = __KERNEL_PERCPU,
21061
21062 .__cr3 = __pa_nodebug(swapper_pg_dir),
21063diff --git a/arch/x86/kernel/dumpstack.c b/arch/x86/kernel/dumpstack.c
21064index deb6421..76bbc12 100644
21065--- a/arch/x86/kernel/dumpstack.c
21066+++ b/arch/x86/kernel/dumpstack.c
21067@@ -2,6 +2,9 @@
21068 * Copyright (C) 1991, 1992 Linus Torvalds
21069 * Copyright (C) 2000, 2001, 2002 Andi Kleen, SuSE Labs
21070 */
21071+#ifdef CONFIG_GRKERNSEC_HIDESYM
21072+#define __INCLUDED_BY_HIDESYM 1
21073+#endif
21074 #include <linux/kallsyms.h>
21075 #include <linux/kprobes.h>
21076 #include <linux/uaccess.h>
21077@@ -35,16 +38,14 @@ void printk_address(unsigned long address, int reliable)
21078 static void
21079 print_ftrace_graph_addr(unsigned long addr, void *data,
21080 const struct stacktrace_ops *ops,
21081- struct thread_info *tinfo, int *graph)
21082+ struct task_struct *task, int *graph)
21083 {
21084- struct task_struct *task;
21085 unsigned long ret_addr;
21086 int index;
21087
21088 if (addr != (unsigned long)return_to_handler)
21089 return;
21090
21091- task = tinfo->task;
21092 index = task->curr_ret_stack;
21093
21094 if (!task->ret_stack || index < *graph)
21095@@ -61,7 +62,7 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
21096 static inline void
21097 print_ftrace_graph_addr(unsigned long addr, void *data,
21098 const struct stacktrace_ops *ops,
21099- struct thread_info *tinfo, int *graph)
21100+ struct task_struct *task, int *graph)
21101 { }
21102 #endif
21103
21104@@ -72,10 +73,8 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
21105 * severe exception (double fault, nmi, stack fault, debug, mce) hardware stack
21106 */
21107
21108-static inline int valid_stack_ptr(struct thread_info *tinfo,
21109- void *p, unsigned int size, void *end)
21110+static inline int valid_stack_ptr(void *t, void *p, unsigned int size, void *end)
21111 {
21112- void *t = tinfo;
21113 if (end) {
21114 if (p < end && p >= (end-THREAD_SIZE))
21115 return 1;
21116@@ -86,14 +85,14 @@ static inline int valid_stack_ptr(struct thread_info *tinfo,
21117 }
21118
21119 unsigned long
21120-print_context_stack(struct thread_info *tinfo,
21121+print_context_stack(struct task_struct *task, void *stack_start,
21122 unsigned long *stack, unsigned long bp,
21123 const struct stacktrace_ops *ops, void *data,
21124 unsigned long *end, int *graph)
21125 {
21126 struct stack_frame *frame = (struct stack_frame *)bp;
21127
21128- while (valid_stack_ptr(tinfo, stack, sizeof(*stack), end)) {
21129+ while (valid_stack_ptr(stack_start, stack, sizeof(*stack), end)) {
21130 unsigned long addr;
21131
21132 addr = *stack;
21133@@ -105,7 +104,7 @@ print_context_stack(struct thread_info *tinfo,
21134 } else {
21135 ops->address(data, addr, 0);
21136 }
21137- print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
21138+ print_ftrace_graph_addr(addr, data, ops, task, graph);
21139 }
21140 stack++;
21141 }
21142@@ -114,7 +113,7 @@ print_context_stack(struct thread_info *tinfo,
21143 EXPORT_SYMBOL_GPL(print_context_stack);
21144
21145 unsigned long
21146-print_context_stack_bp(struct thread_info *tinfo,
21147+print_context_stack_bp(struct task_struct *task, void *stack_start,
21148 unsigned long *stack, unsigned long bp,
21149 const struct stacktrace_ops *ops, void *data,
21150 unsigned long *end, int *graph)
21151@@ -122,7 +121,7 @@ print_context_stack_bp(struct thread_info *tinfo,
21152 struct stack_frame *frame = (struct stack_frame *)bp;
21153 unsigned long *ret_addr = &frame->return_address;
21154
21155- while (valid_stack_ptr(tinfo, ret_addr, sizeof(*ret_addr), end)) {
21156+ while (valid_stack_ptr(stack_start, ret_addr, sizeof(*ret_addr), end)) {
21157 unsigned long addr = *ret_addr;
21158
21159 if (!__kernel_text_address(addr))
21160@@ -131,7 +130,7 @@ print_context_stack_bp(struct thread_info *tinfo,
21161 ops->address(data, addr, 1);
21162 frame = frame->next_frame;
21163 ret_addr = &frame->return_address;
21164- print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
21165+ print_ftrace_graph_addr(addr, data, ops, task, graph);
21166 }
21167
21168 return (unsigned long)frame;
21169@@ -150,7 +149,7 @@ static int print_trace_stack(void *data, char *name)
21170 static void print_trace_address(void *data, unsigned long addr, int reliable)
21171 {
21172 touch_nmi_watchdog();
21173- printk(data);
21174+ printk("%s", (char *)data);
21175 printk_address(addr, reliable);
21176 }
21177
21178@@ -219,6 +218,8 @@ unsigned __kprobes long oops_begin(void)
21179 }
21180 EXPORT_SYMBOL_GPL(oops_begin);
21181
21182+extern void gr_handle_kernel_exploit(void);
21183+
21184 void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
21185 {
21186 if (regs && kexec_should_crash(current))
21187@@ -240,7 +241,10 @@ void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
21188 panic("Fatal exception in interrupt");
21189 if (panic_on_oops)
21190 panic("Fatal exception");
21191- do_exit(signr);
21192+
21193+ gr_handle_kernel_exploit();
21194+
21195+ do_group_exit(signr);
21196 }
21197
21198 int __kprobes __die(const char *str, struct pt_regs *regs, long err)
21199@@ -268,7 +272,7 @@ int __kprobes __die(const char *str, struct pt_regs *regs, long err)
21200 print_modules();
21201 show_regs(regs);
21202 #ifdef CONFIG_X86_32
21203- if (user_mode_vm(regs)) {
21204+ if (user_mode(regs)) {
21205 sp = regs->sp;
21206 ss = regs->ss & 0xffff;
21207 } else {
21208@@ -296,7 +300,7 @@ void die(const char *str, struct pt_regs *regs, long err)
21209 unsigned long flags = oops_begin();
21210 int sig = SIGSEGV;
21211
21212- if (!user_mode_vm(regs))
21213+ if (!user_mode(regs))
21214 report_bug(regs->ip, regs);
21215
21216 if (__die(str, regs, err))
21217diff --git a/arch/x86/kernel/dumpstack_32.c b/arch/x86/kernel/dumpstack_32.c
21218index f2a1770..540657f 100644
21219--- a/arch/x86/kernel/dumpstack_32.c
21220+++ b/arch/x86/kernel/dumpstack_32.c
21221@@ -38,15 +38,13 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
21222 bp = stack_frame(task, regs);
21223
21224 for (;;) {
21225- struct thread_info *context;
21226+ void *stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
21227
21228- context = (struct thread_info *)
21229- ((unsigned long)stack & (~(THREAD_SIZE - 1)));
21230- bp = ops->walk_stack(context, stack, bp, ops, data, NULL, &graph);
21231+ bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
21232
21233- stack = (unsigned long *)context->previous_esp;
21234- if (!stack)
21235+ if (stack_start == task_stack_page(task))
21236 break;
21237+ stack = *(unsigned long **)stack_start;
21238 if (ops->stack(data, "IRQ") < 0)
21239 break;
21240 touch_nmi_watchdog();
21241@@ -87,27 +85,28 @@ void show_regs(struct pt_regs *regs)
21242 int i;
21243
21244 show_regs_print_info(KERN_EMERG);
21245- __show_regs(regs, !user_mode_vm(regs));
21246+ __show_regs(regs, !user_mode(regs));
21247
21248 /*
21249 * When in-kernel, we also print out the stack and code at the
21250 * time of the fault..
21251 */
21252- if (!user_mode_vm(regs)) {
21253+ if (!user_mode(regs)) {
21254 unsigned int code_prologue = code_bytes * 43 / 64;
21255 unsigned int code_len = code_bytes;
21256 unsigned char c;
21257 u8 *ip;
21258+ unsigned long cs_base = get_desc_base(&get_cpu_gdt_table(0)[(0xffff & regs->cs) >> 3]);
21259
21260 pr_emerg("Stack:\n");
21261 show_stack_log_lvl(NULL, regs, &regs->sp, 0, KERN_EMERG);
21262
21263 pr_emerg("Code:");
21264
21265- ip = (u8 *)regs->ip - code_prologue;
21266+ ip = (u8 *)regs->ip - code_prologue + cs_base;
21267 if (ip < (u8 *)PAGE_OFFSET || probe_kernel_address(ip, c)) {
21268 /* try starting at IP */
21269- ip = (u8 *)regs->ip;
21270+ ip = (u8 *)regs->ip + cs_base;
21271 code_len = code_len - code_prologue + 1;
21272 }
21273 for (i = 0; i < code_len; i++, ip++) {
21274@@ -116,7 +115,7 @@ void show_regs(struct pt_regs *regs)
21275 pr_cont(" Bad EIP value.");
21276 break;
21277 }
21278- if (ip == (u8 *)regs->ip)
21279+ if (ip == (u8 *)regs->ip + cs_base)
21280 pr_cont(" <%02x>", c);
21281 else
21282 pr_cont(" %02x", c);
21283@@ -129,6 +128,7 @@ int is_valid_bugaddr(unsigned long ip)
21284 {
21285 unsigned short ud2;
21286
21287+ ip = ktla_ktva(ip);
21288 if (ip < PAGE_OFFSET)
21289 return 0;
21290 if (probe_kernel_address((unsigned short *)ip, ud2))
21291@@ -136,3 +136,15 @@ int is_valid_bugaddr(unsigned long ip)
21292
21293 return ud2 == 0x0b0f;
21294 }
21295+
21296+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
21297+void pax_check_alloca(unsigned long size)
21298+{
21299+ unsigned long sp = (unsigned long)&sp, stack_left;
21300+
21301+ /* all kernel stacks are of the same size */
21302+ stack_left = sp & (THREAD_SIZE - 1);
21303+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
21304+}
21305+EXPORT_SYMBOL(pax_check_alloca);
21306+#endif
21307diff --git a/arch/x86/kernel/dumpstack_64.c b/arch/x86/kernel/dumpstack_64.c
21308index addb207..99635fa 100644
21309--- a/arch/x86/kernel/dumpstack_64.c
21310+++ b/arch/x86/kernel/dumpstack_64.c
21311@@ -119,9 +119,9 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
21312 unsigned long *irq_stack_end =
21313 (unsigned long *)per_cpu(irq_stack_ptr, cpu);
21314 unsigned used = 0;
21315- struct thread_info *tinfo;
21316 int graph = 0;
21317 unsigned long dummy;
21318+ void *stack_start;
21319
21320 if (!task)
21321 task = current;
21322@@ -142,10 +142,10 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
21323 * current stack address. If the stacks consist of nested
21324 * exceptions
21325 */
21326- tinfo = task_thread_info(task);
21327 for (;;) {
21328 char *id;
21329 unsigned long *estack_end;
21330+
21331 estack_end = in_exception_stack(cpu, (unsigned long)stack,
21332 &used, &id);
21333
21334@@ -153,7 +153,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
21335 if (ops->stack(data, id) < 0)
21336 break;
21337
21338- bp = ops->walk_stack(tinfo, stack, bp, ops,
21339+ bp = ops->walk_stack(task, estack_end - EXCEPTION_STKSZ, stack, bp, ops,
21340 data, estack_end, &graph);
21341 ops->stack(data, "<EOE>");
21342 /*
21343@@ -161,6 +161,8 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
21344 * second-to-last pointer (index -2 to end) in the
21345 * exception stack:
21346 */
21347+ if ((u16)estack_end[-1] != __KERNEL_DS)
21348+ goto out;
21349 stack = (unsigned long *) estack_end[-2];
21350 continue;
21351 }
21352@@ -172,7 +174,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
21353 if (in_irq_stack(stack, irq_stack, irq_stack_end)) {
21354 if (ops->stack(data, "IRQ") < 0)
21355 break;
21356- bp = ops->walk_stack(tinfo, stack, bp,
21357+ bp = ops->walk_stack(task, irq_stack, stack, bp,
21358 ops, data, irq_stack_end, &graph);
21359 /*
21360 * We link to the next stack (which would be
21361@@ -191,7 +193,9 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
21362 /*
21363 * This handles the process stack:
21364 */
21365- bp = ops->walk_stack(tinfo, stack, bp, ops, data, NULL, &graph);
21366+ stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
21367+ bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
21368+out:
21369 put_cpu();
21370 }
21371 EXPORT_SYMBOL(dump_trace);
21372@@ -300,3 +304,50 @@ int is_valid_bugaddr(unsigned long ip)
21373
21374 return ud2 == 0x0b0f;
21375 }
21376+
21377+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
21378+void pax_check_alloca(unsigned long size)
21379+{
21380+ unsigned long sp = (unsigned long)&sp, stack_start, stack_end;
21381+ unsigned cpu, used;
21382+ char *id;
21383+
21384+ /* check the process stack first */
21385+ stack_start = (unsigned long)task_stack_page(current);
21386+ stack_end = stack_start + THREAD_SIZE;
21387+ if (likely(stack_start <= sp && sp < stack_end)) {
21388+ unsigned long stack_left = sp & (THREAD_SIZE - 1);
21389+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
21390+ return;
21391+ }
21392+
21393+ cpu = get_cpu();
21394+
21395+ /* check the irq stacks */
21396+ stack_end = (unsigned long)per_cpu(irq_stack_ptr, cpu);
21397+ stack_start = stack_end - IRQ_STACK_SIZE;
21398+ if (stack_start <= sp && sp < stack_end) {
21399+ unsigned long stack_left = sp & (IRQ_STACK_SIZE - 1);
21400+ put_cpu();
21401+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
21402+ return;
21403+ }
21404+
21405+ /* check the exception stacks */
21406+ used = 0;
21407+ stack_end = (unsigned long)in_exception_stack(cpu, sp, &used, &id);
21408+ stack_start = stack_end - EXCEPTION_STKSZ;
21409+ if (stack_end && stack_start <= sp && sp < stack_end) {
21410+ unsigned long stack_left = sp & (EXCEPTION_STKSZ - 1);
21411+ put_cpu();
21412+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
21413+ return;
21414+ }
21415+
21416+ put_cpu();
21417+
21418+ /* unknown stack */
21419+ BUG();
21420+}
21421+EXPORT_SYMBOL(pax_check_alloca);
21422+#endif
21423diff --git a/arch/x86/kernel/e820.c b/arch/x86/kernel/e820.c
21424index 174da5f..5e55606 100644
21425--- a/arch/x86/kernel/e820.c
21426+++ b/arch/x86/kernel/e820.c
21427@@ -803,8 +803,8 @@ unsigned long __init e820_end_of_low_ram_pfn(void)
21428
21429 static void early_panic(char *msg)
21430 {
21431- early_printk(msg);
21432- panic(msg);
21433+ early_printk("%s", msg);
21434+ panic("%s", msg);
21435 }
21436
21437 static int userdef __initdata;
21438diff --git a/arch/x86/kernel/early_printk.c b/arch/x86/kernel/early_printk.c
21439index d15f575..d692043 100644
21440--- a/arch/x86/kernel/early_printk.c
21441+++ b/arch/x86/kernel/early_printk.c
21442@@ -7,6 +7,7 @@
21443 #include <linux/pci_regs.h>
21444 #include <linux/pci_ids.h>
21445 #include <linux/errno.h>
21446+#include <linux/sched.h>
21447 #include <asm/io.h>
21448 #include <asm/processor.h>
21449 #include <asm/fcntl.h>
21450diff --git a/arch/x86/kernel/entry_32.S b/arch/x86/kernel/entry_32.S
21451index f0dcb0c..9f39b80 100644
21452--- a/arch/x86/kernel/entry_32.S
21453+++ b/arch/x86/kernel/entry_32.S
21454@@ -177,13 +177,153 @@
21455 /*CFI_REL_OFFSET gs, PT_GS*/
21456 .endm
21457 .macro SET_KERNEL_GS reg
21458+
21459+#ifdef CONFIG_CC_STACKPROTECTOR
21460 movl $(__KERNEL_STACK_CANARY), \reg
21461+#elif defined(CONFIG_PAX_MEMORY_UDEREF)
21462+ movl $(__USER_DS), \reg
21463+#else
21464+ xorl \reg, \reg
21465+#endif
21466+
21467 movl \reg, %gs
21468 .endm
21469
21470 #endif /* CONFIG_X86_32_LAZY_GS */
21471
21472-.macro SAVE_ALL
21473+.macro pax_enter_kernel
21474+#ifdef CONFIG_PAX_KERNEXEC
21475+ call pax_enter_kernel
21476+#endif
21477+.endm
21478+
21479+.macro pax_exit_kernel
21480+#ifdef CONFIG_PAX_KERNEXEC
21481+ call pax_exit_kernel
21482+#endif
21483+.endm
21484+
21485+#ifdef CONFIG_PAX_KERNEXEC
21486+ENTRY(pax_enter_kernel)
21487+#ifdef CONFIG_PARAVIRT
21488+ pushl %eax
21489+ pushl %ecx
21490+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0)
21491+ mov %eax, %esi
21492+#else
21493+ mov %cr0, %esi
21494+#endif
21495+ bts $16, %esi
21496+ jnc 1f
21497+ mov %cs, %esi
21498+ cmp $__KERNEL_CS, %esi
21499+ jz 3f
21500+ ljmp $__KERNEL_CS, $3f
21501+1: ljmp $__KERNEXEC_KERNEL_CS, $2f
21502+2:
21503+#ifdef CONFIG_PARAVIRT
21504+ mov %esi, %eax
21505+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
21506+#else
21507+ mov %esi, %cr0
21508+#endif
21509+3:
21510+#ifdef CONFIG_PARAVIRT
21511+ popl %ecx
21512+ popl %eax
21513+#endif
21514+ ret
21515+ENDPROC(pax_enter_kernel)
21516+
21517+ENTRY(pax_exit_kernel)
21518+#ifdef CONFIG_PARAVIRT
21519+ pushl %eax
21520+ pushl %ecx
21521+#endif
21522+ mov %cs, %esi
21523+ cmp $__KERNEXEC_KERNEL_CS, %esi
21524+ jnz 2f
21525+#ifdef CONFIG_PARAVIRT
21526+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0);
21527+ mov %eax, %esi
21528+#else
21529+ mov %cr0, %esi
21530+#endif
21531+ btr $16, %esi
21532+ ljmp $__KERNEL_CS, $1f
21533+1:
21534+#ifdef CONFIG_PARAVIRT
21535+ mov %esi, %eax
21536+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0);
21537+#else
21538+ mov %esi, %cr0
21539+#endif
21540+2:
21541+#ifdef CONFIG_PARAVIRT
21542+ popl %ecx
21543+ popl %eax
21544+#endif
21545+ ret
21546+ENDPROC(pax_exit_kernel)
21547+#endif
21548+
21549+ .macro pax_erase_kstack
21550+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
21551+ call pax_erase_kstack
21552+#endif
21553+ .endm
21554+
21555+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
21556+/*
21557+ * ebp: thread_info
21558+ */
21559+ENTRY(pax_erase_kstack)
21560+ pushl %edi
21561+ pushl %ecx
21562+ pushl %eax
21563+
21564+ mov TI_lowest_stack(%ebp), %edi
21565+ mov $-0xBEEF, %eax
21566+ std
21567+
21568+1: mov %edi, %ecx
21569+ and $THREAD_SIZE_asm - 1, %ecx
21570+ shr $2, %ecx
21571+ repne scasl
21572+ jecxz 2f
21573+
21574+ cmp $2*16, %ecx
21575+ jc 2f
21576+
21577+ mov $2*16, %ecx
21578+ repe scasl
21579+ jecxz 2f
21580+ jne 1b
21581+
21582+2: cld
21583+ mov %esp, %ecx
21584+ sub %edi, %ecx
21585+
21586+ cmp $THREAD_SIZE_asm, %ecx
21587+ jb 3f
21588+ ud2
21589+3:
21590+
21591+ shr $2, %ecx
21592+ rep stosl
21593+
21594+ mov TI_task_thread_sp0(%ebp), %edi
21595+ sub $128, %edi
21596+ mov %edi, TI_lowest_stack(%ebp)
21597+
21598+ popl %eax
21599+ popl %ecx
21600+ popl %edi
21601+ ret
21602+ENDPROC(pax_erase_kstack)
21603+#endif
21604+
21605+.macro __SAVE_ALL _DS
21606 cld
21607 PUSH_GS
21608 pushl_cfi %fs
21609@@ -206,7 +346,7 @@
21610 CFI_REL_OFFSET ecx, 0
21611 pushl_cfi %ebx
21612 CFI_REL_OFFSET ebx, 0
21613- movl $(__USER_DS), %edx
21614+ movl $\_DS, %edx
21615 movl %edx, %ds
21616 movl %edx, %es
21617 movl $(__KERNEL_PERCPU), %edx
21618@@ -214,6 +354,15 @@
21619 SET_KERNEL_GS %edx
21620 .endm
21621
21622+.macro SAVE_ALL
21623+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
21624+ __SAVE_ALL __KERNEL_DS
21625+ pax_enter_kernel
21626+#else
21627+ __SAVE_ALL __USER_DS
21628+#endif
21629+.endm
21630+
21631 .macro RESTORE_INT_REGS
21632 popl_cfi %ebx
21633 CFI_RESTORE ebx
21634@@ -297,7 +446,7 @@ ENTRY(ret_from_fork)
21635 popfl_cfi
21636 jmp syscall_exit
21637 CFI_ENDPROC
21638-END(ret_from_fork)
21639+ENDPROC(ret_from_fork)
21640
21641 ENTRY(ret_from_kernel_thread)
21642 CFI_STARTPROC
21643@@ -344,7 +493,15 @@ ret_from_intr:
21644 andl $SEGMENT_RPL_MASK, %eax
21645 #endif
21646 cmpl $USER_RPL, %eax
21647+
21648+#ifdef CONFIG_PAX_KERNEXEC
21649+ jae resume_userspace
21650+
21651+ pax_exit_kernel
21652+ jmp resume_kernel
21653+#else
21654 jb resume_kernel # not returning to v8086 or userspace
21655+#endif
21656
21657 ENTRY(resume_userspace)
21658 LOCKDEP_SYS_EXIT
21659@@ -356,8 +513,8 @@ ENTRY(resume_userspace)
21660 andl $_TIF_WORK_MASK, %ecx # is there any work to be done on
21661 # int/exception return?
21662 jne work_pending
21663- jmp restore_all
21664-END(ret_from_exception)
21665+ jmp restore_all_pax
21666+ENDPROC(ret_from_exception)
21667
21668 #ifdef CONFIG_PREEMPT
21669 ENTRY(resume_kernel)
21670@@ -372,7 +529,7 @@ need_resched:
21671 jz restore_all
21672 call preempt_schedule_irq
21673 jmp need_resched
21674-END(resume_kernel)
21675+ENDPROC(resume_kernel)
21676 #endif
21677 CFI_ENDPROC
21678 /*
21679@@ -406,30 +563,45 @@ sysenter_past_esp:
21680 /*CFI_REL_OFFSET cs, 0*/
21681 /*
21682 * Push current_thread_info()->sysenter_return to the stack.
21683- * A tiny bit of offset fixup is necessary - 4*4 means the 4 words
21684- * pushed above; +8 corresponds to copy_thread's esp0 setting.
21685 */
21686- pushl_cfi ((TI_sysenter_return)-THREAD_SIZE+8+4*4)(%esp)
21687+ pushl_cfi $0
21688 CFI_REL_OFFSET eip, 0
21689
21690 pushl_cfi %eax
21691 SAVE_ALL
21692+ GET_THREAD_INFO(%ebp)
21693+ movl TI_sysenter_return(%ebp),%ebp
21694+ movl %ebp,PT_EIP(%esp)
21695 ENABLE_INTERRUPTS(CLBR_NONE)
21696
21697 /*
21698 * Load the potential sixth argument from user stack.
21699 * Careful about security.
21700 */
21701+ movl PT_OLDESP(%esp),%ebp
21702+
21703+#ifdef CONFIG_PAX_MEMORY_UDEREF
21704+ mov PT_OLDSS(%esp),%ds
21705+1: movl %ds:(%ebp),%ebp
21706+ push %ss
21707+ pop %ds
21708+#else
21709 cmpl $__PAGE_OFFSET-3,%ebp
21710 jae syscall_fault
21711 ASM_STAC
21712 1: movl (%ebp),%ebp
21713 ASM_CLAC
21714+#endif
21715+
21716 movl %ebp,PT_EBP(%esp)
21717 _ASM_EXTABLE(1b,syscall_fault)
21718
21719 GET_THREAD_INFO(%ebp)
21720
21721+#ifdef CONFIG_PAX_RANDKSTACK
21722+ pax_erase_kstack
21723+#endif
21724+
21725 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
21726 jnz sysenter_audit
21727 sysenter_do_call:
21728@@ -444,12 +616,24 @@ sysenter_do_call:
21729 testl $_TIF_ALLWORK_MASK, %ecx
21730 jne sysexit_audit
21731 sysenter_exit:
21732+
21733+#ifdef CONFIG_PAX_RANDKSTACK
21734+ pushl_cfi %eax
21735+ movl %esp, %eax
21736+ call pax_randomize_kstack
21737+ popl_cfi %eax
21738+#endif
21739+
21740+ pax_erase_kstack
21741+
21742 /* if something modifies registers it must also disable sysexit */
21743 movl PT_EIP(%esp), %edx
21744 movl PT_OLDESP(%esp), %ecx
21745 xorl %ebp,%ebp
21746 TRACE_IRQS_ON
21747 1: mov PT_FS(%esp), %fs
21748+2: mov PT_DS(%esp), %ds
21749+3: mov PT_ES(%esp), %es
21750 PTGS_TO_GS
21751 ENABLE_INTERRUPTS_SYSEXIT
21752
21753@@ -466,6 +650,9 @@ sysenter_audit:
21754 movl %eax,%edx /* 2nd arg: syscall number */
21755 movl $AUDIT_ARCH_I386,%eax /* 1st arg: audit arch */
21756 call __audit_syscall_entry
21757+
21758+ pax_erase_kstack
21759+
21760 pushl_cfi %ebx
21761 movl PT_EAX(%esp),%eax /* reload syscall number */
21762 jmp sysenter_do_call
21763@@ -491,10 +678,16 @@ sysexit_audit:
21764
21765 CFI_ENDPROC
21766 .pushsection .fixup,"ax"
21767-2: movl $0,PT_FS(%esp)
21768+4: movl $0,PT_FS(%esp)
21769+ jmp 1b
21770+5: movl $0,PT_DS(%esp)
21771+ jmp 1b
21772+6: movl $0,PT_ES(%esp)
21773 jmp 1b
21774 .popsection
21775- _ASM_EXTABLE(1b,2b)
21776+ _ASM_EXTABLE(1b,4b)
21777+ _ASM_EXTABLE(2b,5b)
21778+ _ASM_EXTABLE(3b,6b)
21779 PTGS_TO_GS_EX
21780 ENDPROC(ia32_sysenter_target)
21781
21782@@ -509,6 +702,11 @@ ENTRY(system_call)
21783 pushl_cfi %eax # save orig_eax
21784 SAVE_ALL
21785 GET_THREAD_INFO(%ebp)
21786+
21787+#ifdef CONFIG_PAX_RANDKSTACK
21788+ pax_erase_kstack
21789+#endif
21790+
21791 # system call tracing in operation / emulation
21792 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
21793 jnz syscall_trace_entry
21794@@ -527,6 +725,15 @@ syscall_exit:
21795 testl $_TIF_ALLWORK_MASK, %ecx # current->work
21796 jne syscall_exit_work
21797
21798+restore_all_pax:
21799+
21800+#ifdef CONFIG_PAX_RANDKSTACK
21801+ movl %esp, %eax
21802+ call pax_randomize_kstack
21803+#endif
21804+
21805+ pax_erase_kstack
21806+
21807 restore_all:
21808 TRACE_IRQS_IRET
21809 restore_all_notrace:
21810@@ -583,14 +790,34 @@ ldt_ss:
21811 * compensating for the offset by changing to the ESPFIX segment with
21812 * a base address that matches for the difference.
21813 */
21814-#define GDT_ESPFIX_SS PER_CPU_VAR(gdt_page) + (GDT_ENTRY_ESPFIX_SS * 8)
21815+#define GDT_ESPFIX_SS (GDT_ENTRY_ESPFIX_SS * 8)(%ebx)
21816 mov %esp, %edx /* load kernel esp */
21817 mov PT_OLDESP(%esp), %eax /* load userspace esp */
21818 mov %dx, %ax /* eax: new kernel esp */
21819 sub %eax, %edx /* offset (low word is 0) */
21820+#ifdef CONFIG_SMP
21821+ movl PER_CPU_VAR(cpu_number), %ebx
21822+ shll $PAGE_SHIFT_asm, %ebx
21823+ addl $cpu_gdt_table, %ebx
21824+#else
21825+ movl $cpu_gdt_table, %ebx
21826+#endif
21827 shr $16, %edx
21828- mov %dl, GDT_ESPFIX_SS + 4 /* bits 16..23 */
21829- mov %dh, GDT_ESPFIX_SS + 7 /* bits 24..31 */
21830+
21831+#ifdef CONFIG_PAX_KERNEXEC
21832+ mov %cr0, %esi
21833+ btr $16, %esi
21834+ mov %esi, %cr0
21835+#endif
21836+
21837+ mov %dl, 4 + GDT_ESPFIX_SS /* bits 16..23 */
21838+ mov %dh, 7 + GDT_ESPFIX_SS /* bits 24..31 */
21839+
21840+#ifdef CONFIG_PAX_KERNEXEC
21841+ bts $16, %esi
21842+ mov %esi, %cr0
21843+#endif
21844+
21845 pushl_cfi $__ESPFIX_SS
21846 pushl_cfi %eax /* new kernel esp */
21847 /* Disable interrupts, but do not irqtrace this section: we
21848@@ -619,20 +846,18 @@ work_resched:
21849 movl TI_flags(%ebp), %ecx
21850 andl $_TIF_WORK_MASK, %ecx # is there any work to be done other
21851 # than syscall tracing?
21852- jz restore_all
21853+ jz restore_all_pax
21854 testb $_TIF_NEED_RESCHED, %cl
21855 jnz work_resched
21856
21857 work_notifysig: # deal with pending signals and
21858 # notify-resume requests
21859+ movl %esp, %eax
21860 #ifdef CONFIG_VM86
21861 testl $X86_EFLAGS_VM, PT_EFLAGS(%esp)
21862- movl %esp, %eax
21863 jne work_notifysig_v86 # returning to kernel-space or
21864 # vm86-space
21865 1:
21866-#else
21867- movl %esp, %eax
21868 #endif
21869 TRACE_IRQS_ON
21870 ENABLE_INTERRUPTS(CLBR_NONE)
21871@@ -653,7 +878,7 @@ work_notifysig_v86:
21872 movl %eax, %esp
21873 jmp 1b
21874 #endif
21875-END(work_pending)
21876+ENDPROC(work_pending)
21877
21878 # perform syscall exit tracing
21879 ALIGN
21880@@ -661,11 +886,14 @@ syscall_trace_entry:
21881 movl $-ENOSYS,PT_EAX(%esp)
21882 movl %esp, %eax
21883 call syscall_trace_enter
21884+
21885+ pax_erase_kstack
21886+
21887 /* What it returned is what we'll actually use. */
21888 cmpl $(NR_syscalls), %eax
21889 jnae syscall_call
21890 jmp syscall_exit
21891-END(syscall_trace_entry)
21892+ENDPROC(syscall_trace_entry)
21893
21894 # perform syscall exit tracing
21895 ALIGN
21896@@ -678,21 +906,25 @@ syscall_exit_work:
21897 movl %esp, %eax
21898 call syscall_trace_leave
21899 jmp resume_userspace
21900-END(syscall_exit_work)
21901+ENDPROC(syscall_exit_work)
21902 CFI_ENDPROC
21903
21904 RING0_INT_FRAME # can't unwind into user space anyway
21905 syscall_fault:
21906+#ifdef CONFIG_PAX_MEMORY_UDEREF
21907+ push %ss
21908+ pop %ds
21909+#endif
21910 ASM_CLAC
21911 GET_THREAD_INFO(%ebp)
21912 movl $-EFAULT,PT_EAX(%esp)
21913 jmp resume_userspace
21914-END(syscall_fault)
21915+ENDPROC(syscall_fault)
21916
21917 syscall_badsys:
21918 movl $-ENOSYS,PT_EAX(%esp)
21919 jmp resume_userspace
21920-END(syscall_badsys)
21921+ENDPROC(syscall_badsys)
21922 CFI_ENDPROC
21923 /*
21924 * End of kprobes section
21925@@ -708,8 +940,15 @@ END(syscall_badsys)
21926 * normal stack and adjusts ESP with the matching offset.
21927 */
21928 /* fixup the stack */
21929- mov GDT_ESPFIX_SS + 4, %al /* bits 16..23 */
21930- mov GDT_ESPFIX_SS + 7, %ah /* bits 24..31 */
21931+#ifdef CONFIG_SMP
21932+ movl PER_CPU_VAR(cpu_number), %ebx
21933+ shll $PAGE_SHIFT_asm, %ebx
21934+ addl $cpu_gdt_table, %ebx
21935+#else
21936+ movl $cpu_gdt_table, %ebx
21937+#endif
21938+ mov 4 + GDT_ESPFIX_SS, %al /* bits 16..23 */
21939+ mov 7 + GDT_ESPFIX_SS, %ah /* bits 24..31 */
21940 shl $16, %eax
21941 addl %esp, %eax /* the adjusted stack pointer */
21942 pushl_cfi $__KERNEL_DS
21943@@ -762,7 +1001,7 @@ vector=vector+1
21944 .endr
21945 2: jmp common_interrupt
21946 .endr
21947-END(irq_entries_start)
21948+ENDPROC(irq_entries_start)
21949
21950 .previous
21951 END(interrupt)
21952@@ -823,7 +1062,7 @@ ENTRY(coprocessor_error)
21953 pushl_cfi $do_coprocessor_error
21954 jmp error_code
21955 CFI_ENDPROC
21956-END(coprocessor_error)
21957+ENDPROC(coprocessor_error)
21958
21959 ENTRY(simd_coprocessor_error)
21960 RING0_INT_FRAME
21961@@ -836,7 +1075,7 @@ ENTRY(simd_coprocessor_error)
21962 .section .altinstructions,"a"
21963 altinstruction_entry 661b, 663f, X86_FEATURE_XMM, 662b-661b, 664f-663f
21964 .previous
21965-.section .altinstr_replacement,"ax"
21966+.section .altinstr_replacement,"a"
21967 663: pushl $do_simd_coprocessor_error
21968 664:
21969 .previous
21970@@ -845,7 +1084,7 @@ ENTRY(simd_coprocessor_error)
21971 #endif
21972 jmp error_code
21973 CFI_ENDPROC
21974-END(simd_coprocessor_error)
21975+ENDPROC(simd_coprocessor_error)
21976
21977 ENTRY(device_not_available)
21978 RING0_INT_FRAME
21979@@ -854,18 +1093,18 @@ ENTRY(device_not_available)
21980 pushl_cfi $do_device_not_available
21981 jmp error_code
21982 CFI_ENDPROC
21983-END(device_not_available)
21984+ENDPROC(device_not_available)
21985
21986 #ifdef CONFIG_PARAVIRT
21987 ENTRY(native_iret)
21988 iret
21989 _ASM_EXTABLE(native_iret, iret_exc)
21990-END(native_iret)
21991+ENDPROC(native_iret)
21992
21993 ENTRY(native_irq_enable_sysexit)
21994 sti
21995 sysexit
21996-END(native_irq_enable_sysexit)
21997+ENDPROC(native_irq_enable_sysexit)
21998 #endif
21999
22000 ENTRY(overflow)
22001@@ -875,7 +1114,7 @@ ENTRY(overflow)
22002 pushl_cfi $do_overflow
22003 jmp error_code
22004 CFI_ENDPROC
22005-END(overflow)
22006+ENDPROC(overflow)
22007
22008 ENTRY(bounds)
22009 RING0_INT_FRAME
22010@@ -884,7 +1123,7 @@ ENTRY(bounds)
22011 pushl_cfi $do_bounds
22012 jmp error_code
22013 CFI_ENDPROC
22014-END(bounds)
22015+ENDPROC(bounds)
22016
22017 ENTRY(invalid_op)
22018 RING0_INT_FRAME
22019@@ -893,7 +1132,7 @@ ENTRY(invalid_op)
22020 pushl_cfi $do_invalid_op
22021 jmp error_code
22022 CFI_ENDPROC
22023-END(invalid_op)
22024+ENDPROC(invalid_op)
22025
22026 ENTRY(coprocessor_segment_overrun)
22027 RING0_INT_FRAME
22028@@ -902,7 +1141,7 @@ ENTRY(coprocessor_segment_overrun)
22029 pushl_cfi $do_coprocessor_segment_overrun
22030 jmp error_code
22031 CFI_ENDPROC
22032-END(coprocessor_segment_overrun)
22033+ENDPROC(coprocessor_segment_overrun)
22034
22035 ENTRY(invalid_TSS)
22036 RING0_EC_FRAME
22037@@ -910,7 +1149,7 @@ ENTRY(invalid_TSS)
22038 pushl_cfi $do_invalid_TSS
22039 jmp error_code
22040 CFI_ENDPROC
22041-END(invalid_TSS)
22042+ENDPROC(invalid_TSS)
22043
22044 ENTRY(segment_not_present)
22045 RING0_EC_FRAME
22046@@ -918,7 +1157,7 @@ ENTRY(segment_not_present)
22047 pushl_cfi $do_segment_not_present
22048 jmp error_code
22049 CFI_ENDPROC
22050-END(segment_not_present)
22051+ENDPROC(segment_not_present)
22052
22053 ENTRY(stack_segment)
22054 RING0_EC_FRAME
22055@@ -926,7 +1165,7 @@ ENTRY(stack_segment)
22056 pushl_cfi $do_stack_segment
22057 jmp error_code
22058 CFI_ENDPROC
22059-END(stack_segment)
22060+ENDPROC(stack_segment)
22061
22062 ENTRY(alignment_check)
22063 RING0_EC_FRAME
22064@@ -934,7 +1173,7 @@ ENTRY(alignment_check)
22065 pushl_cfi $do_alignment_check
22066 jmp error_code
22067 CFI_ENDPROC
22068-END(alignment_check)
22069+ENDPROC(alignment_check)
22070
22071 ENTRY(divide_error)
22072 RING0_INT_FRAME
22073@@ -943,7 +1182,7 @@ ENTRY(divide_error)
22074 pushl_cfi $do_divide_error
22075 jmp error_code
22076 CFI_ENDPROC
22077-END(divide_error)
22078+ENDPROC(divide_error)
22079
22080 #ifdef CONFIG_X86_MCE
22081 ENTRY(machine_check)
22082@@ -953,7 +1192,7 @@ ENTRY(machine_check)
22083 pushl_cfi machine_check_vector
22084 jmp error_code
22085 CFI_ENDPROC
22086-END(machine_check)
22087+ENDPROC(machine_check)
22088 #endif
22089
22090 ENTRY(spurious_interrupt_bug)
22091@@ -963,7 +1202,7 @@ ENTRY(spurious_interrupt_bug)
22092 pushl_cfi $do_spurious_interrupt_bug
22093 jmp error_code
22094 CFI_ENDPROC
22095-END(spurious_interrupt_bug)
22096+ENDPROC(spurious_interrupt_bug)
22097 /*
22098 * End of kprobes section
22099 */
22100@@ -1073,7 +1312,7 @@ BUILD_INTERRUPT3(hyperv_callback_vector, HYPERVISOR_CALLBACK_VECTOR,
22101
22102 ENTRY(mcount)
22103 ret
22104-END(mcount)
22105+ENDPROC(mcount)
22106
22107 ENTRY(ftrace_caller)
22108 cmpl $0, function_trace_stop
22109@@ -1106,7 +1345,7 @@ ftrace_graph_call:
22110 .globl ftrace_stub
22111 ftrace_stub:
22112 ret
22113-END(ftrace_caller)
22114+ENDPROC(ftrace_caller)
22115
22116 ENTRY(ftrace_regs_caller)
22117 pushf /* push flags before compare (in cs location) */
22118@@ -1210,7 +1449,7 @@ trace:
22119 popl %ecx
22120 popl %eax
22121 jmp ftrace_stub
22122-END(mcount)
22123+ENDPROC(mcount)
22124 #endif /* CONFIG_DYNAMIC_FTRACE */
22125 #endif /* CONFIG_FUNCTION_TRACER */
22126
22127@@ -1228,7 +1467,7 @@ ENTRY(ftrace_graph_caller)
22128 popl %ecx
22129 popl %eax
22130 ret
22131-END(ftrace_graph_caller)
22132+ENDPROC(ftrace_graph_caller)
22133
22134 .globl return_to_handler
22135 return_to_handler:
22136@@ -1284,15 +1523,18 @@ error_code:
22137 movl $-1, PT_ORIG_EAX(%esp) # no syscall to restart
22138 REG_TO_PTGS %ecx
22139 SET_KERNEL_GS %ecx
22140- movl $(__USER_DS), %ecx
22141+ movl $(__KERNEL_DS), %ecx
22142 movl %ecx, %ds
22143 movl %ecx, %es
22144+
22145+ pax_enter_kernel
22146+
22147 TRACE_IRQS_OFF
22148 movl %esp,%eax # pt_regs pointer
22149 call *%edi
22150 jmp ret_from_exception
22151 CFI_ENDPROC
22152-END(page_fault)
22153+ENDPROC(page_fault)
22154
22155 /*
22156 * Debug traps and NMI can happen at the one SYSENTER instruction
22157@@ -1335,7 +1577,7 @@ debug_stack_correct:
22158 call do_debug
22159 jmp ret_from_exception
22160 CFI_ENDPROC
22161-END(debug)
22162+ENDPROC(debug)
22163
22164 /*
22165 * NMI is doubly nasty. It can happen _while_ we're handling
22166@@ -1373,6 +1615,9 @@ nmi_stack_correct:
22167 xorl %edx,%edx # zero error code
22168 movl %esp,%eax # pt_regs pointer
22169 call do_nmi
22170+
22171+ pax_exit_kernel
22172+
22173 jmp restore_all_notrace
22174 CFI_ENDPROC
22175
22176@@ -1409,12 +1654,15 @@ nmi_espfix_stack:
22177 FIXUP_ESPFIX_STACK # %eax == %esp
22178 xorl %edx,%edx # zero error code
22179 call do_nmi
22180+
22181+ pax_exit_kernel
22182+
22183 RESTORE_REGS
22184 lss 12+4(%esp), %esp # back to espfix stack
22185 CFI_ADJUST_CFA_OFFSET -24
22186 jmp irq_return
22187 CFI_ENDPROC
22188-END(nmi)
22189+ENDPROC(nmi)
22190
22191 ENTRY(int3)
22192 RING0_INT_FRAME
22193@@ -1427,14 +1675,14 @@ ENTRY(int3)
22194 call do_int3
22195 jmp ret_from_exception
22196 CFI_ENDPROC
22197-END(int3)
22198+ENDPROC(int3)
22199
22200 ENTRY(general_protection)
22201 RING0_EC_FRAME
22202 pushl_cfi $do_general_protection
22203 jmp error_code
22204 CFI_ENDPROC
22205-END(general_protection)
22206+ENDPROC(general_protection)
22207
22208 #ifdef CONFIG_KVM_GUEST
22209 ENTRY(async_page_fault)
22210@@ -1443,7 +1691,7 @@ ENTRY(async_page_fault)
22211 pushl_cfi $do_async_page_fault
22212 jmp error_code
22213 CFI_ENDPROC
22214-END(async_page_fault)
22215+ENDPROC(async_page_fault)
22216 #endif
22217
22218 /*
22219diff --git a/arch/x86/kernel/entry_64.S b/arch/x86/kernel/entry_64.S
22220index b077f4c..8e0df9f 100644
22221--- a/arch/x86/kernel/entry_64.S
22222+++ b/arch/x86/kernel/entry_64.S
22223@@ -59,6 +59,8 @@
22224 #include <asm/context_tracking.h>
22225 #include <asm/smap.h>
22226 #include <linux/err.h>
22227+#include <asm/pgtable.h>
22228+#include <asm/alternative-asm.h>
22229
22230 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
22231 #include <linux/elf-em.h>
22232@@ -80,8 +82,9 @@
22233 #ifdef CONFIG_DYNAMIC_FTRACE
22234
22235 ENTRY(function_hook)
22236+ pax_force_retaddr
22237 retq
22238-END(function_hook)
22239+ENDPROC(function_hook)
22240
22241 /* skip is set if stack has been adjusted */
22242 .macro ftrace_caller_setup skip=0
22243@@ -122,8 +125,9 @@ GLOBAL(ftrace_graph_call)
22244 #endif
22245
22246 GLOBAL(ftrace_stub)
22247+ pax_force_retaddr
22248 retq
22249-END(ftrace_caller)
22250+ENDPROC(ftrace_caller)
22251
22252 ENTRY(ftrace_regs_caller)
22253 /* Save the current flags before compare (in SS location)*/
22254@@ -191,7 +195,7 @@ ftrace_restore_flags:
22255 popfq
22256 jmp ftrace_stub
22257
22258-END(ftrace_regs_caller)
22259+ENDPROC(ftrace_regs_caller)
22260
22261
22262 #else /* ! CONFIG_DYNAMIC_FTRACE */
22263@@ -212,6 +216,7 @@ ENTRY(function_hook)
22264 #endif
22265
22266 GLOBAL(ftrace_stub)
22267+ pax_force_retaddr
22268 retq
22269
22270 trace:
22271@@ -225,12 +230,13 @@ trace:
22272 #endif
22273 subq $MCOUNT_INSN_SIZE, %rdi
22274
22275+ pax_force_fptr ftrace_trace_function
22276 call *ftrace_trace_function
22277
22278 MCOUNT_RESTORE_FRAME
22279
22280 jmp ftrace_stub
22281-END(function_hook)
22282+ENDPROC(function_hook)
22283 #endif /* CONFIG_DYNAMIC_FTRACE */
22284 #endif /* CONFIG_FUNCTION_TRACER */
22285
22286@@ -252,8 +258,9 @@ ENTRY(ftrace_graph_caller)
22287
22288 MCOUNT_RESTORE_FRAME
22289
22290+ pax_force_retaddr
22291 retq
22292-END(ftrace_graph_caller)
22293+ENDPROC(ftrace_graph_caller)
22294
22295 GLOBAL(return_to_handler)
22296 subq $24, %rsp
22297@@ -269,7 +276,9 @@ GLOBAL(return_to_handler)
22298 movq 8(%rsp), %rdx
22299 movq (%rsp), %rax
22300 addq $24, %rsp
22301+ pax_force_fptr %rdi
22302 jmp *%rdi
22303+ENDPROC(return_to_handler)
22304 #endif
22305
22306
22307@@ -284,6 +293,430 @@ ENTRY(native_usergs_sysret64)
22308 ENDPROC(native_usergs_sysret64)
22309 #endif /* CONFIG_PARAVIRT */
22310
22311+ .macro ljmpq sel, off
22312+#if defined(CONFIG_MPSC) || defined(CONFIG_MCORE2) || defined (CONFIG_MATOM)
22313+ .byte 0x48; ljmp *1234f(%rip)
22314+ .pushsection .rodata
22315+ .align 16
22316+ 1234: .quad \off; .word \sel
22317+ .popsection
22318+#else
22319+ pushq $\sel
22320+ pushq $\off
22321+ lretq
22322+#endif
22323+ .endm
22324+
22325+ .macro pax_enter_kernel
22326+ pax_set_fptr_mask
22327+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
22328+ call pax_enter_kernel
22329+#endif
22330+ .endm
22331+
22332+ .macro pax_exit_kernel
22333+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
22334+ call pax_exit_kernel
22335+#endif
22336+
22337+ .endm
22338+
22339+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
22340+ENTRY(pax_enter_kernel)
22341+ pushq %rdi
22342+
22343+#ifdef CONFIG_PARAVIRT
22344+ PV_SAVE_REGS(CLBR_RDI)
22345+#endif
22346+
22347+#ifdef CONFIG_PAX_KERNEXEC
22348+ GET_CR0_INTO_RDI
22349+ bts $16,%rdi
22350+ jnc 3f
22351+ mov %cs,%edi
22352+ cmp $__KERNEL_CS,%edi
22353+ jnz 2f
22354+1:
22355+#endif
22356+
22357+#ifdef CONFIG_PAX_MEMORY_UDEREF
22358+ 661: jmp 111f
22359+ .pushsection .altinstr_replacement, "a"
22360+ 662: ASM_NOP2
22361+ .popsection
22362+ .pushsection .altinstructions, "a"
22363+ altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
22364+ .popsection
22365+ GET_CR3_INTO_RDI
22366+ cmp $0,%dil
22367+ jnz 112f
22368+ mov $__KERNEL_DS,%edi
22369+ mov %edi,%ss
22370+ jmp 111f
22371+112: cmp $1,%dil
22372+ jz 113f
22373+ ud2
22374+113: sub $4097,%rdi
22375+ bts $63,%rdi
22376+ SET_RDI_INTO_CR3
22377+ mov $__UDEREF_KERNEL_DS,%edi
22378+ mov %edi,%ss
22379+111:
22380+#endif
22381+
22382+#ifdef CONFIG_PARAVIRT
22383+ PV_RESTORE_REGS(CLBR_RDI)
22384+#endif
22385+
22386+ popq %rdi
22387+ pax_force_retaddr
22388+ retq
22389+
22390+#ifdef CONFIG_PAX_KERNEXEC
22391+2: ljmpq __KERNEL_CS,1b
22392+3: ljmpq __KERNEXEC_KERNEL_CS,4f
22393+4: SET_RDI_INTO_CR0
22394+ jmp 1b
22395+#endif
22396+ENDPROC(pax_enter_kernel)
22397+
22398+ENTRY(pax_exit_kernel)
22399+ pushq %rdi
22400+
22401+#ifdef CONFIG_PARAVIRT
22402+ PV_SAVE_REGS(CLBR_RDI)
22403+#endif
22404+
22405+#ifdef CONFIG_PAX_KERNEXEC
22406+ mov %cs,%rdi
22407+ cmp $__KERNEXEC_KERNEL_CS,%edi
22408+ jz 2f
22409+ GET_CR0_INTO_RDI
22410+ bts $16,%rdi
22411+ jnc 4f
22412+1:
22413+#endif
22414+
22415+#ifdef CONFIG_PAX_MEMORY_UDEREF
22416+ 661: jmp 111f
22417+ .pushsection .altinstr_replacement, "a"
22418+ 662: ASM_NOP2
22419+ .popsection
22420+ .pushsection .altinstructions, "a"
22421+ altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
22422+ .popsection
22423+ mov %ss,%edi
22424+ cmp $__UDEREF_KERNEL_DS,%edi
22425+ jnz 111f
22426+ GET_CR3_INTO_RDI
22427+ cmp $0,%dil
22428+ jz 112f
22429+ ud2
22430+112: add $4097,%rdi
22431+ bts $63,%rdi
22432+ SET_RDI_INTO_CR3
22433+ mov $__KERNEL_DS,%edi
22434+ mov %edi,%ss
22435+111:
22436+#endif
22437+
22438+#ifdef CONFIG_PARAVIRT
22439+ PV_RESTORE_REGS(CLBR_RDI);
22440+#endif
22441+
22442+ popq %rdi
22443+ pax_force_retaddr
22444+ retq
22445+
22446+#ifdef CONFIG_PAX_KERNEXEC
22447+2: GET_CR0_INTO_RDI
22448+ btr $16,%rdi
22449+ jnc 4f
22450+ ljmpq __KERNEL_CS,3f
22451+3: SET_RDI_INTO_CR0
22452+ jmp 1b
22453+4: ud2
22454+ jmp 4b
22455+#endif
22456+ENDPROC(pax_exit_kernel)
22457+#endif
22458+
22459+ .macro pax_enter_kernel_user
22460+ pax_set_fptr_mask
22461+#ifdef CONFIG_PAX_MEMORY_UDEREF
22462+ call pax_enter_kernel_user
22463+#endif
22464+ .endm
22465+
22466+ .macro pax_exit_kernel_user
22467+#ifdef CONFIG_PAX_MEMORY_UDEREF
22468+ call pax_exit_kernel_user
22469+#endif
22470+#ifdef CONFIG_PAX_RANDKSTACK
22471+ pushq %rax
22472+ pushq %r11
22473+ call pax_randomize_kstack
22474+ popq %r11
22475+ popq %rax
22476+#endif
22477+ .endm
22478+
22479+#ifdef CONFIG_PAX_MEMORY_UDEREF
22480+ENTRY(pax_enter_kernel_user)
22481+ pushq %rdi
22482+ pushq %rbx
22483+
22484+#ifdef CONFIG_PARAVIRT
22485+ PV_SAVE_REGS(CLBR_RDI)
22486+#endif
22487+
22488+ 661: jmp 111f
22489+ .pushsection .altinstr_replacement, "a"
22490+ 662: ASM_NOP2
22491+ .popsection
22492+ .pushsection .altinstructions, "a"
22493+ altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
22494+ .popsection
22495+ GET_CR3_INTO_RDI
22496+ cmp $1,%dil
22497+ jnz 4f
22498+ sub $4097,%rdi
22499+ bts $63,%rdi
22500+ SET_RDI_INTO_CR3
22501+ jmp 3f
22502+111:
22503+
22504+ GET_CR3_INTO_RDI
22505+ mov %rdi,%rbx
22506+ add $__START_KERNEL_map,%rbx
22507+ sub phys_base(%rip),%rbx
22508+
22509+#ifdef CONFIG_PARAVIRT
22510+ cmpl $0, pv_info+PARAVIRT_enabled
22511+ jz 1f
22512+ pushq %rdi
22513+ i = 0
22514+ .rept USER_PGD_PTRS
22515+ mov i*8(%rbx),%rsi
22516+ mov $0,%sil
22517+ lea i*8(%rbx),%rdi
22518+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
22519+ i = i + 1
22520+ .endr
22521+ popq %rdi
22522+ jmp 2f
22523+1:
22524+#endif
22525+
22526+ i = 0
22527+ .rept USER_PGD_PTRS
22528+ movb $0,i*8(%rbx)
22529+ i = i + 1
22530+ .endr
22531+
22532+2: SET_RDI_INTO_CR3
22533+
22534+#ifdef CONFIG_PAX_KERNEXEC
22535+ GET_CR0_INTO_RDI
22536+ bts $16,%rdi
22537+ SET_RDI_INTO_CR0
22538+#endif
22539+
22540+3:
22541+
22542+#ifdef CONFIG_PARAVIRT
22543+ PV_RESTORE_REGS(CLBR_RDI)
22544+#endif
22545+
22546+ popq %rbx
22547+ popq %rdi
22548+ pax_force_retaddr
22549+ retq
22550+4: ud2
22551+ENDPROC(pax_enter_kernel_user)
22552+
22553+ENTRY(pax_exit_kernel_user)
22554+ pushq %rdi
22555+ pushq %rbx
22556+
22557+#ifdef CONFIG_PARAVIRT
22558+ PV_SAVE_REGS(CLBR_RDI)
22559+#endif
22560+
22561+ GET_CR3_INTO_RDI
22562+ 661: jmp 1f
22563+ .pushsection .altinstr_replacement, "a"
22564+ 662: ASM_NOP2
22565+ .popsection
22566+ .pushsection .altinstructions, "a"
22567+ altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
22568+ .popsection
22569+ cmp $0,%dil
22570+ jnz 3f
22571+ add $4097,%rdi
22572+ bts $63,%rdi
22573+ SET_RDI_INTO_CR3
22574+ jmp 2f
22575+1:
22576+
22577+ mov %rdi,%rbx
22578+
22579+#ifdef CONFIG_PAX_KERNEXEC
22580+ GET_CR0_INTO_RDI
22581+ btr $16,%rdi
22582+ jnc 3f
22583+ SET_RDI_INTO_CR0
22584+#endif
22585+
22586+ add $__START_KERNEL_map,%rbx
22587+ sub phys_base(%rip),%rbx
22588+
22589+#ifdef CONFIG_PARAVIRT
22590+ cmpl $0, pv_info+PARAVIRT_enabled
22591+ jz 1f
22592+ i = 0
22593+ .rept USER_PGD_PTRS
22594+ mov i*8(%rbx),%rsi
22595+ mov $0x67,%sil
22596+ lea i*8(%rbx),%rdi
22597+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
22598+ i = i + 1
22599+ .endr
22600+ jmp 2f
22601+1:
22602+#endif
22603+
22604+ i = 0
22605+ .rept USER_PGD_PTRS
22606+ movb $0x67,i*8(%rbx)
22607+ i = i + 1
22608+ .endr
22609+2:
22610+
22611+#ifdef CONFIG_PARAVIRT
22612+ PV_RESTORE_REGS(CLBR_RDI)
22613+#endif
22614+
22615+ popq %rbx
22616+ popq %rdi
22617+ pax_force_retaddr
22618+ retq
22619+3: ud2
22620+ENDPROC(pax_exit_kernel_user)
22621+#endif
22622+
22623+ .macro pax_enter_kernel_nmi
22624+ pax_set_fptr_mask
22625+
22626+#ifdef CONFIG_PAX_KERNEXEC
22627+ GET_CR0_INTO_RDI
22628+ bts $16,%rdi
22629+ jc 110f
22630+ SET_RDI_INTO_CR0
22631+ or $2,%ebx
22632+110:
22633+#endif
22634+
22635+#ifdef CONFIG_PAX_MEMORY_UDEREF
22636+ 661: jmp 111f
22637+ .pushsection .altinstr_replacement, "a"
22638+ 662: ASM_NOP2
22639+ .popsection
22640+ .pushsection .altinstructions, "a"
22641+ altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
22642+ .popsection
22643+ GET_CR3_INTO_RDI
22644+ cmp $0,%dil
22645+ jz 111f
22646+ sub $4097,%rdi
22647+ or $4,%ebx
22648+ bts $63,%rdi
22649+ SET_RDI_INTO_CR3
22650+ mov $__UDEREF_KERNEL_DS,%edi
22651+ mov %edi,%ss
22652+111:
22653+#endif
22654+ .endm
22655+
22656+ .macro pax_exit_kernel_nmi
22657+#ifdef CONFIG_PAX_KERNEXEC
22658+ btr $1,%ebx
22659+ jnc 110f
22660+ GET_CR0_INTO_RDI
22661+ btr $16,%rdi
22662+ SET_RDI_INTO_CR0
22663+110:
22664+#endif
22665+
22666+#ifdef CONFIG_PAX_MEMORY_UDEREF
22667+ btr $2,%ebx
22668+ jnc 111f
22669+ GET_CR3_INTO_RDI
22670+ add $4097,%rdi
22671+ bts $63,%rdi
22672+ SET_RDI_INTO_CR3
22673+ mov $__KERNEL_DS,%edi
22674+ mov %edi,%ss
22675+111:
22676+#endif
22677+ .endm
22678+
22679+ .macro pax_erase_kstack
22680+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
22681+ call pax_erase_kstack
22682+#endif
22683+ .endm
22684+
22685+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
22686+ENTRY(pax_erase_kstack)
22687+ pushq %rdi
22688+ pushq %rcx
22689+ pushq %rax
22690+ pushq %r11
22691+
22692+ GET_THREAD_INFO(%r11)
22693+ mov TI_lowest_stack(%r11), %rdi
22694+ mov $-0xBEEF, %rax
22695+ std
22696+
22697+1: mov %edi, %ecx
22698+ and $THREAD_SIZE_asm - 1, %ecx
22699+ shr $3, %ecx
22700+ repne scasq
22701+ jecxz 2f
22702+
22703+ cmp $2*8, %ecx
22704+ jc 2f
22705+
22706+ mov $2*8, %ecx
22707+ repe scasq
22708+ jecxz 2f
22709+ jne 1b
22710+
22711+2: cld
22712+ mov %esp, %ecx
22713+ sub %edi, %ecx
22714+
22715+ cmp $THREAD_SIZE_asm, %rcx
22716+ jb 3f
22717+ ud2
22718+3:
22719+
22720+ shr $3, %ecx
22721+ rep stosq
22722+
22723+ mov TI_task_thread_sp0(%r11), %rdi
22724+ sub $256, %rdi
22725+ mov %rdi, TI_lowest_stack(%r11)
22726+
22727+ popq %r11
22728+ popq %rax
22729+ popq %rcx
22730+ popq %rdi
22731+ pax_force_retaddr
22732+ ret
22733+ENDPROC(pax_erase_kstack)
22734+#endif
22735
22736 .macro TRACE_IRQS_IRETQ offset=ARGOFFSET
22737 #ifdef CONFIG_TRACE_IRQFLAGS
22738@@ -320,7 +753,7 @@ ENDPROC(native_usergs_sysret64)
22739 .endm
22740
22741 .macro TRACE_IRQS_IRETQ_DEBUG offset=ARGOFFSET
22742- bt $9,EFLAGS-\offset(%rsp) /* interrupts off? */
22743+ bt $X86_EFLAGS_IF_BIT,EFLAGS-\offset(%rsp) /* interrupts off? */
22744 jnc 1f
22745 TRACE_IRQS_ON_DEBUG
22746 1:
22747@@ -358,27 +791,6 @@ ENDPROC(native_usergs_sysret64)
22748 movq \tmp,R11+\offset(%rsp)
22749 .endm
22750
22751- .macro FAKE_STACK_FRAME child_rip
22752- /* push in order ss, rsp, eflags, cs, rip */
22753- xorl %eax, %eax
22754- pushq_cfi $__KERNEL_DS /* ss */
22755- /*CFI_REL_OFFSET ss,0*/
22756- pushq_cfi %rax /* rsp */
22757- CFI_REL_OFFSET rsp,0
22758- pushq_cfi $(X86_EFLAGS_IF|X86_EFLAGS_FIXED) /* eflags - interrupts on */
22759- /*CFI_REL_OFFSET rflags,0*/
22760- pushq_cfi $__KERNEL_CS /* cs */
22761- /*CFI_REL_OFFSET cs,0*/
22762- pushq_cfi \child_rip /* rip */
22763- CFI_REL_OFFSET rip,0
22764- pushq_cfi %rax /* orig rax */
22765- .endm
22766-
22767- .macro UNFAKE_STACK_FRAME
22768- addq $8*6, %rsp
22769- CFI_ADJUST_CFA_OFFSET -(6*8)
22770- .endm
22771-
22772 /*
22773 * initial frame state for interrupts (and exceptions without error code)
22774 */
22775@@ -445,25 +857,26 @@ ENDPROC(native_usergs_sysret64)
22776 /* save partial stack frame */
22777 .macro SAVE_ARGS_IRQ
22778 cld
22779- /* start from rbp in pt_regs and jump over */
22780- movq_cfi rdi, (RDI-RBP)
22781- movq_cfi rsi, (RSI-RBP)
22782- movq_cfi rdx, (RDX-RBP)
22783- movq_cfi rcx, (RCX-RBP)
22784- movq_cfi rax, (RAX-RBP)
22785- movq_cfi r8, (R8-RBP)
22786- movq_cfi r9, (R9-RBP)
22787- movq_cfi r10, (R10-RBP)
22788- movq_cfi r11, (R11-RBP)
22789+ /* start from r15 in pt_regs and jump over */
22790+ movq_cfi rdi, RDI
22791+ movq_cfi rsi, RSI
22792+ movq_cfi rdx, RDX
22793+ movq_cfi rcx, RCX
22794+ movq_cfi rax, RAX
22795+ movq_cfi r8, R8
22796+ movq_cfi r9, R9
22797+ movq_cfi r10, R10
22798+ movq_cfi r11, R11
22799+ movq_cfi r12, R12
22800
22801 /* Save rbp so that we can unwind from get_irq_regs() */
22802- movq_cfi rbp, 0
22803+ movq_cfi rbp, RBP
22804
22805 /* Save previous stack value */
22806 movq %rsp, %rsi
22807
22808- leaq -RBP(%rsp),%rdi /* arg1 for handler */
22809- testl $3, CS-RBP(%rsi)
22810+ movq %rsp,%rdi /* arg1 for handler */
22811+ testb $3, CS(%rsi)
22812 je 1f
22813 SWAPGS
22814 /*
22815@@ -514,9 +927,10 @@ ENTRY(save_paranoid)
22816 js 1f /* negative -> in kernel */
22817 SWAPGS
22818 xorl %ebx,%ebx
22819-1: ret
22820+1: pax_force_retaddr_bts
22821+ ret
22822 CFI_ENDPROC
22823-END(save_paranoid)
22824+ENDPROC(save_paranoid)
22825 .popsection
22826
22827 /*
22828@@ -538,7 +952,7 @@ ENTRY(ret_from_fork)
22829
22830 RESTORE_REST
22831
22832- testl $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
22833+ testb $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
22834 jz 1f
22835
22836 testl $_TIF_IA32, TI_flags(%rcx) # 32-bit compat task needs IRET
22837@@ -548,15 +962,13 @@ ENTRY(ret_from_fork)
22838 jmp ret_from_sys_call # go to the SYSRET fastpath
22839
22840 1:
22841- subq $REST_SKIP, %rsp # leave space for volatiles
22842- CFI_ADJUST_CFA_OFFSET REST_SKIP
22843 movq %rbp, %rdi
22844 call *%rbx
22845 movl $0, RAX(%rsp)
22846 RESTORE_REST
22847 jmp int_ret_from_sys_call
22848 CFI_ENDPROC
22849-END(ret_from_fork)
22850+ENDPROC(ret_from_fork)
22851
22852 /*
22853 * System call entry. Up to 6 arguments in registers are supported.
22854@@ -593,7 +1005,7 @@ END(ret_from_fork)
22855 ENTRY(system_call)
22856 CFI_STARTPROC simple
22857 CFI_SIGNAL_FRAME
22858- CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
22859+ CFI_DEF_CFA rsp,0
22860 CFI_REGISTER rip,rcx
22861 /*CFI_REGISTER rflags,r11*/
22862 SWAPGS_UNSAFE_STACK
22863@@ -606,16 +1018,23 @@ GLOBAL(system_call_after_swapgs)
22864
22865 movq %rsp,PER_CPU_VAR(old_rsp)
22866 movq PER_CPU_VAR(kernel_stack),%rsp
22867+ SAVE_ARGS 8*6,0
22868+ pax_enter_kernel_user
22869+
22870+#ifdef CONFIG_PAX_RANDKSTACK
22871+ pax_erase_kstack
22872+#endif
22873+
22874 /*
22875 * No need to follow this irqs off/on section - it's straight
22876 * and short:
22877 */
22878 ENABLE_INTERRUPTS(CLBR_NONE)
22879- SAVE_ARGS 8,0
22880 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
22881 movq %rcx,RIP-ARGOFFSET(%rsp)
22882 CFI_REL_OFFSET rip,RIP-ARGOFFSET
22883- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
22884+ GET_THREAD_INFO(%rcx)
22885+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%rcx)
22886 jnz tracesys
22887 system_call_fastpath:
22888 #if __SYSCALL_MASK == ~0
22889@@ -639,10 +1058,13 @@ sysret_check:
22890 LOCKDEP_SYS_EXIT
22891 DISABLE_INTERRUPTS(CLBR_NONE)
22892 TRACE_IRQS_OFF
22893- movl TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET),%edx
22894+ GET_THREAD_INFO(%rcx)
22895+ movl TI_flags(%rcx),%edx
22896 andl %edi,%edx
22897 jnz sysret_careful
22898 CFI_REMEMBER_STATE
22899+ pax_exit_kernel_user
22900+ pax_erase_kstack
22901 /*
22902 * sysretq will re-enable interrupts:
22903 */
22904@@ -701,6 +1123,9 @@ auditsys:
22905 movq %rax,%rsi /* 2nd arg: syscall number */
22906 movl $AUDIT_ARCH_X86_64,%edi /* 1st arg: audit arch */
22907 call __audit_syscall_entry
22908+
22909+ pax_erase_kstack
22910+
22911 LOAD_ARGS 0 /* reload call-clobbered registers */
22912 jmp system_call_fastpath
22913
22914@@ -722,7 +1147,7 @@ sysret_audit:
22915 /* Do syscall tracing */
22916 tracesys:
22917 #ifdef CONFIG_AUDITSYSCALL
22918- testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
22919+ testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%rcx)
22920 jz auditsys
22921 #endif
22922 SAVE_REST
22923@@ -730,12 +1155,15 @@ tracesys:
22924 FIXUP_TOP_OF_STACK %rdi
22925 movq %rsp,%rdi
22926 call syscall_trace_enter
22927+
22928+ pax_erase_kstack
22929+
22930 /*
22931 * Reload arg registers from stack in case ptrace changed them.
22932 * We don't reload %rax because syscall_trace_enter() returned
22933 * the value it wants us to use in the table lookup.
22934 */
22935- LOAD_ARGS ARGOFFSET, 1
22936+ LOAD_ARGS 1
22937 RESTORE_REST
22938 #if __SYSCALL_MASK == ~0
22939 cmpq $__NR_syscall_max,%rax
22940@@ -765,7 +1193,9 @@ GLOBAL(int_with_check)
22941 andl %edi,%edx
22942 jnz int_careful
22943 andl $~TS_COMPAT,TI_status(%rcx)
22944- jmp retint_swapgs
22945+ pax_exit_kernel_user
22946+ pax_erase_kstack
22947+ jmp retint_swapgs_pax
22948
22949 /* Either reschedule or signal or syscall exit tracking needed. */
22950 /* First do a reschedule test. */
22951@@ -811,7 +1241,7 @@ int_restore_rest:
22952 TRACE_IRQS_OFF
22953 jmp int_with_check
22954 CFI_ENDPROC
22955-END(system_call)
22956+ENDPROC(system_call)
22957
22958 .macro FORK_LIKE func
22959 ENTRY(stub_\func)
22960@@ -824,9 +1254,10 @@ ENTRY(stub_\func)
22961 DEFAULT_FRAME 0 8 /* offset 8: return address */
22962 call sys_\func
22963 RESTORE_TOP_OF_STACK %r11, 8
22964- ret $REST_SKIP /* pop extended registers */
22965+ pax_force_retaddr
22966+ ret
22967 CFI_ENDPROC
22968-END(stub_\func)
22969+ENDPROC(stub_\func)
22970 .endm
22971
22972 .macro FIXED_FRAME label,func
22973@@ -836,9 +1267,10 @@ ENTRY(\label)
22974 FIXUP_TOP_OF_STACK %r11, 8-ARGOFFSET
22975 call \func
22976 RESTORE_TOP_OF_STACK %r11, 8-ARGOFFSET
22977+ pax_force_retaddr
22978 ret
22979 CFI_ENDPROC
22980-END(\label)
22981+ENDPROC(\label)
22982 .endm
22983
22984 FORK_LIKE clone
22985@@ -846,19 +1278,6 @@ END(\label)
22986 FORK_LIKE vfork
22987 FIXED_FRAME stub_iopl, sys_iopl
22988
22989-ENTRY(ptregscall_common)
22990- DEFAULT_FRAME 1 8 /* offset 8: return address */
22991- RESTORE_TOP_OF_STACK %r11, 8
22992- movq_cfi_restore R15+8, r15
22993- movq_cfi_restore R14+8, r14
22994- movq_cfi_restore R13+8, r13
22995- movq_cfi_restore R12+8, r12
22996- movq_cfi_restore RBP+8, rbp
22997- movq_cfi_restore RBX+8, rbx
22998- ret $REST_SKIP /* pop extended registers */
22999- CFI_ENDPROC
23000-END(ptregscall_common)
23001-
23002 ENTRY(stub_execve)
23003 CFI_STARTPROC
23004 addq $8, %rsp
23005@@ -870,7 +1289,7 @@ ENTRY(stub_execve)
23006 RESTORE_REST
23007 jmp int_ret_from_sys_call
23008 CFI_ENDPROC
23009-END(stub_execve)
23010+ENDPROC(stub_execve)
23011
23012 /*
23013 * sigreturn is special because it needs to restore all registers on return.
23014@@ -887,7 +1306,7 @@ ENTRY(stub_rt_sigreturn)
23015 RESTORE_REST
23016 jmp int_ret_from_sys_call
23017 CFI_ENDPROC
23018-END(stub_rt_sigreturn)
23019+ENDPROC(stub_rt_sigreturn)
23020
23021 #ifdef CONFIG_X86_X32_ABI
23022 ENTRY(stub_x32_rt_sigreturn)
23023@@ -901,7 +1320,7 @@ ENTRY(stub_x32_rt_sigreturn)
23024 RESTORE_REST
23025 jmp int_ret_from_sys_call
23026 CFI_ENDPROC
23027-END(stub_x32_rt_sigreturn)
23028+ENDPROC(stub_x32_rt_sigreturn)
23029
23030 ENTRY(stub_x32_execve)
23031 CFI_STARTPROC
23032@@ -915,7 +1334,7 @@ ENTRY(stub_x32_execve)
23033 RESTORE_REST
23034 jmp int_ret_from_sys_call
23035 CFI_ENDPROC
23036-END(stub_x32_execve)
23037+ENDPROC(stub_x32_execve)
23038
23039 #endif
23040
23041@@ -952,7 +1371,7 @@ vector=vector+1
23042 2: jmp common_interrupt
23043 .endr
23044 CFI_ENDPROC
23045-END(irq_entries_start)
23046+ENDPROC(irq_entries_start)
23047
23048 .previous
23049 END(interrupt)
23050@@ -969,9 +1388,19 @@ END(interrupt)
23051 /* 0(%rsp): ~(interrupt number) */
23052 .macro interrupt func
23053 /* reserve pt_regs for scratch regs and rbp */
23054- subq $ORIG_RAX-RBP, %rsp
23055- CFI_ADJUST_CFA_OFFSET ORIG_RAX-RBP
23056+ subq $ORIG_RAX, %rsp
23057+ CFI_ADJUST_CFA_OFFSET ORIG_RAX
23058 SAVE_ARGS_IRQ
23059+#ifdef CONFIG_PAX_MEMORY_UDEREF
23060+ testb $3, CS(%rdi)
23061+ jnz 1f
23062+ pax_enter_kernel
23063+ jmp 2f
23064+1: pax_enter_kernel_user
23065+2:
23066+#else
23067+ pax_enter_kernel
23068+#endif
23069 call \func
23070 .endm
23071
23072@@ -997,14 +1426,14 @@ ret_from_intr:
23073
23074 /* Restore saved previous stack */
23075 popq %rsi
23076- CFI_DEF_CFA rsi,SS+8-RBP /* reg/off reset after def_cfa_expr */
23077- leaq ARGOFFSET-RBP(%rsi), %rsp
23078+ CFI_DEF_CFA rsi,SS+8 /* reg/off reset after def_cfa_expr */
23079+ movq %rsi, %rsp
23080 CFI_DEF_CFA_REGISTER rsp
23081- CFI_ADJUST_CFA_OFFSET RBP-ARGOFFSET
23082+ CFI_ADJUST_CFA_OFFSET -ARGOFFSET
23083
23084 exit_intr:
23085 GET_THREAD_INFO(%rcx)
23086- testl $3,CS-ARGOFFSET(%rsp)
23087+ testb $3,CS-ARGOFFSET(%rsp)
23088 je retint_kernel
23089
23090 /* Interrupt came from user space */
23091@@ -1026,12 +1455,16 @@ retint_swapgs: /* return to user-space */
23092 * The iretq could re-enable interrupts:
23093 */
23094 DISABLE_INTERRUPTS(CLBR_ANY)
23095+ pax_exit_kernel_user
23096+retint_swapgs_pax:
23097 TRACE_IRQS_IRETQ
23098 SWAPGS
23099 jmp restore_args
23100
23101 retint_restore_args: /* return to kernel space */
23102 DISABLE_INTERRUPTS(CLBR_ANY)
23103+ pax_exit_kernel
23104+ pax_force_retaddr (RIP-ARGOFFSET)
23105 /*
23106 * The iretq could re-enable interrupts:
23107 */
23108@@ -1114,7 +1547,7 @@ ENTRY(retint_kernel)
23109 #endif
23110
23111 CFI_ENDPROC
23112-END(common_interrupt)
23113+ENDPROC(common_interrupt)
23114 /*
23115 * End of kprobes section
23116 */
23117@@ -1132,7 +1565,7 @@ ENTRY(\sym)
23118 interrupt \do_sym
23119 jmp ret_from_intr
23120 CFI_ENDPROC
23121-END(\sym)
23122+ENDPROC(\sym)
23123 .endm
23124
23125 #ifdef CONFIG_TRACING
23126@@ -1215,12 +1648,22 @@ ENTRY(\sym)
23127 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
23128 call error_entry
23129 DEFAULT_FRAME 0
23130+#ifdef CONFIG_PAX_MEMORY_UDEREF
23131+ testb $3, CS(%rsp)
23132+ jnz 1f
23133+ pax_enter_kernel
23134+ jmp 2f
23135+1: pax_enter_kernel_user
23136+2:
23137+#else
23138+ pax_enter_kernel
23139+#endif
23140 movq %rsp,%rdi /* pt_regs pointer */
23141 xorl %esi,%esi /* no error code */
23142 call \do_sym
23143 jmp error_exit /* %ebx: no swapgs flag */
23144 CFI_ENDPROC
23145-END(\sym)
23146+ENDPROC(\sym)
23147 .endm
23148
23149 .macro paranoidzeroentry sym do_sym
23150@@ -1233,15 +1676,25 @@ ENTRY(\sym)
23151 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
23152 call save_paranoid
23153 TRACE_IRQS_OFF
23154+#ifdef CONFIG_PAX_MEMORY_UDEREF
23155+ testb $3, CS(%rsp)
23156+ jnz 1f
23157+ pax_enter_kernel
23158+ jmp 2f
23159+1: pax_enter_kernel_user
23160+2:
23161+#else
23162+ pax_enter_kernel
23163+#endif
23164 movq %rsp,%rdi /* pt_regs pointer */
23165 xorl %esi,%esi /* no error code */
23166 call \do_sym
23167 jmp paranoid_exit /* %ebx: no swapgs flag */
23168 CFI_ENDPROC
23169-END(\sym)
23170+ENDPROC(\sym)
23171 .endm
23172
23173-#define INIT_TSS_IST(x) PER_CPU_VAR(init_tss) + (TSS_ist + ((x) - 1) * 8)
23174+#define INIT_TSS_IST(x) (TSS_ist + ((x) - 1) * 8)(%r13)
23175 .macro paranoidzeroentry_ist sym do_sym ist
23176 ENTRY(\sym)
23177 INTR_FRAME
23178@@ -1252,14 +1705,30 @@ ENTRY(\sym)
23179 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
23180 call save_paranoid
23181 TRACE_IRQS_OFF_DEBUG
23182+#ifdef CONFIG_PAX_MEMORY_UDEREF
23183+ testb $3, CS(%rsp)
23184+ jnz 1f
23185+ pax_enter_kernel
23186+ jmp 2f
23187+1: pax_enter_kernel_user
23188+2:
23189+#else
23190+ pax_enter_kernel
23191+#endif
23192 movq %rsp,%rdi /* pt_regs pointer */
23193 xorl %esi,%esi /* no error code */
23194+#ifdef CONFIG_SMP
23195+ imul $TSS_size, PER_CPU_VAR(cpu_number), %r13d
23196+ lea init_tss(%r13), %r13
23197+#else
23198+ lea init_tss(%rip), %r13
23199+#endif
23200 subq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
23201 call \do_sym
23202 addq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
23203 jmp paranoid_exit /* %ebx: no swapgs flag */
23204 CFI_ENDPROC
23205-END(\sym)
23206+ENDPROC(\sym)
23207 .endm
23208
23209 .macro errorentry sym do_sym
23210@@ -1271,13 +1740,23 @@ ENTRY(\sym)
23211 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
23212 call error_entry
23213 DEFAULT_FRAME 0
23214+#ifdef CONFIG_PAX_MEMORY_UDEREF
23215+ testb $3, CS(%rsp)
23216+ jnz 1f
23217+ pax_enter_kernel
23218+ jmp 2f
23219+1: pax_enter_kernel_user
23220+2:
23221+#else
23222+ pax_enter_kernel
23223+#endif
23224 movq %rsp,%rdi /* pt_regs pointer */
23225 movq ORIG_RAX(%rsp),%rsi /* get error code */
23226 movq $-1,ORIG_RAX(%rsp) /* no syscall to restart */
23227 call \do_sym
23228 jmp error_exit /* %ebx: no swapgs flag */
23229 CFI_ENDPROC
23230-END(\sym)
23231+ENDPROC(\sym)
23232 .endm
23233
23234 /* error code is on the stack already */
23235@@ -1291,13 +1770,23 @@ ENTRY(\sym)
23236 call save_paranoid
23237 DEFAULT_FRAME 0
23238 TRACE_IRQS_OFF
23239+#ifdef CONFIG_PAX_MEMORY_UDEREF
23240+ testb $3, CS(%rsp)
23241+ jnz 1f
23242+ pax_enter_kernel
23243+ jmp 2f
23244+1: pax_enter_kernel_user
23245+2:
23246+#else
23247+ pax_enter_kernel
23248+#endif
23249 movq %rsp,%rdi /* pt_regs pointer */
23250 movq ORIG_RAX(%rsp),%rsi /* get error code */
23251 movq $-1,ORIG_RAX(%rsp) /* no syscall to restart */
23252 call \do_sym
23253 jmp paranoid_exit /* %ebx: no swapgs flag */
23254 CFI_ENDPROC
23255-END(\sym)
23256+ENDPROC(\sym)
23257 .endm
23258
23259 zeroentry divide_error do_divide_error
23260@@ -1327,9 +1816,10 @@ gs_change:
23261 2: mfence /* workaround */
23262 SWAPGS
23263 popfq_cfi
23264+ pax_force_retaddr
23265 ret
23266 CFI_ENDPROC
23267-END(native_load_gs_index)
23268+ENDPROC(native_load_gs_index)
23269
23270 _ASM_EXTABLE(gs_change,bad_gs)
23271 .section .fixup,"ax"
23272@@ -1357,9 +1847,10 @@ ENTRY(call_softirq)
23273 CFI_DEF_CFA_REGISTER rsp
23274 CFI_ADJUST_CFA_OFFSET -8
23275 decl PER_CPU_VAR(irq_count)
23276+ pax_force_retaddr
23277 ret
23278 CFI_ENDPROC
23279-END(call_softirq)
23280+ENDPROC(call_softirq)
23281
23282 #ifdef CONFIG_XEN
23283 zeroentry xen_hypervisor_callback xen_do_hypervisor_callback
23284@@ -1397,7 +1888,7 @@ ENTRY(xen_do_hypervisor_callback) # do_hypervisor_callback(struct *pt_regs)
23285 decl PER_CPU_VAR(irq_count)
23286 jmp error_exit
23287 CFI_ENDPROC
23288-END(xen_do_hypervisor_callback)
23289+ENDPROC(xen_do_hypervisor_callback)
23290
23291 /*
23292 * Hypervisor uses this for application faults while it executes.
23293@@ -1456,7 +1947,7 @@ ENTRY(xen_failsafe_callback)
23294 SAVE_ALL
23295 jmp error_exit
23296 CFI_ENDPROC
23297-END(xen_failsafe_callback)
23298+ENDPROC(xen_failsafe_callback)
23299
23300 apicinterrupt3 HYPERVISOR_CALLBACK_VECTOR \
23301 xen_hvm_callback_vector xen_evtchn_do_upcall
23302@@ -1508,18 +1999,33 @@ ENTRY(paranoid_exit)
23303 DEFAULT_FRAME
23304 DISABLE_INTERRUPTS(CLBR_NONE)
23305 TRACE_IRQS_OFF_DEBUG
23306- testl %ebx,%ebx /* swapgs needed? */
23307+ testl $1,%ebx /* swapgs needed? */
23308 jnz paranoid_restore
23309- testl $3,CS(%rsp)
23310+ testb $3,CS(%rsp)
23311 jnz paranoid_userspace
23312+#ifdef CONFIG_PAX_MEMORY_UDEREF
23313+ pax_exit_kernel
23314+ TRACE_IRQS_IRETQ 0
23315+ SWAPGS_UNSAFE_STACK
23316+ RESTORE_ALL 8
23317+ pax_force_retaddr_bts
23318+ jmp irq_return
23319+#endif
23320 paranoid_swapgs:
23321+#ifdef CONFIG_PAX_MEMORY_UDEREF
23322+ pax_exit_kernel_user
23323+#else
23324+ pax_exit_kernel
23325+#endif
23326 TRACE_IRQS_IRETQ 0
23327 SWAPGS_UNSAFE_STACK
23328 RESTORE_ALL 8
23329 jmp irq_return
23330 paranoid_restore:
23331+ pax_exit_kernel
23332 TRACE_IRQS_IRETQ_DEBUG 0
23333 RESTORE_ALL 8
23334+ pax_force_retaddr_bts
23335 jmp irq_return
23336 paranoid_userspace:
23337 GET_THREAD_INFO(%rcx)
23338@@ -1548,7 +2054,7 @@ paranoid_schedule:
23339 TRACE_IRQS_OFF
23340 jmp paranoid_userspace
23341 CFI_ENDPROC
23342-END(paranoid_exit)
23343+ENDPROC(paranoid_exit)
23344
23345 /*
23346 * Exception entry point. This expects an error code/orig_rax on the stack.
23347@@ -1575,12 +2081,13 @@ ENTRY(error_entry)
23348 movq_cfi r14, R14+8
23349 movq_cfi r15, R15+8
23350 xorl %ebx,%ebx
23351- testl $3,CS+8(%rsp)
23352+ testb $3,CS+8(%rsp)
23353 je error_kernelspace
23354 error_swapgs:
23355 SWAPGS
23356 error_sti:
23357 TRACE_IRQS_OFF
23358+ pax_force_retaddr_bts
23359 ret
23360
23361 /*
23362@@ -1607,7 +2114,7 @@ bstep_iret:
23363 movq %rcx,RIP+8(%rsp)
23364 jmp error_swapgs
23365 CFI_ENDPROC
23366-END(error_entry)
23367+ENDPROC(error_entry)
23368
23369
23370 /* ebx: no swapgs flag (1: don't need swapgs, 0: need it) */
23371@@ -1618,7 +2125,7 @@ ENTRY(error_exit)
23372 DISABLE_INTERRUPTS(CLBR_NONE)
23373 TRACE_IRQS_OFF
23374 GET_THREAD_INFO(%rcx)
23375- testl %eax,%eax
23376+ testl $1,%eax
23377 jne retint_kernel
23378 LOCKDEP_SYS_EXIT_IRQ
23379 movl TI_flags(%rcx),%edx
23380@@ -1627,7 +2134,7 @@ ENTRY(error_exit)
23381 jnz retint_careful
23382 jmp retint_swapgs
23383 CFI_ENDPROC
23384-END(error_exit)
23385+ENDPROC(error_exit)
23386
23387 /*
23388 * Test if a given stack is an NMI stack or not.
23389@@ -1685,9 +2192,11 @@ ENTRY(nmi)
23390 * If %cs was not the kernel segment, then the NMI triggered in user
23391 * space, which means it is definitely not nested.
23392 */
23393+ cmpl $__KERNEXEC_KERNEL_CS, 16(%rsp)
23394+ je 1f
23395 cmpl $__KERNEL_CS, 16(%rsp)
23396 jne first_nmi
23397-
23398+1:
23399 /*
23400 * Check the special variable on the stack to see if NMIs are
23401 * executing.
23402@@ -1721,8 +2230,7 @@ nested_nmi:
23403
23404 1:
23405 /* Set up the interrupted NMIs stack to jump to repeat_nmi */
23406- leaq -1*8(%rsp), %rdx
23407- movq %rdx, %rsp
23408+ subq $8, %rsp
23409 CFI_ADJUST_CFA_OFFSET 1*8
23410 leaq -10*8(%rsp), %rdx
23411 pushq_cfi $__KERNEL_DS
23412@@ -1740,6 +2248,7 @@ nested_nmi_out:
23413 CFI_RESTORE rdx
23414
23415 /* No need to check faults here */
23416+# pax_force_retaddr_bts
23417 INTERRUPT_RETURN
23418
23419 CFI_RESTORE_STATE
23420@@ -1852,9 +2361,11 @@ end_repeat_nmi:
23421 * NMI itself takes a page fault, the page fault that was preempted
23422 * will read the information from the NMI page fault and not the
23423 * origin fault. Save it off and restore it if it changes.
23424- * Use the r12 callee-saved register.
23425+ * Use the r13 callee-saved register.
23426 */
23427- movq %cr2, %r12
23428+ movq %cr2, %r13
23429+
23430+ pax_enter_kernel_nmi
23431
23432 /* paranoidentry do_nmi, 0; without TRACE_IRQS_OFF */
23433 movq %rsp,%rdi
23434@@ -1863,31 +2374,36 @@ end_repeat_nmi:
23435
23436 /* Did the NMI take a page fault? Restore cr2 if it did */
23437 movq %cr2, %rcx
23438- cmpq %rcx, %r12
23439+ cmpq %rcx, %r13
23440 je 1f
23441- movq %r12, %cr2
23442+ movq %r13, %cr2
23443 1:
23444
23445- testl %ebx,%ebx /* swapgs needed? */
23446+ testl $1,%ebx /* swapgs needed? */
23447 jnz nmi_restore
23448 nmi_swapgs:
23449 SWAPGS_UNSAFE_STACK
23450 nmi_restore:
23451+ pax_exit_kernel_nmi
23452 /* Pop the extra iret frame at once */
23453 RESTORE_ALL 6*8
23454+ testb $3, 8(%rsp)
23455+ jnz 1f
23456+ pax_force_retaddr_bts
23457+1:
23458
23459 /* Clear the NMI executing stack variable */
23460 movq $0, 5*8(%rsp)
23461 jmp irq_return
23462 CFI_ENDPROC
23463-END(nmi)
23464+ENDPROC(nmi)
23465
23466 ENTRY(ignore_sysret)
23467 CFI_STARTPROC
23468 mov $-ENOSYS,%eax
23469 sysret
23470 CFI_ENDPROC
23471-END(ignore_sysret)
23472+ENDPROC(ignore_sysret)
23473
23474 /*
23475 * End of kprobes section
23476diff --git a/arch/x86/kernel/ftrace.c b/arch/x86/kernel/ftrace.c
23477index d4bdd25..912664c 100644
23478--- a/arch/x86/kernel/ftrace.c
23479+++ b/arch/x86/kernel/ftrace.c
23480@@ -105,6 +105,8 @@ ftrace_modify_code_direct(unsigned long ip, unsigned const char *old_code,
23481 {
23482 unsigned char replaced[MCOUNT_INSN_SIZE];
23483
23484+ ip = ktla_ktva(ip);
23485+
23486 /*
23487 * Note: Due to modules and __init, code can
23488 * disappear and change, we need to protect against faulting
23489@@ -227,7 +229,7 @@ int ftrace_update_ftrace_func(ftrace_func_t func)
23490 unsigned char old[MCOUNT_INSN_SIZE], *new;
23491 int ret;
23492
23493- memcpy(old, &ftrace_call, MCOUNT_INSN_SIZE);
23494+ memcpy(old, (void *)ktla_ktva((unsigned long)ftrace_call), MCOUNT_INSN_SIZE);
23495 new = ftrace_call_replace(ip, (unsigned long)func);
23496
23497 /* See comment above by declaration of modifying_ftrace_code */
23498@@ -238,7 +240,7 @@ int ftrace_update_ftrace_func(ftrace_func_t func)
23499 /* Also update the regs callback function */
23500 if (!ret) {
23501 ip = (unsigned long)(&ftrace_regs_call);
23502- memcpy(old, &ftrace_regs_call, MCOUNT_INSN_SIZE);
23503+ memcpy(old, ktla_ktva((void *)&ftrace_regs_call), MCOUNT_INSN_SIZE);
23504 new = ftrace_call_replace(ip, (unsigned long)func);
23505 ret = ftrace_modify_code(ip, old, new);
23506 }
23507@@ -291,7 +293,7 @@ static int ftrace_write(unsigned long ip, const char *val, int size)
23508 * kernel identity mapping to modify code.
23509 */
23510 if (within(ip, (unsigned long)_text, (unsigned long)_etext))
23511- ip = (unsigned long)__va(__pa_symbol(ip));
23512+ ip = (unsigned long)__va(__pa_symbol(ktla_ktva(ip)));
23513
23514 return probe_kernel_write((void *)ip, val, size);
23515 }
23516@@ -301,7 +303,7 @@ static int add_break(unsigned long ip, const char *old)
23517 unsigned char replaced[MCOUNT_INSN_SIZE];
23518 unsigned char brk = BREAKPOINT_INSTRUCTION;
23519
23520- if (probe_kernel_read(replaced, (void *)ip, MCOUNT_INSN_SIZE))
23521+ if (probe_kernel_read(replaced, (void *)ktla_ktva(ip), MCOUNT_INSN_SIZE))
23522 return -EFAULT;
23523
23524 /* Make sure it is what we expect it to be */
23525@@ -649,7 +651,7 @@ ftrace_modify_code(unsigned long ip, unsigned const char *old_code,
23526 return ret;
23527
23528 fail_update:
23529- probe_kernel_write((void *)ip, &old_code[0], 1);
23530+ probe_kernel_write((void *)ktla_ktva(ip), &old_code[0], 1);
23531 goto out;
23532 }
23533
23534@@ -682,6 +684,8 @@ static int ftrace_mod_jmp(unsigned long ip,
23535 {
23536 unsigned char code[MCOUNT_INSN_SIZE];
23537
23538+ ip = ktla_ktva(ip);
23539+
23540 if (probe_kernel_read(code, (void *)ip, MCOUNT_INSN_SIZE))
23541 return -EFAULT;
23542
23543diff --git a/arch/x86/kernel/head64.c b/arch/x86/kernel/head64.c
23544index 1be8e43..d9b9ef6 100644
23545--- a/arch/x86/kernel/head64.c
23546+++ b/arch/x86/kernel/head64.c
23547@@ -67,12 +67,12 @@ again:
23548 pgd = *pgd_p;
23549
23550 /*
23551- * The use of __START_KERNEL_map rather than __PAGE_OFFSET here is
23552- * critical -- __PAGE_OFFSET would point us back into the dynamic
23553+ * The use of __early_va rather than __va here is critical:
23554+ * __va would point us back into the dynamic
23555 * range and we might end up looping forever...
23556 */
23557 if (pgd)
23558- pud_p = (pudval_t *)((pgd & PTE_PFN_MASK) + __START_KERNEL_map - phys_base);
23559+ pud_p = (pudval_t *)(__early_va(pgd & PTE_PFN_MASK));
23560 else {
23561 if (next_early_pgt >= EARLY_DYNAMIC_PAGE_TABLES) {
23562 reset_early_page_tables();
23563@@ -82,13 +82,13 @@ again:
23564 pud_p = (pudval_t *)early_dynamic_pgts[next_early_pgt++];
23565 for (i = 0; i < PTRS_PER_PUD; i++)
23566 pud_p[i] = 0;
23567- *pgd_p = (pgdval_t)pud_p - __START_KERNEL_map + phys_base + _KERNPG_TABLE;
23568+ *pgd_p = (pgdval_t)__pa(pud_p) + _KERNPG_TABLE;
23569 }
23570 pud_p += pud_index(address);
23571 pud = *pud_p;
23572
23573 if (pud)
23574- pmd_p = (pmdval_t *)((pud & PTE_PFN_MASK) + __START_KERNEL_map - phys_base);
23575+ pmd_p = (pmdval_t *)(__early_va(pud & PTE_PFN_MASK));
23576 else {
23577 if (next_early_pgt >= EARLY_DYNAMIC_PAGE_TABLES) {
23578 reset_early_page_tables();
23579@@ -98,7 +98,7 @@ again:
23580 pmd_p = (pmdval_t *)early_dynamic_pgts[next_early_pgt++];
23581 for (i = 0; i < PTRS_PER_PMD; i++)
23582 pmd_p[i] = 0;
23583- *pud_p = (pudval_t)pmd_p - __START_KERNEL_map + phys_base + _KERNPG_TABLE;
23584+ *pud_p = (pudval_t)__pa(pmd_p) + _KERNPG_TABLE;
23585 }
23586 pmd = (physaddr & PMD_MASK) + early_pmd_flags;
23587 pmd_p[pmd_index(address)] = pmd;
23588@@ -175,7 +175,6 @@ asmlinkage void __init x86_64_start_kernel(char * real_mode_data)
23589 if (console_loglevel == 10)
23590 early_printk("Kernel alive\n");
23591
23592- clear_page(init_level4_pgt);
23593 /* set init_level4_pgt kernel high mapping*/
23594 init_level4_pgt[511] = early_level4_pgt[511];
23595
23596diff --git a/arch/x86/kernel/head_32.S b/arch/x86/kernel/head_32.S
23597index 81ba276..30c5411 100644
23598--- a/arch/x86/kernel/head_32.S
23599+++ b/arch/x86/kernel/head_32.S
23600@@ -26,6 +26,12 @@
23601 /* Physical address */
23602 #define pa(X) ((X) - __PAGE_OFFSET)
23603
23604+#ifdef CONFIG_PAX_KERNEXEC
23605+#define ta(X) (X)
23606+#else
23607+#define ta(X) ((X) - __PAGE_OFFSET)
23608+#endif
23609+
23610 /*
23611 * References to members of the new_cpu_data structure.
23612 */
23613@@ -55,11 +61,7 @@
23614 * and small than max_low_pfn, otherwise will waste some page table entries
23615 */
23616
23617-#if PTRS_PER_PMD > 1
23618-#define PAGE_TABLE_SIZE(pages) (((pages) / PTRS_PER_PMD) + PTRS_PER_PGD)
23619-#else
23620-#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PGD)
23621-#endif
23622+#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PTE)
23623
23624 /* Number of possible pages in the lowmem region */
23625 LOWMEM_PAGES = (((1<<32) - __PAGE_OFFSET) >> PAGE_SHIFT)
23626@@ -78,6 +80,12 @@ INIT_MAP_SIZE = PAGE_TABLE_SIZE(KERNEL_PAGES) * PAGE_SIZE
23627 RESERVE_BRK(pagetables, INIT_MAP_SIZE)
23628
23629 /*
23630+ * Real beginning of normal "text" segment
23631+ */
23632+ENTRY(stext)
23633+ENTRY(_stext)
23634+
23635+/*
23636 * 32-bit kernel entrypoint; only used by the boot CPU. On entry,
23637 * %esi points to the real-mode code as a 32-bit pointer.
23638 * CS and DS must be 4 GB flat segments, but we don't depend on
23639@@ -85,6 +93,13 @@ RESERVE_BRK(pagetables, INIT_MAP_SIZE)
23640 * can.
23641 */
23642 __HEAD
23643+
23644+#ifdef CONFIG_PAX_KERNEXEC
23645+ jmp startup_32
23646+/* PaX: fill first page in .text with int3 to catch NULL derefs in kernel mode */
23647+.fill PAGE_SIZE-5,1,0xcc
23648+#endif
23649+
23650 ENTRY(startup_32)
23651 movl pa(stack_start),%ecx
23652
23653@@ -106,6 +121,59 @@ ENTRY(startup_32)
23654 2:
23655 leal -__PAGE_OFFSET(%ecx),%esp
23656
23657+#ifdef CONFIG_SMP
23658+ movl $pa(cpu_gdt_table),%edi
23659+ movl $__per_cpu_load,%eax
23660+ movw %ax,GDT_ENTRY_PERCPU * 8 + 2(%edi)
23661+ rorl $16,%eax
23662+ movb %al,GDT_ENTRY_PERCPU * 8 + 4(%edi)
23663+ movb %ah,GDT_ENTRY_PERCPU * 8 + 7(%edi)
23664+ movl $__per_cpu_end - 1,%eax
23665+ subl $__per_cpu_start,%eax
23666+ movw %ax,GDT_ENTRY_PERCPU * 8 + 0(%edi)
23667+#endif
23668+
23669+#ifdef CONFIG_PAX_MEMORY_UDEREF
23670+ movl $NR_CPUS,%ecx
23671+ movl $pa(cpu_gdt_table),%edi
23672+1:
23673+ movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c09700),GDT_ENTRY_KERNEL_DS * 8 + 4(%edi)
23674+ movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0fb00),GDT_ENTRY_DEFAULT_USER_CS * 8 + 4(%edi)
23675+ movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0f300),GDT_ENTRY_DEFAULT_USER_DS * 8 + 4(%edi)
23676+ addl $PAGE_SIZE_asm,%edi
23677+ loop 1b
23678+#endif
23679+
23680+#ifdef CONFIG_PAX_KERNEXEC
23681+ movl $pa(boot_gdt),%edi
23682+ movl $__LOAD_PHYSICAL_ADDR,%eax
23683+ movw %ax,GDT_ENTRY_BOOT_CS * 8 + 2(%edi)
23684+ rorl $16,%eax
23685+ movb %al,GDT_ENTRY_BOOT_CS * 8 + 4(%edi)
23686+ movb %ah,GDT_ENTRY_BOOT_CS * 8 + 7(%edi)
23687+ rorl $16,%eax
23688+
23689+ ljmp $(__BOOT_CS),$1f
23690+1:
23691+
23692+ movl $NR_CPUS,%ecx
23693+ movl $pa(cpu_gdt_table),%edi
23694+ addl $__PAGE_OFFSET,%eax
23695+1:
23696+ movb $0xc0,GDT_ENTRY_KERNEL_CS * 8 + 6(%edi)
23697+ movb $0xc0,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 6(%edi)
23698+ movw %ax,GDT_ENTRY_KERNEL_CS * 8 + 2(%edi)
23699+ movw %ax,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 2(%edi)
23700+ rorl $16,%eax
23701+ movb %al,GDT_ENTRY_KERNEL_CS * 8 + 4(%edi)
23702+ movb %al,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 4(%edi)
23703+ movb %ah,GDT_ENTRY_KERNEL_CS * 8 + 7(%edi)
23704+ movb %ah,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 7(%edi)
23705+ rorl $16,%eax
23706+ addl $PAGE_SIZE_asm,%edi
23707+ loop 1b
23708+#endif
23709+
23710 /*
23711 * Clear BSS first so that there are no surprises...
23712 */
23713@@ -201,8 +269,11 @@ ENTRY(startup_32)
23714 movl %eax, pa(max_pfn_mapped)
23715
23716 /* Do early initialization of the fixmap area */
23717- movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
23718- movl %eax,pa(initial_pg_pmd+0x1000*KPMDS-8)
23719+#ifdef CONFIG_COMPAT_VDSO
23720+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_pg_pmd+0x1000*KPMDS-8)
23721+#else
23722+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_pg_pmd+0x1000*KPMDS-8)
23723+#endif
23724 #else /* Not PAE */
23725
23726 page_pde_offset = (__PAGE_OFFSET >> 20);
23727@@ -232,8 +303,11 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
23728 movl %eax, pa(max_pfn_mapped)
23729
23730 /* Do early initialization of the fixmap area */
23731- movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
23732- movl %eax,pa(initial_page_table+0xffc)
23733+#ifdef CONFIG_COMPAT_VDSO
23734+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_page_table+0xffc)
23735+#else
23736+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_page_table+0xffc)
23737+#endif
23738 #endif
23739
23740 #ifdef CONFIG_PARAVIRT
23741@@ -247,9 +321,7 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
23742 cmpl $num_subarch_entries, %eax
23743 jae bad_subarch
23744
23745- movl pa(subarch_entries)(,%eax,4), %eax
23746- subl $__PAGE_OFFSET, %eax
23747- jmp *%eax
23748+ jmp *pa(subarch_entries)(,%eax,4)
23749
23750 bad_subarch:
23751 WEAK(lguest_entry)
23752@@ -261,10 +333,10 @@ WEAK(xen_entry)
23753 __INITDATA
23754
23755 subarch_entries:
23756- .long default_entry /* normal x86/PC */
23757- .long lguest_entry /* lguest hypervisor */
23758- .long xen_entry /* Xen hypervisor */
23759- .long default_entry /* Moorestown MID */
23760+ .long ta(default_entry) /* normal x86/PC */
23761+ .long ta(lguest_entry) /* lguest hypervisor */
23762+ .long ta(xen_entry) /* Xen hypervisor */
23763+ .long ta(default_entry) /* Moorestown MID */
23764 num_subarch_entries = (. - subarch_entries) / 4
23765 .previous
23766 #else
23767@@ -354,6 +426,7 @@ default_entry:
23768 movl pa(mmu_cr4_features),%eax
23769 movl %eax,%cr4
23770
23771+#ifdef CONFIG_X86_PAE
23772 testb $X86_CR4_PAE, %al # check if PAE is enabled
23773 jz enable_paging
23774
23775@@ -382,6 +455,9 @@ default_entry:
23776 /* Make changes effective */
23777 wrmsr
23778
23779+ btsl $_PAGE_BIT_NX-32,pa(__supported_pte_mask+4)
23780+#endif
23781+
23782 enable_paging:
23783
23784 /*
23785@@ -449,14 +525,20 @@ is486:
23786 1: movl $(__KERNEL_DS),%eax # reload all the segment registers
23787 movl %eax,%ss # after changing gdt.
23788
23789- movl $(__USER_DS),%eax # DS/ES contains default USER segment
23790+# movl $(__KERNEL_DS),%eax # DS/ES contains default KERNEL segment
23791 movl %eax,%ds
23792 movl %eax,%es
23793
23794 movl $(__KERNEL_PERCPU), %eax
23795 movl %eax,%fs # set this cpu's percpu
23796
23797+#ifdef CONFIG_CC_STACKPROTECTOR
23798 movl $(__KERNEL_STACK_CANARY),%eax
23799+#elif defined(CONFIG_PAX_MEMORY_UDEREF)
23800+ movl $(__USER_DS),%eax
23801+#else
23802+ xorl %eax,%eax
23803+#endif
23804 movl %eax,%gs
23805
23806 xorl %eax,%eax # Clear LDT
23807@@ -512,8 +594,11 @@ setup_once:
23808 * relocation. Manually set base address in stack canary
23809 * segment descriptor.
23810 */
23811- movl $gdt_page,%eax
23812+ movl $cpu_gdt_table,%eax
23813 movl $stack_canary,%ecx
23814+#ifdef CONFIG_SMP
23815+ addl $__per_cpu_load,%ecx
23816+#endif
23817 movw %cx, 8 * GDT_ENTRY_STACK_CANARY + 2(%eax)
23818 shrl $16, %ecx
23819 movb %cl, 8 * GDT_ENTRY_STACK_CANARY + 4(%eax)
23820@@ -544,7 +629,7 @@ ENDPROC(early_idt_handlers)
23821 /* This is global to keep gas from relaxing the jumps */
23822 ENTRY(early_idt_handler)
23823 cld
23824- cmpl $2,%ss:early_recursion_flag
23825+ cmpl $1,%ss:early_recursion_flag
23826 je hlt_loop
23827 incl %ss:early_recursion_flag
23828
23829@@ -582,8 +667,8 @@ ENTRY(early_idt_handler)
23830 pushl (20+6*4)(%esp) /* trapno */
23831 pushl $fault_msg
23832 call printk
23833-#endif
23834 call dump_stack
23835+#endif
23836 hlt_loop:
23837 hlt
23838 jmp hlt_loop
23839@@ -602,8 +687,11 @@ ENDPROC(early_idt_handler)
23840 /* This is the default interrupt "handler" :-) */
23841 ALIGN
23842 ignore_int:
23843- cld
23844 #ifdef CONFIG_PRINTK
23845+ cmpl $2,%ss:early_recursion_flag
23846+ je hlt_loop
23847+ incl %ss:early_recursion_flag
23848+ cld
23849 pushl %eax
23850 pushl %ecx
23851 pushl %edx
23852@@ -612,9 +700,6 @@ ignore_int:
23853 movl $(__KERNEL_DS),%eax
23854 movl %eax,%ds
23855 movl %eax,%es
23856- cmpl $2,early_recursion_flag
23857- je hlt_loop
23858- incl early_recursion_flag
23859 pushl 16(%esp)
23860 pushl 24(%esp)
23861 pushl 32(%esp)
23862@@ -648,29 +733,34 @@ ENTRY(setup_once_ref)
23863 /*
23864 * BSS section
23865 */
23866-__PAGE_ALIGNED_BSS
23867- .align PAGE_SIZE
23868 #ifdef CONFIG_X86_PAE
23869+.section .initial_pg_pmd,"a",@progbits
23870 initial_pg_pmd:
23871 .fill 1024*KPMDS,4,0
23872 #else
23873+.section .initial_page_table,"a",@progbits
23874 ENTRY(initial_page_table)
23875 .fill 1024,4,0
23876 #endif
23877+.section .initial_pg_fixmap,"a",@progbits
23878 initial_pg_fixmap:
23879 .fill 1024,4,0
23880+.section .empty_zero_page,"a",@progbits
23881 ENTRY(empty_zero_page)
23882 .fill 4096,1,0
23883+.section .swapper_pg_dir,"a",@progbits
23884 ENTRY(swapper_pg_dir)
23885+#ifdef CONFIG_X86_PAE
23886+ .fill 4,8,0
23887+#else
23888 .fill 1024,4,0
23889+#endif
23890
23891 /*
23892 * This starts the data section.
23893 */
23894 #ifdef CONFIG_X86_PAE
23895-__PAGE_ALIGNED_DATA
23896- /* Page-aligned for the benefit of paravirt? */
23897- .align PAGE_SIZE
23898+.section .initial_page_table,"a",@progbits
23899 ENTRY(initial_page_table)
23900 .long pa(initial_pg_pmd+PGD_IDENT_ATTR),0 /* low identity map */
23901 # if KPMDS == 3
23902@@ -689,12 +779,20 @@ ENTRY(initial_page_table)
23903 # error "Kernel PMDs should be 1, 2 or 3"
23904 # endif
23905 .align PAGE_SIZE /* needs to be page-sized too */
23906+
23907+#ifdef CONFIG_PAX_PER_CPU_PGD
23908+ENTRY(cpu_pgd)
23909+ .rept 2*NR_CPUS
23910+ .fill 4,8,0
23911+ .endr
23912+#endif
23913+
23914 #endif
23915
23916 .data
23917 .balign 4
23918 ENTRY(stack_start)
23919- .long init_thread_union+THREAD_SIZE
23920+ .long init_thread_union+THREAD_SIZE-8
23921
23922 __INITRODATA
23923 int_msg:
23924@@ -722,7 +820,7 @@ fault_msg:
23925 * segment size, and 32-bit linear address value:
23926 */
23927
23928- .data
23929+.section .rodata,"a",@progbits
23930 .globl boot_gdt_descr
23931 .globl idt_descr
23932
23933@@ -731,7 +829,7 @@ fault_msg:
23934 .word 0 # 32 bit align gdt_desc.address
23935 boot_gdt_descr:
23936 .word __BOOT_DS+7
23937- .long boot_gdt - __PAGE_OFFSET
23938+ .long pa(boot_gdt)
23939
23940 .word 0 # 32-bit align idt_desc.address
23941 idt_descr:
23942@@ -742,7 +840,7 @@ idt_descr:
23943 .word 0 # 32 bit align gdt_desc.address
23944 ENTRY(early_gdt_descr)
23945 .word GDT_ENTRIES*8-1
23946- .long gdt_page /* Overwritten for secondary CPUs */
23947+ .long cpu_gdt_table /* Overwritten for secondary CPUs */
23948
23949 /*
23950 * The boot_gdt must mirror the equivalent in setup.S and is
23951@@ -751,5 +849,65 @@ ENTRY(early_gdt_descr)
23952 .align L1_CACHE_BYTES
23953 ENTRY(boot_gdt)
23954 .fill GDT_ENTRY_BOOT_CS,8,0
23955- .quad 0x00cf9a000000ffff /* kernel 4GB code at 0x00000000 */
23956- .quad 0x00cf92000000ffff /* kernel 4GB data at 0x00000000 */
23957+ .quad 0x00cf9b000000ffff /* kernel 4GB code at 0x00000000 */
23958+ .quad 0x00cf93000000ffff /* kernel 4GB data at 0x00000000 */
23959+
23960+ .align PAGE_SIZE_asm
23961+ENTRY(cpu_gdt_table)
23962+ .rept NR_CPUS
23963+ .quad 0x0000000000000000 /* NULL descriptor */
23964+ .quad 0x0000000000000000 /* 0x0b reserved */
23965+ .quad 0x0000000000000000 /* 0x13 reserved */
23966+ .quad 0x0000000000000000 /* 0x1b reserved */
23967+
23968+#ifdef CONFIG_PAX_KERNEXEC
23969+ .quad 0x00cf9b000000ffff /* 0x20 alternate kernel 4GB code at 0x00000000 */
23970+#else
23971+ .quad 0x0000000000000000 /* 0x20 unused */
23972+#endif
23973+
23974+ .quad 0x0000000000000000 /* 0x28 unused */
23975+ .quad 0x0000000000000000 /* 0x33 TLS entry 1 */
23976+ .quad 0x0000000000000000 /* 0x3b TLS entry 2 */
23977+ .quad 0x0000000000000000 /* 0x43 TLS entry 3 */
23978+ .quad 0x0000000000000000 /* 0x4b reserved */
23979+ .quad 0x0000000000000000 /* 0x53 reserved */
23980+ .quad 0x0000000000000000 /* 0x5b reserved */
23981+
23982+ .quad 0x00cf9b000000ffff /* 0x60 kernel 4GB code at 0x00000000 */
23983+ .quad 0x00cf93000000ffff /* 0x68 kernel 4GB data at 0x00000000 */
23984+ .quad 0x00cffb000000ffff /* 0x73 user 4GB code at 0x00000000 */
23985+ .quad 0x00cff3000000ffff /* 0x7b user 4GB data at 0x00000000 */
23986+
23987+ .quad 0x0000000000000000 /* 0x80 TSS descriptor */
23988+ .quad 0x0000000000000000 /* 0x88 LDT descriptor */
23989+
23990+ /*
23991+ * Segments used for calling PnP BIOS have byte granularity.
23992+ * The code segments and data segments have fixed 64k limits,
23993+ * the transfer segment sizes are set at run time.
23994+ */
23995+ .quad 0x00409b000000ffff /* 0x90 32-bit code */
23996+ .quad 0x00009b000000ffff /* 0x98 16-bit code */
23997+ .quad 0x000093000000ffff /* 0xa0 16-bit data */
23998+ .quad 0x0000930000000000 /* 0xa8 16-bit data */
23999+ .quad 0x0000930000000000 /* 0xb0 16-bit data */
24000+
24001+ /*
24002+ * The APM segments have byte granularity and their bases
24003+ * are set at run time. All have 64k limits.
24004+ */
24005+ .quad 0x00409b000000ffff /* 0xb8 APM CS code */
24006+ .quad 0x00009b000000ffff /* 0xc0 APM CS 16 code (16 bit) */
24007+ .quad 0x004093000000ffff /* 0xc8 APM DS data */
24008+
24009+ .quad 0x00c0930000000000 /* 0xd0 - ESPFIX SS */
24010+ .quad 0x0040930000000000 /* 0xd8 - PERCPU */
24011+ .quad 0x0040910000000017 /* 0xe0 - STACK_CANARY */
24012+ .quad 0x0000000000000000 /* 0xe8 - PCIBIOS_CS */
24013+ .quad 0x0000000000000000 /* 0xf0 - PCIBIOS_DS */
24014+ .quad 0x0000000000000000 /* 0xf8 - GDT entry 31: double-fault TSS */
24015+
24016+ /* Be sure this is zeroed to avoid false validations in Xen */
24017+ .fill PAGE_SIZE_asm - GDT_SIZE,1,0
24018+ .endr
24019diff --git a/arch/x86/kernel/head_64.S b/arch/x86/kernel/head_64.S
24020index e1aabdb..fee4fee 100644
24021--- a/arch/x86/kernel/head_64.S
24022+++ b/arch/x86/kernel/head_64.S
24023@@ -20,6 +20,8 @@
24024 #include <asm/processor-flags.h>
24025 #include <asm/percpu.h>
24026 #include <asm/nops.h>
24027+#include <asm/cpufeature.h>
24028+#include <asm/alternative-asm.h>
24029
24030 #ifdef CONFIG_PARAVIRT
24031 #include <asm/asm-offsets.h>
24032@@ -41,6 +43,12 @@ L4_PAGE_OFFSET = pgd_index(__PAGE_OFFSET)
24033 L3_PAGE_OFFSET = pud_index(__PAGE_OFFSET)
24034 L4_START_KERNEL = pgd_index(__START_KERNEL_map)
24035 L3_START_KERNEL = pud_index(__START_KERNEL_map)
24036+L4_VMALLOC_START = pgd_index(VMALLOC_START)
24037+L3_VMALLOC_START = pud_index(VMALLOC_START)
24038+L4_VMALLOC_END = pgd_index(VMALLOC_END)
24039+L3_VMALLOC_END = pud_index(VMALLOC_END)
24040+L4_VMEMMAP_START = pgd_index(VMEMMAP_START)
24041+L3_VMEMMAP_START = pud_index(VMEMMAP_START)
24042
24043 .text
24044 __HEAD
24045@@ -89,11 +97,24 @@ startup_64:
24046 * Fixup the physical addresses in the page table
24047 */
24048 addq %rbp, early_level4_pgt + (L4_START_KERNEL*8)(%rip)
24049+ addq %rbp, init_level4_pgt + (L4_PAGE_OFFSET*8)(%rip)
24050+ addq %rbp, init_level4_pgt + (L4_VMALLOC_START*8)(%rip)
24051+ addq %rbp, init_level4_pgt + (L4_VMALLOC_END*8)(%rip)
24052+ addq %rbp, init_level4_pgt + (L4_VMEMMAP_START*8)(%rip)
24053+ addq %rbp, init_level4_pgt + (L4_START_KERNEL*8)(%rip)
24054
24055- addq %rbp, level3_kernel_pgt + (510*8)(%rip)
24056- addq %rbp, level3_kernel_pgt + (511*8)(%rip)
24057+ addq %rbp, level3_ident_pgt + (0*8)(%rip)
24058+#ifndef CONFIG_XEN
24059+ addq %rbp, level3_ident_pgt + (1*8)(%rip)
24060+#endif
24061+
24062+ addq %rbp, level3_vmemmap_pgt + (L3_VMEMMAP_START*8)(%rip)
24063+
24064+ addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8)(%rip)
24065+ addq %rbp, level3_kernel_pgt + ((L3_START_KERNEL+1)*8)(%rip)
24066
24067 addq %rbp, level2_fixmap_pgt + (506*8)(%rip)
24068+ addq %rbp, level2_fixmap_pgt + (507*8)(%rip)
24069
24070 /*
24071 * Set up the identity mapping for the switchover. These
24072@@ -177,8 +198,8 @@ ENTRY(secondary_startup_64)
24073 movq $(init_level4_pgt - __START_KERNEL_map), %rax
24074 1:
24075
24076- /* Enable PAE mode and PGE */
24077- movl $(X86_CR4_PAE | X86_CR4_PGE), %ecx
24078+ /* Enable PAE mode and PSE/PGE */
24079+ movl $(X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE), %ecx
24080 movq %rcx, %cr4
24081
24082 /* Setup early boot stage 4 level pagetables. */
24083@@ -199,10 +220,19 @@ ENTRY(secondary_startup_64)
24084 movl $MSR_EFER, %ecx
24085 rdmsr
24086 btsl $_EFER_SCE, %eax /* Enable System Call */
24087- btl $20,%edi /* No Execute supported? */
24088+ btl $(X86_FEATURE_NX & 31),%edi /* No Execute supported? */
24089 jnc 1f
24090 btsl $_EFER_NX, %eax
24091 btsq $_PAGE_BIT_NX,early_pmd_flags(%rip)
24092+#ifndef CONFIG_EFI
24093+ btsq $_PAGE_BIT_NX, init_level4_pgt + 8*L4_PAGE_OFFSET(%rip)
24094+#endif
24095+ btsq $_PAGE_BIT_NX, init_level4_pgt + 8*L4_VMALLOC_START(%rip)
24096+ btsq $_PAGE_BIT_NX, init_level4_pgt + 8*L4_VMALLOC_END(%rip)
24097+ btsq $_PAGE_BIT_NX, init_level4_pgt + 8*L4_VMEMMAP_START(%rip)
24098+ btsq $_PAGE_BIT_NX, level2_fixmap_pgt + 8*506(%rip)
24099+ btsq $_PAGE_BIT_NX, level2_fixmap_pgt + 8*507(%rip)
24100+ btsq $_PAGE_BIT_NX, __supported_pte_mask(%rip)
24101 1: wrmsr /* Make changes effective */
24102
24103 /* Setup cr0 */
24104@@ -282,6 +312,7 @@ ENTRY(secondary_startup_64)
24105 * REX.W + FF /5 JMP m16:64 Jump far, absolute indirect,
24106 * address given in m16:64.
24107 */
24108+ pax_set_fptr_mask
24109 movq initial_code(%rip),%rax
24110 pushq $0 # fake return address to stop unwinder
24111 pushq $__KERNEL_CS # set correct cs
24112@@ -388,7 +419,7 @@ ENTRY(early_idt_handler)
24113 call dump_stack
24114 #ifdef CONFIG_KALLSYMS
24115 leaq early_idt_ripmsg(%rip),%rdi
24116- movq 40(%rsp),%rsi # %rip again
24117+ movq 88(%rsp),%rsi # %rip again
24118 call __print_symbol
24119 #endif
24120 #endif /* EARLY_PRINTK */
24121@@ -416,6 +447,7 @@ ENDPROC(early_idt_handler)
24122 early_recursion_flag:
24123 .long 0
24124
24125+ .section .rodata,"a",@progbits
24126 #ifdef CONFIG_EARLY_PRINTK
24127 early_idt_msg:
24128 .asciz "PANIC: early exception %02lx rip %lx:%lx error %lx cr2 %lx\n"
24129@@ -443,29 +475,52 @@ NEXT_PAGE(early_level4_pgt)
24130 NEXT_PAGE(early_dynamic_pgts)
24131 .fill 512*EARLY_DYNAMIC_PAGE_TABLES,8,0
24132
24133- .data
24134+ .section .rodata,"a",@progbits
24135
24136-#ifndef CONFIG_XEN
24137 NEXT_PAGE(init_level4_pgt)
24138- .fill 512,8,0
24139-#else
24140-NEXT_PAGE(init_level4_pgt)
24141- .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
24142 .org init_level4_pgt + L4_PAGE_OFFSET*8, 0
24143 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
24144+ .org init_level4_pgt + L4_VMALLOC_START*8, 0
24145+ .quad level3_vmalloc_start_pgt - __START_KERNEL_map + _KERNPG_TABLE
24146+ .org init_level4_pgt + L4_VMALLOC_END*8, 0
24147+ .quad level3_vmalloc_end_pgt - __START_KERNEL_map + _KERNPG_TABLE
24148+ .org init_level4_pgt + L4_VMEMMAP_START*8, 0
24149+ .quad level3_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
24150 .org init_level4_pgt + L4_START_KERNEL*8, 0
24151 /* (2^48-(2*1024*1024*1024))/(2^39) = 511 */
24152 .quad level3_kernel_pgt - __START_KERNEL_map + _PAGE_TABLE
24153
24154+#ifdef CONFIG_PAX_PER_CPU_PGD
24155+NEXT_PAGE(cpu_pgd)
24156+ .rept 2*NR_CPUS
24157+ .fill 512,8,0
24158+ .endr
24159+#endif
24160+
24161 NEXT_PAGE(level3_ident_pgt)
24162 .quad level2_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
24163+#ifdef CONFIG_XEN
24164 .fill 511, 8, 0
24165+#else
24166+ .quad level2_ident_pgt + PAGE_SIZE - __START_KERNEL_map + _KERNPG_TABLE
24167+ .fill 510,8,0
24168+#endif
24169+
24170+NEXT_PAGE(level3_vmalloc_start_pgt)
24171+ .fill 512,8,0
24172+
24173+NEXT_PAGE(level3_vmalloc_end_pgt)
24174+ .fill 512,8,0
24175+
24176+NEXT_PAGE(level3_vmemmap_pgt)
24177+ .fill L3_VMEMMAP_START,8,0
24178+ .quad level2_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
24179+
24180 NEXT_PAGE(level2_ident_pgt)
24181- /* Since I easily can, map the first 1G.
24182+ /* Since I easily can, map the first 2G.
24183 * Don't set NX because code runs from these pages.
24184 */
24185- PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, PTRS_PER_PMD)
24186-#endif
24187+ PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, 2*PTRS_PER_PMD)
24188
24189 NEXT_PAGE(level3_kernel_pgt)
24190 .fill L3_START_KERNEL,8,0
24191@@ -473,6 +528,9 @@ NEXT_PAGE(level3_kernel_pgt)
24192 .quad level2_kernel_pgt - __START_KERNEL_map + _KERNPG_TABLE
24193 .quad level2_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
24194
24195+NEXT_PAGE(level2_vmemmap_pgt)
24196+ .fill 512,8,0
24197+
24198 NEXT_PAGE(level2_kernel_pgt)
24199 /*
24200 * 512 MB kernel mapping. We spend a full page on this pagetable
24201@@ -490,28 +548,64 @@ NEXT_PAGE(level2_kernel_pgt)
24202 NEXT_PAGE(level2_fixmap_pgt)
24203 .fill 506,8,0
24204 .quad level1_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
24205- /* 8MB reserved for vsyscalls + a 2MB hole = 4 + 1 entries */
24206- .fill 5,8,0
24207+ .quad level1_vsyscall_pgt - __START_KERNEL_map + _PAGE_TABLE
24208+ /* 6MB reserved for vsyscalls + a 2MB hole = 3 + 1 entries */
24209+ .fill 4,8,0
24210
24211 NEXT_PAGE(level1_fixmap_pgt)
24212 .fill 512,8,0
24213
24214+NEXT_PAGE(level1_vsyscall_pgt)
24215+ .fill 512,8,0
24216+
24217 #undef PMDS
24218
24219- .data
24220+ .align PAGE_SIZE
24221+ENTRY(cpu_gdt_table)
24222+ .rept NR_CPUS
24223+ .quad 0x0000000000000000 /* NULL descriptor */
24224+ .quad 0x00cf9b000000ffff /* __KERNEL32_CS */
24225+ .quad 0x00af9b000000ffff /* __KERNEL_CS */
24226+ .quad 0x00cf93000000ffff /* __KERNEL_DS */
24227+ .quad 0x00cffb000000ffff /* __USER32_CS */
24228+ .quad 0x00cff3000000ffff /* __USER_DS, __USER32_DS */
24229+ .quad 0x00affb000000ffff /* __USER_CS */
24230+
24231+#ifdef CONFIG_PAX_KERNEXEC
24232+ .quad 0x00af9b000000ffff /* __KERNEXEC_KERNEL_CS */
24233+#else
24234+ .quad 0x0 /* unused */
24235+#endif
24236+
24237+ .quad 0,0 /* TSS */
24238+ .quad 0,0 /* LDT */
24239+ .quad 0,0,0 /* three TLS descriptors */
24240+ .quad 0x0000f40000000000 /* node/CPU stored in limit */
24241+ /* asm/segment.h:GDT_ENTRIES must match this */
24242+
24243+#ifdef CONFIG_PAX_MEMORY_UDEREF
24244+ .quad 0x00cf93000000ffff /* __UDEREF_KERNEL_DS */
24245+#else
24246+ .quad 0x0 /* unused */
24247+#endif
24248+
24249+ /* zero the remaining page */
24250+ .fill PAGE_SIZE / 8 - GDT_ENTRIES,8,0
24251+ .endr
24252+
24253 .align 16
24254 .globl early_gdt_descr
24255 early_gdt_descr:
24256 .word GDT_ENTRIES*8-1
24257 early_gdt_descr_base:
24258- .quad INIT_PER_CPU_VAR(gdt_page)
24259+ .quad cpu_gdt_table
24260
24261 ENTRY(phys_base)
24262 /* This must match the first entry in level2_kernel_pgt */
24263 .quad 0x0000000000000000
24264
24265 #include "../../x86/xen/xen-head.S"
24266-
24267- __PAGE_ALIGNED_BSS
24268+
24269+ .section .rodata,"a",@progbits
24270 NEXT_PAGE(empty_zero_page)
24271 .skip PAGE_SIZE
24272diff --git a/arch/x86/kernel/i386_ksyms_32.c b/arch/x86/kernel/i386_ksyms_32.c
24273index 0fa6912..b37438b 100644
24274--- a/arch/x86/kernel/i386_ksyms_32.c
24275+++ b/arch/x86/kernel/i386_ksyms_32.c
24276@@ -20,8 +20,12 @@ extern void cmpxchg8b_emu(void);
24277 EXPORT_SYMBOL(cmpxchg8b_emu);
24278 #endif
24279
24280+EXPORT_SYMBOL_GPL(cpu_gdt_table);
24281+
24282 /* Networking helper routines. */
24283 EXPORT_SYMBOL(csum_partial_copy_generic);
24284+EXPORT_SYMBOL(csum_partial_copy_generic_to_user);
24285+EXPORT_SYMBOL(csum_partial_copy_generic_from_user);
24286
24287 EXPORT_SYMBOL(__get_user_1);
24288 EXPORT_SYMBOL(__get_user_2);
24289@@ -37,3 +41,11 @@ EXPORT_SYMBOL(strstr);
24290
24291 EXPORT_SYMBOL(csum_partial);
24292 EXPORT_SYMBOL(empty_zero_page);
24293+
24294+#ifdef CONFIG_PAX_KERNEXEC
24295+EXPORT_SYMBOL(__LOAD_PHYSICAL_ADDR);
24296+#endif
24297+
24298+#ifdef CONFIG_PAX_PER_CPU_PGD
24299+EXPORT_SYMBOL(cpu_pgd);
24300+#endif
24301diff --git a/arch/x86/kernel/i387.c b/arch/x86/kernel/i387.c
24302index 5d576ab..1403a03 100644
24303--- a/arch/x86/kernel/i387.c
24304+++ b/arch/x86/kernel/i387.c
24305@@ -51,7 +51,7 @@ static inline bool interrupted_kernel_fpu_idle(void)
24306 static inline bool interrupted_user_mode(void)
24307 {
24308 struct pt_regs *regs = get_irq_regs();
24309- return regs && user_mode_vm(regs);
24310+ return regs && user_mode(regs);
24311 }
24312
24313 /*
24314diff --git a/arch/x86/kernel/i8259.c b/arch/x86/kernel/i8259.c
24315index 9a5c460..84868423 100644
24316--- a/arch/x86/kernel/i8259.c
24317+++ b/arch/x86/kernel/i8259.c
24318@@ -110,7 +110,7 @@ static int i8259A_irq_pending(unsigned int irq)
24319 static void make_8259A_irq(unsigned int irq)
24320 {
24321 disable_irq_nosync(irq);
24322- io_apic_irqs &= ~(1<<irq);
24323+ io_apic_irqs &= ~(1UL<<irq);
24324 irq_set_chip_and_handler_name(irq, &i8259A_chip, handle_level_irq,
24325 i8259A_chip.name);
24326 enable_irq(irq);
24327@@ -209,7 +209,7 @@ spurious_8259A_irq:
24328 "spurious 8259A interrupt: IRQ%d.\n", irq);
24329 spurious_irq_mask |= irqmask;
24330 }
24331- atomic_inc(&irq_err_count);
24332+ atomic_inc_unchecked(&irq_err_count);
24333 /*
24334 * Theoretically we do not have to handle this IRQ,
24335 * but in Linux this does not cause problems and is
24336@@ -333,14 +333,16 @@ static void init_8259A(int auto_eoi)
24337 /* (slave's support for AEOI in flat mode is to be investigated) */
24338 outb_pic(SLAVE_ICW4_DEFAULT, PIC_SLAVE_IMR);
24339
24340+ pax_open_kernel();
24341 if (auto_eoi)
24342 /*
24343 * In AEOI mode we just have to mask the interrupt
24344 * when acking.
24345 */
24346- i8259A_chip.irq_mask_ack = disable_8259A_irq;
24347+ *(void **)&i8259A_chip.irq_mask_ack = disable_8259A_irq;
24348 else
24349- i8259A_chip.irq_mask_ack = mask_and_ack_8259A;
24350+ *(void **)&i8259A_chip.irq_mask_ack = mask_and_ack_8259A;
24351+ pax_close_kernel();
24352
24353 udelay(100); /* wait for 8259A to initialize */
24354
24355diff --git a/arch/x86/kernel/io_delay.c b/arch/x86/kernel/io_delay.c
24356index a979b5b..1d6db75 100644
24357--- a/arch/x86/kernel/io_delay.c
24358+++ b/arch/x86/kernel/io_delay.c
24359@@ -58,7 +58,7 @@ static int __init dmi_io_delay_0xed_port(const struct dmi_system_id *id)
24360 * Quirk table for systems that misbehave (lock up, etc.) if port
24361 * 0x80 is used:
24362 */
24363-static struct dmi_system_id __initdata io_delay_0xed_port_dmi_table[] = {
24364+static const struct dmi_system_id __initconst io_delay_0xed_port_dmi_table[] = {
24365 {
24366 .callback = dmi_io_delay_0xed_port,
24367 .ident = "Compaq Presario V6000",
24368diff --git a/arch/x86/kernel/ioport.c b/arch/x86/kernel/ioport.c
24369index 4ddaf66..49d5c18 100644
24370--- a/arch/x86/kernel/ioport.c
24371+++ b/arch/x86/kernel/ioport.c
24372@@ -6,6 +6,7 @@
24373 #include <linux/sched.h>
24374 #include <linux/kernel.h>
24375 #include <linux/capability.h>
24376+#include <linux/security.h>
24377 #include <linux/errno.h>
24378 #include <linux/types.h>
24379 #include <linux/ioport.h>
24380@@ -30,6 +31,12 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
24381 return -EINVAL;
24382 if (turn_on && !capable(CAP_SYS_RAWIO))
24383 return -EPERM;
24384+#ifdef CONFIG_GRKERNSEC_IO
24385+ if (turn_on && grsec_disable_privio) {
24386+ gr_handle_ioperm();
24387+ return -ENODEV;
24388+ }
24389+#endif
24390
24391 /*
24392 * If it's the first ioperm() call in this thread's lifetime, set the
24393@@ -54,7 +61,7 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
24394 * because the ->io_bitmap_max value must match the bitmap
24395 * contents:
24396 */
24397- tss = &per_cpu(init_tss, get_cpu());
24398+ tss = init_tss + get_cpu();
24399
24400 if (turn_on)
24401 bitmap_clear(t->io_bitmap_ptr, from, num);
24402@@ -105,6 +112,12 @@ SYSCALL_DEFINE1(iopl, unsigned int, level)
24403 if (level > old) {
24404 if (!capable(CAP_SYS_RAWIO))
24405 return -EPERM;
24406+#ifdef CONFIG_GRKERNSEC_IO
24407+ if (grsec_disable_privio) {
24408+ gr_handle_iopl();
24409+ return -ENODEV;
24410+ }
24411+#endif
24412 }
24413 regs->flags = (regs->flags & ~X86_EFLAGS_IOPL) | (level << 12);
24414 t->iopl = level << 12;
24415diff --git a/arch/x86/kernel/irq.c b/arch/x86/kernel/irq.c
24416index 22d0687..e07b2a5 100644
24417--- a/arch/x86/kernel/irq.c
24418+++ b/arch/x86/kernel/irq.c
24419@@ -21,7 +21,7 @@
24420 #define CREATE_TRACE_POINTS
24421 #include <asm/trace/irq_vectors.h>
24422
24423-atomic_t irq_err_count;
24424+atomic_unchecked_t irq_err_count;
24425
24426 /* Function pointer for generic interrupt vector handling */
24427 void (*x86_platform_ipi_callback)(void) = NULL;
24428@@ -125,9 +125,9 @@ int arch_show_interrupts(struct seq_file *p, int prec)
24429 seq_printf(p, "%10u ", per_cpu(mce_poll_count, j));
24430 seq_printf(p, " Machine check polls\n");
24431 #endif
24432- seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read(&irq_err_count));
24433+ seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read_unchecked(&irq_err_count));
24434 #if defined(CONFIG_X86_IO_APIC)
24435- seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read(&irq_mis_count));
24436+ seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read_unchecked(&irq_mis_count));
24437 #endif
24438 return 0;
24439 }
24440@@ -167,7 +167,7 @@ u64 arch_irq_stat_cpu(unsigned int cpu)
24441
24442 u64 arch_irq_stat(void)
24443 {
24444- u64 sum = atomic_read(&irq_err_count);
24445+ u64 sum = atomic_read_unchecked(&irq_err_count);
24446 return sum;
24447 }
24448
24449diff --git a/arch/x86/kernel/irq_32.c b/arch/x86/kernel/irq_32.c
24450index 4186755..18d6a9e 100644
24451--- a/arch/x86/kernel/irq_32.c
24452+++ b/arch/x86/kernel/irq_32.c
24453@@ -39,7 +39,7 @@ static int check_stack_overflow(void)
24454 __asm__ __volatile__("andl %%esp,%0" :
24455 "=r" (sp) : "0" (THREAD_SIZE - 1));
24456
24457- return sp < (sizeof(struct thread_info) + STACK_WARN);
24458+ return sp < STACK_WARN;
24459 }
24460
24461 static void print_stack_overflow(void)
24462@@ -59,8 +59,8 @@ static inline void print_stack_overflow(void) { }
24463 * per-CPU IRQ handling contexts (thread information and stack)
24464 */
24465 union irq_ctx {
24466- struct thread_info tinfo;
24467- u32 stack[THREAD_SIZE/sizeof(u32)];
24468+ unsigned long previous_esp;
24469+ u32 stack[THREAD_SIZE/sizeof(u32)];
24470 } __attribute__((aligned(THREAD_SIZE)));
24471
24472 static DEFINE_PER_CPU(union irq_ctx *, hardirq_ctx);
24473@@ -80,10 +80,9 @@ static void call_on_stack(void *func, void *stack)
24474 static inline int
24475 execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
24476 {
24477- union irq_ctx *curctx, *irqctx;
24478+ union irq_ctx *irqctx;
24479 u32 *isp, arg1, arg2;
24480
24481- curctx = (union irq_ctx *) current_thread_info();
24482 irqctx = __this_cpu_read(hardirq_ctx);
24483
24484 /*
24485@@ -92,16 +91,16 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
24486 * handler) we can't do that and just have to keep using the
24487 * current stack (which is the irq stack already after all)
24488 */
24489- if (unlikely(curctx == irqctx))
24490+ if (unlikely((void *)current_stack_pointer - (void *)irqctx < THREAD_SIZE))
24491 return 0;
24492
24493 /* build the stack frame on the IRQ stack */
24494- isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
24495- irqctx->tinfo.task = curctx->tinfo.task;
24496- irqctx->tinfo.previous_esp = current_stack_pointer;
24497+ isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
24498+ irqctx->previous_esp = current_stack_pointer;
24499
24500- /* Copy the preempt_count so that the [soft]irq checks work. */
24501- irqctx->tinfo.preempt_count = curctx->tinfo.preempt_count;
24502+#ifdef CONFIG_PAX_MEMORY_UDEREF
24503+ __set_fs(MAKE_MM_SEG(0));
24504+#endif
24505
24506 if (unlikely(overflow))
24507 call_on_stack(print_stack_overflow, isp);
24508@@ -113,6 +112,11 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
24509 : "0" (irq), "1" (desc), "2" (isp),
24510 "D" (desc->handle_irq)
24511 : "memory", "cc", "ecx");
24512+
24513+#ifdef CONFIG_PAX_MEMORY_UDEREF
24514+ __set_fs(current_thread_info()->addr_limit);
24515+#endif
24516+
24517 return 1;
24518 }
24519
24520@@ -121,29 +125,11 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
24521 */
24522 void irq_ctx_init(int cpu)
24523 {
24524- union irq_ctx *irqctx;
24525-
24526 if (per_cpu(hardirq_ctx, cpu))
24527 return;
24528
24529- irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
24530- THREADINFO_GFP,
24531- THREAD_SIZE_ORDER));
24532- memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
24533- irqctx->tinfo.cpu = cpu;
24534- irqctx->tinfo.preempt_count = HARDIRQ_OFFSET;
24535- irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
24536-
24537- per_cpu(hardirq_ctx, cpu) = irqctx;
24538-
24539- irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
24540- THREADINFO_GFP,
24541- THREAD_SIZE_ORDER));
24542- memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
24543- irqctx->tinfo.cpu = cpu;
24544- irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
24545-
24546- per_cpu(softirq_ctx, cpu) = irqctx;
24547+ per_cpu(hardirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREADINFO_GFP, THREAD_SIZE_ORDER));
24548+ per_cpu(softirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREADINFO_GFP, THREAD_SIZE_ORDER));
24549
24550 printk(KERN_DEBUG "CPU %u irqstacks, hard=%p soft=%p\n",
24551 cpu, per_cpu(hardirq_ctx, cpu), per_cpu(softirq_ctx, cpu));
24552@@ -152,7 +138,6 @@ void irq_ctx_init(int cpu)
24553 asmlinkage void do_softirq(void)
24554 {
24555 unsigned long flags;
24556- struct thread_info *curctx;
24557 union irq_ctx *irqctx;
24558 u32 *isp;
24559
24560@@ -162,15 +147,22 @@ asmlinkage void do_softirq(void)
24561 local_irq_save(flags);
24562
24563 if (local_softirq_pending()) {
24564- curctx = current_thread_info();
24565 irqctx = __this_cpu_read(softirq_ctx);
24566- irqctx->tinfo.task = curctx->task;
24567- irqctx->tinfo.previous_esp = current_stack_pointer;
24568+ irqctx->previous_esp = current_stack_pointer;
24569
24570 /* build the stack frame on the softirq stack */
24571- isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
24572+ isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
24573+
24574+#ifdef CONFIG_PAX_MEMORY_UDEREF
24575+ __set_fs(MAKE_MM_SEG(0));
24576+#endif
24577
24578 call_on_stack(__do_softirq, isp);
24579+
24580+#ifdef CONFIG_PAX_MEMORY_UDEREF
24581+ __set_fs(current_thread_info()->addr_limit);
24582+#endif
24583+
24584 /*
24585 * Shouldn't happen, we returned above if in_interrupt():
24586 */
24587@@ -191,7 +183,7 @@ bool handle_irq(unsigned irq, struct pt_regs *regs)
24588 if (unlikely(!desc))
24589 return false;
24590
24591- if (user_mode_vm(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
24592+ if (user_mode(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
24593 if (unlikely(overflow))
24594 print_stack_overflow();
24595 desc->handle_irq(irq, desc);
24596diff --git a/arch/x86/kernel/irq_64.c b/arch/x86/kernel/irq_64.c
24597index d04d3ec..ea4b374 100644
24598--- a/arch/x86/kernel/irq_64.c
24599+++ b/arch/x86/kernel/irq_64.c
24600@@ -44,7 +44,7 @@ static inline void stack_overflow_check(struct pt_regs *regs)
24601 u64 estack_top, estack_bottom;
24602 u64 curbase = (u64)task_stack_page(current);
24603
24604- if (user_mode_vm(regs))
24605+ if (user_mode(regs))
24606 return;
24607
24608 if (regs->sp >= curbase + sizeof(struct thread_info) +
24609diff --git a/arch/x86/kernel/jump_label.c b/arch/x86/kernel/jump_label.c
24610index ee11b7d..4df4d0c 100644
24611--- a/arch/x86/kernel/jump_label.c
24612+++ b/arch/x86/kernel/jump_label.c
24613@@ -49,7 +49,7 @@ static void __jump_label_transform(struct jump_entry *entry,
24614 * We are enabling this jump label. If it is not a nop
24615 * then something must have gone wrong.
24616 */
24617- if (unlikely(memcmp((void *)entry->code, ideal_nop, 5) != 0))
24618+ if (unlikely(memcmp((void *)ktla_ktva(entry->code), ideal_nop, 5) != 0))
24619 bug_at((void *)entry->code, __LINE__);
24620
24621 code.jump = 0xe9;
24622@@ -64,13 +64,13 @@ static void __jump_label_transform(struct jump_entry *entry,
24623 */
24624 if (init) {
24625 const unsigned char default_nop[] = { STATIC_KEY_INIT_NOP };
24626- if (unlikely(memcmp((void *)entry->code, default_nop, 5) != 0))
24627+ if (unlikely(memcmp((void *)ktla_ktva(entry->code), default_nop, 5) != 0))
24628 bug_at((void *)entry->code, __LINE__);
24629 } else {
24630 code.jump = 0xe9;
24631 code.offset = entry->target -
24632 (entry->code + JUMP_LABEL_NOP_SIZE);
24633- if (unlikely(memcmp((void *)entry->code, &code, 5) != 0))
24634+ if (unlikely(memcmp((void *)ktla_ktva(entry->code), &code, 5) != 0))
24635 bug_at((void *)entry->code, __LINE__);
24636 }
24637 memcpy(&code, ideal_nops[NOP_ATOMIC5], JUMP_LABEL_NOP_SIZE);
24638diff --git a/arch/x86/kernel/kgdb.c b/arch/x86/kernel/kgdb.c
24639index 836f832..a8bda67 100644
24640--- a/arch/x86/kernel/kgdb.c
24641+++ b/arch/x86/kernel/kgdb.c
24642@@ -127,11 +127,11 @@ char *dbg_get_reg(int regno, void *mem, struct pt_regs *regs)
24643 #ifdef CONFIG_X86_32
24644 switch (regno) {
24645 case GDB_SS:
24646- if (!user_mode_vm(regs))
24647+ if (!user_mode(regs))
24648 *(unsigned long *)mem = __KERNEL_DS;
24649 break;
24650 case GDB_SP:
24651- if (!user_mode_vm(regs))
24652+ if (!user_mode(regs))
24653 *(unsigned long *)mem = kernel_stack_pointer(regs);
24654 break;
24655 case GDB_GS:
24656@@ -229,7 +229,10 @@ static void kgdb_correct_hw_break(void)
24657 bp->attr.bp_addr = breakinfo[breakno].addr;
24658 bp->attr.bp_len = breakinfo[breakno].len;
24659 bp->attr.bp_type = breakinfo[breakno].type;
24660- info->address = breakinfo[breakno].addr;
24661+ if (breakinfo[breakno].type == X86_BREAKPOINT_EXECUTE)
24662+ info->address = ktla_ktva(breakinfo[breakno].addr);
24663+ else
24664+ info->address = breakinfo[breakno].addr;
24665 info->len = breakinfo[breakno].len;
24666 info->type = breakinfo[breakno].type;
24667 val = arch_install_hw_breakpoint(bp);
24668@@ -476,12 +479,12 @@ int kgdb_arch_handle_exception(int e_vector, int signo, int err_code,
24669 case 'k':
24670 /* clear the trace bit */
24671 linux_regs->flags &= ~X86_EFLAGS_TF;
24672- atomic_set(&kgdb_cpu_doing_single_step, -1);
24673+ atomic_set_unchecked(&kgdb_cpu_doing_single_step, -1);
24674
24675 /* set the trace bit if we're stepping */
24676 if (remcomInBuffer[0] == 's') {
24677 linux_regs->flags |= X86_EFLAGS_TF;
24678- atomic_set(&kgdb_cpu_doing_single_step,
24679+ atomic_set_unchecked(&kgdb_cpu_doing_single_step,
24680 raw_smp_processor_id());
24681 }
24682
24683@@ -546,7 +549,7 @@ static int __kgdb_notify(struct die_args *args, unsigned long cmd)
24684
24685 switch (cmd) {
24686 case DIE_DEBUG:
24687- if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
24688+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
24689 if (user_mode(regs))
24690 return single_step_cont(regs, args);
24691 break;
24692@@ -751,11 +754,11 @@ int kgdb_arch_set_breakpoint(struct kgdb_bkpt *bpt)
24693 #endif /* CONFIG_DEBUG_RODATA */
24694
24695 bpt->type = BP_BREAKPOINT;
24696- err = probe_kernel_read(bpt->saved_instr, (char *)bpt->bpt_addr,
24697+ err = probe_kernel_read(bpt->saved_instr, ktla_ktva((char *)bpt->bpt_addr),
24698 BREAK_INSTR_SIZE);
24699 if (err)
24700 return err;
24701- err = probe_kernel_write((char *)bpt->bpt_addr,
24702+ err = probe_kernel_write(ktla_ktva((char *)bpt->bpt_addr),
24703 arch_kgdb_ops.gdb_bpt_instr, BREAK_INSTR_SIZE);
24704 #ifdef CONFIG_DEBUG_RODATA
24705 if (!err)
24706@@ -768,7 +771,7 @@ int kgdb_arch_set_breakpoint(struct kgdb_bkpt *bpt)
24707 return -EBUSY;
24708 text_poke((void *)bpt->bpt_addr, arch_kgdb_ops.gdb_bpt_instr,
24709 BREAK_INSTR_SIZE);
24710- err = probe_kernel_read(opc, (char *)bpt->bpt_addr, BREAK_INSTR_SIZE);
24711+ err = probe_kernel_read(opc, ktla_ktva((char *)bpt->bpt_addr), BREAK_INSTR_SIZE);
24712 if (err)
24713 return err;
24714 if (memcmp(opc, arch_kgdb_ops.gdb_bpt_instr, BREAK_INSTR_SIZE))
24715@@ -793,13 +796,13 @@ int kgdb_arch_remove_breakpoint(struct kgdb_bkpt *bpt)
24716 if (mutex_is_locked(&text_mutex))
24717 goto knl_write;
24718 text_poke((void *)bpt->bpt_addr, bpt->saved_instr, BREAK_INSTR_SIZE);
24719- err = probe_kernel_read(opc, (char *)bpt->bpt_addr, BREAK_INSTR_SIZE);
24720+ err = probe_kernel_read(opc, ktla_ktva((char *)bpt->bpt_addr), BREAK_INSTR_SIZE);
24721 if (err || memcmp(opc, bpt->saved_instr, BREAK_INSTR_SIZE))
24722 goto knl_write;
24723 return err;
24724 knl_write:
24725 #endif /* CONFIG_DEBUG_RODATA */
24726- return probe_kernel_write((char *)bpt->bpt_addr,
24727+ return probe_kernel_write(ktla_ktva((char *)bpt->bpt_addr),
24728 (char *)bpt->saved_instr, BREAK_INSTR_SIZE);
24729 }
24730
24731diff --git a/arch/x86/kernel/kprobes/core.c b/arch/x86/kernel/kprobes/core.c
24732index 79a3f96..6ba030a 100644
24733--- a/arch/x86/kernel/kprobes/core.c
24734+++ b/arch/x86/kernel/kprobes/core.c
24735@@ -119,9 +119,12 @@ static void __kprobes __synthesize_relative_insn(void *from, void *to, u8 op)
24736 s32 raddr;
24737 } __packed *insn;
24738
24739- insn = (struct __arch_relative_insn *)from;
24740+ insn = (struct __arch_relative_insn *)ktla_ktva(from);
24741+
24742+ pax_open_kernel();
24743 insn->raddr = (s32)((long)(to) - ((long)(from) + 5));
24744 insn->op = op;
24745+ pax_close_kernel();
24746 }
24747
24748 /* Insert a jump instruction at address 'from', which jumps to address 'to'.*/
24749@@ -164,7 +167,7 @@ int __kprobes can_boost(kprobe_opcode_t *opcodes)
24750 kprobe_opcode_t opcode;
24751 kprobe_opcode_t *orig_opcodes = opcodes;
24752
24753- if (search_exception_tables((unsigned long)opcodes))
24754+ if (search_exception_tables(ktva_ktla((unsigned long)opcodes)))
24755 return 0; /* Page fault may occur on this address. */
24756
24757 retry:
24758@@ -238,9 +241,9 @@ __recover_probed_insn(kprobe_opcode_t *buf, unsigned long addr)
24759 * for the first byte, we can recover the original instruction
24760 * from it and kp->opcode.
24761 */
24762- memcpy(buf, kp->addr, MAX_INSN_SIZE * sizeof(kprobe_opcode_t));
24763+ memcpy(buf, ktla_ktva(kp->addr), MAX_INSN_SIZE * sizeof(kprobe_opcode_t));
24764 buf[0] = kp->opcode;
24765- return (unsigned long)buf;
24766+ return ktva_ktla((unsigned long)buf);
24767 }
24768
24769 /*
24770@@ -332,7 +335,9 @@ int __kprobes __copy_instruction(u8 *dest, u8 *src)
24771 /* Another subsystem puts a breakpoint, failed to recover */
24772 if (insn.opcode.bytes[0] == BREAKPOINT_INSTRUCTION)
24773 return 0;
24774+ pax_open_kernel();
24775 memcpy(dest, insn.kaddr, insn.length);
24776+ pax_close_kernel();
24777
24778 #ifdef CONFIG_X86_64
24779 if (insn_rip_relative(&insn)) {
24780@@ -359,7 +364,9 @@ int __kprobes __copy_instruction(u8 *dest, u8 *src)
24781 return 0;
24782 }
24783 disp = (u8 *) dest + insn_offset_displacement(&insn);
24784+ pax_open_kernel();
24785 *(s32 *) disp = (s32) newdisp;
24786+ pax_close_kernel();
24787 }
24788 #endif
24789 return insn.length;
24790@@ -498,7 +505,7 @@ setup_singlestep(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *k
24791 * nor set current_kprobe, because it doesn't use single
24792 * stepping.
24793 */
24794- regs->ip = (unsigned long)p->ainsn.insn;
24795+ regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
24796 preempt_enable_no_resched();
24797 return;
24798 }
24799@@ -515,9 +522,9 @@ setup_singlestep(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *k
24800 regs->flags &= ~X86_EFLAGS_IF;
24801 /* single step inline if the instruction is an int3 */
24802 if (p->opcode == BREAKPOINT_INSTRUCTION)
24803- regs->ip = (unsigned long)p->addr;
24804+ regs->ip = ktla_ktva((unsigned long)p->addr);
24805 else
24806- regs->ip = (unsigned long)p->ainsn.insn;
24807+ regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
24808 }
24809
24810 /*
24811@@ -596,7 +603,7 @@ static int __kprobes kprobe_handler(struct pt_regs *regs)
24812 setup_singlestep(p, regs, kcb, 0);
24813 return 1;
24814 }
24815- } else if (*addr != BREAKPOINT_INSTRUCTION) {
24816+ } else if (*(kprobe_opcode_t *)ktla_ktva((unsigned long)addr) != BREAKPOINT_INSTRUCTION) {
24817 /*
24818 * The breakpoint instruction was removed right
24819 * after we hit it. Another cpu has removed
24820@@ -642,6 +649,9 @@ static void __used __kprobes kretprobe_trampoline_holder(void)
24821 " movq %rax, 152(%rsp)\n"
24822 RESTORE_REGS_STRING
24823 " popfq\n"
24824+#ifdef KERNEXEC_PLUGIN
24825+ " btsq $63,(%rsp)\n"
24826+#endif
24827 #else
24828 " pushf\n"
24829 SAVE_REGS_STRING
24830@@ -779,7 +789,7 @@ static void __kprobes
24831 resume_execution(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *kcb)
24832 {
24833 unsigned long *tos = stack_addr(regs);
24834- unsigned long copy_ip = (unsigned long)p->ainsn.insn;
24835+ unsigned long copy_ip = ktva_ktla((unsigned long)p->ainsn.insn);
24836 unsigned long orig_ip = (unsigned long)p->addr;
24837 kprobe_opcode_t *insn = p->ainsn.insn;
24838
24839@@ -961,7 +971,7 @@ kprobe_exceptions_notify(struct notifier_block *self, unsigned long val, void *d
24840 struct die_args *args = data;
24841 int ret = NOTIFY_DONE;
24842
24843- if (args->regs && user_mode_vm(args->regs))
24844+ if (args->regs && user_mode(args->regs))
24845 return ret;
24846
24847 switch (val) {
24848diff --git a/arch/x86/kernel/kprobes/opt.c b/arch/x86/kernel/kprobes/opt.c
24849index 898160b..758cde8 100644
24850--- a/arch/x86/kernel/kprobes/opt.c
24851+++ b/arch/x86/kernel/kprobes/opt.c
24852@@ -79,6 +79,7 @@ found:
24853 /* Insert a move instruction which sets a pointer to eax/rdi (1st arg). */
24854 static void __kprobes synthesize_set_arg1(kprobe_opcode_t *addr, unsigned long val)
24855 {
24856+ pax_open_kernel();
24857 #ifdef CONFIG_X86_64
24858 *addr++ = 0x48;
24859 *addr++ = 0xbf;
24860@@ -86,6 +87,7 @@ static void __kprobes synthesize_set_arg1(kprobe_opcode_t *addr, unsigned long v
24861 *addr++ = 0xb8;
24862 #endif
24863 *(unsigned long *)addr = val;
24864+ pax_close_kernel();
24865 }
24866
24867 asm (
24868@@ -335,7 +337,7 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
24869 * Verify if the address gap is in 2GB range, because this uses
24870 * a relative jump.
24871 */
24872- rel = (long)op->optinsn.insn - (long)op->kp.addr + RELATIVEJUMP_SIZE;
24873+ rel = (long)op->optinsn.insn - ktla_ktva((long)op->kp.addr) + RELATIVEJUMP_SIZE;
24874 if (abs(rel) > 0x7fffffff)
24875 return -ERANGE;
24876
24877@@ -350,16 +352,18 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
24878 op->optinsn.size = ret;
24879
24880 /* Copy arch-dep-instance from template */
24881- memcpy(buf, &optprobe_template_entry, TMPL_END_IDX);
24882+ pax_open_kernel();
24883+ memcpy(buf, ktla_ktva(&optprobe_template_entry), TMPL_END_IDX);
24884+ pax_close_kernel();
24885
24886 /* Set probe information */
24887 synthesize_set_arg1(buf + TMPL_MOVE_IDX, (unsigned long)op);
24888
24889 /* Set probe function call */
24890- synthesize_relcall(buf + TMPL_CALL_IDX, optimized_callback);
24891+ synthesize_relcall(ktva_ktla(buf) + TMPL_CALL_IDX, optimized_callback);
24892
24893 /* Set returning jmp instruction at the tail of out-of-line buffer */
24894- synthesize_reljump(buf + TMPL_END_IDX + op->optinsn.size,
24895+ synthesize_reljump(ktva_ktla(buf) + TMPL_END_IDX + op->optinsn.size,
24896 (u8 *)op->kp.addr + op->optinsn.size);
24897
24898 flush_icache_range((unsigned long) buf,
24899@@ -384,7 +388,7 @@ void __kprobes arch_optimize_kprobes(struct list_head *oplist)
24900 WARN_ON(kprobe_disabled(&op->kp));
24901
24902 /* Backup instructions which will be replaced by jump address */
24903- memcpy(op->optinsn.copied_insn, op->kp.addr + INT3_SIZE,
24904+ memcpy(op->optinsn.copied_insn, ktla_ktva(op->kp.addr) + INT3_SIZE,
24905 RELATIVE_ADDR_SIZE);
24906
24907 insn_buf[0] = RELATIVEJUMP_OPCODE;
24908@@ -433,7 +437,7 @@ setup_detour_execution(struct kprobe *p, struct pt_regs *regs, int reenter)
24909 /* This kprobe is really able to run optimized path. */
24910 op = container_of(p, struct optimized_kprobe, kp);
24911 /* Detour through copied instructions */
24912- regs->ip = (unsigned long)op->optinsn.insn + TMPL_END_IDX;
24913+ regs->ip = ktva_ktla((unsigned long)op->optinsn.insn) + TMPL_END_IDX;
24914 if (!reenter)
24915 reset_current_kprobe();
24916 preempt_enable_no_resched();
24917diff --git a/arch/x86/kernel/ldt.c b/arch/x86/kernel/ldt.c
24918index ebc9873..1b9724b 100644
24919--- a/arch/x86/kernel/ldt.c
24920+++ b/arch/x86/kernel/ldt.c
24921@@ -66,13 +66,13 @@ static int alloc_ldt(mm_context_t *pc, int mincount, int reload)
24922 if (reload) {
24923 #ifdef CONFIG_SMP
24924 preempt_disable();
24925- load_LDT(pc);
24926+ load_LDT_nolock(pc);
24927 if (!cpumask_equal(mm_cpumask(current->mm),
24928 cpumask_of(smp_processor_id())))
24929 smp_call_function(flush_ldt, current->mm, 1);
24930 preempt_enable();
24931 #else
24932- load_LDT(pc);
24933+ load_LDT_nolock(pc);
24934 #endif
24935 }
24936 if (oldsize) {
24937@@ -94,7 +94,7 @@ static inline int copy_ldt(mm_context_t *new, mm_context_t *old)
24938 return err;
24939
24940 for (i = 0; i < old->size; i++)
24941- write_ldt_entry(new->ldt, i, old->ldt + i * LDT_ENTRY_SIZE);
24942+ write_ldt_entry(new->ldt, i, old->ldt + i);
24943 return 0;
24944 }
24945
24946@@ -115,6 +115,24 @@ int init_new_context(struct task_struct *tsk, struct mm_struct *mm)
24947 retval = copy_ldt(&mm->context, &old_mm->context);
24948 mutex_unlock(&old_mm->context.lock);
24949 }
24950+
24951+ if (tsk == current) {
24952+ mm->context.vdso = 0;
24953+
24954+#ifdef CONFIG_X86_32
24955+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
24956+ mm->context.user_cs_base = 0UL;
24957+ mm->context.user_cs_limit = ~0UL;
24958+
24959+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
24960+ cpus_clear(mm->context.cpu_user_cs_mask);
24961+#endif
24962+
24963+#endif
24964+#endif
24965+
24966+ }
24967+
24968 return retval;
24969 }
24970
24971@@ -229,6 +247,13 @@ static int write_ldt(void __user *ptr, unsigned long bytecount, int oldmode)
24972 }
24973 }
24974
24975+#ifdef CONFIG_PAX_SEGMEXEC
24976+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (ldt_info.contents & MODIFY_LDT_CONTENTS_CODE)) {
24977+ error = -EINVAL;
24978+ goto out_unlock;
24979+ }
24980+#endif
24981+
24982 fill_ldt(&ldt, &ldt_info);
24983 if (oldmode)
24984 ldt.avl = 0;
24985diff --git a/arch/x86/kernel/machine_kexec_32.c b/arch/x86/kernel/machine_kexec_32.c
24986index 5b19e4d..6476a76 100644
24987--- a/arch/x86/kernel/machine_kexec_32.c
24988+++ b/arch/x86/kernel/machine_kexec_32.c
24989@@ -26,7 +26,7 @@
24990 #include <asm/cacheflush.h>
24991 #include <asm/debugreg.h>
24992
24993-static void set_idt(void *newidt, __u16 limit)
24994+static void set_idt(struct desc_struct *newidt, __u16 limit)
24995 {
24996 struct desc_ptr curidt;
24997
24998@@ -38,7 +38,7 @@ static void set_idt(void *newidt, __u16 limit)
24999 }
25000
25001
25002-static void set_gdt(void *newgdt, __u16 limit)
25003+static void set_gdt(struct desc_struct *newgdt, __u16 limit)
25004 {
25005 struct desc_ptr curgdt;
25006
25007@@ -216,7 +216,7 @@ void machine_kexec(struct kimage *image)
25008 }
25009
25010 control_page = page_address(image->control_code_page);
25011- memcpy(control_page, relocate_kernel, KEXEC_CONTROL_CODE_MAX_SIZE);
25012+ memcpy(control_page, (void *)ktla_ktva((unsigned long)relocate_kernel), KEXEC_CONTROL_CODE_MAX_SIZE);
25013
25014 relocate_kernel_ptr = control_page;
25015 page_list[PA_CONTROL_PAGE] = __pa(control_page);
25016diff --git a/arch/x86/kernel/microcode_core.c b/arch/x86/kernel/microcode_core.c
25017index 15c9876..0a43909 100644
25018--- a/arch/x86/kernel/microcode_core.c
25019+++ b/arch/x86/kernel/microcode_core.c
25020@@ -513,7 +513,7 @@ mc_cpu_callback(struct notifier_block *nb, unsigned long action, void *hcpu)
25021 return NOTIFY_OK;
25022 }
25023
25024-static struct notifier_block __refdata mc_cpu_notifier = {
25025+static struct notifier_block mc_cpu_notifier = {
25026 .notifier_call = mc_cpu_callback,
25027 };
25028
25029diff --git a/arch/x86/kernel/microcode_intel.c b/arch/x86/kernel/microcode_intel.c
25030index 5fb2ceb..3ae90bb 100644
25031--- a/arch/x86/kernel/microcode_intel.c
25032+++ b/arch/x86/kernel/microcode_intel.c
25033@@ -293,13 +293,13 @@ static enum ucode_state request_microcode_fw(int cpu, struct device *device,
25034
25035 static int get_ucode_user(void *to, const void *from, size_t n)
25036 {
25037- return copy_from_user(to, from, n);
25038+ return copy_from_user(to, (const void __force_user *)from, n);
25039 }
25040
25041 static enum ucode_state
25042 request_microcode_user(int cpu, const void __user *buf, size_t size)
25043 {
25044- return generic_load_microcode(cpu, (void *)buf, size, &get_ucode_user);
25045+ return generic_load_microcode(cpu, (__force_kernel void *)buf, size, &get_ucode_user);
25046 }
25047
25048 static void microcode_fini_cpu(int cpu)
25049diff --git a/arch/x86/kernel/module.c b/arch/x86/kernel/module.c
25050index 216a4d7..228255a 100644
25051--- a/arch/x86/kernel/module.c
25052+++ b/arch/x86/kernel/module.c
25053@@ -43,15 +43,60 @@ do { \
25054 } while (0)
25055 #endif
25056
25057-void *module_alloc(unsigned long size)
25058+static inline void *__module_alloc(unsigned long size, pgprot_t prot)
25059 {
25060- if (PAGE_ALIGN(size) > MODULES_LEN)
25061+ if (!size || PAGE_ALIGN(size) > MODULES_LEN)
25062 return NULL;
25063 return __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END,
25064- GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
25065+ GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, prot,
25066 -1, __builtin_return_address(0));
25067 }
25068
25069+void *module_alloc(unsigned long size)
25070+{
25071+
25072+#ifdef CONFIG_PAX_KERNEXEC
25073+ return __module_alloc(size, PAGE_KERNEL);
25074+#else
25075+ return __module_alloc(size, PAGE_KERNEL_EXEC);
25076+#endif
25077+
25078+}
25079+
25080+#ifdef CONFIG_PAX_KERNEXEC
25081+#ifdef CONFIG_X86_32
25082+void *module_alloc_exec(unsigned long size)
25083+{
25084+ struct vm_struct *area;
25085+
25086+ if (size == 0)
25087+ return NULL;
25088+
25089+ area = __get_vm_area(size, VM_ALLOC, (unsigned long)&MODULES_EXEC_VADDR, (unsigned long)&MODULES_EXEC_END);
25090+ return area ? area->addr : NULL;
25091+}
25092+EXPORT_SYMBOL(module_alloc_exec);
25093+
25094+void module_free_exec(struct module *mod, void *module_region)
25095+{
25096+ vunmap(module_region);
25097+}
25098+EXPORT_SYMBOL(module_free_exec);
25099+#else
25100+void module_free_exec(struct module *mod, void *module_region)
25101+{
25102+ module_free(mod, module_region);
25103+}
25104+EXPORT_SYMBOL(module_free_exec);
25105+
25106+void *module_alloc_exec(unsigned long size)
25107+{
25108+ return __module_alloc(size, PAGE_KERNEL_RX);
25109+}
25110+EXPORT_SYMBOL(module_alloc_exec);
25111+#endif
25112+#endif
25113+
25114 #ifdef CONFIG_X86_32
25115 int apply_relocate(Elf32_Shdr *sechdrs,
25116 const char *strtab,
25117@@ -62,14 +107,16 @@ int apply_relocate(Elf32_Shdr *sechdrs,
25118 unsigned int i;
25119 Elf32_Rel *rel = (void *)sechdrs[relsec].sh_addr;
25120 Elf32_Sym *sym;
25121- uint32_t *location;
25122+ uint32_t *plocation, location;
25123
25124 DEBUGP("Applying relocate section %u to %u\n",
25125 relsec, sechdrs[relsec].sh_info);
25126 for (i = 0; i < sechdrs[relsec].sh_size / sizeof(*rel); i++) {
25127 /* This is where to make the change */
25128- location = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr
25129- + rel[i].r_offset;
25130+ plocation = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr + rel[i].r_offset;
25131+ location = (uint32_t)plocation;
25132+ if (sechdrs[sechdrs[relsec].sh_info].sh_flags & SHF_EXECINSTR)
25133+ plocation = ktla_ktva((void *)plocation);
25134 /* This is the symbol it is referring to. Note that all
25135 undefined symbols have been resolved. */
25136 sym = (Elf32_Sym *)sechdrs[symindex].sh_addr
25137@@ -78,11 +125,15 @@ int apply_relocate(Elf32_Shdr *sechdrs,
25138 switch (ELF32_R_TYPE(rel[i].r_info)) {
25139 case R_386_32:
25140 /* We add the value into the location given */
25141- *location += sym->st_value;
25142+ pax_open_kernel();
25143+ *plocation += sym->st_value;
25144+ pax_close_kernel();
25145 break;
25146 case R_386_PC32:
25147 /* Add the value, subtract its position */
25148- *location += sym->st_value - (uint32_t)location;
25149+ pax_open_kernel();
25150+ *plocation += sym->st_value - location;
25151+ pax_close_kernel();
25152 break;
25153 default:
25154 pr_err("%s: Unknown relocation: %u\n",
25155@@ -127,21 +178,30 @@ int apply_relocate_add(Elf64_Shdr *sechdrs,
25156 case R_X86_64_NONE:
25157 break;
25158 case R_X86_64_64:
25159+ pax_open_kernel();
25160 *(u64 *)loc = val;
25161+ pax_close_kernel();
25162 break;
25163 case R_X86_64_32:
25164+ pax_open_kernel();
25165 *(u32 *)loc = val;
25166+ pax_close_kernel();
25167 if (val != *(u32 *)loc)
25168 goto overflow;
25169 break;
25170 case R_X86_64_32S:
25171+ pax_open_kernel();
25172 *(s32 *)loc = val;
25173+ pax_close_kernel();
25174 if ((s64)val != *(s32 *)loc)
25175 goto overflow;
25176 break;
25177 case R_X86_64_PC32:
25178 val -= (u64)loc;
25179+ pax_open_kernel();
25180 *(u32 *)loc = val;
25181+ pax_close_kernel();
25182+
25183 #if 0
25184 if ((s64)val != *(s32 *)loc)
25185 goto overflow;
25186diff --git a/arch/x86/kernel/msr.c b/arch/x86/kernel/msr.c
25187index 88458fa..349f7a4 100644
25188--- a/arch/x86/kernel/msr.c
25189+++ b/arch/x86/kernel/msr.c
25190@@ -233,7 +233,7 @@ static int msr_class_cpu_callback(struct notifier_block *nfb,
25191 return notifier_from_errno(err);
25192 }
25193
25194-static struct notifier_block __refdata msr_class_cpu_notifier = {
25195+static struct notifier_block msr_class_cpu_notifier = {
25196 .notifier_call = msr_class_cpu_callback,
25197 };
25198
25199diff --git a/arch/x86/kernel/nmi.c b/arch/x86/kernel/nmi.c
25200index 6fcb49c..5b3f4ff 100644
25201--- a/arch/x86/kernel/nmi.c
25202+++ b/arch/x86/kernel/nmi.c
25203@@ -138,7 +138,7 @@ static int __kprobes nmi_handle(unsigned int type, struct pt_regs *regs, bool b2
25204 return handled;
25205 }
25206
25207-int __register_nmi_handler(unsigned int type, struct nmiaction *action)
25208+int __register_nmi_handler(unsigned int type, const struct nmiaction *action)
25209 {
25210 struct nmi_desc *desc = nmi_to_desc(type);
25211 unsigned long flags;
25212@@ -162,9 +162,9 @@ int __register_nmi_handler(unsigned int type, struct nmiaction *action)
25213 * event confuses some handlers (kdump uses this flag)
25214 */
25215 if (action->flags & NMI_FLAG_FIRST)
25216- list_add_rcu(&action->list, &desc->head);
25217+ pax_list_add_rcu((struct list_head *)&action->list, &desc->head);
25218 else
25219- list_add_tail_rcu(&action->list, &desc->head);
25220+ pax_list_add_tail_rcu((struct list_head *)&action->list, &desc->head);
25221
25222 spin_unlock_irqrestore(&desc->lock, flags);
25223 return 0;
25224@@ -187,7 +187,7 @@ void unregister_nmi_handler(unsigned int type, const char *name)
25225 if (!strcmp(n->name, name)) {
25226 WARN(in_nmi(),
25227 "Trying to free NMI (%s) from NMI context!\n", n->name);
25228- list_del_rcu(&n->list);
25229+ pax_list_del_rcu((struct list_head *)&n->list);
25230 break;
25231 }
25232 }
25233@@ -512,6 +512,17 @@ static inline void nmi_nesting_postprocess(void)
25234 dotraplinkage notrace __kprobes void
25235 do_nmi(struct pt_regs *regs, long error_code)
25236 {
25237+
25238+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
25239+ if (!user_mode(regs)) {
25240+ unsigned long cs = regs->cs & 0xFFFF;
25241+ unsigned long ip = ktva_ktla(regs->ip);
25242+
25243+ if ((cs == __KERNEL_CS || cs == __KERNEXEC_KERNEL_CS) && ip <= (unsigned long)_etext)
25244+ regs->ip = ip;
25245+ }
25246+#endif
25247+
25248 nmi_nesting_preprocess(regs);
25249
25250 nmi_enter();
25251diff --git a/arch/x86/kernel/nmi_selftest.c b/arch/x86/kernel/nmi_selftest.c
25252index 6d9582e..f746287 100644
25253--- a/arch/x86/kernel/nmi_selftest.c
25254+++ b/arch/x86/kernel/nmi_selftest.c
25255@@ -43,7 +43,7 @@ static void __init init_nmi_testsuite(void)
25256 {
25257 /* trap all the unknown NMIs we may generate */
25258 register_nmi_handler(NMI_UNKNOWN, nmi_unk_cb, 0, "nmi_selftest_unk",
25259- __initdata);
25260+ __initconst);
25261 }
25262
25263 static void __init cleanup_nmi_testsuite(void)
25264@@ -66,7 +66,7 @@ static void __init test_nmi_ipi(struct cpumask *mask)
25265 unsigned long timeout;
25266
25267 if (register_nmi_handler(NMI_LOCAL, test_nmi_ipi_callback,
25268- NMI_FLAG_FIRST, "nmi_selftest", __initdata)) {
25269+ NMI_FLAG_FIRST, "nmi_selftest", __initconst)) {
25270 nmi_fail = FAILURE;
25271 return;
25272 }
25273diff --git a/arch/x86/kernel/paravirt-spinlocks.c b/arch/x86/kernel/paravirt-spinlocks.c
25274index bbb6c73..24a58ef 100644
25275--- a/arch/x86/kernel/paravirt-spinlocks.c
25276+++ b/arch/x86/kernel/paravirt-spinlocks.c
25277@@ -8,7 +8,7 @@
25278
25279 #include <asm/paravirt.h>
25280
25281-struct pv_lock_ops pv_lock_ops = {
25282+struct pv_lock_ops pv_lock_ops __read_only = {
25283 #ifdef CONFIG_SMP
25284 .lock_spinning = __PV_IS_CALLEE_SAVE(paravirt_nop),
25285 .unlock_kick = paravirt_nop,
25286diff --git a/arch/x86/kernel/paravirt.c b/arch/x86/kernel/paravirt.c
25287index 1b10af8..0b58cbc 100644
25288--- a/arch/x86/kernel/paravirt.c
25289+++ b/arch/x86/kernel/paravirt.c
25290@@ -55,6 +55,9 @@ u64 _paravirt_ident_64(u64 x)
25291 {
25292 return x;
25293 }
25294+#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
25295+PV_CALLEE_SAVE_REGS_THUNK(_paravirt_ident_64);
25296+#endif
25297
25298 void __init default_banner(void)
25299 {
25300@@ -142,15 +145,19 @@ unsigned paravirt_patch_default(u8 type, u16 clobbers, void *insnbuf,
25301 if (opfunc == NULL)
25302 /* If there's no function, patch it with a ud2a (BUG) */
25303 ret = paravirt_patch_insns(insnbuf, len, ud2a, ud2a+sizeof(ud2a));
25304- else if (opfunc == _paravirt_nop)
25305+ else if (opfunc == (void *)_paravirt_nop)
25306 /* If the operation is a nop, then nop the callsite */
25307 ret = paravirt_patch_nop();
25308
25309 /* identity functions just return their single argument */
25310- else if (opfunc == _paravirt_ident_32)
25311+ else if (opfunc == (void *)_paravirt_ident_32)
25312 ret = paravirt_patch_ident_32(insnbuf, len);
25313- else if (opfunc == _paravirt_ident_64)
25314+ else if (opfunc == (void *)_paravirt_ident_64)
25315 ret = paravirt_patch_ident_64(insnbuf, len);
25316+#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
25317+ else if (opfunc == (void *)__raw_callee_save__paravirt_ident_64)
25318+ ret = paravirt_patch_ident_64(insnbuf, len);
25319+#endif
25320
25321 else if (type == PARAVIRT_PATCH(pv_cpu_ops.iret) ||
25322 type == PARAVIRT_PATCH(pv_cpu_ops.irq_enable_sysexit) ||
25323@@ -175,7 +182,7 @@ unsigned paravirt_patch_insns(void *insnbuf, unsigned len,
25324 if (insn_len > len || start == NULL)
25325 insn_len = len;
25326 else
25327- memcpy(insnbuf, start, insn_len);
25328+ memcpy(insnbuf, ktla_ktva(start), insn_len);
25329
25330 return insn_len;
25331 }
25332@@ -299,7 +306,7 @@ enum paravirt_lazy_mode paravirt_get_lazy_mode(void)
25333 return this_cpu_read(paravirt_lazy_mode);
25334 }
25335
25336-struct pv_info pv_info = {
25337+struct pv_info pv_info __read_only = {
25338 .name = "bare hardware",
25339 .paravirt_enabled = 0,
25340 .kernel_rpl = 0,
25341@@ -310,16 +317,16 @@ struct pv_info pv_info = {
25342 #endif
25343 };
25344
25345-struct pv_init_ops pv_init_ops = {
25346+struct pv_init_ops pv_init_ops __read_only = {
25347 .patch = native_patch,
25348 };
25349
25350-struct pv_time_ops pv_time_ops = {
25351+struct pv_time_ops pv_time_ops __read_only = {
25352 .sched_clock = native_sched_clock,
25353 .steal_clock = native_steal_clock,
25354 };
25355
25356-__visible struct pv_irq_ops pv_irq_ops = {
25357+__visible struct pv_irq_ops pv_irq_ops __read_only = {
25358 .save_fl = __PV_IS_CALLEE_SAVE(native_save_fl),
25359 .restore_fl = __PV_IS_CALLEE_SAVE(native_restore_fl),
25360 .irq_disable = __PV_IS_CALLEE_SAVE(native_irq_disable),
25361@@ -331,7 +338,7 @@ __visible struct pv_irq_ops pv_irq_ops = {
25362 #endif
25363 };
25364
25365-__visible struct pv_cpu_ops pv_cpu_ops = {
25366+__visible struct pv_cpu_ops pv_cpu_ops __read_only = {
25367 .cpuid = native_cpuid,
25368 .get_debugreg = native_get_debugreg,
25369 .set_debugreg = native_set_debugreg,
25370@@ -389,21 +396,26 @@ __visible struct pv_cpu_ops pv_cpu_ops = {
25371 .end_context_switch = paravirt_nop,
25372 };
25373
25374-struct pv_apic_ops pv_apic_ops = {
25375+struct pv_apic_ops pv_apic_ops __read_only= {
25376 #ifdef CONFIG_X86_LOCAL_APIC
25377 .startup_ipi_hook = paravirt_nop,
25378 #endif
25379 };
25380
25381-#if defined(CONFIG_X86_32) && !defined(CONFIG_X86_PAE)
25382+#ifdef CONFIG_X86_32
25383+#ifdef CONFIG_X86_PAE
25384+/* 64-bit pagetable entries */
25385+#define PTE_IDENT PV_CALLEE_SAVE(_paravirt_ident_64)
25386+#else
25387 /* 32-bit pagetable entries */
25388 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_32)
25389+#endif
25390 #else
25391 /* 64-bit pagetable entries */
25392 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_64)
25393 #endif
25394
25395-struct pv_mmu_ops pv_mmu_ops = {
25396+struct pv_mmu_ops pv_mmu_ops __read_only = {
25397
25398 .read_cr2 = native_read_cr2,
25399 .write_cr2 = native_write_cr2,
25400@@ -453,6 +465,7 @@ struct pv_mmu_ops pv_mmu_ops = {
25401 .make_pud = PTE_IDENT,
25402
25403 .set_pgd = native_set_pgd,
25404+ .set_pgd_batched = native_set_pgd_batched,
25405 #endif
25406 #endif /* PAGETABLE_LEVELS >= 3 */
25407
25408@@ -473,6 +486,12 @@ struct pv_mmu_ops pv_mmu_ops = {
25409 },
25410
25411 .set_fixmap = native_set_fixmap,
25412+
25413+#ifdef CONFIG_PAX_KERNEXEC
25414+ .pax_open_kernel = native_pax_open_kernel,
25415+ .pax_close_kernel = native_pax_close_kernel,
25416+#endif
25417+
25418 };
25419
25420 EXPORT_SYMBOL_GPL(pv_time_ops);
25421diff --git a/arch/x86/kernel/pci-calgary_64.c b/arch/x86/kernel/pci-calgary_64.c
25422index 299d493..2ccb0ee 100644
25423--- a/arch/x86/kernel/pci-calgary_64.c
25424+++ b/arch/x86/kernel/pci-calgary_64.c
25425@@ -1339,7 +1339,7 @@ static void __init get_tce_space_from_tar(void)
25426 tce_space = be64_to_cpu(readq(target));
25427 tce_space = tce_space & TAR_SW_BITS;
25428
25429- tce_space = tce_space & (~specified_table_size);
25430+ tce_space = tce_space & (~(unsigned long)specified_table_size);
25431 info->tce_space = (u64 *)__va(tce_space);
25432 }
25433 }
25434diff --git a/arch/x86/kernel/pci-iommu_table.c b/arch/x86/kernel/pci-iommu_table.c
25435index 35ccf75..7a15747 100644
25436--- a/arch/x86/kernel/pci-iommu_table.c
25437+++ b/arch/x86/kernel/pci-iommu_table.c
25438@@ -2,7 +2,7 @@
25439 #include <asm/iommu_table.h>
25440 #include <linux/string.h>
25441 #include <linux/kallsyms.h>
25442-
25443+#include <linux/sched.h>
25444
25445 #define DEBUG 1
25446
25447diff --git a/arch/x86/kernel/pci-swiotlb.c b/arch/x86/kernel/pci-swiotlb.c
25448index 6c483ba..d10ce2f 100644
25449--- a/arch/x86/kernel/pci-swiotlb.c
25450+++ b/arch/x86/kernel/pci-swiotlb.c
25451@@ -32,7 +32,7 @@ static void x86_swiotlb_free_coherent(struct device *dev, size_t size,
25452 void *vaddr, dma_addr_t dma_addr,
25453 struct dma_attrs *attrs)
25454 {
25455- swiotlb_free_coherent(dev, size, vaddr, dma_addr);
25456+ swiotlb_free_coherent(dev, size, vaddr, dma_addr, attrs);
25457 }
25458
25459 static struct dma_map_ops swiotlb_dma_ops = {
25460diff --git a/arch/x86/kernel/process.c b/arch/x86/kernel/process.c
25461index 3fb8d95..254dc51 100644
25462--- a/arch/x86/kernel/process.c
25463+++ b/arch/x86/kernel/process.c
25464@@ -36,7 +36,8 @@
25465 * section. Since TSS's are completely CPU-local, we want them
25466 * on exact cacheline boundaries, to eliminate cacheline ping-pong.
25467 */
25468-__visible DEFINE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss) = INIT_TSS;
25469+struct tss_struct init_tss[NR_CPUS] __visible ____cacheline_internodealigned_in_smp = { [0 ... NR_CPUS-1] = INIT_TSS };
25470+EXPORT_SYMBOL(init_tss);
25471
25472 #ifdef CONFIG_X86_64
25473 static DEFINE_PER_CPU(unsigned char, is_idle);
25474@@ -92,7 +93,7 @@ void arch_task_cache_init(void)
25475 task_xstate_cachep =
25476 kmem_cache_create("task_xstate", xstate_size,
25477 __alignof__(union thread_xstate),
25478- SLAB_PANIC | SLAB_NOTRACK, NULL);
25479+ SLAB_PANIC | SLAB_NOTRACK | SLAB_USERCOPY, NULL);
25480 }
25481
25482 /*
25483@@ -105,7 +106,7 @@ void exit_thread(void)
25484 unsigned long *bp = t->io_bitmap_ptr;
25485
25486 if (bp) {
25487- struct tss_struct *tss = &per_cpu(init_tss, get_cpu());
25488+ struct tss_struct *tss = init_tss + get_cpu();
25489
25490 t->io_bitmap_ptr = NULL;
25491 clear_thread_flag(TIF_IO_BITMAP);
25492@@ -125,6 +126,9 @@ void flush_thread(void)
25493 {
25494 struct task_struct *tsk = current;
25495
25496+#if defined(CONFIG_X86_32) && !defined(CONFIG_CC_STACKPROTECTOR) && !defined(CONFIG_PAX_MEMORY_UDEREF)
25497+ loadsegment(gs, 0);
25498+#endif
25499 flush_ptrace_hw_breakpoint(tsk);
25500 memset(tsk->thread.tls_array, 0, sizeof(tsk->thread.tls_array));
25501 drop_init_fpu(tsk);
25502@@ -271,7 +275,7 @@ static void __exit_idle(void)
25503 void exit_idle(void)
25504 {
25505 /* idle loop has pid 0 */
25506- if (current->pid)
25507+ if (task_pid_nr(current))
25508 return;
25509 __exit_idle();
25510 }
25511@@ -327,7 +331,7 @@ bool xen_set_default_idle(void)
25512 return ret;
25513 }
25514 #endif
25515-void stop_this_cpu(void *dummy)
25516+__noreturn void stop_this_cpu(void *dummy)
25517 {
25518 local_irq_disable();
25519 /*
25520@@ -456,16 +460,37 @@ static int __init idle_setup(char *str)
25521 }
25522 early_param("idle", idle_setup);
25523
25524-unsigned long arch_align_stack(unsigned long sp)
25525+#ifdef CONFIG_PAX_RANDKSTACK
25526+void pax_randomize_kstack(struct pt_regs *regs)
25527 {
25528- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
25529- sp -= get_random_int() % 8192;
25530- return sp & ~0xf;
25531-}
25532+ struct thread_struct *thread = &current->thread;
25533+ unsigned long time;
25534
25535-unsigned long arch_randomize_brk(struct mm_struct *mm)
25536-{
25537- unsigned long range_end = mm->brk + 0x02000000;
25538- return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
25539-}
25540+ if (!randomize_va_space)
25541+ return;
25542+
25543+ if (v8086_mode(regs))
25544+ return;
25545
25546+ rdtscl(time);
25547+
25548+ /* P4 seems to return a 0 LSB, ignore it */
25549+#ifdef CONFIG_MPENTIUM4
25550+ time &= 0x3EUL;
25551+ time <<= 2;
25552+#elif defined(CONFIG_X86_64)
25553+ time &= 0xFUL;
25554+ time <<= 4;
25555+#else
25556+ time &= 0x1FUL;
25557+ time <<= 3;
25558+#endif
25559+
25560+ thread->sp0 ^= time;
25561+ load_sp0(init_tss + smp_processor_id(), thread);
25562+
25563+#ifdef CONFIG_X86_64
25564+ this_cpu_write(kernel_stack, thread->sp0);
25565+#endif
25566+}
25567+#endif
25568diff --git a/arch/x86/kernel/process_32.c b/arch/x86/kernel/process_32.c
25569index 884f98f..ec23e04 100644
25570--- a/arch/x86/kernel/process_32.c
25571+++ b/arch/x86/kernel/process_32.c
25572@@ -65,6 +65,7 @@ asmlinkage void ret_from_kernel_thread(void) __asm__("ret_from_kernel_thread");
25573 unsigned long thread_saved_pc(struct task_struct *tsk)
25574 {
25575 return ((unsigned long *)tsk->thread.sp)[3];
25576+//XXX return tsk->thread.eip;
25577 }
25578
25579 void __show_regs(struct pt_regs *regs, int all)
25580@@ -74,19 +75,18 @@ void __show_regs(struct pt_regs *regs, int all)
25581 unsigned long sp;
25582 unsigned short ss, gs;
25583
25584- if (user_mode_vm(regs)) {
25585+ if (user_mode(regs)) {
25586 sp = regs->sp;
25587 ss = regs->ss & 0xffff;
25588- gs = get_user_gs(regs);
25589 } else {
25590 sp = kernel_stack_pointer(regs);
25591 savesegment(ss, ss);
25592- savesegment(gs, gs);
25593 }
25594+ gs = get_user_gs(regs);
25595
25596 printk(KERN_DEFAULT "EIP: %04x:[<%08lx>] EFLAGS: %08lx CPU: %d\n",
25597 (u16)regs->cs, regs->ip, regs->flags,
25598- smp_processor_id());
25599+ raw_smp_processor_id());
25600 print_symbol("EIP is at %s\n", regs->ip);
25601
25602 printk(KERN_DEFAULT "EAX: %08lx EBX: %08lx ECX: %08lx EDX: %08lx\n",
25603@@ -133,20 +133,21 @@ void release_thread(struct task_struct *dead_task)
25604 int copy_thread(unsigned long clone_flags, unsigned long sp,
25605 unsigned long arg, struct task_struct *p)
25606 {
25607- struct pt_regs *childregs = task_pt_regs(p);
25608+ struct pt_regs *childregs = task_stack_page(p) + THREAD_SIZE - sizeof(struct pt_regs) - 8;
25609 struct task_struct *tsk;
25610 int err;
25611
25612 p->thread.sp = (unsigned long) childregs;
25613 p->thread.sp0 = (unsigned long) (childregs+1);
25614+ p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
25615
25616 if (unlikely(p->flags & PF_KTHREAD)) {
25617 /* kernel thread */
25618 memset(childregs, 0, sizeof(struct pt_regs));
25619 p->thread.ip = (unsigned long) ret_from_kernel_thread;
25620- task_user_gs(p) = __KERNEL_STACK_CANARY;
25621- childregs->ds = __USER_DS;
25622- childregs->es = __USER_DS;
25623+ savesegment(gs, childregs->gs);
25624+ childregs->ds = __KERNEL_DS;
25625+ childregs->es = __KERNEL_DS;
25626 childregs->fs = __KERNEL_PERCPU;
25627 childregs->bx = sp; /* function */
25628 childregs->bp = arg;
25629@@ -253,7 +254,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
25630 struct thread_struct *prev = &prev_p->thread,
25631 *next = &next_p->thread;
25632 int cpu = smp_processor_id();
25633- struct tss_struct *tss = &per_cpu(init_tss, cpu);
25634+ struct tss_struct *tss = init_tss + cpu;
25635 fpu_switch_t fpu;
25636
25637 /* never put a printk in __switch_to... printk() calls wake_up*() indirectly */
25638@@ -277,6 +278,10 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
25639 */
25640 lazy_save_gs(prev->gs);
25641
25642+#ifdef CONFIG_PAX_MEMORY_UDEREF
25643+ __set_fs(task_thread_info(next_p)->addr_limit);
25644+#endif
25645+
25646 /*
25647 * Load the per-thread Thread-Local Storage descriptor.
25648 */
25649@@ -307,6 +312,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
25650 */
25651 arch_end_context_switch(next_p);
25652
25653+ this_cpu_write(current_task, next_p);
25654+ this_cpu_write(current_tinfo, &next_p->tinfo);
25655+
25656 /*
25657 * Restore %gs if needed (which is common)
25658 */
25659@@ -315,8 +323,6 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
25660
25661 switch_fpu_finish(next_p, fpu);
25662
25663- this_cpu_write(current_task, next_p);
25664-
25665 return prev_p;
25666 }
25667
25668@@ -346,4 +352,3 @@ unsigned long get_wchan(struct task_struct *p)
25669 } while (count++ < 16);
25670 return 0;
25671 }
25672-
25673diff --git a/arch/x86/kernel/process_64.c b/arch/x86/kernel/process_64.c
25674index bb1dc51..08dda7f 100644
25675--- a/arch/x86/kernel/process_64.c
25676+++ b/arch/x86/kernel/process_64.c
25677@@ -158,10 +158,11 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
25678 struct pt_regs *childregs;
25679 struct task_struct *me = current;
25680
25681- p->thread.sp0 = (unsigned long)task_stack_page(p) + THREAD_SIZE;
25682+ p->thread.sp0 = (unsigned long)task_stack_page(p) + THREAD_SIZE - 16;
25683 childregs = task_pt_regs(p);
25684 p->thread.sp = (unsigned long) childregs;
25685 p->thread.usersp = me->thread.usersp;
25686+ p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
25687 set_tsk_thread_flag(p, TIF_FORK);
25688 p->fpu_counter = 0;
25689 p->thread.io_bitmap_ptr = NULL;
25690@@ -172,6 +173,8 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
25691 p->thread.fs = p->thread.fsindex ? 0 : me->thread.fs;
25692 savesegment(es, p->thread.es);
25693 savesegment(ds, p->thread.ds);
25694+ savesegment(ss, p->thread.ss);
25695+ BUG_ON(p->thread.ss == __UDEREF_KERNEL_DS);
25696 memset(p->thread.ptrace_bps, 0, sizeof(p->thread.ptrace_bps));
25697
25698 if (unlikely(p->flags & PF_KTHREAD)) {
25699@@ -280,7 +283,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
25700 struct thread_struct *prev = &prev_p->thread;
25701 struct thread_struct *next = &next_p->thread;
25702 int cpu = smp_processor_id();
25703- struct tss_struct *tss = &per_cpu(init_tss, cpu);
25704+ struct tss_struct *tss = init_tss + cpu;
25705 unsigned fsindex, gsindex;
25706 fpu_switch_t fpu;
25707
25708@@ -303,6 +306,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
25709 if (unlikely(next->ds | prev->ds))
25710 loadsegment(ds, next->ds);
25711
25712+ savesegment(ss, prev->ss);
25713+ if (unlikely(next->ss != prev->ss))
25714+ loadsegment(ss, next->ss);
25715
25716 /* We must save %fs and %gs before load_TLS() because
25717 * %fs and %gs may be cleared by load_TLS().
25718@@ -362,10 +368,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
25719 prev->usersp = this_cpu_read(old_rsp);
25720 this_cpu_write(old_rsp, next->usersp);
25721 this_cpu_write(current_task, next_p);
25722+ this_cpu_write(current_tinfo, &next_p->tinfo);
25723
25724- this_cpu_write(kernel_stack,
25725- (unsigned long)task_stack_page(next_p) +
25726- THREAD_SIZE - KERNEL_STACK_OFFSET);
25727+ this_cpu_write(kernel_stack, next->sp0);
25728
25729 /*
25730 * Now maybe reload the debug registers and handle I/O bitmaps
25731@@ -434,12 +439,11 @@ unsigned long get_wchan(struct task_struct *p)
25732 if (!p || p == current || p->state == TASK_RUNNING)
25733 return 0;
25734 stack = (unsigned long)task_stack_page(p);
25735- if (p->thread.sp < stack || p->thread.sp >= stack+THREAD_SIZE)
25736+ if (p->thread.sp < stack || p->thread.sp > stack+THREAD_SIZE-16-sizeof(u64))
25737 return 0;
25738 fp = *(u64 *)(p->thread.sp);
25739 do {
25740- if (fp < (unsigned long)stack ||
25741- fp >= (unsigned long)stack+THREAD_SIZE)
25742+ if (fp < stack || fp > stack+THREAD_SIZE-16-sizeof(u64))
25743 return 0;
25744 ip = *(u64 *)(fp+8);
25745 if (!in_sched_functions(ip))
25746diff --git a/arch/x86/kernel/ptrace.c b/arch/x86/kernel/ptrace.c
25747index 7461f50..1334029 100644
25748--- a/arch/x86/kernel/ptrace.c
25749+++ b/arch/x86/kernel/ptrace.c
25750@@ -184,14 +184,13 @@ unsigned long kernel_stack_pointer(struct pt_regs *regs)
25751 {
25752 unsigned long context = (unsigned long)regs & ~(THREAD_SIZE - 1);
25753 unsigned long sp = (unsigned long)&regs->sp;
25754- struct thread_info *tinfo;
25755
25756- if (context == (sp & ~(THREAD_SIZE - 1)))
25757+ if (context == ((sp + 8) & ~(THREAD_SIZE - 1)))
25758 return sp;
25759
25760- tinfo = (struct thread_info *)context;
25761- if (tinfo->previous_esp)
25762- return tinfo->previous_esp;
25763+ sp = *(unsigned long *)context;
25764+ if (sp)
25765+ return sp;
25766
25767 return (unsigned long)regs;
25768 }
25769@@ -588,7 +587,7 @@ static void ptrace_triggered(struct perf_event *bp,
25770 static unsigned long ptrace_get_dr7(struct perf_event *bp[])
25771 {
25772 int i;
25773- int dr7 = 0;
25774+ unsigned long dr7 = 0;
25775 struct arch_hw_breakpoint *info;
25776
25777 for (i = 0; i < HBP_NUM; i++) {
25778@@ -822,7 +821,7 @@ long arch_ptrace(struct task_struct *child, long request,
25779 unsigned long addr, unsigned long data)
25780 {
25781 int ret;
25782- unsigned long __user *datap = (unsigned long __user *)data;
25783+ unsigned long __user *datap = (__force unsigned long __user *)data;
25784
25785 switch (request) {
25786 /* read the word at location addr in the USER area. */
25787@@ -907,14 +906,14 @@ long arch_ptrace(struct task_struct *child, long request,
25788 if ((int) addr < 0)
25789 return -EIO;
25790 ret = do_get_thread_area(child, addr,
25791- (struct user_desc __user *)data);
25792+ (__force struct user_desc __user *) data);
25793 break;
25794
25795 case PTRACE_SET_THREAD_AREA:
25796 if ((int) addr < 0)
25797 return -EIO;
25798 ret = do_set_thread_area(child, addr,
25799- (struct user_desc __user *)data, 0);
25800+ (__force struct user_desc __user *) data, 0);
25801 break;
25802 #endif
25803
25804@@ -1292,7 +1291,7 @@ long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
25805
25806 #ifdef CONFIG_X86_64
25807
25808-static struct user_regset x86_64_regsets[] __read_mostly = {
25809+static user_regset_no_const x86_64_regsets[] __read_only = {
25810 [REGSET_GENERAL] = {
25811 .core_note_type = NT_PRSTATUS,
25812 .n = sizeof(struct user_regs_struct) / sizeof(long),
25813@@ -1333,7 +1332,7 @@ static const struct user_regset_view user_x86_64_view = {
25814 #endif /* CONFIG_X86_64 */
25815
25816 #if defined CONFIG_X86_32 || defined CONFIG_IA32_EMULATION
25817-static struct user_regset x86_32_regsets[] __read_mostly = {
25818+static user_regset_no_const x86_32_regsets[] __read_only = {
25819 [REGSET_GENERAL] = {
25820 .core_note_type = NT_PRSTATUS,
25821 .n = sizeof(struct user_regs_struct32) / sizeof(u32),
25822@@ -1386,7 +1385,7 @@ static const struct user_regset_view user_x86_32_view = {
25823 */
25824 u64 xstate_fx_sw_bytes[USER_XSTATE_FX_SW_WORDS];
25825
25826-void update_regset_xstate_info(unsigned int size, u64 xstate_mask)
25827+void __init update_regset_xstate_info(unsigned int size, u64 xstate_mask)
25828 {
25829 #ifdef CONFIG_X86_64
25830 x86_64_regsets[REGSET_XSTATE].n = size / sizeof(u64);
25831@@ -1421,7 +1420,7 @@ static void fill_sigtrap_info(struct task_struct *tsk,
25832 memset(info, 0, sizeof(*info));
25833 info->si_signo = SIGTRAP;
25834 info->si_code = si_code;
25835- info->si_addr = user_mode_vm(regs) ? (void __user *)regs->ip : NULL;
25836+ info->si_addr = user_mode(regs) ? (__force void __user *)regs->ip : NULL;
25837 }
25838
25839 void user_single_step_siginfo(struct task_struct *tsk,
25840@@ -1450,6 +1449,10 @@ void send_sigtrap(struct task_struct *tsk, struct pt_regs *regs,
25841 # define IS_IA32 0
25842 #endif
25843
25844+#ifdef CONFIG_GRKERNSEC_SETXID
25845+extern void gr_delayed_cred_worker(void);
25846+#endif
25847+
25848 /*
25849 * We must return the syscall number to actually look up in the table.
25850 * This can be -1L to skip running any syscall at all.
25851@@ -1460,6 +1463,11 @@ long syscall_trace_enter(struct pt_regs *regs)
25852
25853 user_exit();
25854
25855+#ifdef CONFIG_GRKERNSEC_SETXID
25856+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
25857+ gr_delayed_cred_worker();
25858+#endif
25859+
25860 /*
25861 * If we stepped into a sysenter/syscall insn, it trapped in
25862 * kernel mode; do_debug() cleared TF and set TIF_SINGLESTEP.
25863@@ -1515,6 +1523,11 @@ void syscall_trace_leave(struct pt_regs *regs)
25864 */
25865 user_exit();
25866
25867+#ifdef CONFIG_GRKERNSEC_SETXID
25868+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
25869+ gr_delayed_cred_worker();
25870+#endif
25871+
25872 audit_syscall_exit(regs);
25873
25874 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
25875diff --git a/arch/x86/kernel/pvclock.c b/arch/x86/kernel/pvclock.c
25876index a16bae3..1f65f25 100644
25877--- a/arch/x86/kernel/pvclock.c
25878+++ b/arch/x86/kernel/pvclock.c
25879@@ -43,11 +43,11 @@ unsigned long pvclock_tsc_khz(struct pvclock_vcpu_time_info *src)
25880 return pv_tsc_khz;
25881 }
25882
25883-static atomic64_t last_value = ATOMIC64_INIT(0);
25884+static atomic64_unchecked_t last_value = ATOMIC64_INIT(0);
25885
25886 void pvclock_resume(void)
25887 {
25888- atomic64_set(&last_value, 0);
25889+ atomic64_set_unchecked(&last_value, 0);
25890 }
25891
25892 u8 pvclock_read_flags(struct pvclock_vcpu_time_info *src)
25893@@ -92,11 +92,11 @@ cycle_t pvclock_clocksource_read(struct pvclock_vcpu_time_info *src)
25894 * updating at the same time, and one of them could be slightly behind,
25895 * making the assumption that last_value always go forward fail to hold.
25896 */
25897- last = atomic64_read(&last_value);
25898+ last = atomic64_read_unchecked(&last_value);
25899 do {
25900 if (ret < last)
25901 return last;
25902- last = atomic64_cmpxchg(&last_value, last, ret);
25903+ last = atomic64_cmpxchg_unchecked(&last_value, last, ret);
25904 } while (unlikely(last != ret));
25905
25906 return ret;
25907diff --git a/arch/x86/kernel/reboot.c b/arch/x86/kernel/reboot.c
25908index 618ce26..ec7e21c 100644
25909--- a/arch/x86/kernel/reboot.c
25910+++ b/arch/x86/kernel/reboot.c
25911@@ -68,6 +68,11 @@ static int __init set_bios_reboot(const struct dmi_system_id *d)
25912
25913 void __noreturn machine_real_restart(unsigned int type)
25914 {
25915+
25916+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
25917+ struct desc_struct *gdt;
25918+#endif
25919+
25920 local_irq_disable();
25921
25922 /*
25923@@ -95,7 +100,29 @@ void __noreturn machine_real_restart(unsigned int type)
25924
25925 /* Jump to the identity-mapped low memory code */
25926 #ifdef CONFIG_X86_32
25927- asm volatile("jmpl *%0" : :
25928+
25929+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
25930+ gdt = get_cpu_gdt_table(smp_processor_id());
25931+ pax_open_kernel();
25932+#ifdef CONFIG_PAX_MEMORY_UDEREF
25933+ gdt[GDT_ENTRY_KERNEL_DS].type = 3;
25934+ gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
25935+ loadsegment(ds, __KERNEL_DS);
25936+ loadsegment(es, __KERNEL_DS);
25937+ loadsegment(ss, __KERNEL_DS);
25938+#endif
25939+#ifdef CONFIG_PAX_KERNEXEC
25940+ gdt[GDT_ENTRY_KERNEL_CS].base0 = 0;
25941+ gdt[GDT_ENTRY_KERNEL_CS].base1 = 0;
25942+ gdt[GDT_ENTRY_KERNEL_CS].base2 = 0;
25943+ gdt[GDT_ENTRY_KERNEL_CS].limit0 = 0xffff;
25944+ gdt[GDT_ENTRY_KERNEL_CS].limit = 0xf;
25945+ gdt[GDT_ENTRY_KERNEL_CS].g = 1;
25946+#endif
25947+ pax_close_kernel();
25948+#endif
25949+
25950+ asm volatile("ljmpl *%0" : :
25951 "rm" (real_mode_header->machine_real_restart_asm),
25952 "a" (type));
25953 #else
25954@@ -466,7 +493,7 @@ void __attribute__((weak)) mach_reboot_fixups(void)
25955 * try to force a triple fault and then cycle between hitting the keyboard
25956 * controller and doing that
25957 */
25958-static void native_machine_emergency_restart(void)
25959+static void __noreturn native_machine_emergency_restart(void)
25960 {
25961 int i;
25962 int attempt = 0;
25963@@ -575,13 +602,13 @@ void native_machine_shutdown(void)
25964 #endif
25965 }
25966
25967-static void __machine_emergency_restart(int emergency)
25968+static void __noreturn __machine_emergency_restart(int emergency)
25969 {
25970 reboot_emergency = emergency;
25971 machine_ops.emergency_restart();
25972 }
25973
25974-static void native_machine_restart(char *__unused)
25975+static void __noreturn native_machine_restart(char *__unused)
25976 {
25977 pr_notice("machine restart\n");
25978
25979@@ -590,7 +617,7 @@ static void native_machine_restart(char *__unused)
25980 __machine_emergency_restart(0);
25981 }
25982
25983-static void native_machine_halt(void)
25984+static void __noreturn native_machine_halt(void)
25985 {
25986 /* Stop other cpus and apics */
25987 machine_shutdown();
25988@@ -600,7 +627,7 @@ static void native_machine_halt(void)
25989 stop_this_cpu(NULL);
25990 }
25991
25992-static void native_machine_power_off(void)
25993+static void __noreturn native_machine_power_off(void)
25994 {
25995 if (pm_power_off) {
25996 if (!reboot_force)
25997@@ -609,9 +636,10 @@ static void native_machine_power_off(void)
25998 }
25999 /* A fallback in case there is no PM info available */
26000 tboot_shutdown(TB_SHUTDOWN_HALT);
26001+ unreachable();
26002 }
26003
26004-struct machine_ops machine_ops = {
26005+struct machine_ops machine_ops __read_only = {
26006 .power_off = native_machine_power_off,
26007 .shutdown = native_machine_shutdown,
26008 .emergency_restart = native_machine_emergency_restart,
26009diff --git a/arch/x86/kernel/reboot_fixups_32.c b/arch/x86/kernel/reboot_fixups_32.c
26010index c8e41e9..64049ef 100644
26011--- a/arch/x86/kernel/reboot_fixups_32.c
26012+++ b/arch/x86/kernel/reboot_fixups_32.c
26013@@ -57,7 +57,7 @@ struct device_fixup {
26014 unsigned int vendor;
26015 unsigned int device;
26016 void (*reboot_fixup)(struct pci_dev *);
26017-};
26018+} __do_const;
26019
26020 /*
26021 * PCI ids solely used for fixups_table go here
26022diff --git a/arch/x86/kernel/relocate_kernel_64.S b/arch/x86/kernel/relocate_kernel_64.S
26023index 3fd2c69..16ef367 100644
26024--- a/arch/x86/kernel/relocate_kernel_64.S
26025+++ b/arch/x86/kernel/relocate_kernel_64.S
26026@@ -11,6 +11,7 @@
26027 #include <asm/kexec.h>
26028 #include <asm/processor-flags.h>
26029 #include <asm/pgtable_types.h>
26030+#include <asm/alternative-asm.h>
26031
26032 /*
26033 * Must be relocatable PIC code callable as a C function
26034@@ -96,8 +97,7 @@ relocate_kernel:
26035
26036 /* jump to identity mapped page */
26037 addq $(identity_mapped - relocate_kernel), %r8
26038- pushq %r8
26039- ret
26040+ jmp *%r8
26041
26042 identity_mapped:
26043 /* set return address to 0 if not preserving context */
26044@@ -167,6 +167,7 @@ identity_mapped:
26045 xorl %r14d, %r14d
26046 xorl %r15d, %r15d
26047
26048+ pax_force_retaddr 0, 1
26049 ret
26050
26051 1:
26052diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
26053index f0de629..a4978a8f 100644
26054--- a/arch/x86/kernel/setup.c
26055+++ b/arch/x86/kernel/setup.c
26056@@ -110,6 +110,7 @@
26057 #include <asm/mce.h>
26058 #include <asm/alternative.h>
26059 #include <asm/prom.h>
26060+#include <asm/boot.h>
26061
26062 /*
26063 * max_low_pfn_mapped: highest direct mapped pfn under 4GB
26064@@ -205,12 +206,50 @@ EXPORT_SYMBOL(boot_cpu_data);
26065 #endif
26066
26067
26068-#if !defined(CONFIG_X86_PAE) || defined(CONFIG_X86_64)
26069-__visible unsigned long mmu_cr4_features;
26070+#ifdef CONFIG_X86_64
26071+__visible unsigned long mmu_cr4_features __read_only = X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE;
26072+#elif defined(CONFIG_X86_PAE)
26073+__visible unsigned long mmu_cr4_features __read_only = X86_CR4_PAE;
26074 #else
26075-__visible unsigned long mmu_cr4_features = X86_CR4_PAE;
26076+__visible unsigned long mmu_cr4_features __read_only;
26077 #endif
26078
26079+void set_in_cr4(unsigned long mask)
26080+{
26081+ unsigned long cr4 = read_cr4();
26082+
26083+ if ((cr4 & mask) == mask && cr4 == mmu_cr4_features)
26084+ return;
26085+
26086+ pax_open_kernel();
26087+ mmu_cr4_features |= mask;
26088+ pax_close_kernel();
26089+
26090+ if (trampoline_cr4_features)
26091+ *trampoline_cr4_features = mmu_cr4_features;
26092+ cr4 |= mask;
26093+ write_cr4(cr4);
26094+}
26095+EXPORT_SYMBOL(set_in_cr4);
26096+
26097+void clear_in_cr4(unsigned long mask)
26098+{
26099+ unsigned long cr4 = read_cr4();
26100+
26101+ if (!(cr4 & mask) && cr4 == mmu_cr4_features)
26102+ return;
26103+
26104+ pax_open_kernel();
26105+ mmu_cr4_features &= ~mask;
26106+ pax_close_kernel();
26107+
26108+ if (trampoline_cr4_features)
26109+ *trampoline_cr4_features = mmu_cr4_features;
26110+ cr4 &= ~mask;
26111+ write_cr4(cr4);
26112+}
26113+EXPORT_SYMBOL(clear_in_cr4);
26114+
26115 /* Boot loader ID and version as integers, for the benefit of proc_dointvec */
26116 int bootloader_type, bootloader_version;
26117
26118@@ -768,7 +807,7 @@ static void __init trim_bios_range(void)
26119 * area (640->1Mb) as ram even though it is not.
26120 * take them out.
26121 */
26122- e820_remove_range(BIOS_BEGIN, BIOS_END - BIOS_BEGIN, E820_RAM, 1);
26123+ e820_remove_range(ISA_START_ADDRESS, ISA_END_ADDRESS - ISA_START_ADDRESS, E820_RAM, 1);
26124
26125 sanitize_e820_map(e820.map, ARRAY_SIZE(e820.map), &e820.nr_map);
26126 }
26127@@ -776,7 +815,7 @@ static void __init trim_bios_range(void)
26128 /* called before trim_bios_range() to spare extra sanitize */
26129 static void __init e820_add_kernel_range(void)
26130 {
26131- u64 start = __pa_symbol(_text);
26132+ u64 start = __pa_symbol(ktla_ktva(_text));
26133 u64 size = __pa_symbol(_end) - start;
26134
26135 /*
26136@@ -838,8 +877,12 @@ static void __init trim_low_memory_range(void)
26137
26138 void __init setup_arch(char **cmdline_p)
26139 {
26140+#ifdef CONFIG_X86_32
26141+ memblock_reserve(LOAD_PHYSICAL_ADDR, __pa_symbol(__bss_stop) - LOAD_PHYSICAL_ADDR);
26142+#else
26143 memblock_reserve(__pa_symbol(_text),
26144 (unsigned long)__bss_stop - (unsigned long)_text);
26145+#endif
26146
26147 early_reserve_initrd();
26148
26149@@ -931,14 +974,14 @@ void __init setup_arch(char **cmdline_p)
26150
26151 if (!boot_params.hdr.root_flags)
26152 root_mountflags &= ~MS_RDONLY;
26153- init_mm.start_code = (unsigned long) _text;
26154- init_mm.end_code = (unsigned long) _etext;
26155+ init_mm.start_code = ktla_ktva((unsigned long) _text);
26156+ init_mm.end_code = ktla_ktva((unsigned long) _etext);
26157 init_mm.end_data = (unsigned long) _edata;
26158 init_mm.brk = _brk_end;
26159
26160- code_resource.start = __pa_symbol(_text);
26161- code_resource.end = __pa_symbol(_etext)-1;
26162- data_resource.start = __pa_symbol(_etext);
26163+ code_resource.start = __pa_symbol(ktla_ktva(_text));
26164+ code_resource.end = __pa_symbol(ktla_ktva(_etext))-1;
26165+ data_resource.start = __pa_symbol(_sdata);
26166 data_resource.end = __pa_symbol(_edata)-1;
26167 bss_resource.start = __pa_symbol(__bss_start);
26168 bss_resource.end = __pa_symbol(__bss_stop)-1;
26169diff --git a/arch/x86/kernel/setup_percpu.c b/arch/x86/kernel/setup_percpu.c
26170index 5cdff03..80fa283 100644
26171--- a/arch/x86/kernel/setup_percpu.c
26172+++ b/arch/x86/kernel/setup_percpu.c
26173@@ -21,19 +21,17 @@
26174 #include <asm/cpu.h>
26175 #include <asm/stackprotector.h>
26176
26177-DEFINE_PER_CPU_READ_MOSTLY(int, cpu_number);
26178+#ifdef CONFIG_SMP
26179+DEFINE_PER_CPU_READ_MOSTLY(unsigned int, cpu_number);
26180 EXPORT_PER_CPU_SYMBOL(cpu_number);
26181+#endif
26182
26183-#ifdef CONFIG_X86_64
26184 #define BOOT_PERCPU_OFFSET ((unsigned long)__per_cpu_load)
26185-#else
26186-#define BOOT_PERCPU_OFFSET 0
26187-#endif
26188
26189 DEFINE_PER_CPU(unsigned long, this_cpu_off) = BOOT_PERCPU_OFFSET;
26190 EXPORT_PER_CPU_SYMBOL(this_cpu_off);
26191
26192-unsigned long __per_cpu_offset[NR_CPUS] __read_mostly = {
26193+unsigned long __per_cpu_offset[NR_CPUS] __read_only = {
26194 [0 ... NR_CPUS-1] = BOOT_PERCPU_OFFSET,
26195 };
26196 EXPORT_SYMBOL(__per_cpu_offset);
26197@@ -66,7 +64,7 @@ static bool __init pcpu_need_numa(void)
26198 {
26199 #ifdef CONFIG_NEED_MULTIPLE_NODES
26200 pg_data_t *last = NULL;
26201- unsigned int cpu;
26202+ int cpu;
26203
26204 for_each_possible_cpu(cpu) {
26205 int node = early_cpu_to_node(cpu);
26206@@ -155,10 +153,10 @@ static inline void setup_percpu_segment(int cpu)
26207 {
26208 #ifdef CONFIG_X86_32
26209 struct desc_struct gdt;
26210+ unsigned long base = per_cpu_offset(cpu);
26211
26212- pack_descriptor(&gdt, per_cpu_offset(cpu), 0xFFFFF,
26213- 0x2 | DESCTYPE_S, 0x8);
26214- gdt.s = 1;
26215+ pack_descriptor(&gdt, base, (VMALLOC_END - base - 1) >> PAGE_SHIFT,
26216+ 0x83 | DESCTYPE_S, 0xC);
26217 write_gdt_entry(get_cpu_gdt_table(cpu),
26218 GDT_ENTRY_PERCPU, &gdt, DESCTYPE_S);
26219 #endif
26220@@ -219,6 +217,11 @@ void __init setup_per_cpu_areas(void)
26221 /* alrighty, percpu areas up and running */
26222 delta = (unsigned long)pcpu_base_addr - (unsigned long)__per_cpu_start;
26223 for_each_possible_cpu(cpu) {
26224+#ifdef CONFIG_CC_STACKPROTECTOR
26225+#ifdef CONFIG_X86_32
26226+ unsigned long canary = per_cpu(stack_canary.canary, cpu);
26227+#endif
26228+#endif
26229 per_cpu_offset(cpu) = delta + pcpu_unit_offsets[cpu];
26230 per_cpu(this_cpu_off, cpu) = per_cpu_offset(cpu);
26231 per_cpu(cpu_number, cpu) = cpu;
26232@@ -259,6 +262,12 @@ void __init setup_per_cpu_areas(void)
26233 */
26234 set_cpu_numa_node(cpu, early_cpu_to_node(cpu));
26235 #endif
26236+#ifdef CONFIG_CC_STACKPROTECTOR
26237+#ifdef CONFIG_X86_32
26238+ if (!cpu)
26239+ per_cpu(stack_canary.canary, cpu) = canary;
26240+#endif
26241+#endif
26242 /*
26243 * Up to this point, the boot CPU has been using .init.data
26244 * area. Reload any changed state for the boot CPU.
26245diff --git a/arch/x86/kernel/signal.c b/arch/x86/kernel/signal.c
26246index 9e5de68..16c53cb 100644
26247--- a/arch/x86/kernel/signal.c
26248+++ b/arch/x86/kernel/signal.c
26249@@ -190,7 +190,7 @@ static unsigned long align_sigframe(unsigned long sp)
26250 * Align the stack pointer according to the i386 ABI,
26251 * i.e. so that on function entry ((sp + 4) & 15) == 0.
26252 */
26253- sp = ((sp + 4) & -16ul) - 4;
26254+ sp = ((sp - 12) & -16ul) - 4;
26255 #else /* !CONFIG_X86_32 */
26256 sp = round_down(sp, 16) - 8;
26257 #endif
26258@@ -298,9 +298,9 @@ __setup_frame(int sig, struct ksignal *ksig, sigset_t *set,
26259 }
26260
26261 if (current->mm->context.vdso)
26262- restorer = VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
26263+ restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
26264 else
26265- restorer = &frame->retcode;
26266+ restorer = (void __user *)&frame->retcode;
26267 if (ksig->ka.sa.sa_flags & SA_RESTORER)
26268 restorer = ksig->ka.sa.sa_restorer;
26269
26270@@ -314,7 +314,7 @@ __setup_frame(int sig, struct ksignal *ksig, sigset_t *set,
26271 * reasons and because gdb uses it as a signature to notice
26272 * signal handler stack frames.
26273 */
26274- err |= __put_user(*((u64 *)&retcode), (u64 *)frame->retcode);
26275+ err |= __put_user(*((u64 *)&retcode), (u64 __user *)frame->retcode);
26276
26277 if (err)
26278 return -EFAULT;
26279@@ -361,7 +361,10 @@ static int __setup_rt_frame(int sig, struct ksignal *ksig,
26280 save_altstack_ex(&frame->uc.uc_stack, regs->sp);
26281
26282 /* Set up to return from userspace. */
26283- restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
26284+ if (current->mm->context.vdso)
26285+ restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
26286+ else
26287+ restorer = (void __user *)&frame->retcode;
26288 if (ksig->ka.sa.sa_flags & SA_RESTORER)
26289 restorer = ksig->ka.sa.sa_restorer;
26290 put_user_ex(restorer, &frame->pretcode);
26291@@ -373,7 +376,7 @@ static int __setup_rt_frame(int sig, struct ksignal *ksig,
26292 * reasons and because gdb uses it as a signature to notice
26293 * signal handler stack frames.
26294 */
26295- put_user_ex(*((u64 *)&rt_retcode), (u64 *)frame->retcode);
26296+ put_user_ex(*((u64 *)&rt_retcode), (u64 __user *)frame->retcode);
26297 } put_user_catch(err);
26298
26299 err |= copy_siginfo_to_user(&frame->info, &ksig->info);
26300@@ -609,7 +612,12 @@ setup_rt_frame(struct ksignal *ksig, struct pt_regs *regs)
26301 {
26302 int usig = signr_convert(ksig->sig);
26303 sigset_t *set = sigmask_to_save();
26304- compat_sigset_t *cset = (compat_sigset_t *) set;
26305+ sigset_t sigcopy;
26306+ compat_sigset_t *cset;
26307+
26308+ sigcopy = *set;
26309+
26310+ cset = (compat_sigset_t *) &sigcopy;
26311
26312 /* Set up the stack frame */
26313 if (is_ia32_frame()) {
26314@@ -620,7 +628,7 @@ setup_rt_frame(struct ksignal *ksig, struct pt_regs *regs)
26315 } else if (is_x32_frame()) {
26316 return x32_setup_rt_frame(ksig, cset, regs);
26317 } else {
26318- return __setup_rt_frame(ksig->sig, ksig, set, regs);
26319+ return __setup_rt_frame(ksig->sig, ksig, &sigcopy, regs);
26320 }
26321 }
26322
26323diff --git a/arch/x86/kernel/smp.c b/arch/x86/kernel/smp.c
26324index 7c3a5a6..f0a8961 100644
26325--- a/arch/x86/kernel/smp.c
26326+++ b/arch/x86/kernel/smp.c
26327@@ -341,7 +341,7 @@ static int __init nonmi_ipi_setup(char *str)
26328
26329 __setup("nonmi_ipi", nonmi_ipi_setup);
26330
26331-struct smp_ops smp_ops = {
26332+struct smp_ops smp_ops __read_only = {
26333 .smp_prepare_boot_cpu = native_smp_prepare_boot_cpu,
26334 .smp_prepare_cpus = native_smp_prepare_cpus,
26335 .smp_cpus_done = native_smp_cpus_done,
26336diff --git a/arch/x86/kernel/smpboot.c b/arch/x86/kernel/smpboot.c
26337index 6cacab6..750636a 100644
26338--- a/arch/x86/kernel/smpboot.c
26339+++ b/arch/x86/kernel/smpboot.c
26340@@ -251,14 +251,18 @@ static void notrace start_secondary(void *unused)
26341
26342 enable_start_cpu0 = 0;
26343
26344-#ifdef CONFIG_X86_32
26345- /* switch away from the initial page table */
26346- load_cr3(swapper_pg_dir);
26347- __flush_tlb_all();
26348-#endif
26349-
26350 /* otherwise gcc will move up smp_processor_id before the cpu_init */
26351 barrier();
26352+
26353+ /* switch away from the initial page table */
26354+#ifdef CONFIG_PAX_PER_CPU_PGD
26355+ load_cr3(get_cpu_pgd(smp_processor_id(), kernel));
26356+ __flush_tlb_all();
26357+#elif defined(CONFIG_X86_32)
26358+ load_cr3(swapper_pg_dir);
26359+ __flush_tlb_all();
26360+#endif
26361+
26362 /*
26363 * Check TSC synchronization with the BP:
26364 */
26365@@ -749,6 +753,7 @@ static int do_boot_cpu(int apicid, int cpu, struct task_struct *idle)
26366 idle->thread.sp = (unsigned long) (((struct pt_regs *)
26367 (THREAD_SIZE + task_stack_page(idle))) - 1);
26368 per_cpu(current_task, cpu) = idle;
26369+ per_cpu(current_tinfo, cpu) = &idle->tinfo;
26370
26371 #ifdef CONFIG_X86_32
26372 /* Stack for startup_32 can be just as for start_secondary onwards */
26373@@ -756,11 +761,13 @@ static int do_boot_cpu(int apicid, int cpu, struct task_struct *idle)
26374 #else
26375 clear_tsk_thread_flag(idle, TIF_FORK);
26376 initial_gs = per_cpu_offset(cpu);
26377- per_cpu(kernel_stack, cpu) =
26378- (unsigned long)task_stack_page(idle) -
26379- KERNEL_STACK_OFFSET + THREAD_SIZE;
26380+ per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
26381 #endif
26382+
26383+ pax_open_kernel();
26384 early_gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
26385+ pax_close_kernel();
26386+
26387 initial_code = (unsigned long)start_secondary;
26388 stack_start = idle->thread.sp;
26389
26390@@ -909,6 +916,15 @@ int native_cpu_up(unsigned int cpu, struct task_struct *tidle)
26391 /* the FPU context is blank, nobody can own it */
26392 __cpu_disable_lazy_restore(cpu);
26393
26394+#ifdef CONFIG_PAX_PER_CPU_PGD
26395+ clone_pgd_range(get_cpu_pgd(cpu, kernel) + KERNEL_PGD_BOUNDARY,
26396+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
26397+ KERNEL_PGD_PTRS);
26398+ clone_pgd_range(get_cpu_pgd(cpu, user) + KERNEL_PGD_BOUNDARY,
26399+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
26400+ KERNEL_PGD_PTRS);
26401+#endif
26402+
26403 err = do_boot_cpu(apicid, cpu, tidle);
26404 if (err) {
26405 pr_debug("do_boot_cpu failed %d\n", err);
26406diff --git a/arch/x86/kernel/step.c b/arch/x86/kernel/step.c
26407index 9b4d51d..5d28b58 100644
26408--- a/arch/x86/kernel/step.c
26409+++ b/arch/x86/kernel/step.c
26410@@ -27,10 +27,10 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
26411 struct desc_struct *desc;
26412 unsigned long base;
26413
26414- seg &= ~7UL;
26415+ seg >>= 3;
26416
26417 mutex_lock(&child->mm->context.lock);
26418- if (unlikely((seg >> 3) >= child->mm->context.size))
26419+ if (unlikely(seg >= child->mm->context.size))
26420 addr = -1L; /* bogus selector, access would fault */
26421 else {
26422 desc = child->mm->context.ldt + seg;
26423@@ -42,7 +42,8 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
26424 addr += base;
26425 }
26426 mutex_unlock(&child->mm->context.lock);
26427- }
26428+ } else if (seg == __KERNEL_CS || seg == __KERNEXEC_KERNEL_CS)
26429+ addr = ktla_ktva(addr);
26430
26431 return addr;
26432 }
26433@@ -53,6 +54,9 @@ static int is_setting_trap_flag(struct task_struct *child, struct pt_regs *regs)
26434 unsigned char opcode[15];
26435 unsigned long addr = convert_ip_to_linear(child, regs);
26436
26437+ if (addr == -EINVAL)
26438+ return 0;
26439+
26440 copied = access_process_vm(child, addr, opcode, sizeof(opcode), 0);
26441 for (i = 0; i < copied; i++) {
26442 switch (opcode[i]) {
26443diff --git a/arch/x86/kernel/sys_i386_32.c b/arch/x86/kernel/sys_i386_32.c
26444new file mode 100644
26445index 0000000..5877189
26446--- /dev/null
26447+++ b/arch/x86/kernel/sys_i386_32.c
26448@@ -0,0 +1,189 @@
26449+/*
26450+ * This file contains various random system calls that
26451+ * have a non-standard calling sequence on the Linux/i386
26452+ * platform.
26453+ */
26454+
26455+#include <linux/errno.h>
26456+#include <linux/sched.h>
26457+#include <linux/mm.h>
26458+#include <linux/fs.h>
26459+#include <linux/smp.h>
26460+#include <linux/sem.h>
26461+#include <linux/msg.h>
26462+#include <linux/shm.h>
26463+#include <linux/stat.h>
26464+#include <linux/syscalls.h>
26465+#include <linux/mman.h>
26466+#include <linux/file.h>
26467+#include <linux/utsname.h>
26468+#include <linux/ipc.h>
26469+#include <linux/elf.h>
26470+
26471+#include <linux/uaccess.h>
26472+#include <linux/unistd.h>
26473+
26474+#include <asm/syscalls.h>
26475+
26476+int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags)
26477+{
26478+ unsigned long pax_task_size = TASK_SIZE;
26479+
26480+#ifdef CONFIG_PAX_SEGMEXEC
26481+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
26482+ pax_task_size = SEGMEXEC_TASK_SIZE;
26483+#endif
26484+
26485+ if (flags & MAP_FIXED)
26486+ if (len > pax_task_size || addr > pax_task_size - len)
26487+ return -EINVAL;
26488+
26489+ return 0;
26490+}
26491+
26492+/*
26493+ * Align a virtual address to avoid aliasing in the I$ on AMD F15h.
26494+ */
26495+static unsigned long get_align_mask(void)
26496+{
26497+ if (va_align.flags < 0 || !(va_align.flags & ALIGN_VA_32))
26498+ return 0;
26499+
26500+ if (!(current->flags & PF_RANDOMIZE))
26501+ return 0;
26502+
26503+ return va_align.mask;
26504+}
26505+
26506+unsigned long
26507+arch_get_unmapped_area(struct file *filp, unsigned long addr,
26508+ unsigned long len, unsigned long pgoff, unsigned long flags)
26509+{
26510+ struct mm_struct *mm = current->mm;
26511+ struct vm_area_struct *vma;
26512+ unsigned long pax_task_size = TASK_SIZE;
26513+ struct vm_unmapped_area_info info;
26514+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
26515+
26516+#ifdef CONFIG_PAX_SEGMEXEC
26517+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
26518+ pax_task_size = SEGMEXEC_TASK_SIZE;
26519+#endif
26520+
26521+ pax_task_size -= PAGE_SIZE;
26522+
26523+ if (len > pax_task_size)
26524+ return -ENOMEM;
26525+
26526+ if (flags & MAP_FIXED)
26527+ return addr;
26528+
26529+#ifdef CONFIG_PAX_RANDMMAP
26530+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
26531+#endif
26532+
26533+ if (addr) {
26534+ addr = PAGE_ALIGN(addr);
26535+ if (pax_task_size - len >= addr) {
26536+ vma = find_vma(mm, addr);
26537+ if (check_heap_stack_gap(vma, addr, len, offset))
26538+ return addr;
26539+ }
26540+ }
26541+
26542+ info.flags = 0;
26543+ info.length = len;
26544+ info.align_mask = filp ? get_align_mask() : 0;
26545+ info.align_offset = pgoff << PAGE_SHIFT;
26546+ info.threadstack_offset = offset;
26547+
26548+#ifdef CONFIG_PAX_PAGEEXEC
26549+ if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE)) {
26550+ info.low_limit = 0x00110000UL;
26551+ info.high_limit = mm->start_code;
26552+
26553+#ifdef CONFIG_PAX_RANDMMAP
26554+ if (mm->pax_flags & MF_PAX_RANDMMAP)
26555+ info.low_limit += mm->delta_mmap & 0x03FFF000UL;
26556+#endif
26557+
26558+ if (info.low_limit < info.high_limit) {
26559+ addr = vm_unmapped_area(&info);
26560+ if (!IS_ERR_VALUE(addr))
26561+ return addr;
26562+ }
26563+ } else
26564+#endif
26565+
26566+ info.low_limit = mm->mmap_base;
26567+ info.high_limit = pax_task_size;
26568+
26569+ return vm_unmapped_area(&info);
26570+}
26571+
26572+unsigned long
26573+arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
26574+ const unsigned long len, const unsigned long pgoff,
26575+ const unsigned long flags)
26576+{
26577+ struct vm_area_struct *vma;
26578+ struct mm_struct *mm = current->mm;
26579+ unsigned long addr = addr0, pax_task_size = TASK_SIZE;
26580+ struct vm_unmapped_area_info info;
26581+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
26582+
26583+#ifdef CONFIG_PAX_SEGMEXEC
26584+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
26585+ pax_task_size = SEGMEXEC_TASK_SIZE;
26586+#endif
26587+
26588+ pax_task_size -= PAGE_SIZE;
26589+
26590+ /* requested length too big for entire address space */
26591+ if (len > pax_task_size)
26592+ return -ENOMEM;
26593+
26594+ if (flags & MAP_FIXED)
26595+ return addr;
26596+
26597+#ifdef CONFIG_PAX_PAGEEXEC
26598+ if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE))
26599+ goto bottomup;
26600+#endif
26601+
26602+#ifdef CONFIG_PAX_RANDMMAP
26603+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
26604+#endif
26605+
26606+ /* requesting a specific address */
26607+ if (addr) {
26608+ addr = PAGE_ALIGN(addr);
26609+ if (pax_task_size - len >= addr) {
26610+ vma = find_vma(mm, addr);
26611+ if (check_heap_stack_gap(vma, addr, len, offset))
26612+ return addr;
26613+ }
26614+ }
26615+
26616+ info.flags = VM_UNMAPPED_AREA_TOPDOWN;
26617+ info.length = len;
26618+ info.low_limit = PAGE_SIZE;
26619+ info.high_limit = mm->mmap_base;
26620+ info.align_mask = filp ? get_align_mask() : 0;
26621+ info.align_offset = pgoff << PAGE_SHIFT;
26622+ info.threadstack_offset = offset;
26623+
26624+ addr = vm_unmapped_area(&info);
26625+ if (!(addr & ~PAGE_MASK))
26626+ return addr;
26627+ VM_BUG_ON(addr != -ENOMEM);
26628+
26629+bottomup:
26630+ /*
26631+ * A failed mmap() very likely causes application failure,
26632+ * so fall back to the bottom-up function here. This scenario
26633+ * can happen with large stack limits and large mmap()
26634+ * allocations.
26635+ */
26636+ return arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
26637+}
26638diff --git a/arch/x86/kernel/sys_x86_64.c b/arch/x86/kernel/sys_x86_64.c
26639index 30277e2..5664a29 100644
26640--- a/arch/x86/kernel/sys_x86_64.c
26641+++ b/arch/x86/kernel/sys_x86_64.c
26642@@ -81,8 +81,8 @@ out:
26643 return error;
26644 }
26645
26646-static void find_start_end(unsigned long flags, unsigned long *begin,
26647- unsigned long *end)
26648+static void find_start_end(struct mm_struct *mm, unsigned long flags,
26649+ unsigned long *begin, unsigned long *end)
26650 {
26651 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT)) {
26652 unsigned long new_begin;
26653@@ -101,7 +101,7 @@ static void find_start_end(unsigned long flags, unsigned long *begin,
26654 *begin = new_begin;
26655 }
26656 } else {
26657- *begin = current->mm->mmap_legacy_base;
26658+ *begin = mm->mmap_legacy_base;
26659 *end = TASK_SIZE;
26660 }
26661 }
26662@@ -114,20 +114,24 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
26663 struct vm_area_struct *vma;
26664 struct vm_unmapped_area_info info;
26665 unsigned long begin, end;
26666+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
26667
26668 if (flags & MAP_FIXED)
26669 return addr;
26670
26671- find_start_end(flags, &begin, &end);
26672+ find_start_end(mm, flags, &begin, &end);
26673
26674 if (len > end)
26675 return -ENOMEM;
26676
26677+#ifdef CONFIG_PAX_RANDMMAP
26678+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
26679+#endif
26680+
26681 if (addr) {
26682 addr = PAGE_ALIGN(addr);
26683 vma = find_vma(mm, addr);
26684- if (end - len >= addr &&
26685- (!vma || addr + len <= vma->vm_start))
26686+ if (end - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
26687 return addr;
26688 }
26689
26690@@ -137,6 +141,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
26691 info.high_limit = end;
26692 info.align_mask = filp ? get_align_mask() : 0;
26693 info.align_offset = pgoff << PAGE_SHIFT;
26694+ info.threadstack_offset = offset;
26695 return vm_unmapped_area(&info);
26696 }
26697
26698@@ -149,6 +154,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
26699 struct mm_struct *mm = current->mm;
26700 unsigned long addr = addr0;
26701 struct vm_unmapped_area_info info;
26702+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
26703
26704 /* requested length too big for entire address space */
26705 if (len > TASK_SIZE)
26706@@ -161,12 +167,15 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
26707 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT))
26708 goto bottomup;
26709
26710+#ifdef CONFIG_PAX_RANDMMAP
26711+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
26712+#endif
26713+
26714 /* requesting a specific address */
26715 if (addr) {
26716 addr = PAGE_ALIGN(addr);
26717 vma = find_vma(mm, addr);
26718- if (TASK_SIZE - len >= addr &&
26719- (!vma || addr + len <= vma->vm_start))
26720+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
26721 return addr;
26722 }
26723
26724@@ -176,6 +185,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
26725 info.high_limit = mm->mmap_base;
26726 info.align_mask = filp ? get_align_mask() : 0;
26727 info.align_offset = pgoff << PAGE_SHIFT;
26728+ info.threadstack_offset = offset;
26729 addr = vm_unmapped_area(&info);
26730 if (!(addr & ~PAGE_MASK))
26731 return addr;
26732diff --git a/arch/x86/kernel/tboot.c b/arch/x86/kernel/tboot.c
26733index 91a4496..1730bff 100644
26734--- a/arch/x86/kernel/tboot.c
26735+++ b/arch/x86/kernel/tboot.c
26736@@ -221,7 +221,7 @@ static int tboot_setup_sleep(void)
26737
26738 void tboot_shutdown(u32 shutdown_type)
26739 {
26740- void (*shutdown)(void);
26741+ void (* __noreturn shutdown)(void);
26742
26743 if (!tboot_enabled())
26744 return;
26745@@ -243,7 +243,7 @@ void tboot_shutdown(u32 shutdown_type)
26746
26747 switch_to_tboot_pt();
26748
26749- shutdown = (void(*)(void))(unsigned long)tboot->shutdown_entry;
26750+ shutdown = (void *)tboot->shutdown_entry;
26751 shutdown();
26752
26753 /* should not reach here */
26754@@ -310,7 +310,7 @@ static int tboot_extended_sleep(u8 sleep_state, u32 val_a, u32 val_b)
26755 return -ENODEV;
26756 }
26757
26758-static atomic_t ap_wfs_count;
26759+static atomic_unchecked_t ap_wfs_count;
26760
26761 static int tboot_wait_for_aps(int num_aps)
26762 {
26763@@ -334,9 +334,9 @@ static int tboot_cpu_callback(struct notifier_block *nfb, unsigned long action,
26764 {
26765 switch (action) {
26766 case CPU_DYING:
26767- atomic_inc(&ap_wfs_count);
26768+ atomic_inc_unchecked(&ap_wfs_count);
26769 if (num_online_cpus() == 1)
26770- if (tboot_wait_for_aps(atomic_read(&ap_wfs_count)))
26771+ if (tboot_wait_for_aps(atomic_read_unchecked(&ap_wfs_count)))
26772 return NOTIFY_BAD;
26773 break;
26774 }
26775@@ -422,7 +422,7 @@ static __init int tboot_late_init(void)
26776
26777 tboot_create_trampoline();
26778
26779- atomic_set(&ap_wfs_count, 0);
26780+ atomic_set_unchecked(&ap_wfs_count, 0);
26781 register_hotcpu_notifier(&tboot_cpu_notifier);
26782
26783 #ifdef CONFIG_DEBUG_FS
26784diff --git a/arch/x86/kernel/time.c b/arch/x86/kernel/time.c
26785index 24d3c91..d06b473 100644
26786--- a/arch/x86/kernel/time.c
26787+++ b/arch/x86/kernel/time.c
26788@@ -30,9 +30,9 @@ unsigned long profile_pc(struct pt_regs *regs)
26789 {
26790 unsigned long pc = instruction_pointer(regs);
26791
26792- if (!user_mode_vm(regs) && in_lock_functions(pc)) {
26793+ if (!user_mode(regs) && in_lock_functions(pc)) {
26794 #ifdef CONFIG_FRAME_POINTER
26795- return *(unsigned long *)(regs->bp + sizeof(long));
26796+ return ktla_ktva(*(unsigned long *)(regs->bp + sizeof(long)));
26797 #else
26798 unsigned long *sp =
26799 (unsigned long *)kernel_stack_pointer(regs);
26800@@ -41,11 +41,17 @@ unsigned long profile_pc(struct pt_regs *regs)
26801 * or above a saved flags. Eflags has bits 22-31 zero,
26802 * kernel addresses don't.
26803 */
26804+
26805+#ifdef CONFIG_PAX_KERNEXEC
26806+ return ktla_ktva(sp[0]);
26807+#else
26808 if (sp[0] >> 22)
26809 return sp[0];
26810 if (sp[1] >> 22)
26811 return sp[1];
26812 #endif
26813+
26814+#endif
26815 }
26816 return pc;
26817 }
26818diff --git a/arch/x86/kernel/tls.c b/arch/x86/kernel/tls.c
26819index f7fec09..9991981 100644
26820--- a/arch/x86/kernel/tls.c
26821+++ b/arch/x86/kernel/tls.c
26822@@ -84,6 +84,11 @@ int do_set_thread_area(struct task_struct *p, int idx,
26823 if (idx < GDT_ENTRY_TLS_MIN || idx > GDT_ENTRY_TLS_MAX)
26824 return -EINVAL;
26825
26826+#ifdef CONFIG_PAX_SEGMEXEC
26827+ if ((p->mm->pax_flags & MF_PAX_SEGMEXEC) && (info.contents & MODIFY_LDT_CONTENTS_CODE))
26828+ return -EINVAL;
26829+#endif
26830+
26831 set_tls_desc(p, idx, &info, 1);
26832
26833 return 0;
26834@@ -200,7 +205,7 @@ int regset_tls_set(struct task_struct *target, const struct user_regset *regset,
26835
26836 if (kbuf)
26837 info = kbuf;
26838- else if (__copy_from_user(infobuf, ubuf, count))
26839+ else if (count > sizeof infobuf || __copy_from_user(infobuf, ubuf, count))
26840 return -EFAULT;
26841 else
26842 info = infobuf;
26843diff --git a/arch/x86/kernel/tracepoint.c b/arch/x86/kernel/tracepoint.c
26844index 1c113db..287b42e 100644
26845--- a/arch/x86/kernel/tracepoint.c
26846+++ b/arch/x86/kernel/tracepoint.c
26847@@ -9,11 +9,11 @@
26848 #include <linux/atomic.h>
26849
26850 atomic_t trace_idt_ctr = ATOMIC_INIT(0);
26851-struct desc_ptr trace_idt_descr = { NR_VECTORS * 16 - 1,
26852+const struct desc_ptr trace_idt_descr = { NR_VECTORS * 16 - 1,
26853 (unsigned long) trace_idt_table };
26854
26855 /* No need to be aligned, but done to keep all IDTs defined the same way. */
26856-gate_desc trace_idt_table[NR_VECTORS] __page_aligned_bss;
26857+gate_desc trace_idt_table[NR_VECTORS] __page_aligned_rodata;
26858
26859 static int trace_irq_vector_refcount;
26860 static DEFINE_MUTEX(irq_vector_mutex);
26861diff --git a/arch/x86/kernel/traps.c b/arch/x86/kernel/traps.c
26862index 8c8093b..c93f581 100644
26863--- a/arch/x86/kernel/traps.c
26864+++ b/arch/x86/kernel/traps.c
26865@@ -66,7 +66,7 @@
26866 #include <asm/proto.h>
26867
26868 /* No need to be aligned, but done to keep all IDTs defined the same way. */
26869-gate_desc debug_idt_table[NR_VECTORS] __page_aligned_bss;
26870+gate_desc debug_idt_table[NR_VECTORS] __page_aligned_rodata;
26871 #else
26872 #include <asm/processor-flags.h>
26873 #include <asm/setup.h>
26874@@ -75,7 +75,7 @@ asmlinkage int system_call(void);
26875 #endif
26876
26877 /* Must be page-aligned because the real IDT is used in a fixmap. */
26878-gate_desc idt_table[NR_VECTORS] __page_aligned_bss;
26879+gate_desc idt_table[NR_VECTORS] __page_aligned_rodata;
26880
26881 DECLARE_BITMAP(used_vectors, NR_VECTORS);
26882 EXPORT_SYMBOL_GPL(used_vectors);
26883@@ -107,11 +107,11 @@ static inline void preempt_conditional_cli(struct pt_regs *regs)
26884 }
26885
26886 static int __kprobes
26887-do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
26888+do_trap_no_signal(struct task_struct *tsk, int trapnr, const char *str,
26889 struct pt_regs *regs, long error_code)
26890 {
26891 #ifdef CONFIG_X86_32
26892- if (regs->flags & X86_VM_MASK) {
26893+ if (v8086_mode(regs)) {
26894 /*
26895 * Traps 0, 1, 3, 4, and 5 should be forwarded to vm86.
26896 * On nmi (interrupt 2), do_trap should not be called.
26897@@ -124,12 +124,24 @@ do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
26898 return -1;
26899 }
26900 #endif
26901- if (!user_mode(regs)) {
26902+ if (!user_mode_novm(regs)) {
26903 if (!fixup_exception(regs)) {
26904 tsk->thread.error_code = error_code;
26905 tsk->thread.trap_nr = trapnr;
26906+
26907+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
26908+ if (trapnr == 12 && ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS))
26909+ str = "PAX: suspicious stack segment fault";
26910+#endif
26911+
26912 die(str, regs, error_code);
26913 }
26914+
26915+#ifdef CONFIG_PAX_REFCOUNT
26916+ if (trapnr == 4)
26917+ pax_report_refcount_overflow(regs);
26918+#endif
26919+
26920 return 0;
26921 }
26922
26923@@ -137,7 +149,7 @@ do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
26924 }
26925
26926 static void __kprobes
26927-do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
26928+do_trap(int trapnr, int signr, const char *str, struct pt_regs *regs,
26929 long error_code, siginfo_t *info)
26930 {
26931 struct task_struct *tsk = current;
26932@@ -161,7 +173,7 @@ do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
26933 if (show_unhandled_signals && unhandled_signal(tsk, signr) &&
26934 printk_ratelimit()) {
26935 pr_info("%s[%d] trap %s ip:%lx sp:%lx error:%lx",
26936- tsk->comm, tsk->pid, str,
26937+ tsk->comm, task_pid_nr(tsk), str,
26938 regs->ip, regs->sp, error_code);
26939 print_vma_addr(" in ", regs->ip);
26940 pr_cont("\n");
26941@@ -277,7 +289,7 @@ do_general_protection(struct pt_regs *regs, long error_code)
26942 conditional_sti(regs);
26943
26944 #ifdef CONFIG_X86_32
26945- if (regs->flags & X86_VM_MASK) {
26946+ if (v8086_mode(regs)) {
26947 local_irq_enable();
26948 handle_vm86_fault((struct kernel_vm86_regs *) regs, error_code);
26949 goto exit;
26950@@ -285,18 +297,42 @@ do_general_protection(struct pt_regs *regs, long error_code)
26951 #endif
26952
26953 tsk = current;
26954- if (!user_mode(regs)) {
26955+ if (!user_mode_novm(regs)) {
26956 if (fixup_exception(regs))
26957 goto exit;
26958
26959 tsk->thread.error_code = error_code;
26960 tsk->thread.trap_nr = X86_TRAP_GP;
26961 if (notify_die(DIE_GPF, "general protection fault", regs, error_code,
26962- X86_TRAP_GP, SIGSEGV) != NOTIFY_STOP)
26963+ X86_TRAP_GP, SIGSEGV) != NOTIFY_STOP) {
26964+
26965+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
26966+ if ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS)
26967+ die("PAX: suspicious general protection fault", regs, error_code);
26968+ else
26969+#endif
26970+
26971 die("general protection fault", regs, error_code);
26972+ }
26973 goto exit;
26974 }
26975
26976+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
26977+ if (!(__supported_pte_mask & _PAGE_NX) && tsk->mm && (tsk->mm->pax_flags & MF_PAX_PAGEEXEC)) {
26978+ struct mm_struct *mm = tsk->mm;
26979+ unsigned long limit;
26980+
26981+ down_write(&mm->mmap_sem);
26982+ limit = mm->context.user_cs_limit;
26983+ if (limit < TASK_SIZE) {
26984+ track_exec_limit(mm, limit, TASK_SIZE, VM_EXEC);
26985+ up_write(&mm->mmap_sem);
26986+ return;
26987+ }
26988+ up_write(&mm->mmap_sem);
26989+ }
26990+#endif
26991+
26992 tsk->thread.error_code = error_code;
26993 tsk->thread.trap_nr = X86_TRAP_GP;
26994
26995@@ -457,7 +493,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
26996 /* It's safe to allow irq's after DR6 has been saved */
26997 preempt_conditional_sti(regs);
26998
26999- if (regs->flags & X86_VM_MASK) {
27000+ if (v8086_mode(regs)) {
27001 handle_vm86_trap((struct kernel_vm86_regs *) regs, error_code,
27002 X86_TRAP_DB);
27003 preempt_conditional_cli(regs);
27004@@ -472,7 +508,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
27005 * We already checked v86 mode above, so we can check for kernel mode
27006 * by just checking the CPL of CS.
27007 */
27008- if ((dr6 & DR_STEP) && !user_mode(regs)) {
27009+ if ((dr6 & DR_STEP) && !user_mode_novm(regs)) {
27010 tsk->thread.debugreg6 &= ~DR_STEP;
27011 set_tsk_thread_flag(tsk, TIF_SINGLESTEP);
27012 regs->flags &= ~X86_EFLAGS_TF;
27013@@ -504,7 +540,7 @@ void math_error(struct pt_regs *regs, int error_code, int trapnr)
27014 return;
27015 conditional_sti(regs);
27016
27017- if (!user_mode_vm(regs))
27018+ if (!user_mode(regs))
27019 {
27020 if (!fixup_exception(regs)) {
27021 task->thread.error_code = error_code;
27022diff --git a/arch/x86/kernel/uprobes.c b/arch/x86/kernel/uprobes.c
27023index 2ed8459..7cf329f 100644
27024--- a/arch/x86/kernel/uprobes.c
27025+++ b/arch/x86/kernel/uprobes.c
27026@@ -629,7 +629,7 @@ int arch_uprobe_exception_notify(struct notifier_block *self, unsigned long val,
27027 int ret = NOTIFY_DONE;
27028
27029 /* We are only interested in userspace traps */
27030- if (regs && !user_mode_vm(regs))
27031+ if (regs && !user_mode(regs))
27032 return NOTIFY_DONE;
27033
27034 switch (val) {
27035@@ -719,7 +719,7 @@ arch_uretprobe_hijack_return_addr(unsigned long trampoline_vaddr, struct pt_regs
27036
27037 if (ncopied != rasize) {
27038 pr_err("uprobe: return address clobbered: pid=%d, %%sp=%#lx, "
27039- "%%ip=%#lx\n", current->pid, regs->sp, regs->ip);
27040+ "%%ip=%#lx\n", task_pid_nr(current), regs->sp, regs->ip);
27041
27042 force_sig_info(SIGSEGV, SEND_SIG_FORCED, current);
27043 }
27044diff --git a/arch/x86/kernel/verify_cpu.S b/arch/x86/kernel/verify_cpu.S
27045index b9242ba..50c5edd 100644
27046--- a/arch/x86/kernel/verify_cpu.S
27047+++ b/arch/x86/kernel/verify_cpu.S
27048@@ -20,6 +20,7 @@
27049 * arch/x86/boot/compressed/head_64.S: Boot cpu verification
27050 * arch/x86/kernel/trampoline_64.S: secondary processor verification
27051 * arch/x86/kernel/head_32.S: processor startup
27052+ * arch/x86/kernel/acpi/realmode/wakeup.S: 32bit processor resume
27053 *
27054 * verify_cpu, returns the status of longmode and SSE in register %eax.
27055 * 0: Success 1: Failure
27056diff --git a/arch/x86/kernel/vm86_32.c b/arch/x86/kernel/vm86_32.c
27057index e8edcf5..27f9344 100644
27058--- a/arch/x86/kernel/vm86_32.c
27059+++ b/arch/x86/kernel/vm86_32.c
27060@@ -44,6 +44,7 @@
27061 #include <linux/ptrace.h>
27062 #include <linux/audit.h>
27063 #include <linux/stddef.h>
27064+#include <linux/grsecurity.h>
27065
27066 #include <asm/uaccess.h>
27067 #include <asm/io.h>
27068@@ -150,7 +151,7 @@ struct pt_regs *save_v86_state(struct kernel_vm86_regs *regs)
27069 do_exit(SIGSEGV);
27070 }
27071
27072- tss = &per_cpu(init_tss, get_cpu());
27073+ tss = init_tss + get_cpu();
27074 current->thread.sp0 = current->thread.saved_sp0;
27075 current->thread.sysenter_cs = __KERNEL_CS;
27076 load_sp0(tss, &current->thread);
27077@@ -214,6 +215,14 @@ SYSCALL_DEFINE1(vm86old, struct vm86_struct __user *, v86)
27078
27079 if (tsk->thread.saved_sp0)
27080 return -EPERM;
27081+
27082+#ifdef CONFIG_GRKERNSEC_VM86
27083+ if (!capable(CAP_SYS_RAWIO)) {
27084+ gr_handle_vm86();
27085+ return -EPERM;
27086+ }
27087+#endif
27088+
27089 tmp = copy_vm86_regs_from_user(&info.regs, &v86->regs,
27090 offsetof(struct kernel_vm86_struct, vm86plus) -
27091 sizeof(info.regs));
27092@@ -238,6 +247,13 @@ SYSCALL_DEFINE2(vm86, unsigned long, cmd, unsigned long, arg)
27093 int tmp;
27094 struct vm86plus_struct __user *v86;
27095
27096+#ifdef CONFIG_GRKERNSEC_VM86
27097+ if (!capable(CAP_SYS_RAWIO)) {
27098+ gr_handle_vm86();
27099+ return -EPERM;
27100+ }
27101+#endif
27102+
27103 tsk = current;
27104 switch (cmd) {
27105 case VM86_REQUEST_IRQ:
27106@@ -318,7 +334,7 @@ static void do_sys_vm86(struct kernel_vm86_struct *info, struct task_struct *tsk
27107 tsk->thread.saved_fs = info->regs32->fs;
27108 tsk->thread.saved_gs = get_user_gs(info->regs32);
27109
27110- tss = &per_cpu(init_tss, get_cpu());
27111+ tss = init_tss + get_cpu();
27112 tsk->thread.sp0 = (unsigned long) &info->VM86_TSS_ESP0;
27113 if (cpu_has_sep)
27114 tsk->thread.sysenter_cs = 0;
27115@@ -525,7 +541,7 @@ static void do_int(struct kernel_vm86_regs *regs, int i,
27116 goto cannot_handle;
27117 if (i == 0x21 && is_revectored(AH(regs), &KVM86->int21_revectored))
27118 goto cannot_handle;
27119- intr_ptr = (unsigned long __user *) (i << 2);
27120+ intr_ptr = (__force unsigned long __user *) (i << 2);
27121 if (get_user(segoffs, intr_ptr))
27122 goto cannot_handle;
27123 if ((segoffs >> 16) == BIOSSEG)
27124diff --git a/arch/x86/kernel/vmlinux.lds.S b/arch/x86/kernel/vmlinux.lds.S
27125index 10c4f30..65408b9 100644
27126--- a/arch/x86/kernel/vmlinux.lds.S
27127+++ b/arch/x86/kernel/vmlinux.lds.S
27128@@ -26,6 +26,13 @@
27129 #include <asm/page_types.h>
27130 #include <asm/cache.h>
27131 #include <asm/boot.h>
27132+#include <asm/segment.h>
27133+
27134+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
27135+#define __KERNEL_TEXT_OFFSET (LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR)
27136+#else
27137+#define __KERNEL_TEXT_OFFSET 0
27138+#endif
27139
27140 #undef i386 /* in case the preprocessor is a 32bit one */
27141
27142@@ -69,30 +76,43 @@ jiffies_64 = jiffies;
27143
27144 PHDRS {
27145 text PT_LOAD FLAGS(5); /* R_E */
27146+#ifdef CONFIG_X86_32
27147+ module PT_LOAD FLAGS(5); /* R_E */
27148+#endif
27149+#ifdef CONFIG_XEN
27150+ rodata PT_LOAD FLAGS(5); /* R_E */
27151+#else
27152+ rodata PT_LOAD FLAGS(4); /* R__ */
27153+#endif
27154 data PT_LOAD FLAGS(6); /* RW_ */
27155-#ifdef CONFIG_X86_64
27156+ init.begin PT_LOAD FLAGS(6); /* RW_ */
27157 #ifdef CONFIG_SMP
27158 percpu PT_LOAD FLAGS(6); /* RW_ */
27159 #endif
27160+ text.init PT_LOAD FLAGS(5); /* R_E */
27161+ text.exit PT_LOAD FLAGS(5); /* R_E */
27162 init PT_LOAD FLAGS(7); /* RWE */
27163-#endif
27164 note PT_NOTE FLAGS(0); /* ___ */
27165 }
27166
27167 SECTIONS
27168 {
27169 #ifdef CONFIG_X86_32
27170- . = LOAD_OFFSET + LOAD_PHYSICAL_ADDR;
27171- phys_startup_32 = startup_32 - LOAD_OFFSET;
27172+ . = LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR;
27173 #else
27174- . = __START_KERNEL;
27175- phys_startup_64 = startup_64 - LOAD_OFFSET;
27176+ . = __START_KERNEL;
27177 #endif
27178
27179 /* Text and read-only data */
27180- .text : AT(ADDR(.text) - LOAD_OFFSET) {
27181- _text = .;
27182+ .text (. - __KERNEL_TEXT_OFFSET): AT(ADDR(.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
27183 /* bootstrapping code */
27184+#ifdef CONFIG_X86_32
27185+ phys_startup_32 = startup_32 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
27186+#else
27187+ phys_startup_64 = startup_64 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
27188+#endif
27189+ __LOAD_PHYSICAL_ADDR = . - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
27190+ _text = .;
27191 HEAD_TEXT
27192 . = ALIGN(8);
27193 _stext = .;
27194@@ -104,13 +124,47 @@ SECTIONS
27195 IRQENTRY_TEXT
27196 *(.fixup)
27197 *(.gnu.warning)
27198- /* End of text section */
27199- _etext = .;
27200 } :text = 0x9090
27201
27202- NOTES :text :note
27203+ . += __KERNEL_TEXT_OFFSET;
27204
27205- EXCEPTION_TABLE(16) :text = 0x9090
27206+#ifdef CONFIG_X86_32
27207+ . = ALIGN(PAGE_SIZE);
27208+ .module.text : AT(ADDR(.module.text) - LOAD_OFFSET) {
27209+
27210+#ifdef CONFIG_PAX_KERNEXEC
27211+ MODULES_EXEC_VADDR = .;
27212+ BYTE(0)
27213+ . += (CONFIG_PAX_KERNEXEC_MODULE_TEXT * 1024 * 1024);
27214+ . = ALIGN(HPAGE_SIZE) - 1;
27215+ MODULES_EXEC_END = .;
27216+#endif
27217+
27218+ } :module
27219+#endif
27220+
27221+ .text.end : AT(ADDR(.text.end) - LOAD_OFFSET) {
27222+ /* End of text section */
27223+ BYTE(0)
27224+ _etext = . - __KERNEL_TEXT_OFFSET;
27225+ }
27226+
27227+#ifdef CONFIG_X86_32
27228+ . = ALIGN(PAGE_SIZE);
27229+ .rodata.page_aligned : AT(ADDR(.rodata.page_aligned) - LOAD_OFFSET) {
27230+ . = ALIGN(PAGE_SIZE);
27231+ *(.empty_zero_page)
27232+ *(.initial_pg_fixmap)
27233+ *(.initial_pg_pmd)
27234+ *(.initial_page_table)
27235+ *(.swapper_pg_dir)
27236+ } :rodata
27237+#endif
27238+
27239+ . = ALIGN(PAGE_SIZE);
27240+ NOTES :rodata :note
27241+
27242+ EXCEPTION_TABLE(16) :rodata
27243
27244 #if defined(CONFIG_DEBUG_RODATA)
27245 /* .text should occupy whole number of pages */
27246@@ -122,16 +176,20 @@ SECTIONS
27247
27248 /* Data */
27249 .data : AT(ADDR(.data) - LOAD_OFFSET) {
27250+
27251+#ifdef CONFIG_PAX_KERNEXEC
27252+ . = ALIGN(HPAGE_SIZE);
27253+#else
27254+ . = ALIGN(PAGE_SIZE);
27255+#endif
27256+
27257 /* Start of data section */
27258 _sdata = .;
27259
27260 /* init_task */
27261 INIT_TASK_DATA(THREAD_SIZE)
27262
27263-#ifdef CONFIG_X86_32
27264- /* 32 bit has nosave before _edata */
27265 NOSAVE_DATA
27266-#endif
27267
27268 PAGE_ALIGNED_DATA(PAGE_SIZE)
27269
27270@@ -172,12 +230,19 @@ SECTIONS
27271 #endif /* CONFIG_X86_64 */
27272
27273 /* Init code and data - will be freed after init */
27274- . = ALIGN(PAGE_SIZE);
27275 .init.begin : AT(ADDR(.init.begin) - LOAD_OFFSET) {
27276+ BYTE(0)
27277+
27278+#ifdef CONFIG_PAX_KERNEXEC
27279+ . = ALIGN(HPAGE_SIZE);
27280+#else
27281+ . = ALIGN(PAGE_SIZE);
27282+#endif
27283+
27284 __init_begin = .; /* paired with __init_end */
27285- }
27286+ } :init.begin
27287
27288-#if defined(CONFIG_X86_64) && defined(CONFIG_SMP)
27289+#ifdef CONFIG_SMP
27290 /*
27291 * percpu offsets are zero-based on SMP. PERCPU_VADDR() changes the
27292 * output PHDR, so the next output section - .init.text - should
27293@@ -186,12 +251,27 @@ SECTIONS
27294 PERCPU_VADDR(INTERNODE_CACHE_BYTES, 0, :percpu)
27295 #endif
27296
27297- INIT_TEXT_SECTION(PAGE_SIZE)
27298-#ifdef CONFIG_X86_64
27299- :init
27300-#endif
27301+ . = ALIGN(PAGE_SIZE);
27302+ init_begin = .;
27303+ .init.text (. - __KERNEL_TEXT_OFFSET): AT(init_begin - LOAD_OFFSET) {
27304+ VMLINUX_SYMBOL(_sinittext) = .;
27305+ INIT_TEXT
27306+ VMLINUX_SYMBOL(_einittext) = .;
27307+ . = ALIGN(PAGE_SIZE);
27308+ } :text.init
27309
27310- INIT_DATA_SECTION(16)
27311+ /*
27312+ * .exit.text is discard at runtime, not link time, to deal with
27313+ * references from .altinstructions and .eh_frame
27314+ */
27315+ .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
27316+ EXIT_TEXT
27317+ . = ALIGN(16);
27318+ } :text.exit
27319+ . = init_begin + SIZEOF(.init.text) + SIZEOF(.exit.text);
27320+
27321+ . = ALIGN(PAGE_SIZE);
27322+ INIT_DATA_SECTION(16) :init
27323
27324 .x86_cpu_dev.init : AT(ADDR(.x86_cpu_dev.init) - LOAD_OFFSET) {
27325 __x86_cpu_dev_start = .;
27326@@ -253,19 +333,12 @@ SECTIONS
27327 }
27328
27329 . = ALIGN(8);
27330- /*
27331- * .exit.text is discard at runtime, not link time, to deal with
27332- * references from .altinstructions and .eh_frame
27333- */
27334- .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET) {
27335- EXIT_TEXT
27336- }
27337
27338 .exit.data : AT(ADDR(.exit.data) - LOAD_OFFSET) {
27339 EXIT_DATA
27340 }
27341
27342-#if !defined(CONFIG_X86_64) || !defined(CONFIG_SMP)
27343+#ifndef CONFIG_SMP
27344 PERCPU_SECTION(INTERNODE_CACHE_BYTES)
27345 #endif
27346
27347@@ -284,16 +357,10 @@ SECTIONS
27348 .smp_locks : AT(ADDR(.smp_locks) - LOAD_OFFSET) {
27349 __smp_locks = .;
27350 *(.smp_locks)
27351- . = ALIGN(PAGE_SIZE);
27352 __smp_locks_end = .;
27353+ . = ALIGN(PAGE_SIZE);
27354 }
27355
27356-#ifdef CONFIG_X86_64
27357- .data_nosave : AT(ADDR(.data_nosave) - LOAD_OFFSET) {
27358- NOSAVE_DATA
27359- }
27360-#endif
27361-
27362 /* BSS */
27363 . = ALIGN(PAGE_SIZE);
27364 .bss : AT(ADDR(.bss) - LOAD_OFFSET) {
27365@@ -309,6 +376,7 @@ SECTIONS
27366 __brk_base = .;
27367 . += 64 * 1024; /* 64k alignment slop space */
27368 *(.brk_reservation) /* areas brk users have reserved */
27369+ . = ALIGN(HPAGE_SIZE);
27370 __brk_limit = .;
27371 }
27372
27373@@ -335,13 +403,12 @@ SECTIONS
27374 * for the boot processor.
27375 */
27376 #define INIT_PER_CPU(x) init_per_cpu__##x = x + __per_cpu_load
27377-INIT_PER_CPU(gdt_page);
27378 INIT_PER_CPU(irq_stack_union);
27379
27380 /*
27381 * Build-time check on the image size:
27382 */
27383-. = ASSERT((_end - _text <= KERNEL_IMAGE_SIZE),
27384+. = ASSERT((_end - _text - __KERNEL_TEXT_OFFSET <= KERNEL_IMAGE_SIZE),
27385 "kernel image bigger than KERNEL_IMAGE_SIZE");
27386
27387 #ifdef CONFIG_SMP
27388diff --git a/arch/x86/kernel/vsyscall_64.c b/arch/x86/kernel/vsyscall_64.c
27389index 1f96f93..d5c8f7a 100644
27390--- a/arch/x86/kernel/vsyscall_64.c
27391+++ b/arch/x86/kernel/vsyscall_64.c
27392@@ -56,15 +56,13 @@
27393 DEFINE_VVAR(int, vgetcpu_mode);
27394 DEFINE_VVAR(struct vsyscall_gtod_data, vsyscall_gtod_data);
27395
27396-static enum { EMULATE, NATIVE, NONE } vsyscall_mode = EMULATE;
27397+static enum { EMULATE, NONE } vsyscall_mode = EMULATE;
27398
27399 static int __init vsyscall_setup(char *str)
27400 {
27401 if (str) {
27402 if (!strcmp("emulate", str))
27403 vsyscall_mode = EMULATE;
27404- else if (!strcmp("native", str))
27405- vsyscall_mode = NATIVE;
27406 else if (!strcmp("none", str))
27407 vsyscall_mode = NONE;
27408 else
27409@@ -323,8 +321,7 @@ do_ret:
27410 return true;
27411
27412 sigsegv:
27413- force_sig(SIGSEGV, current);
27414- return true;
27415+ do_group_exit(SIGKILL);
27416 }
27417
27418 /*
27419@@ -377,10 +374,7 @@ void __init map_vsyscall(void)
27420 extern char __vvar_page;
27421 unsigned long physaddr_vvar_page = __pa_symbol(&__vvar_page);
27422
27423- __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall,
27424- vsyscall_mode == NATIVE
27425- ? PAGE_KERNEL_VSYSCALL
27426- : PAGE_KERNEL_VVAR);
27427+ __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall, PAGE_KERNEL_VVAR);
27428 BUILD_BUG_ON((unsigned long)__fix_to_virt(VSYSCALL_FIRST_PAGE) !=
27429 (unsigned long)VSYSCALL_START);
27430
27431diff --git a/arch/x86/kernel/x8664_ksyms_64.c b/arch/x86/kernel/x8664_ksyms_64.c
27432index b014d94..e775258 100644
27433--- a/arch/x86/kernel/x8664_ksyms_64.c
27434+++ b/arch/x86/kernel/x8664_ksyms_64.c
27435@@ -34,8 +34,6 @@ EXPORT_SYMBOL(copy_user_generic_string);
27436 EXPORT_SYMBOL(copy_user_generic_unrolled);
27437 EXPORT_SYMBOL(copy_user_enhanced_fast_string);
27438 EXPORT_SYMBOL(__copy_user_nocache);
27439-EXPORT_SYMBOL(_copy_from_user);
27440-EXPORT_SYMBOL(_copy_to_user);
27441
27442 EXPORT_SYMBOL(copy_page);
27443 EXPORT_SYMBOL(clear_page);
27444@@ -66,3 +64,7 @@ EXPORT_SYMBOL(empty_zero_page);
27445 #ifndef CONFIG_PARAVIRT
27446 EXPORT_SYMBOL(native_load_gs_index);
27447 #endif
27448+
27449+#ifdef CONFIG_PAX_PER_CPU_PGD
27450+EXPORT_SYMBOL(cpu_pgd);
27451+#endif
27452diff --git a/arch/x86/kernel/x86_init.c b/arch/x86/kernel/x86_init.c
27453index 8ce0072..431a0e7 100644
27454--- a/arch/x86/kernel/x86_init.c
27455+++ b/arch/x86/kernel/x86_init.c
27456@@ -93,7 +93,7 @@ struct x86_cpuinit_ops x86_cpuinit = {
27457 static void default_nmi_init(void) { };
27458 static int default_i8042_detect(void) { return 1; };
27459
27460-struct x86_platform_ops x86_platform = {
27461+struct x86_platform_ops x86_platform __read_only = {
27462 .calibrate_tsc = native_calibrate_tsc,
27463 .get_wallclock = mach_get_cmos_time,
27464 .set_wallclock = mach_set_rtc_mmss,
27465@@ -109,7 +109,7 @@ struct x86_platform_ops x86_platform = {
27466 EXPORT_SYMBOL_GPL(x86_platform);
27467
27468 #if defined(CONFIG_PCI_MSI)
27469-struct x86_msi_ops x86_msi = {
27470+struct x86_msi_ops x86_msi __read_only = {
27471 .setup_msi_irqs = native_setup_msi_irqs,
27472 .compose_msi_msg = native_compose_msi_msg,
27473 .teardown_msi_irq = native_teardown_msi_irq,
27474@@ -140,7 +140,7 @@ void arch_restore_msi_irqs(struct pci_dev *dev, int irq)
27475 }
27476 #endif
27477
27478-struct x86_io_apic_ops x86_io_apic_ops = {
27479+struct x86_io_apic_ops x86_io_apic_ops __read_only = {
27480 .init = native_io_apic_init_mappings,
27481 .read = native_io_apic_read,
27482 .write = native_io_apic_write,
27483diff --git a/arch/x86/kernel/xsave.c b/arch/x86/kernel/xsave.c
27484index 422fd82..c3687ca 100644
27485--- a/arch/x86/kernel/xsave.c
27486+++ b/arch/x86/kernel/xsave.c
27487@@ -199,6 +199,7 @@ static inline int save_user_xstate(struct xsave_struct __user *buf)
27488 {
27489 int err;
27490
27491+ buf = (struct xsave_struct __user *)____m(buf);
27492 if (use_xsave())
27493 err = xsave_user(buf);
27494 else if (use_fxsr())
27495@@ -311,6 +312,7 @@ sanitize_restored_xstate(struct task_struct *tsk,
27496 */
27497 static inline int restore_user_xstate(void __user *buf, u64 xbv, int fx_only)
27498 {
27499+ buf = (void __user *)____m(buf);
27500 if (use_xsave()) {
27501 if ((unsigned long)buf % 64 || fx_only) {
27502 u64 init_bv = pcntxt_mask & ~XSTATE_FPSSE;
27503diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c
27504index b110fe6..d9c19f2 100644
27505--- a/arch/x86/kvm/cpuid.c
27506+++ b/arch/x86/kvm/cpuid.c
27507@@ -124,15 +124,20 @@ int kvm_vcpu_ioctl_set_cpuid2(struct kvm_vcpu *vcpu,
27508 struct kvm_cpuid2 *cpuid,
27509 struct kvm_cpuid_entry2 __user *entries)
27510 {
27511- int r;
27512+ int r, i;
27513
27514 r = -E2BIG;
27515 if (cpuid->nent > KVM_MAX_CPUID_ENTRIES)
27516 goto out;
27517 r = -EFAULT;
27518- if (copy_from_user(&vcpu->arch.cpuid_entries, entries,
27519- cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
27520+ if (!access_ok(VERIFY_READ, entries, cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
27521 goto out;
27522+ for (i = 0; i < cpuid->nent; ++i) {
27523+ struct kvm_cpuid_entry2 cpuid_entry;
27524+ if (__copy_from_user(&cpuid_entry, entries + i, sizeof(cpuid_entry)))
27525+ goto out;
27526+ vcpu->arch.cpuid_entries[i] = cpuid_entry;
27527+ }
27528 vcpu->arch.cpuid_nent = cpuid->nent;
27529 kvm_apic_set_version(vcpu);
27530 kvm_x86_ops->cpuid_update(vcpu);
27531@@ -147,15 +152,19 @@ int kvm_vcpu_ioctl_get_cpuid2(struct kvm_vcpu *vcpu,
27532 struct kvm_cpuid2 *cpuid,
27533 struct kvm_cpuid_entry2 __user *entries)
27534 {
27535- int r;
27536+ int r, i;
27537
27538 r = -E2BIG;
27539 if (cpuid->nent < vcpu->arch.cpuid_nent)
27540 goto out;
27541 r = -EFAULT;
27542- if (copy_to_user(entries, &vcpu->arch.cpuid_entries,
27543- vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
27544+ if (!access_ok(VERIFY_WRITE, entries, vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
27545 goto out;
27546+ for (i = 0; i < vcpu->arch.cpuid_nent; ++i) {
27547+ struct kvm_cpuid_entry2 cpuid_entry = vcpu->arch.cpuid_entries[i];
27548+ if (__copy_to_user(entries + i, &cpuid_entry, sizeof(cpuid_entry)))
27549+ goto out;
27550+ }
27551 return 0;
27552
27553 out:
27554diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c
27555index 1673940..4bce95e 100644
27556--- a/arch/x86/kvm/lapic.c
27557+++ b/arch/x86/kvm/lapic.c
27558@@ -55,7 +55,7 @@
27559 #define APIC_BUS_CYCLE_NS 1
27560
27561 /* #define apic_debug(fmt,arg...) printk(KERN_WARNING fmt,##arg) */
27562-#define apic_debug(fmt, arg...)
27563+#define apic_debug(fmt, arg...) do {} while (0)
27564
27565 #define APIC_LVT_NUM 6
27566 /* 14 is the version for Xeon and Pentium 8.4.8*/
27567diff --git a/arch/x86/kvm/paging_tmpl.h b/arch/x86/kvm/paging_tmpl.h
27568index ad75d77..a679d32 100644
27569--- a/arch/x86/kvm/paging_tmpl.h
27570+++ b/arch/x86/kvm/paging_tmpl.h
27571@@ -331,7 +331,7 @@ retry_walk:
27572 if (unlikely(kvm_is_error_hva(host_addr)))
27573 goto error;
27574
27575- ptep_user = (pt_element_t __user *)((void *)host_addr + offset);
27576+ ptep_user = (pt_element_t __force_user *)((void *)host_addr + offset);
27577 if (unlikely(__copy_from_user(&pte, ptep_user, sizeof(pte))))
27578 goto error;
27579 walker->ptep_user[walker->level - 1] = ptep_user;
27580diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
27581index c0bc803..6837a50 100644
27582--- a/arch/x86/kvm/svm.c
27583+++ b/arch/x86/kvm/svm.c
27584@@ -3501,7 +3501,11 @@ static void reload_tss(struct kvm_vcpu *vcpu)
27585 int cpu = raw_smp_processor_id();
27586
27587 struct svm_cpu_data *sd = per_cpu(svm_data, cpu);
27588+
27589+ pax_open_kernel();
27590 sd->tss_desc->type = 9; /* available 32/64-bit TSS */
27591+ pax_close_kernel();
27592+
27593 load_TR_desc();
27594 }
27595
27596@@ -3902,6 +3906,10 @@ static void svm_vcpu_run(struct kvm_vcpu *vcpu)
27597 #endif
27598 #endif
27599
27600+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
27601+ __set_fs(current_thread_info()->addr_limit);
27602+#endif
27603+
27604 reload_tss(vcpu);
27605
27606 local_irq_disable();
27607diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
27608index 6128914..8be1dd2 100644
27609--- a/arch/x86/kvm/vmx.c
27610+++ b/arch/x86/kvm/vmx.c
27611@@ -1316,12 +1316,12 @@ static void vmcs_write64(unsigned long field, u64 value)
27612 #endif
27613 }
27614
27615-static void vmcs_clear_bits(unsigned long field, u32 mask)
27616+static void vmcs_clear_bits(unsigned long field, unsigned long mask)
27617 {
27618 vmcs_writel(field, vmcs_readl(field) & ~mask);
27619 }
27620
27621-static void vmcs_set_bits(unsigned long field, u32 mask)
27622+static void vmcs_set_bits(unsigned long field, unsigned long mask)
27623 {
27624 vmcs_writel(field, vmcs_readl(field) | mask);
27625 }
27626@@ -1522,7 +1522,11 @@ static void reload_tss(void)
27627 struct desc_struct *descs;
27628
27629 descs = (void *)gdt->address;
27630+
27631+ pax_open_kernel();
27632 descs[GDT_ENTRY_TSS].type = 9; /* available TSS */
27633+ pax_close_kernel();
27634+
27635 load_TR_desc();
27636 }
27637
27638@@ -1746,6 +1750,10 @@ static void vmx_vcpu_load(struct kvm_vcpu *vcpu, int cpu)
27639 vmcs_writel(HOST_TR_BASE, kvm_read_tr_base()); /* 22.2.4 */
27640 vmcs_writel(HOST_GDTR_BASE, gdt->address); /* 22.2.4 */
27641
27642+#ifdef CONFIG_PAX_PER_CPU_PGD
27643+ vmcs_writel(HOST_CR3, read_cr3()); /* 22.2.3 FIXME: shadow tables */
27644+#endif
27645+
27646 rdmsrl(MSR_IA32_SYSENTER_ESP, sysenter_esp);
27647 vmcs_writel(HOST_IA32_SYSENTER_ESP, sysenter_esp); /* 22.2.3 */
27648 vmx->loaded_vmcs->cpu = cpu;
27649@@ -2037,7 +2045,7 @@ static void setup_msrs(struct vcpu_vmx *vmx)
27650 * reads and returns guest's timestamp counter "register"
27651 * guest_tsc = host_tsc + tsc_offset -- 21.3
27652 */
27653-static u64 guest_read_tsc(void)
27654+static u64 __intentional_overflow(-1) guest_read_tsc(void)
27655 {
27656 u64 host_tsc, tsc_offset;
27657
27658@@ -2982,8 +2990,11 @@ static __init int hardware_setup(void)
27659 if (!cpu_has_vmx_flexpriority())
27660 flexpriority_enabled = 0;
27661
27662- if (!cpu_has_vmx_tpr_shadow())
27663- kvm_x86_ops->update_cr8_intercept = NULL;
27664+ if (!cpu_has_vmx_tpr_shadow()) {
27665+ pax_open_kernel();
27666+ *(void **)&kvm_x86_ops->update_cr8_intercept = NULL;
27667+ pax_close_kernel();
27668+ }
27669
27670 if (enable_ept && !cpu_has_vmx_ept_2m_page())
27671 kvm_disable_largepages();
27672@@ -2994,13 +3005,15 @@ static __init int hardware_setup(void)
27673 if (!cpu_has_vmx_apicv())
27674 enable_apicv = 0;
27675
27676+ pax_open_kernel();
27677 if (enable_apicv)
27678- kvm_x86_ops->update_cr8_intercept = NULL;
27679+ *(void **)&kvm_x86_ops->update_cr8_intercept = NULL;
27680 else {
27681- kvm_x86_ops->hwapic_irr_update = NULL;
27682- kvm_x86_ops->deliver_posted_interrupt = NULL;
27683- kvm_x86_ops->sync_pir_to_irr = vmx_sync_pir_to_irr_dummy;
27684+ *(void **)&kvm_x86_ops->hwapic_irr_update = NULL;
27685+ *(void **)&kvm_x86_ops->deliver_posted_interrupt = NULL;
27686+ *(void **)&kvm_x86_ops->sync_pir_to_irr = vmx_sync_pir_to_irr_dummy;
27687 }
27688+ pax_close_kernel();
27689
27690 if (nested)
27691 nested_vmx_setup_ctls_msrs();
27692@@ -4127,7 +4140,10 @@ static void vmx_set_constant_host_state(struct vcpu_vmx *vmx)
27693
27694 vmcs_writel(HOST_CR0, read_cr0() & ~X86_CR0_TS); /* 22.2.3 */
27695 vmcs_writel(HOST_CR4, read_cr4()); /* 22.2.3, 22.2.5 */
27696+
27697+#ifndef CONFIG_PAX_PER_CPU_PGD
27698 vmcs_writel(HOST_CR3, read_cr3()); /* 22.2.3 FIXME: shadow tables */
27699+#endif
27700
27701 vmcs_write16(HOST_CS_SELECTOR, __KERNEL_CS); /* 22.2.4 */
27702 #ifdef CONFIG_X86_64
27703@@ -4149,7 +4165,7 @@ static void vmx_set_constant_host_state(struct vcpu_vmx *vmx)
27704 vmcs_writel(HOST_IDTR_BASE, dt.address); /* 22.2.4 */
27705 vmx->host_idt_base = dt.address;
27706
27707- vmcs_writel(HOST_RIP, vmx_return); /* 22.2.5 */
27708+ vmcs_writel(HOST_RIP, ktla_ktva(vmx_return)); /* 22.2.5 */
27709
27710 rdmsr(MSR_IA32_SYSENTER_CS, low32, high32);
27711 vmcs_write32(HOST_IA32_SYSENTER_CS, low32);
27712@@ -7191,6 +7207,12 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
27713 "jmp 2f \n\t"
27714 "1: " __ex(ASM_VMX_VMRESUME) "\n\t"
27715 "2: "
27716+
27717+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
27718+ "ljmp %[cs],$3f\n\t"
27719+ "3: "
27720+#endif
27721+
27722 /* Save guest registers, load host registers, keep flags */
27723 "mov %0, %c[wordsize](%%" _ASM_SP ") \n\t"
27724 "pop %0 \n\t"
27725@@ -7243,6 +7265,11 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
27726 #endif
27727 [cr2]"i"(offsetof(struct vcpu_vmx, vcpu.arch.cr2)),
27728 [wordsize]"i"(sizeof(ulong))
27729+
27730+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
27731+ ,[cs]"i"(__KERNEL_CS)
27732+#endif
27733+
27734 : "cc", "memory"
27735 #ifdef CONFIG_X86_64
27736 , "rax", "rbx", "rdi", "rsi"
27737@@ -7256,7 +7283,7 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
27738 if (debugctlmsr)
27739 update_debugctlmsr(debugctlmsr);
27740
27741-#ifndef CONFIG_X86_64
27742+#ifdef CONFIG_X86_32
27743 /*
27744 * The sysexit path does not restore ds/es, so we must set them to
27745 * a reasonable value ourselves.
27746@@ -7265,8 +7292,18 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
27747 * may be executed in interrupt context, which saves and restore segments
27748 * around it, nullifying its effect.
27749 */
27750- loadsegment(ds, __USER_DS);
27751- loadsegment(es, __USER_DS);
27752+ loadsegment(ds, __KERNEL_DS);
27753+ loadsegment(es, __KERNEL_DS);
27754+ loadsegment(ss, __KERNEL_DS);
27755+
27756+#ifdef CONFIG_PAX_KERNEXEC
27757+ loadsegment(fs, __KERNEL_PERCPU);
27758+#endif
27759+
27760+#ifdef CONFIG_PAX_MEMORY_UDEREF
27761+ __set_fs(current_thread_info()->addr_limit);
27762+#endif
27763+
27764 #endif
27765
27766 vcpu->arch.regs_avail = ~((1 << VCPU_REGS_RIP) | (1 << VCPU_REGS_RSP)
27767diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
27768index eb9b9c9..0f30b12 100644
27769--- a/arch/x86/kvm/x86.c
27770+++ b/arch/x86/kvm/x86.c
27771@@ -1779,8 +1779,8 @@ static int xen_hvm_config(struct kvm_vcpu *vcpu, u64 data)
27772 {
27773 struct kvm *kvm = vcpu->kvm;
27774 int lm = is_long_mode(vcpu);
27775- u8 *blob_addr = lm ? (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_64
27776- : (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
27777+ u8 __user *blob_addr = lm ? (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_64
27778+ : (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
27779 u8 blob_size = lm ? kvm->arch.xen_hvm_config.blob_size_64
27780 : kvm->arch.xen_hvm_config.blob_size_32;
27781 u32 page_num = data & ~PAGE_MASK;
27782@@ -2663,6 +2663,8 @@ long kvm_arch_dev_ioctl(struct file *filp,
27783 if (n < msr_list.nmsrs)
27784 goto out;
27785 r = -EFAULT;
27786+ if (num_msrs_to_save > ARRAY_SIZE(msrs_to_save))
27787+ goto out;
27788 if (copy_to_user(user_msr_list->indices, &msrs_to_save,
27789 num_msrs_to_save * sizeof(u32)))
27790 goto out;
27791@@ -5461,7 +5463,7 @@ static struct notifier_block pvclock_gtod_notifier = {
27792 };
27793 #endif
27794
27795-int kvm_arch_init(void *opaque)
27796+int kvm_arch_init(const void *opaque)
27797 {
27798 int r;
27799 struct kvm_x86_ops *ops = opaque;
27800diff --git a/arch/x86/lguest/boot.c b/arch/x86/lguest/boot.c
27801index bdf8532..f63c587 100644
27802--- a/arch/x86/lguest/boot.c
27803+++ b/arch/x86/lguest/boot.c
27804@@ -1206,9 +1206,10 @@ static __init int early_put_chars(u32 vtermno, const char *buf, int count)
27805 * Rebooting also tells the Host we're finished, but the RESTART flag tells the
27806 * Launcher to reboot us.
27807 */
27808-static void lguest_restart(char *reason)
27809+static __noreturn void lguest_restart(char *reason)
27810 {
27811 hcall(LHCALL_SHUTDOWN, __pa(reason), LGUEST_SHUTDOWN_RESTART, 0, 0);
27812+ BUG();
27813 }
27814
27815 /*G:050
27816diff --git a/arch/x86/lib/atomic64_386_32.S b/arch/x86/lib/atomic64_386_32.S
27817index 00933d5..3a64af9 100644
27818--- a/arch/x86/lib/atomic64_386_32.S
27819+++ b/arch/x86/lib/atomic64_386_32.S
27820@@ -48,6 +48,10 @@ BEGIN(read)
27821 movl (v), %eax
27822 movl 4(v), %edx
27823 RET_ENDP
27824+BEGIN(read_unchecked)
27825+ movl (v), %eax
27826+ movl 4(v), %edx
27827+RET_ENDP
27828 #undef v
27829
27830 #define v %esi
27831@@ -55,6 +59,10 @@ BEGIN(set)
27832 movl %ebx, (v)
27833 movl %ecx, 4(v)
27834 RET_ENDP
27835+BEGIN(set_unchecked)
27836+ movl %ebx, (v)
27837+ movl %ecx, 4(v)
27838+RET_ENDP
27839 #undef v
27840
27841 #define v %esi
27842@@ -70,6 +78,20 @@ RET_ENDP
27843 BEGIN(add)
27844 addl %eax, (v)
27845 adcl %edx, 4(v)
27846+
27847+#ifdef CONFIG_PAX_REFCOUNT
27848+ jno 0f
27849+ subl %eax, (v)
27850+ sbbl %edx, 4(v)
27851+ int $4
27852+0:
27853+ _ASM_EXTABLE(0b, 0b)
27854+#endif
27855+
27856+RET_ENDP
27857+BEGIN(add_unchecked)
27858+ addl %eax, (v)
27859+ adcl %edx, 4(v)
27860 RET_ENDP
27861 #undef v
27862
27863@@ -77,6 +99,24 @@ RET_ENDP
27864 BEGIN(add_return)
27865 addl (v), %eax
27866 adcl 4(v), %edx
27867+
27868+#ifdef CONFIG_PAX_REFCOUNT
27869+ into
27870+1234:
27871+ _ASM_EXTABLE(1234b, 2f)
27872+#endif
27873+
27874+ movl %eax, (v)
27875+ movl %edx, 4(v)
27876+
27877+#ifdef CONFIG_PAX_REFCOUNT
27878+2:
27879+#endif
27880+
27881+RET_ENDP
27882+BEGIN(add_return_unchecked)
27883+ addl (v), %eax
27884+ adcl 4(v), %edx
27885 movl %eax, (v)
27886 movl %edx, 4(v)
27887 RET_ENDP
27888@@ -86,6 +126,20 @@ RET_ENDP
27889 BEGIN(sub)
27890 subl %eax, (v)
27891 sbbl %edx, 4(v)
27892+
27893+#ifdef CONFIG_PAX_REFCOUNT
27894+ jno 0f
27895+ addl %eax, (v)
27896+ adcl %edx, 4(v)
27897+ int $4
27898+0:
27899+ _ASM_EXTABLE(0b, 0b)
27900+#endif
27901+
27902+RET_ENDP
27903+BEGIN(sub_unchecked)
27904+ subl %eax, (v)
27905+ sbbl %edx, 4(v)
27906 RET_ENDP
27907 #undef v
27908
27909@@ -96,6 +150,27 @@ BEGIN(sub_return)
27910 sbbl $0, %edx
27911 addl (v), %eax
27912 adcl 4(v), %edx
27913+
27914+#ifdef CONFIG_PAX_REFCOUNT
27915+ into
27916+1234:
27917+ _ASM_EXTABLE(1234b, 2f)
27918+#endif
27919+
27920+ movl %eax, (v)
27921+ movl %edx, 4(v)
27922+
27923+#ifdef CONFIG_PAX_REFCOUNT
27924+2:
27925+#endif
27926+
27927+RET_ENDP
27928+BEGIN(sub_return_unchecked)
27929+ negl %edx
27930+ negl %eax
27931+ sbbl $0, %edx
27932+ addl (v), %eax
27933+ adcl 4(v), %edx
27934 movl %eax, (v)
27935 movl %edx, 4(v)
27936 RET_ENDP
27937@@ -105,6 +180,20 @@ RET_ENDP
27938 BEGIN(inc)
27939 addl $1, (v)
27940 adcl $0, 4(v)
27941+
27942+#ifdef CONFIG_PAX_REFCOUNT
27943+ jno 0f
27944+ subl $1, (v)
27945+ sbbl $0, 4(v)
27946+ int $4
27947+0:
27948+ _ASM_EXTABLE(0b, 0b)
27949+#endif
27950+
27951+RET_ENDP
27952+BEGIN(inc_unchecked)
27953+ addl $1, (v)
27954+ adcl $0, 4(v)
27955 RET_ENDP
27956 #undef v
27957
27958@@ -114,6 +203,26 @@ BEGIN(inc_return)
27959 movl 4(v), %edx
27960 addl $1, %eax
27961 adcl $0, %edx
27962+
27963+#ifdef CONFIG_PAX_REFCOUNT
27964+ into
27965+1234:
27966+ _ASM_EXTABLE(1234b, 2f)
27967+#endif
27968+
27969+ movl %eax, (v)
27970+ movl %edx, 4(v)
27971+
27972+#ifdef CONFIG_PAX_REFCOUNT
27973+2:
27974+#endif
27975+
27976+RET_ENDP
27977+BEGIN(inc_return_unchecked)
27978+ movl (v), %eax
27979+ movl 4(v), %edx
27980+ addl $1, %eax
27981+ adcl $0, %edx
27982 movl %eax, (v)
27983 movl %edx, 4(v)
27984 RET_ENDP
27985@@ -123,6 +232,20 @@ RET_ENDP
27986 BEGIN(dec)
27987 subl $1, (v)
27988 sbbl $0, 4(v)
27989+
27990+#ifdef CONFIG_PAX_REFCOUNT
27991+ jno 0f
27992+ addl $1, (v)
27993+ adcl $0, 4(v)
27994+ int $4
27995+0:
27996+ _ASM_EXTABLE(0b, 0b)
27997+#endif
27998+
27999+RET_ENDP
28000+BEGIN(dec_unchecked)
28001+ subl $1, (v)
28002+ sbbl $0, 4(v)
28003 RET_ENDP
28004 #undef v
28005
28006@@ -132,6 +255,26 @@ BEGIN(dec_return)
28007 movl 4(v), %edx
28008 subl $1, %eax
28009 sbbl $0, %edx
28010+
28011+#ifdef CONFIG_PAX_REFCOUNT
28012+ into
28013+1234:
28014+ _ASM_EXTABLE(1234b, 2f)
28015+#endif
28016+
28017+ movl %eax, (v)
28018+ movl %edx, 4(v)
28019+
28020+#ifdef CONFIG_PAX_REFCOUNT
28021+2:
28022+#endif
28023+
28024+RET_ENDP
28025+BEGIN(dec_return_unchecked)
28026+ movl (v), %eax
28027+ movl 4(v), %edx
28028+ subl $1, %eax
28029+ sbbl $0, %edx
28030 movl %eax, (v)
28031 movl %edx, 4(v)
28032 RET_ENDP
28033@@ -143,6 +286,13 @@ BEGIN(add_unless)
28034 adcl %edx, %edi
28035 addl (v), %eax
28036 adcl 4(v), %edx
28037+
28038+#ifdef CONFIG_PAX_REFCOUNT
28039+ into
28040+1234:
28041+ _ASM_EXTABLE(1234b, 2f)
28042+#endif
28043+
28044 cmpl %eax, %ecx
28045 je 3f
28046 1:
28047@@ -168,6 +318,13 @@ BEGIN(inc_not_zero)
28048 1:
28049 addl $1, %eax
28050 adcl $0, %edx
28051+
28052+#ifdef CONFIG_PAX_REFCOUNT
28053+ into
28054+1234:
28055+ _ASM_EXTABLE(1234b, 2f)
28056+#endif
28057+
28058 movl %eax, (v)
28059 movl %edx, 4(v)
28060 movl $1, %eax
28061@@ -186,6 +343,13 @@ BEGIN(dec_if_positive)
28062 movl 4(v), %edx
28063 subl $1, %eax
28064 sbbl $0, %edx
28065+
28066+#ifdef CONFIG_PAX_REFCOUNT
28067+ into
28068+1234:
28069+ _ASM_EXTABLE(1234b, 1f)
28070+#endif
28071+
28072 js 1f
28073 movl %eax, (v)
28074 movl %edx, 4(v)
28075diff --git a/arch/x86/lib/atomic64_cx8_32.S b/arch/x86/lib/atomic64_cx8_32.S
28076index f5cc9eb..51fa319 100644
28077--- a/arch/x86/lib/atomic64_cx8_32.S
28078+++ b/arch/x86/lib/atomic64_cx8_32.S
28079@@ -35,10 +35,20 @@ ENTRY(atomic64_read_cx8)
28080 CFI_STARTPROC
28081
28082 read64 %ecx
28083+ pax_force_retaddr
28084 ret
28085 CFI_ENDPROC
28086 ENDPROC(atomic64_read_cx8)
28087
28088+ENTRY(atomic64_read_unchecked_cx8)
28089+ CFI_STARTPROC
28090+
28091+ read64 %ecx
28092+ pax_force_retaddr
28093+ ret
28094+ CFI_ENDPROC
28095+ENDPROC(atomic64_read_unchecked_cx8)
28096+
28097 ENTRY(atomic64_set_cx8)
28098 CFI_STARTPROC
28099
28100@@ -48,10 +58,25 @@ ENTRY(atomic64_set_cx8)
28101 cmpxchg8b (%esi)
28102 jne 1b
28103
28104+ pax_force_retaddr
28105 ret
28106 CFI_ENDPROC
28107 ENDPROC(atomic64_set_cx8)
28108
28109+ENTRY(atomic64_set_unchecked_cx8)
28110+ CFI_STARTPROC
28111+
28112+1:
28113+/* we don't need LOCK_PREFIX since aligned 64-bit writes
28114+ * are atomic on 586 and newer */
28115+ cmpxchg8b (%esi)
28116+ jne 1b
28117+
28118+ pax_force_retaddr
28119+ ret
28120+ CFI_ENDPROC
28121+ENDPROC(atomic64_set_unchecked_cx8)
28122+
28123 ENTRY(atomic64_xchg_cx8)
28124 CFI_STARTPROC
28125
28126@@ -60,12 +85,13 @@ ENTRY(atomic64_xchg_cx8)
28127 cmpxchg8b (%esi)
28128 jne 1b
28129
28130+ pax_force_retaddr
28131 ret
28132 CFI_ENDPROC
28133 ENDPROC(atomic64_xchg_cx8)
28134
28135-.macro addsub_return func ins insc
28136-ENTRY(atomic64_\func\()_return_cx8)
28137+.macro addsub_return func ins insc unchecked=""
28138+ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
28139 CFI_STARTPROC
28140 SAVE ebp
28141 SAVE ebx
28142@@ -82,27 +108,44 @@ ENTRY(atomic64_\func\()_return_cx8)
28143 movl %edx, %ecx
28144 \ins\()l %esi, %ebx
28145 \insc\()l %edi, %ecx
28146+
28147+.ifb \unchecked
28148+#ifdef CONFIG_PAX_REFCOUNT
28149+ into
28150+2:
28151+ _ASM_EXTABLE(2b, 3f)
28152+#endif
28153+.endif
28154+
28155 LOCK_PREFIX
28156 cmpxchg8b (%ebp)
28157 jne 1b
28158-
28159-10:
28160 movl %ebx, %eax
28161 movl %ecx, %edx
28162+
28163+.ifb \unchecked
28164+#ifdef CONFIG_PAX_REFCOUNT
28165+3:
28166+#endif
28167+.endif
28168+
28169 RESTORE edi
28170 RESTORE esi
28171 RESTORE ebx
28172 RESTORE ebp
28173+ pax_force_retaddr
28174 ret
28175 CFI_ENDPROC
28176-ENDPROC(atomic64_\func\()_return_cx8)
28177+ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
28178 .endm
28179
28180 addsub_return add add adc
28181 addsub_return sub sub sbb
28182+addsub_return add add adc _unchecked
28183+addsub_return sub sub sbb _unchecked
28184
28185-.macro incdec_return func ins insc
28186-ENTRY(atomic64_\func\()_return_cx8)
28187+.macro incdec_return func ins insc unchecked=""
28188+ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
28189 CFI_STARTPROC
28190 SAVE ebx
28191
28192@@ -112,21 +155,39 @@ ENTRY(atomic64_\func\()_return_cx8)
28193 movl %edx, %ecx
28194 \ins\()l $1, %ebx
28195 \insc\()l $0, %ecx
28196+
28197+.ifb \unchecked
28198+#ifdef CONFIG_PAX_REFCOUNT
28199+ into
28200+2:
28201+ _ASM_EXTABLE(2b, 3f)
28202+#endif
28203+.endif
28204+
28205 LOCK_PREFIX
28206 cmpxchg8b (%esi)
28207 jne 1b
28208
28209-10:
28210 movl %ebx, %eax
28211 movl %ecx, %edx
28212+
28213+.ifb \unchecked
28214+#ifdef CONFIG_PAX_REFCOUNT
28215+3:
28216+#endif
28217+.endif
28218+
28219 RESTORE ebx
28220+ pax_force_retaddr
28221 ret
28222 CFI_ENDPROC
28223-ENDPROC(atomic64_\func\()_return_cx8)
28224+ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
28225 .endm
28226
28227 incdec_return inc add adc
28228 incdec_return dec sub sbb
28229+incdec_return inc add adc _unchecked
28230+incdec_return dec sub sbb _unchecked
28231
28232 ENTRY(atomic64_dec_if_positive_cx8)
28233 CFI_STARTPROC
28234@@ -138,6 +199,13 @@ ENTRY(atomic64_dec_if_positive_cx8)
28235 movl %edx, %ecx
28236 subl $1, %ebx
28237 sbb $0, %ecx
28238+
28239+#ifdef CONFIG_PAX_REFCOUNT
28240+ into
28241+1234:
28242+ _ASM_EXTABLE(1234b, 2f)
28243+#endif
28244+
28245 js 2f
28246 LOCK_PREFIX
28247 cmpxchg8b (%esi)
28248@@ -147,6 +215,7 @@ ENTRY(atomic64_dec_if_positive_cx8)
28249 movl %ebx, %eax
28250 movl %ecx, %edx
28251 RESTORE ebx
28252+ pax_force_retaddr
28253 ret
28254 CFI_ENDPROC
28255 ENDPROC(atomic64_dec_if_positive_cx8)
28256@@ -171,6 +240,13 @@ ENTRY(atomic64_add_unless_cx8)
28257 movl %edx, %ecx
28258 addl %ebp, %ebx
28259 adcl %edi, %ecx
28260+
28261+#ifdef CONFIG_PAX_REFCOUNT
28262+ into
28263+1234:
28264+ _ASM_EXTABLE(1234b, 3f)
28265+#endif
28266+
28267 LOCK_PREFIX
28268 cmpxchg8b (%esi)
28269 jne 1b
28270@@ -181,6 +257,7 @@ ENTRY(atomic64_add_unless_cx8)
28271 CFI_ADJUST_CFA_OFFSET -8
28272 RESTORE ebx
28273 RESTORE ebp
28274+ pax_force_retaddr
28275 ret
28276 4:
28277 cmpl %edx, 4(%esp)
28278@@ -203,6 +280,13 @@ ENTRY(atomic64_inc_not_zero_cx8)
28279 xorl %ecx, %ecx
28280 addl $1, %ebx
28281 adcl %edx, %ecx
28282+
28283+#ifdef CONFIG_PAX_REFCOUNT
28284+ into
28285+1234:
28286+ _ASM_EXTABLE(1234b, 3f)
28287+#endif
28288+
28289 LOCK_PREFIX
28290 cmpxchg8b (%esi)
28291 jne 1b
28292@@ -210,6 +294,7 @@ ENTRY(atomic64_inc_not_zero_cx8)
28293 movl $1, %eax
28294 3:
28295 RESTORE ebx
28296+ pax_force_retaddr
28297 ret
28298 CFI_ENDPROC
28299 ENDPROC(atomic64_inc_not_zero_cx8)
28300diff --git a/arch/x86/lib/checksum_32.S b/arch/x86/lib/checksum_32.S
28301index e78b8ee..7e173a8 100644
28302--- a/arch/x86/lib/checksum_32.S
28303+++ b/arch/x86/lib/checksum_32.S
28304@@ -29,7 +29,8 @@
28305 #include <asm/dwarf2.h>
28306 #include <asm/errno.h>
28307 #include <asm/asm.h>
28308-
28309+#include <asm/segment.h>
28310+
28311 /*
28312 * computes a partial checksum, e.g. for TCP/UDP fragments
28313 */
28314@@ -293,9 +294,24 @@ unsigned int csum_partial_copy_generic (const char *src, char *dst,
28315
28316 #define ARGBASE 16
28317 #define FP 12
28318-
28319-ENTRY(csum_partial_copy_generic)
28320+
28321+ENTRY(csum_partial_copy_generic_to_user)
28322 CFI_STARTPROC
28323+
28324+#ifdef CONFIG_PAX_MEMORY_UDEREF
28325+ pushl_cfi %gs
28326+ popl_cfi %es
28327+ jmp csum_partial_copy_generic
28328+#endif
28329+
28330+ENTRY(csum_partial_copy_generic_from_user)
28331+
28332+#ifdef CONFIG_PAX_MEMORY_UDEREF
28333+ pushl_cfi %gs
28334+ popl_cfi %ds
28335+#endif
28336+
28337+ENTRY(csum_partial_copy_generic)
28338 subl $4,%esp
28339 CFI_ADJUST_CFA_OFFSET 4
28340 pushl_cfi %edi
28341@@ -317,7 +333,7 @@ ENTRY(csum_partial_copy_generic)
28342 jmp 4f
28343 SRC(1: movw (%esi), %bx )
28344 addl $2, %esi
28345-DST( movw %bx, (%edi) )
28346+DST( movw %bx, %es:(%edi) )
28347 addl $2, %edi
28348 addw %bx, %ax
28349 adcl $0, %eax
28350@@ -329,30 +345,30 @@ DST( movw %bx, (%edi) )
28351 SRC(1: movl (%esi), %ebx )
28352 SRC( movl 4(%esi), %edx )
28353 adcl %ebx, %eax
28354-DST( movl %ebx, (%edi) )
28355+DST( movl %ebx, %es:(%edi) )
28356 adcl %edx, %eax
28357-DST( movl %edx, 4(%edi) )
28358+DST( movl %edx, %es:4(%edi) )
28359
28360 SRC( movl 8(%esi), %ebx )
28361 SRC( movl 12(%esi), %edx )
28362 adcl %ebx, %eax
28363-DST( movl %ebx, 8(%edi) )
28364+DST( movl %ebx, %es:8(%edi) )
28365 adcl %edx, %eax
28366-DST( movl %edx, 12(%edi) )
28367+DST( movl %edx, %es:12(%edi) )
28368
28369 SRC( movl 16(%esi), %ebx )
28370 SRC( movl 20(%esi), %edx )
28371 adcl %ebx, %eax
28372-DST( movl %ebx, 16(%edi) )
28373+DST( movl %ebx, %es:16(%edi) )
28374 adcl %edx, %eax
28375-DST( movl %edx, 20(%edi) )
28376+DST( movl %edx, %es:20(%edi) )
28377
28378 SRC( movl 24(%esi), %ebx )
28379 SRC( movl 28(%esi), %edx )
28380 adcl %ebx, %eax
28381-DST( movl %ebx, 24(%edi) )
28382+DST( movl %ebx, %es:24(%edi) )
28383 adcl %edx, %eax
28384-DST( movl %edx, 28(%edi) )
28385+DST( movl %edx, %es:28(%edi) )
28386
28387 lea 32(%esi), %esi
28388 lea 32(%edi), %edi
28389@@ -366,7 +382,7 @@ DST( movl %edx, 28(%edi) )
28390 shrl $2, %edx # This clears CF
28391 SRC(3: movl (%esi), %ebx )
28392 adcl %ebx, %eax
28393-DST( movl %ebx, (%edi) )
28394+DST( movl %ebx, %es:(%edi) )
28395 lea 4(%esi), %esi
28396 lea 4(%edi), %edi
28397 dec %edx
28398@@ -378,12 +394,12 @@ DST( movl %ebx, (%edi) )
28399 jb 5f
28400 SRC( movw (%esi), %cx )
28401 leal 2(%esi), %esi
28402-DST( movw %cx, (%edi) )
28403+DST( movw %cx, %es:(%edi) )
28404 leal 2(%edi), %edi
28405 je 6f
28406 shll $16,%ecx
28407 SRC(5: movb (%esi), %cl )
28408-DST( movb %cl, (%edi) )
28409+DST( movb %cl, %es:(%edi) )
28410 6: addl %ecx, %eax
28411 adcl $0, %eax
28412 7:
28413@@ -394,7 +410,7 @@ DST( movb %cl, (%edi) )
28414
28415 6001:
28416 movl ARGBASE+20(%esp), %ebx # src_err_ptr
28417- movl $-EFAULT, (%ebx)
28418+ movl $-EFAULT, %ss:(%ebx)
28419
28420 # zero the complete destination - computing the rest
28421 # is too much work
28422@@ -407,11 +423,15 @@ DST( movb %cl, (%edi) )
28423
28424 6002:
28425 movl ARGBASE+24(%esp), %ebx # dst_err_ptr
28426- movl $-EFAULT,(%ebx)
28427+ movl $-EFAULT,%ss:(%ebx)
28428 jmp 5000b
28429
28430 .previous
28431
28432+ pushl_cfi %ss
28433+ popl_cfi %ds
28434+ pushl_cfi %ss
28435+ popl_cfi %es
28436 popl_cfi %ebx
28437 CFI_RESTORE ebx
28438 popl_cfi %esi
28439@@ -421,26 +441,43 @@ DST( movb %cl, (%edi) )
28440 popl_cfi %ecx # equivalent to addl $4,%esp
28441 ret
28442 CFI_ENDPROC
28443-ENDPROC(csum_partial_copy_generic)
28444+ENDPROC(csum_partial_copy_generic_to_user)
28445
28446 #else
28447
28448 /* Version for PentiumII/PPro */
28449
28450 #define ROUND1(x) \
28451+ nop; nop; nop; \
28452 SRC(movl x(%esi), %ebx ) ; \
28453 addl %ebx, %eax ; \
28454- DST(movl %ebx, x(%edi) ) ;
28455+ DST(movl %ebx, %es:x(%edi)) ;
28456
28457 #define ROUND(x) \
28458+ nop; nop; nop; \
28459 SRC(movl x(%esi), %ebx ) ; \
28460 adcl %ebx, %eax ; \
28461- DST(movl %ebx, x(%edi) ) ;
28462+ DST(movl %ebx, %es:x(%edi)) ;
28463
28464 #define ARGBASE 12
28465-
28466-ENTRY(csum_partial_copy_generic)
28467+
28468+ENTRY(csum_partial_copy_generic_to_user)
28469 CFI_STARTPROC
28470+
28471+#ifdef CONFIG_PAX_MEMORY_UDEREF
28472+ pushl_cfi %gs
28473+ popl_cfi %es
28474+ jmp csum_partial_copy_generic
28475+#endif
28476+
28477+ENTRY(csum_partial_copy_generic_from_user)
28478+
28479+#ifdef CONFIG_PAX_MEMORY_UDEREF
28480+ pushl_cfi %gs
28481+ popl_cfi %ds
28482+#endif
28483+
28484+ENTRY(csum_partial_copy_generic)
28485 pushl_cfi %ebx
28486 CFI_REL_OFFSET ebx, 0
28487 pushl_cfi %edi
28488@@ -461,7 +498,7 @@ ENTRY(csum_partial_copy_generic)
28489 subl %ebx, %edi
28490 lea -1(%esi),%edx
28491 andl $-32,%edx
28492- lea 3f(%ebx,%ebx), %ebx
28493+ lea 3f(%ebx,%ebx,2), %ebx
28494 testl %esi, %esi
28495 jmp *%ebx
28496 1: addl $64,%esi
28497@@ -482,19 +519,19 @@ ENTRY(csum_partial_copy_generic)
28498 jb 5f
28499 SRC( movw (%esi), %dx )
28500 leal 2(%esi), %esi
28501-DST( movw %dx, (%edi) )
28502+DST( movw %dx, %es:(%edi) )
28503 leal 2(%edi), %edi
28504 je 6f
28505 shll $16,%edx
28506 5:
28507 SRC( movb (%esi), %dl )
28508-DST( movb %dl, (%edi) )
28509+DST( movb %dl, %es:(%edi) )
28510 6: addl %edx, %eax
28511 adcl $0, %eax
28512 7:
28513 .section .fixup, "ax"
28514 6001: movl ARGBASE+20(%esp), %ebx # src_err_ptr
28515- movl $-EFAULT, (%ebx)
28516+ movl $-EFAULT, %ss:(%ebx)
28517 # zero the complete destination (computing the rest is too much work)
28518 movl ARGBASE+8(%esp),%edi # dst
28519 movl ARGBASE+12(%esp),%ecx # len
28520@@ -502,10 +539,17 @@ DST( movb %dl, (%edi) )
28521 rep; stosb
28522 jmp 7b
28523 6002: movl ARGBASE+24(%esp), %ebx # dst_err_ptr
28524- movl $-EFAULT, (%ebx)
28525+ movl $-EFAULT, %ss:(%ebx)
28526 jmp 7b
28527 .previous
28528
28529+#ifdef CONFIG_PAX_MEMORY_UDEREF
28530+ pushl_cfi %ss
28531+ popl_cfi %ds
28532+ pushl_cfi %ss
28533+ popl_cfi %es
28534+#endif
28535+
28536 popl_cfi %esi
28537 CFI_RESTORE esi
28538 popl_cfi %edi
28539@@ -514,7 +558,7 @@ DST( movb %dl, (%edi) )
28540 CFI_RESTORE ebx
28541 ret
28542 CFI_ENDPROC
28543-ENDPROC(csum_partial_copy_generic)
28544+ENDPROC(csum_partial_copy_generic_to_user)
28545
28546 #undef ROUND
28547 #undef ROUND1
28548diff --git a/arch/x86/lib/clear_page_64.S b/arch/x86/lib/clear_page_64.S
28549index f2145cf..cea889d 100644
28550--- a/arch/x86/lib/clear_page_64.S
28551+++ b/arch/x86/lib/clear_page_64.S
28552@@ -11,6 +11,7 @@ ENTRY(clear_page_c)
28553 movl $4096/8,%ecx
28554 xorl %eax,%eax
28555 rep stosq
28556+ pax_force_retaddr
28557 ret
28558 CFI_ENDPROC
28559 ENDPROC(clear_page_c)
28560@@ -20,6 +21,7 @@ ENTRY(clear_page_c_e)
28561 movl $4096,%ecx
28562 xorl %eax,%eax
28563 rep stosb
28564+ pax_force_retaddr
28565 ret
28566 CFI_ENDPROC
28567 ENDPROC(clear_page_c_e)
28568@@ -43,6 +45,7 @@ ENTRY(clear_page)
28569 leaq 64(%rdi),%rdi
28570 jnz .Lloop
28571 nop
28572+ pax_force_retaddr
28573 ret
28574 CFI_ENDPROC
28575 .Lclear_page_end:
28576@@ -58,7 +61,7 @@ ENDPROC(clear_page)
28577
28578 #include <asm/cpufeature.h>
28579
28580- .section .altinstr_replacement,"ax"
28581+ .section .altinstr_replacement,"a"
28582 1: .byte 0xeb /* jmp <disp8> */
28583 .byte (clear_page_c - clear_page) - (2f - 1b) /* offset */
28584 2: .byte 0xeb /* jmp <disp8> */
28585diff --git a/arch/x86/lib/cmpxchg16b_emu.S b/arch/x86/lib/cmpxchg16b_emu.S
28586index 1e572c5..2a162cd 100644
28587--- a/arch/x86/lib/cmpxchg16b_emu.S
28588+++ b/arch/x86/lib/cmpxchg16b_emu.S
28589@@ -53,11 +53,13 @@ this_cpu_cmpxchg16b_emu:
28590
28591 popf
28592 mov $1, %al
28593+ pax_force_retaddr
28594 ret
28595
28596 not_same:
28597 popf
28598 xor %al,%al
28599+ pax_force_retaddr
28600 ret
28601
28602 CFI_ENDPROC
28603diff --git a/arch/x86/lib/copy_page_64.S b/arch/x86/lib/copy_page_64.S
28604index 176cca6..e0d658e 100644
28605--- a/arch/x86/lib/copy_page_64.S
28606+++ b/arch/x86/lib/copy_page_64.S
28607@@ -9,6 +9,7 @@ copy_page_rep:
28608 CFI_STARTPROC
28609 movl $4096/8, %ecx
28610 rep movsq
28611+ pax_force_retaddr
28612 ret
28613 CFI_ENDPROC
28614 ENDPROC(copy_page_rep)
28615@@ -24,8 +25,8 @@ ENTRY(copy_page)
28616 CFI_ADJUST_CFA_OFFSET 2*8
28617 movq %rbx, (%rsp)
28618 CFI_REL_OFFSET rbx, 0
28619- movq %r12, 1*8(%rsp)
28620- CFI_REL_OFFSET r12, 1*8
28621+ movq %r13, 1*8(%rsp)
28622+ CFI_REL_OFFSET r13, 1*8
28623
28624 movl $(4096/64)-5, %ecx
28625 .p2align 4
28626@@ -38,7 +39,7 @@ ENTRY(copy_page)
28627 movq 0x8*4(%rsi), %r9
28628 movq 0x8*5(%rsi), %r10
28629 movq 0x8*6(%rsi), %r11
28630- movq 0x8*7(%rsi), %r12
28631+ movq 0x8*7(%rsi), %r13
28632
28633 prefetcht0 5*64(%rsi)
28634
28635@@ -49,7 +50,7 @@ ENTRY(copy_page)
28636 movq %r9, 0x8*4(%rdi)
28637 movq %r10, 0x8*5(%rdi)
28638 movq %r11, 0x8*6(%rdi)
28639- movq %r12, 0x8*7(%rdi)
28640+ movq %r13, 0x8*7(%rdi)
28641
28642 leaq 64 (%rsi), %rsi
28643 leaq 64 (%rdi), %rdi
28644@@ -68,7 +69,7 @@ ENTRY(copy_page)
28645 movq 0x8*4(%rsi), %r9
28646 movq 0x8*5(%rsi), %r10
28647 movq 0x8*6(%rsi), %r11
28648- movq 0x8*7(%rsi), %r12
28649+ movq 0x8*7(%rsi), %r13
28650
28651 movq %rax, 0x8*0(%rdi)
28652 movq %rbx, 0x8*1(%rdi)
28653@@ -77,7 +78,7 @@ ENTRY(copy_page)
28654 movq %r9, 0x8*4(%rdi)
28655 movq %r10, 0x8*5(%rdi)
28656 movq %r11, 0x8*6(%rdi)
28657- movq %r12, 0x8*7(%rdi)
28658+ movq %r13, 0x8*7(%rdi)
28659
28660 leaq 64(%rdi), %rdi
28661 leaq 64(%rsi), %rsi
28662@@ -85,10 +86,11 @@ ENTRY(copy_page)
28663
28664 movq (%rsp), %rbx
28665 CFI_RESTORE rbx
28666- movq 1*8(%rsp), %r12
28667- CFI_RESTORE r12
28668+ movq 1*8(%rsp), %r13
28669+ CFI_RESTORE r13
28670 addq $2*8, %rsp
28671 CFI_ADJUST_CFA_OFFSET -2*8
28672+ pax_force_retaddr
28673 ret
28674 .Lcopy_page_end:
28675 CFI_ENDPROC
28676@@ -99,7 +101,7 @@ ENDPROC(copy_page)
28677
28678 #include <asm/cpufeature.h>
28679
28680- .section .altinstr_replacement,"ax"
28681+ .section .altinstr_replacement,"a"
28682 1: .byte 0xeb /* jmp <disp8> */
28683 .byte (copy_page_rep - copy_page) - (2f - 1b) /* offset */
28684 2:
28685diff --git a/arch/x86/lib/copy_user_64.S b/arch/x86/lib/copy_user_64.S
28686index a30ca15..407412b 100644
28687--- a/arch/x86/lib/copy_user_64.S
28688+++ b/arch/x86/lib/copy_user_64.S
28689@@ -18,31 +18,7 @@
28690 #include <asm/alternative-asm.h>
28691 #include <asm/asm.h>
28692 #include <asm/smap.h>
28693-
28694-/*
28695- * By placing feature2 after feature1 in altinstructions section, we logically
28696- * implement:
28697- * If CPU has feature2, jmp to alt2 is used
28698- * else if CPU has feature1, jmp to alt1 is used
28699- * else jmp to orig is used.
28700- */
28701- .macro ALTERNATIVE_JUMP feature1,feature2,orig,alt1,alt2
28702-0:
28703- .byte 0xe9 /* 32bit jump */
28704- .long \orig-1f /* by default jump to orig */
28705-1:
28706- .section .altinstr_replacement,"ax"
28707-2: .byte 0xe9 /* near jump with 32bit immediate */
28708- .long \alt1-1b /* offset */ /* or alternatively to alt1 */
28709-3: .byte 0xe9 /* near jump with 32bit immediate */
28710- .long \alt2-1b /* offset */ /* or alternatively to alt2 */
28711- .previous
28712-
28713- .section .altinstructions,"a"
28714- altinstruction_entry 0b,2b,\feature1,5,5
28715- altinstruction_entry 0b,3b,\feature2,5,5
28716- .previous
28717- .endm
28718+#include <asm/pgtable.h>
28719
28720 .macro ALIGN_DESTINATION
28721 #ifdef FIX_ALIGNMENT
28722@@ -70,52 +46,6 @@
28723 #endif
28724 .endm
28725
28726-/* Standard copy_to_user with segment limit checking */
28727-ENTRY(_copy_to_user)
28728- CFI_STARTPROC
28729- GET_THREAD_INFO(%rax)
28730- movq %rdi,%rcx
28731- addq %rdx,%rcx
28732- jc bad_to_user
28733- cmpq TI_addr_limit(%rax),%rcx
28734- ja bad_to_user
28735- ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
28736- copy_user_generic_unrolled,copy_user_generic_string, \
28737- copy_user_enhanced_fast_string
28738- CFI_ENDPROC
28739-ENDPROC(_copy_to_user)
28740-
28741-/* Standard copy_from_user with segment limit checking */
28742-ENTRY(_copy_from_user)
28743- CFI_STARTPROC
28744- GET_THREAD_INFO(%rax)
28745- movq %rsi,%rcx
28746- addq %rdx,%rcx
28747- jc bad_from_user
28748- cmpq TI_addr_limit(%rax),%rcx
28749- ja bad_from_user
28750- ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
28751- copy_user_generic_unrolled,copy_user_generic_string, \
28752- copy_user_enhanced_fast_string
28753- CFI_ENDPROC
28754-ENDPROC(_copy_from_user)
28755-
28756- .section .fixup,"ax"
28757- /* must zero dest */
28758-ENTRY(bad_from_user)
28759-bad_from_user:
28760- CFI_STARTPROC
28761- movl %edx,%ecx
28762- xorl %eax,%eax
28763- rep
28764- stosb
28765-bad_to_user:
28766- movl %edx,%eax
28767- ret
28768- CFI_ENDPROC
28769-ENDPROC(bad_from_user)
28770- .previous
28771-
28772 /*
28773 * copy_user_generic_unrolled - memory copy with exception handling.
28774 * This version is for CPUs like P4 that don't have efficient micro
28775@@ -131,6 +61,7 @@ ENDPROC(bad_from_user)
28776 */
28777 ENTRY(copy_user_generic_unrolled)
28778 CFI_STARTPROC
28779+ ASM_PAX_OPEN_USERLAND
28780 ASM_STAC
28781 cmpl $8,%edx
28782 jb 20f /* less then 8 bytes, go to byte copy loop */
28783@@ -180,6 +111,8 @@ ENTRY(copy_user_generic_unrolled)
28784 jnz 21b
28785 23: xor %eax,%eax
28786 ASM_CLAC
28787+ ASM_PAX_CLOSE_USERLAND
28788+ pax_force_retaddr
28789 ret
28790
28791 .section .fixup,"ax"
28792@@ -235,6 +168,7 @@ ENDPROC(copy_user_generic_unrolled)
28793 */
28794 ENTRY(copy_user_generic_string)
28795 CFI_STARTPROC
28796+ ASM_PAX_OPEN_USERLAND
28797 ASM_STAC
28798 andl %edx,%edx
28799 jz 4f
28800@@ -251,6 +185,8 @@ ENTRY(copy_user_generic_string)
28801 movsb
28802 4: xorl %eax,%eax
28803 ASM_CLAC
28804+ ASM_PAX_CLOSE_USERLAND
28805+ pax_force_retaddr
28806 ret
28807
28808 .section .fixup,"ax"
28809@@ -278,6 +214,7 @@ ENDPROC(copy_user_generic_string)
28810 */
28811 ENTRY(copy_user_enhanced_fast_string)
28812 CFI_STARTPROC
28813+ ASM_PAX_OPEN_USERLAND
28814 ASM_STAC
28815 andl %edx,%edx
28816 jz 2f
28817@@ -286,6 +223,8 @@ ENTRY(copy_user_enhanced_fast_string)
28818 movsb
28819 2: xorl %eax,%eax
28820 ASM_CLAC
28821+ ASM_PAX_CLOSE_USERLAND
28822+ pax_force_retaddr
28823 ret
28824
28825 .section .fixup,"ax"
28826diff --git a/arch/x86/lib/copy_user_nocache_64.S b/arch/x86/lib/copy_user_nocache_64.S
28827index 6a4f43c..c70fb52 100644
28828--- a/arch/x86/lib/copy_user_nocache_64.S
28829+++ b/arch/x86/lib/copy_user_nocache_64.S
28830@@ -8,6 +8,7 @@
28831
28832 #include <linux/linkage.h>
28833 #include <asm/dwarf2.h>
28834+#include <asm/alternative-asm.h>
28835
28836 #define FIX_ALIGNMENT 1
28837
28838@@ -16,6 +17,7 @@
28839 #include <asm/thread_info.h>
28840 #include <asm/asm.h>
28841 #include <asm/smap.h>
28842+#include <asm/pgtable.h>
28843
28844 .macro ALIGN_DESTINATION
28845 #ifdef FIX_ALIGNMENT
28846@@ -49,6 +51,16 @@
28847 */
28848 ENTRY(__copy_user_nocache)
28849 CFI_STARTPROC
28850+
28851+#ifdef CONFIG_PAX_MEMORY_UDEREF
28852+ mov pax_user_shadow_base,%rcx
28853+ cmp %rcx,%rsi
28854+ jae 1f
28855+ add %rcx,%rsi
28856+1:
28857+#endif
28858+
28859+ ASM_PAX_OPEN_USERLAND
28860 ASM_STAC
28861 cmpl $8,%edx
28862 jb 20f /* less then 8 bytes, go to byte copy loop */
28863@@ -98,7 +110,9 @@ ENTRY(__copy_user_nocache)
28864 jnz 21b
28865 23: xorl %eax,%eax
28866 ASM_CLAC
28867+ ASM_PAX_CLOSE_USERLAND
28868 sfence
28869+ pax_force_retaddr
28870 ret
28871
28872 .section .fixup,"ax"
28873diff --git a/arch/x86/lib/csum-copy_64.S b/arch/x86/lib/csum-copy_64.S
28874index 2419d5f..fe52d0e 100644
28875--- a/arch/x86/lib/csum-copy_64.S
28876+++ b/arch/x86/lib/csum-copy_64.S
28877@@ -9,6 +9,7 @@
28878 #include <asm/dwarf2.h>
28879 #include <asm/errno.h>
28880 #include <asm/asm.h>
28881+#include <asm/alternative-asm.h>
28882
28883 /*
28884 * Checksum copy with exception handling.
28885@@ -56,8 +57,8 @@ ENTRY(csum_partial_copy_generic)
28886 CFI_ADJUST_CFA_OFFSET 7*8
28887 movq %rbx, 2*8(%rsp)
28888 CFI_REL_OFFSET rbx, 2*8
28889- movq %r12, 3*8(%rsp)
28890- CFI_REL_OFFSET r12, 3*8
28891+ movq %r15, 3*8(%rsp)
28892+ CFI_REL_OFFSET r15, 3*8
28893 movq %r14, 4*8(%rsp)
28894 CFI_REL_OFFSET r14, 4*8
28895 movq %r13, 5*8(%rsp)
28896@@ -72,16 +73,16 @@ ENTRY(csum_partial_copy_generic)
28897 movl %edx, %ecx
28898
28899 xorl %r9d, %r9d
28900- movq %rcx, %r12
28901+ movq %rcx, %r15
28902
28903- shrq $6, %r12
28904+ shrq $6, %r15
28905 jz .Lhandle_tail /* < 64 */
28906
28907 clc
28908
28909 /* main loop. clear in 64 byte blocks */
28910 /* r9: zero, r8: temp2, rbx: temp1, rax: sum, rcx: saved length */
28911- /* r11: temp3, rdx: temp4, r12 loopcnt */
28912+ /* r11: temp3, rdx: temp4, r15 loopcnt */
28913 /* r10: temp5, rbp: temp6, r14 temp7, r13 temp8 */
28914 .p2align 4
28915 .Lloop:
28916@@ -115,7 +116,7 @@ ENTRY(csum_partial_copy_generic)
28917 adcq %r14, %rax
28918 adcq %r13, %rax
28919
28920- decl %r12d
28921+ decl %r15d
28922
28923 dest
28924 movq %rbx, (%rsi)
28925@@ -210,8 +211,8 @@ ENTRY(csum_partial_copy_generic)
28926 .Lende:
28927 movq 2*8(%rsp), %rbx
28928 CFI_RESTORE rbx
28929- movq 3*8(%rsp), %r12
28930- CFI_RESTORE r12
28931+ movq 3*8(%rsp), %r15
28932+ CFI_RESTORE r15
28933 movq 4*8(%rsp), %r14
28934 CFI_RESTORE r14
28935 movq 5*8(%rsp), %r13
28936@@ -220,6 +221,7 @@ ENTRY(csum_partial_copy_generic)
28937 CFI_RESTORE rbp
28938 addq $7*8, %rsp
28939 CFI_ADJUST_CFA_OFFSET -7*8
28940+ pax_force_retaddr
28941 ret
28942 CFI_RESTORE_STATE
28943
28944diff --git a/arch/x86/lib/csum-wrappers_64.c b/arch/x86/lib/csum-wrappers_64.c
28945index 7609e0e..b449b98 100644
28946--- a/arch/x86/lib/csum-wrappers_64.c
28947+++ b/arch/x86/lib/csum-wrappers_64.c
28948@@ -53,10 +53,12 @@ csum_partial_copy_from_user(const void __user *src, void *dst,
28949 len -= 2;
28950 }
28951 }
28952+ pax_open_userland();
28953 stac();
28954- isum = csum_partial_copy_generic((__force const void *)src,
28955+ isum = csum_partial_copy_generic((const void __force_kernel *)____m(src),
28956 dst, len, isum, errp, NULL);
28957 clac();
28958+ pax_close_userland();
28959 if (unlikely(*errp))
28960 goto out_err;
28961
28962@@ -110,10 +112,12 @@ csum_partial_copy_to_user(const void *src, void __user *dst,
28963 }
28964
28965 *errp = 0;
28966+ pax_open_userland();
28967 stac();
28968- ret = csum_partial_copy_generic(src, (void __force *)dst,
28969+ ret = csum_partial_copy_generic(src, (void __force_kernel *)____m(dst),
28970 len, isum, NULL, errp);
28971 clac();
28972+ pax_close_userland();
28973 return ret;
28974 }
28975 EXPORT_SYMBOL(csum_partial_copy_to_user);
28976diff --git a/arch/x86/lib/getuser.S b/arch/x86/lib/getuser.S
28977index a451235..1daa956 100644
28978--- a/arch/x86/lib/getuser.S
28979+++ b/arch/x86/lib/getuser.S
28980@@ -33,17 +33,40 @@
28981 #include <asm/thread_info.h>
28982 #include <asm/asm.h>
28983 #include <asm/smap.h>
28984+#include <asm/segment.h>
28985+#include <asm/pgtable.h>
28986+#include <asm/alternative-asm.h>
28987+
28988+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
28989+#define __copyuser_seg gs;
28990+#else
28991+#define __copyuser_seg
28992+#endif
28993
28994 .text
28995 ENTRY(__get_user_1)
28996 CFI_STARTPROC
28997+
28998+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
28999 GET_THREAD_INFO(%_ASM_DX)
29000 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
29001 jae bad_get_user
29002 ASM_STAC
29003-1: movzbl (%_ASM_AX),%edx
29004+
29005+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
29006+ mov pax_user_shadow_base,%_ASM_DX
29007+ cmp %_ASM_DX,%_ASM_AX
29008+ jae 1234f
29009+ add %_ASM_DX,%_ASM_AX
29010+1234:
29011+#endif
29012+
29013+#endif
29014+
29015+1: __copyuser_seg movzbl (%_ASM_AX),%edx
29016 xor %eax,%eax
29017 ASM_CLAC
29018+ pax_force_retaddr
29019 ret
29020 CFI_ENDPROC
29021 ENDPROC(__get_user_1)
29022@@ -51,14 +74,28 @@ ENDPROC(__get_user_1)
29023 ENTRY(__get_user_2)
29024 CFI_STARTPROC
29025 add $1,%_ASM_AX
29026+
29027+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
29028 jc bad_get_user
29029 GET_THREAD_INFO(%_ASM_DX)
29030 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
29031 jae bad_get_user
29032 ASM_STAC
29033-2: movzwl -1(%_ASM_AX),%edx
29034+
29035+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
29036+ mov pax_user_shadow_base,%_ASM_DX
29037+ cmp %_ASM_DX,%_ASM_AX
29038+ jae 1234f
29039+ add %_ASM_DX,%_ASM_AX
29040+1234:
29041+#endif
29042+
29043+#endif
29044+
29045+2: __copyuser_seg movzwl -1(%_ASM_AX),%edx
29046 xor %eax,%eax
29047 ASM_CLAC
29048+ pax_force_retaddr
29049 ret
29050 CFI_ENDPROC
29051 ENDPROC(__get_user_2)
29052@@ -66,14 +103,28 @@ ENDPROC(__get_user_2)
29053 ENTRY(__get_user_4)
29054 CFI_STARTPROC
29055 add $3,%_ASM_AX
29056+
29057+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
29058 jc bad_get_user
29059 GET_THREAD_INFO(%_ASM_DX)
29060 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
29061 jae bad_get_user
29062 ASM_STAC
29063-3: movl -3(%_ASM_AX),%edx
29064+
29065+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
29066+ mov pax_user_shadow_base,%_ASM_DX
29067+ cmp %_ASM_DX,%_ASM_AX
29068+ jae 1234f
29069+ add %_ASM_DX,%_ASM_AX
29070+1234:
29071+#endif
29072+
29073+#endif
29074+
29075+3: __copyuser_seg movl -3(%_ASM_AX),%edx
29076 xor %eax,%eax
29077 ASM_CLAC
29078+ pax_force_retaddr
29079 ret
29080 CFI_ENDPROC
29081 ENDPROC(__get_user_4)
29082@@ -86,10 +137,20 @@ ENTRY(__get_user_8)
29083 GET_THREAD_INFO(%_ASM_DX)
29084 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
29085 jae bad_get_user
29086+
29087+#ifdef CONFIG_PAX_MEMORY_UDEREF
29088+ mov pax_user_shadow_base,%_ASM_DX
29089+ cmp %_ASM_DX,%_ASM_AX
29090+ jae 1234f
29091+ add %_ASM_DX,%_ASM_AX
29092+1234:
29093+#endif
29094+
29095 ASM_STAC
29096 4: movq -7(%_ASM_AX),%rdx
29097 xor %eax,%eax
29098 ASM_CLAC
29099+ pax_force_retaddr
29100 ret
29101 #else
29102 add $7,%_ASM_AX
29103@@ -98,10 +159,11 @@ ENTRY(__get_user_8)
29104 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
29105 jae bad_get_user_8
29106 ASM_STAC
29107-4: movl -7(%_ASM_AX),%edx
29108-5: movl -3(%_ASM_AX),%ecx
29109+4: __copyuser_seg movl -7(%_ASM_AX),%edx
29110+5: __copyuser_seg movl -3(%_ASM_AX),%ecx
29111 xor %eax,%eax
29112 ASM_CLAC
29113+ pax_force_retaddr
29114 ret
29115 #endif
29116 CFI_ENDPROC
29117@@ -113,6 +175,7 @@ bad_get_user:
29118 xor %edx,%edx
29119 mov $(-EFAULT),%_ASM_AX
29120 ASM_CLAC
29121+ pax_force_retaddr
29122 ret
29123 CFI_ENDPROC
29124 END(bad_get_user)
29125@@ -124,6 +187,7 @@ bad_get_user_8:
29126 xor %ecx,%ecx
29127 mov $(-EFAULT),%_ASM_AX
29128 ASM_CLAC
29129+ pax_force_retaddr
29130 ret
29131 CFI_ENDPROC
29132 END(bad_get_user_8)
29133diff --git a/arch/x86/lib/insn.c b/arch/x86/lib/insn.c
29134index 54fcffe..7be149e 100644
29135--- a/arch/x86/lib/insn.c
29136+++ b/arch/x86/lib/insn.c
29137@@ -20,8 +20,10 @@
29138
29139 #ifdef __KERNEL__
29140 #include <linux/string.h>
29141+#include <asm/pgtable_types.h>
29142 #else
29143 #include <string.h>
29144+#define ktla_ktva(addr) addr
29145 #endif
29146 #include <asm/inat.h>
29147 #include <asm/insn.h>
29148@@ -53,8 +55,8 @@
29149 void insn_init(struct insn *insn, const void *kaddr, int x86_64)
29150 {
29151 memset(insn, 0, sizeof(*insn));
29152- insn->kaddr = kaddr;
29153- insn->next_byte = kaddr;
29154+ insn->kaddr = ktla_ktva(kaddr);
29155+ insn->next_byte = ktla_ktva(kaddr);
29156 insn->x86_64 = x86_64 ? 1 : 0;
29157 insn->opnd_bytes = 4;
29158 if (x86_64)
29159diff --git a/arch/x86/lib/iomap_copy_64.S b/arch/x86/lib/iomap_copy_64.S
29160index 05a95e7..326f2fa 100644
29161--- a/arch/x86/lib/iomap_copy_64.S
29162+++ b/arch/x86/lib/iomap_copy_64.S
29163@@ -17,6 +17,7 @@
29164
29165 #include <linux/linkage.h>
29166 #include <asm/dwarf2.h>
29167+#include <asm/alternative-asm.h>
29168
29169 /*
29170 * override generic version in lib/iomap_copy.c
29171@@ -25,6 +26,7 @@ ENTRY(__iowrite32_copy)
29172 CFI_STARTPROC
29173 movl %edx,%ecx
29174 rep movsd
29175+ pax_force_retaddr
29176 ret
29177 CFI_ENDPROC
29178 ENDPROC(__iowrite32_copy)
29179diff --git a/arch/x86/lib/memcpy_64.S b/arch/x86/lib/memcpy_64.S
29180index 56313a3..0db417e 100644
29181--- a/arch/x86/lib/memcpy_64.S
29182+++ b/arch/x86/lib/memcpy_64.S
29183@@ -24,7 +24,7 @@
29184 * This gets patched over the unrolled variant (below) via the
29185 * alternative instructions framework:
29186 */
29187- .section .altinstr_replacement, "ax", @progbits
29188+ .section .altinstr_replacement, "a", @progbits
29189 .Lmemcpy_c:
29190 movq %rdi, %rax
29191 movq %rdx, %rcx
29192@@ -33,6 +33,7 @@
29193 rep movsq
29194 movl %edx, %ecx
29195 rep movsb
29196+ pax_force_retaddr
29197 ret
29198 .Lmemcpy_e:
29199 .previous
29200@@ -44,11 +45,12 @@
29201 * This gets patched over the unrolled variant (below) via the
29202 * alternative instructions framework:
29203 */
29204- .section .altinstr_replacement, "ax", @progbits
29205+ .section .altinstr_replacement, "a", @progbits
29206 .Lmemcpy_c_e:
29207 movq %rdi, %rax
29208 movq %rdx, %rcx
29209 rep movsb
29210+ pax_force_retaddr
29211 ret
29212 .Lmemcpy_e_e:
29213 .previous
29214@@ -136,6 +138,7 @@ ENTRY(memcpy)
29215 movq %r9, 1*8(%rdi)
29216 movq %r10, -2*8(%rdi, %rdx)
29217 movq %r11, -1*8(%rdi, %rdx)
29218+ pax_force_retaddr
29219 retq
29220 .p2align 4
29221 .Lless_16bytes:
29222@@ -148,6 +151,7 @@ ENTRY(memcpy)
29223 movq -1*8(%rsi, %rdx), %r9
29224 movq %r8, 0*8(%rdi)
29225 movq %r9, -1*8(%rdi, %rdx)
29226+ pax_force_retaddr
29227 retq
29228 .p2align 4
29229 .Lless_8bytes:
29230@@ -161,6 +165,7 @@ ENTRY(memcpy)
29231 movl -4(%rsi, %rdx), %r8d
29232 movl %ecx, (%rdi)
29233 movl %r8d, -4(%rdi, %rdx)
29234+ pax_force_retaddr
29235 retq
29236 .p2align 4
29237 .Lless_3bytes:
29238@@ -179,6 +184,7 @@ ENTRY(memcpy)
29239 movb %cl, (%rdi)
29240
29241 .Lend:
29242+ pax_force_retaddr
29243 retq
29244 CFI_ENDPROC
29245 ENDPROC(memcpy)
29246diff --git a/arch/x86/lib/memmove_64.S b/arch/x86/lib/memmove_64.S
29247index 65268a6..dd1de11 100644
29248--- a/arch/x86/lib/memmove_64.S
29249+++ b/arch/x86/lib/memmove_64.S
29250@@ -202,14 +202,16 @@ ENTRY(memmove)
29251 movb (%rsi), %r11b
29252 movb %r11b, (%rdi)
29253 13:
29254+ pax_force_retaddr
29255 retq
29256 CFI_ENDPROC
29257
29258- .section .altinstr_replacement,"ax"
29259+ .section .altinstr_replacement,"a"
29260 .Lmemmove_begin_forward_efs:
29261 /* Forward moving data. */
29262 movq %rdx, %rcx
29263 rep movsb
29264+ pax_force_retaddr
29265 retq
29266 .Lmemmove_end_forward_efs:
29267 .previous
29268diff --git a/arch/x86/lib/memset_64.S b/arch/x86/lib/memset_64.S
29269index 2dcb380..2eb79fe 100644
29270--- a/arch/x86/lib/memset_64.S
29271+++ b/arch/x86/lib/memset_64.S
29272@@ -16,7 +16,7 @@
29273 *
29274 * rax original destination
29275 */
29276- .section .altinstr_replacement, "ax", @progbits
29277+ .section .altinstr_replacement, "a", @progbits
29278 .Lmemset_c:
29279 movq %rdi,%r9
29280 movq %rdx,%rcx
29281@@ -30,6 +30,7 @@
29282 movl %edx,%ecx
29283 rep stosb
29284 movq %r9,%rax
29285+ pax_force_retaddr
29286 ret
29287 .Lmemset_e:
29288 .previous
29289@@ -45,13 +46,14 @@
29290 *
29291 * rax original destination
29292 */
29293- .section .altinstr_replacement, "ax", @progbits
29294+ .section .altinstr_replacement, "a", @progbits
29295 .Lmemset_c_e:
29296 movq %rdi,%r9
29297 movb %sil,%al
29298 movq %rdx,%rcx
29299 rep stosb
29300 movq %r9,%rax
29301+ pax_force_retaddr
29302 ret
29303 .Lmemset_e_e:
29304 .previous
29305@@ -118,6 +120,7 @@ ENTRY(__memset)
29306
29307 .Lende:
29308 movq %r10,%rax
29309+ pax_force_retaddr
29310 ret
29311
29312 CFI_RESTORE_STATE
29313diff --git a/arch/x86/lib/mmx_32.c b/arch/x86/lib/mmx_32.c
29314index c9f2d9b..e7fd2c0 100644
29315--- a/arch/x86/lib/mmx_32.c
29316+++ b/arch/x86/lib/mmx_32.c
29317@@ -29,6 +29,7 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
29318 {
29319 void *p;
29320 int i;
29321+ unsigned long cr0;
29322
29323 if (unlikely(in_interrupt()))
29324 return __memcpy(to, from, len);
29325@@ -39,44 +40,72 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
29326 kernel_fpu_begin();
29327
29328 __asm__ __volatile__ (
29329- "1: prefetch (%0)\n" /* This set is 28 bytes */
29330- " prefetch 64(%0)\n"
29331- " prefetch 128(%0)\n"
29332- " prefetch 192(%0)\n"
29333- " prefetch 256(%0)\n"
29334+ "1: prefetch (%1)\n" /* This set is 28 bytes */
29335+ " prefetch 64(%1)\n"
29336+ " prefetch 128(%1)\n"
29337+ " prefetch 192(%1)\n"
29338+ " prefetch 256(%1)\n"
29339 "2: \n"
29340 ".section .fixup, \"ax\"\n"
29341- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
29342+ "3: \n"
29343+
29344+#ifdef CONFIG_PAX_KERNEXEC
29345+ " movl %%cr0, %0\n"
29346+ " movl %0, %%eax\n"
29347+ " andl $0xFFFEFFFF, %%eax\n"
29348+ " movl %%eax, %%cr0\n"
29349+#endif
29350+
29351+ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
29352+
29353+#ifdef CONFIG_PAX_KERNEXEC
29354+ " movl %0, %%cr0\n"
29355+#endif
29356+
29357 " jmp 2b\n"
29358 ".previous\n"
29359 _ASM_EXTABLE(1b, 3b)
29360- : : "r" (from));
29361+ : "=&r" (cr0) : "r" (from) : "ax");
29362
29363 for ( ; i > 5; i--) {
29364 __asm__ __volatile__ (
29365- "1: prefetch 320(%0)\n"
29366- "2: movq (%0), %%mm0\n"
29367- " movq 8(%0), %%mm1\n"
29368- " movq 16(%0), %%mm2\n"
29369- " movq 24(%0), %%mm3\n"
29370- " movq %%mm0, (%1)\n"
29371- " movq %%mm1, 8(%1)\n"
29372- " movq %%mm2, 16(%1)\n"
29373- " movq %%mm3, 24(%1)\n"
29374- " movq 32(%0), %%mm0\n"
29375- " movq 40(%0), %%mm1\n"
29376- " movq 48(%0), %%mm2\n"
29377- " movq 56(%0), %%mm3\n"
29378- " movq %%mm0, 32(%1)\n"
29379- " movq %%mm1, 40(%1)\n"
29380- " movq %%mm2, 48(%1)\n"
29381- " movq %%mm3, 56(%1)\n"
29382+ "1: prefetch 320(%1)\n"
29383+ "2: movq (%1), %%mm0\n"
29384+ " movq 8(%1), %%mm1\n"
29385+ " movq 16(%1), %%mm2\n"
29386+ " movq 24(%1), %%mm3\n"
29387+ " movq %%mm0, (%2)\n"
29388+ " movq %%mm1, 8(%2)\n"
29389+ " movq %%mm2, 16(%2)\n"
29390+ " movq %%mm3, 24(%2)\n"
29391+ " movq 32(%1), %%mm0\n"
29392+ " movq 40(%1), %%mm1\n"
29393+ " movq 48(%1), %%mm2\n"
29394+ " movq 56(%1), %%mm3\n"
29395+ " movq %%mm0, 32(%2)\n"
29396+ " movq %%mm1, 40(%2)\n"
29397+ " movq %%mm2, 48(%2)\n"
29398+ " movq %%mm3, 56(%2)\n"
29399 ".section .fixup, \"ax\"\n"
29400- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
29401+ "3:\n"
29402+
29403+#ifdef CONFIG_PAX_KERNEXEC
29404+ " movl %%cr0, %0\n"
29405+ " movl %0, %%eax\n"
29406+ " andl $0xFFFEFFFF, %%eax\n"
29407+ " movl %%eax, %%cr0\n"
29408+#endif
29409+
29410+ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
29411+
29412+#ifdef CONFIG_PAX_KERNEXEC
29413+ " movl %0, %%cr0\n"
29414+#endif
29415+
29416 " jmp 2b\n"
29417 ".previous\n"
29418 _ASM_EXTABLE(1b, 3b)
29419- : : "r" (from), "r" (to) : "memory");
29420+ : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
29421
29422 from += 64;
29423 to += 64;
29424@@ -158,6 +187,7 @@ static void fast_clear_page(void *page)
29425 static void fast_copy_page(void *to, void *from)
29426 {
29427 int i;
29428+ unsigned long cr0;
29429
29430 kernel_fpu_begin();
29431
29432@@ -166,42 +196,70 @@ static void fast_copy_page(void *to, void *from)
29433 * but that is for later. -AV
29434 */
29435 __asm__ __volatile__(
29436- "1: prefetch (%0)\n"
29437- " prefetch 64(%0)\n"
29438- " prefetch 128(%0)\n"
29439- " prefetch 192(%0)\n"
29440- " prefetch 256(%0)\n"
29441+ "1: prefetch (%1)\n"
29442+ " prefetch 64(%1)\n"
29443+ " prefetch 128(%1)\n"
29444+ " prefetch 192(%1)\n"
29445+ " prefetch 256(%1)\n"
29446 "2: \n"
29447 ".section .fixup, \"ax\"\n"
29448- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
29449+ "3: \n"
29450+
29451+#ifdef CONFIG_PAX_KERNEXEC
29452+ " movl %%cr0, %0\n"
29453+ " movl %0, %%eax\n"
29454+ " andl $0xFFFEFFFF, %%eax\n"
29455+ " movl %%eax, %%cr0\n"
29456+#endif
29457+
29458+ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
29459+
29460+#ifdef CONFIG_PAX_KERNEXEC
29461+ " movl %0, %%cr0\n"
29462+#endif
29463+
29464 " jmp 2b\n"
29465 ".previous\n"
29466- _ASM_EXTABLE(1b, 3b) : : "r" (from));
29467+ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
29468
29469 for (i = 0; i < (4096-320)/64; i++) {
29470 __asm__ __volatile__ (
29471- "1: prefetch 320(%0)\n"
29472- "2: movq (%0), %%mm0\n"
29473- " movntq %%mm0, (%1)\n"
29474- " movq 8(%0), %%mm1\n"
29475- " movntq %%mm1, 8(%1)\n"
29476- " movq 16(%0), %%mm2\n"
29477- " movntq %%mm2, 16(%1)\n"
29478- " movq 24(%0), %%mm3\n"
29479- " movntq %%mm3, 24(%1)\n"
29480- " movq 32(%0), %%mm4\n"
29481- " movntq %%mm4, 32(%1)\n"
29482- " movq 40(%0), %%mm5\n"
29483- " movntq %%mm5, 40(%1)\n"
29484- " movq 48(%0), %%mm6\n"
29485- " movntq %%mm6, 48(%1)\n"
29486- " movq 56(%0), %%mm7\n"
29487- " movntq %%mm7, 56(%1)\n"
29488+ "1: prefetch 320(%1)\n"
29489+ "2: movq (%1), %%mm0\n"
29490+ " movntq %%mm0, (%2)\n"
29491+ " movq 8(%1), %%mm1\n"
29492+ " movntq %%mm1, 8(%2)\n"
29493+ " movq 16(%1), %%mm2\n"
29494+ " movntq %%mm2, 16(%2)\n"
29495+ " movq 24(%1), %%mm3\n"
29496+ " movntq %%mm3, 24(%2)\n"
29497+ " movq 32(%1), %%mm4\n"
29498+ " movntq %%mm4, 32(%2)\n"
29499+ " movq 40(%1), %%mm5\n"
29500+ " movntq %%mm5, 40(%2)\n"
29501+ " movq 48(%1), %%mm6\n"
29502+ " movntq %%mm6, 48(%2)\n"
29503+ " movq 56(%1), %%mm7\n"
29504+ " movntq %%mm7, 56(%2)\n"
29505 ".section .fixup, \"ax\"\n"
29506- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
29507+ "3:\n"
29508+
29509+#ifdef CONFIG_PAX_KERNEXEC
29510+ " movl %%cr0, %0\n"
29511+ " movl %0, %%eax\n"
29512+ " andl $0xFFFEFFFF, %%eax\n"
29513+ " movl %%eax, %%cr0\n"
29514+#endif
29515+
29516+ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
29517+
29518+#ifdef CONFIG_PAX_KERNEXEC
29519+ " movl %0, %%cr0\n"
29520+#endif
29521+
29522 " jmp 2b\n"
29523 ".previous\n"
29524- _ASM_EXTABLE(1b, 3b) : : "r" (from), "r" (to) : "memory");
29525+ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
29526
29527 from += 64;
29528 to += 64;
29529@@ -280,47 +338,76 @@ static void fast_clear_page(void *page)
29530 static void fast_copy_page(void *to, void *from)
29531 {
29532 int i;
29533+ unsigned long cr0;
29534
29535 kernel_fpu_begin();
29536
29537 __asm__ __volatile__ (
29538- "1: prefetch (%0)\n"
29539- " prefetch 64(%0)\n"
29540- " prefetch 128(%0)\n"
29541- " prefetch 192(%0)\n"
29542- " prefetch 256(%0)\n"
29543+ "1: prefetch (%1)\n"
29544+ " prefetch 64(%1)\n"
29545+ " prefetch 128(%1)\n"
29546+ " prefetch 192(%1)\n"
29547+ " prefetch 256(%1)\n"
29548 "2: \n"
29549 ".section .fixup, \"ax\"\n"
29550- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
29551+ "3: \n"
29552+
29553+#ifdef CONFIG_PAX_KERNEXEC
29554+ " movl %%cr0, %0\n"
29555+ " movl %0, %%eax\n"
29556+ " andl $0xFFFEFFFF, %%eax\n"
29557+ " movl %%eax, %%cr0\n"
29558+#endif
29559+
29560+ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
29561+
29562+#ifdef CONFIG_PAX_KERNEXEC
29563+ " movl %0, %%cr0\n"
29564+#endif
29565+
29566 " jmp 2b\n"
29567 ".previous\n"
29568- _ASM_EXTABLE(1b, 3b) : : "r" (from));
29569+ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
29570
29571 for (i = 0; i < 4096/64; i++) {
29572 __asm__ __volatile__ (
29573- "1: prefetch 320(%0)\n"
29574- "2: movq (%0), %%mm0\n"
29575- " movq 8(%0), %%mm1\n"
29576- " movq 16(%0), %%mm2\n"
29577- " movq 24(%0), %%mm3\n"
29578- " movq %%mm0, (%1)\n"
29579- " movq %%mm1, 8(%1)\n"
29580- " movq %%mm2, 16(%1)\n"
29581- " movq %%mm3, 24(%1)\n"
29582- " movq 32(%0), %%mm0\n"
29583- " movq 40(%0), %%mm1\n"
29584- " movq 48(%0), %%mm2\n"
29585- " movq 56(%0), %%mm3\n"
29586- " movq %%mm0, 32(%1)\n"
29587- " movq %%mm1, 40(%1)\n"
29588- " movq %%mm2, 48(%1)\n"
29589- " movq %%mm3, 56(%1)\n"
29590+ "1: prefetch 320(%1)\n"
29591+ "2: movq (%1), %%mm0\n"
29592+ " movq 8(%1), %%mm1\n"
29593+ " movq 16(%1), %%mm2\n"
29594+ " movq 24(%1), %%mm3\n"
29595+ " movq %%mm0, (%2)\n"
29596+ " movq %%mm1, 8(%2)\n"
29597+ " movq %%mm2, 16(%2)\n"
29598+ " movq %%mm3, 24(%2)\n"
29599+ " movq 32(%1), %%mm0\n"
29600+ " movq 40(%1), %%mm1\n"
29601+ " movq 48(%1), %%mm2\n"
29602+ " movq 56(%1), %%mm3\n"
29603+ " movq %%mm0, 32(%2)\n"
29604+ " movq %%mm1, 40(%2)\n"
29605+ " movq %%mm2, 48(%2)\n"
29606+ " movq %%mm3, 56(%2)\n"
29607 ".section .fixup, \"ax\"\n"
29608- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
29609+ "3:\n"
29610+
29611+#ifdef CONFIG_PAX_KERNEXEC
29612+ " movl %%cr0, %0\n"
29613+ " movl %0, %%eax\n"
29614+ " andl $0xFFFEFFFF, %%eax\n"
29615+ " movl %%eax, %%cr0\n"
29616+#endif
29617+
29618+ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
29619+
29620+#ifdef CONFIG_PAX_KERNEXEC
29621+ " movl %0, %%cr0\n"
29622+#endif
29623+
29624 " jmp 2b\n"
29625 ".previous\n"
29626 _ASM_EXTABLE(1b, 3b)
29627- : : "r" (from), "r" (to) : "memory");
29628+ : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
29629
29630 from += 64;
29631 to += 64;
29632diff --git a/arch/x86/lib/msr-reg.S b/arch/x86/lib/msr-reg.S
29633index f6d13ee..d789440 100644
29634--- a/arch/x86/lib/msr-reg.S
29635+++ b/arch/x86/lib/msr-reg.S
29636@@ -3,6 +3,7 @@
29637 #include <asm/dwarf2.h>
29638 #include <asm/asm.h>
29639 #include <asm/msr.h>
29640+#include <asm/alternative-asm.h>
29641
29642 #ifdef CONFIG_X86_64
29643 /*
29644@@ -37,6 +38,7 @@ ENTRY(\op\()_safe_regs)
29645 movl %edi, 28(%r10)
29646 popq_cfi %rbp
29647 popq_cfi %rbx
29648+ pax_force_retaddr
29649 ret
29650 3:
29651 CFI_RESTORE_STATE
29652diff --git a/arch/x86/lib/putuser.S b/arch/x86/lib/putuser.S
29653index fc6ba17..d4d989d 100644
29654--- a/arch/x86/lib/putuser.S
29655+++ b/arch/x86/lib/putuser.S
29656@@ -16,7 +16,9 @@
29657 #include <asm/errno.h>
29658 #include <asm/asm.h>
29659 #include <asm/smap.h>
29660-
29661+#include <asm/segment.h>
29662+#include <asm/pgtable.h>
29663+#include <asm/alternative-asm.h>
29664
29665 /*
29666 * __put_user_X
29667@@ -30,57 +32,125 @@
29668 * as they get called from within inline assembly.
29669 */
29670
29671-#define ENTER CFI_STARTPROC ; \
29672- GET_THREAD_INFO(%_ASM_BX)
29673-#define EXIT ASM_CLAC ; \
29674- ret ; \
29675+#define ENTER CFI_STARTPROC
29676+#define EXIT ASM_CLAC ; \
29677+ pax_force_retaddr ; \
29678+ ret ; \
29679 CFI_ENDPROC
29680
29681+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
29682+#define _DEST %_ASM_CX,%_ASM_BX
29683+#else
29684+#define _DEST %_ASM_CX
29685+#endif
29686+
29687+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
29688+#define __copyuser_seg gs;
29689+#else
29690+#define __copyuser_seg
29691+#endif
29692+
29693 .text
29694 ENTRY(__put_user_1)
29695 ENTER
29696+
29697+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
29698+ GET_THREAD_INFO(%_ASM_BX)
29699 cmp TI_addr_limit(%_ASM_BX),%_ASM_CX
29700 jae bad_put_user
29701 ASM_STAC
29702-1: movb %al,(%_ASM_CX)
29703+
29704+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
29705+ mov pax_user_shadow_base,%_ASM_BX
29706+ cmp %_ASM_BX,%_ASM_CX
29707+ jb 1234f
29708+ xor %ebx,%ebx
29709+1234:
29710+#endif
29711+
29712+#endif
29713+
29714+1: __copyuser_seg movb %al,(_DEST)
29715 xor %eax,%eax
29716 EXIT
29717 ENDPROC(__put_user_1)
29718
29719 ENTRY(__put_user_2)
29720 ENTER
29721+
29722+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
29723+ GET_THREAD_INFO(%_ASM_BX)
29724 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
29725 sub $1,%_ASM_BX
29726 cmp %_ASM_BX,%_ASM_CX
29727 jae bad_put_user
29728 ASM_STAC
29729-2: movw %ax,(%_ASM_CX)
29730+
29731+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
29732+ mov pax_user_shadow_base,%_ASM_BX
29733+ cmp %_ASM_BX,%_ASM_CX
29734+ jb 1234f
29735+ xor %ebx,%ebx
29736+1234:
29737+#endif
29738+
29739+#endif
29740+
29741+2: __copyuser_seg movw %ax,(_DEST)
29742 xor %eax,%eax
29743 EXIT
29744 ENDPROC(__put_user_2)
29745
29746 ENTRY(__put_user_4)
29747 ENTER
29748+
29749+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
29750+ GET_THREAD_INFO(%_ASM_BX)
29751 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
29752 sub $3,%_ASM_BX
29753 cmp %_ASM_BX,%_ASM_CX
29754 jae bad_put_user
29755 ASM_STAC
29756-3: movl %eax,(%_ASM_CX)
29757+
29758+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
29759+ mov pax_user_shadow_base,%_ASM_BX
29760+ cmp %_ASM_BX,%_ASM_CX
29761+ jb 1234f
29762+ xor %ebx,%ebx
29763+1234:
29764+#endif
29765+
29766+#endif
29767+
29768+3: __copyuser_seg movl %eax,(_DEST)
29769 xor %eax,%eax
29770 EXIT
29771 ENDPROC(__put_user_4)
29772
29773 ENTRY(__put_user_8)
29774 ENTER
29775+
29776+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
29777+ GET_THREAD_INFO(%_ASM_BX)
29778 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
29779 sub $7,%_ASM_BX
29780 cmp %_ASM_BX,%_ASM_CX
29781 jae bad_put_user
29782 ASM_STAC
29783-4: mov %_ASM_AX,(%_ASM_CX)
29784+
29785+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
29786+ mov pax_user_shadow_base,%_ASM_BX
29787+ cmp %_ASM_BX,%_ASM_CX
29788+ jb 1234f
29789+ xor %ebx,%ebx
29790+1234:
29791+#endif
29792+
29793+#endif
29794+
29795+4: __copyuser_seg mov %_ASM_AX,(_DEST)
29796 #ifdef CONFIG_X86_32
29797-5: movl %edx,4(%_ASM_CX)
29798+5: __copyuser_seg movl %edx,4(_DEST)
29799 #endif
29800 xor %eax,%eax
29801 EXIT
29802diff --git a/arch/x86/lib/rwlock.S b/arch/x86/lib/rwlock.S
29803index 1cad221..de671ee 100644
29804--- a/arch/x86/lib/rwlock.S
29805+++ b/arch/x86/lib/rwlock.S
29806@@ -16,13 +16,34 @@ ENTRY(__write_lock_failed)
29807 FRAME
29808 0: LOCK_PREFIX
29809 WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
29810+
29811+#ifdef CONFIG_PAX_REFCOUNT
29812+ jno 1234f
29813+ LOCK_PREFIX
29814+ WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
29815+ int $4
29816+1234:
29817+ _ASM_EXTABLE(1234b, 1234b)
29818+#endif
29819+
29820 1: rep; nop
29821 cmpl $WRITE_LOCK_CMP, (%__lock_ptr)
29822 jne 1b
29823 LOCK_PREFIX
29824 WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
29825+
29826+#ifdef CONFIG_PAX_REFCOUNT
29827+ jno 1234f
29828+ LOCK_PREFIX
29829+ WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
29830+ int $4
29831+1234:
29832+ _ASM_EXTABLE(1234b, 1234b)
29833+#endif
29834+
29835 jnz 0b
29836 ENDFRAME
29837+ pax_force_retaddr
29838 ret
29839 CFI_ENDPROC
29840 END(__write_lock_failed)
29841@@ -32,13 +53,34 @@ ENTRY(__read_lock_failed)
29842 FRAME
29843 0: LOCK_PREFIX
29844 READ_LOCK_SIZE(inc) (%__lock_ptr)
29845+
29846+#ifdef CONFIG_PAX_REFCOUNT
29847+ jno 1234f
29848+ LOCK_PREFIX
29849+ READ_LOCK_SIZE(dec) (%__lock_ptr)
29850+ int $4
29851+1234:
29852+ _ASM_EXTABLE(1234b, 1234b)
29853+#endif
29854+
29855 1: rep; nop
29856 READ_LOCK_SIZE(cmp) $1, (%__lock_ptr)
29857 js 1b
29858 LOCK_PREFIX
29859 READ_LOCK_SIZE(dec) (%__lock_ptr)
29860+
29861+#ifdef CONFIG_PAX_REFCOUNT
29862+ jno 1234f
29863+ LOCK_PREFIX
29864+ READ_LOCK_SIZE(inc) (%__lock_ptr)
29865+ int $4
29866+1234:
29867+ _ASM_EXTABLE(1234b, 1234b)
29868+#endif
29869+
29870 js 0b
29871 ENDFRAME
29872+ pax_force_retaddr
29873 ret
29874 CFI_ENDPROC
29875 END(__read_lock_failed)
29876diff --git a/arch/x86/lib/rwsem.S b/arch/x86/lib/rwsem.S
29877index 5dff5f0..cadebf4 100644
29878--- a/arch/x86/lib/rwsem.S
29879+++ b/arch/x86/lib/rwsem.S
29880@@ -94,6 +94,7 @@ ENTRY(call_rwsem_down_read_failed)
29881 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
29882 CFI_RESTORE __ASM_REG(dx)
29883 restore_common_regs
29884+ pax_force_retaddr
29885 ret
29886 CFI_ENDPROC
29887 ENDPROC(call_rwsem_down_read_failed)
29888@@ -104,6 +105,7 @@ ENTRY(call_rwsem_down_write_failed)
29889 movq %rax,%rdi
29890 call rwsem_down_write_failed
29891 restore_common_regs
29892+ pax_force_retaddr
29893 ret
29894 CFI_ENDPROC
29895 ENDPROC(call_rwsem_down_write_failed)
29896@@ -117,7 +119,8 @@ ENTRY(call_rwsem_wake)
29897 movq %rax,%rdi
29898 call rwsem_wake
29899 restore_common_regs
29900-1: ret
29901+1: pax_force_retaddr
29902+ ret
29903 CFI_ENDPROC
29904 ENDPROC(call_rwsem_wake)
29905
29906@@ -131,6 +134,7 @@ ENTRY(call_rwsem_downgrade_wake)
29907 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
29908 CFI_RESTORE __ASM_REG(dx)
29909 restore_common_regs
29910+ pax_force_retaddr
29911 ret
29912 CFI_ENDPROC
29913 ENDPROC(call_rwsem_downgrade_wake)
29914diff --git a/arch/x86/lib/thunk_64.S b/arch/x86/lib/thunk_64.S
29915index a63efd6..8149fbe 100644
29916--- a/arch/x86/lib/thunk_64.S
29917+++ b/arch/x86/lib/thunk_64.S
29918@@ -8,6 +8,7 @@
29919 #include <linux/linkage.h>
29920 #include <asm/dwarf2.h>
29921 #include <asm/calling.h>
29922+#include <asm/alternative-asm.h>
29923
29924 /* rdi: arg1 ... normal C conventions. rax is saved/restored. */
29925 .macro THUNK name, func, put_ret_addr_in_rdi=0
29926@@ -15,11 +16,11 @@
29927 \name:
29928 CFI_STARTPROC
29929
29930- /* this one pushes 9 elems, the next one would be %rIP */
29931- SAVE_ARGS
29932+ /* this one pushes 15+1 elems, the next one would be %rIP */
29933+ SAVE_ARGS 8
29934
29935 .if \put_ret_addr_in_rdi
29936- movq_cfi_restore 9*8, rdi
29937+ movq_cfi_restore RIP, rdi
29938 .endif
29939
29940 call \func
29941@@ -38,8 +39,9 @@
29942
29943 /* SAVE_ARGS below is used only for the .cfi directives it contains. */
29944 CFI_STARTPROC
29945- SAVE_ARGS
29946+ SAVE_ARGS 8
29947 restore:
29948- RESTORE_ARGS
29949+ RESTORE_ARGS 1,8
29950+ pax_force_retaddr
29951 ret
29952 CFI_ENDPROC
29953diff --git a/arch/x86/lib/usercopy_32.c b/arch/x86/lib/usercopy_32.c
29954index 3eb18ac..4b22130 100644
29955--- a/arch/x86/lib/usercopy_32.c
29956+++ b/arch/x86/lib/usercopy_32.c
29957@@ -42,11 +42,13 @@ do { \
29958 int __d0; \
29959 might_fault(); \
29960 __asm__ __volatile__( \
29961+ __COPYUSER_SET_ES \
29962 ASM_STAC "\n" \
29963 "0: rep; stosl\n" \
29964 " movl %2,%0\n" \
29965 "1: rep; stosb\n" \
29966 "2: " ASM_CLAC "\n" \
29967+ __COPYUSER_RESTORE_ES \
29968 ".section .fixup,\"ax\"\n" \
29969 "3: lea 0(%2,%0,4),%0\n" \
29970 " jmp 2b\n" \
29971@@ -98,7 +100,7 @@ EXPORT_SYMBOL(__clear_user);
29972
29973 #ifdef CONFIG_X86_INTEL_USERCOPY
29974 static unsigned long
29975-__copy_user_intel(void __user *to, const void *from, unsigned long size)
29976+__generic_copy_to_user_intel(void __user *to, const void *from, unsigned long size)
29977 {
29978 int d0, d1;
29979 __asm__ __volatile__(
29980@@ -110,36 +112,36 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
29981 " .align 2,0x90\n"
29982 "3: movl 0(%4), %%eax\n"
29983 "4: movl 4(%4), %%edx\n"
29984- "5: movl %%eax, 0(%3)\n"
29985- "6: movl %%edx, 4(%3)\n"
29986+ "5: "__copyuser_seg" movl %%eax, 0(%3)\n"
29987+ "6: "__copyuser_seg" movl %%edx, 4(%3)\n"
29988 "7: movl 8(%4), %%eax\n"
29989 "8: movl 12(%4),%%edx\n"
29990- "9: movl %%eax, 8(%3)\n"
29991- "10: movl %%edx, 12(%3)\n"
29992+ "9: "__copyuser_seg" movl %%eax, 8(%3)\n"
29993+ "10: "__copyuser_seg" movl %%edx, 12(%3)\n"
29994 "11: movl 16(%4), %%eax\n"
29995 "12: movl 20(%4), %%edx\n"
29996- "13: movl %%eax, 16(%3)\n"
29997- "14: movl %%edx, 20(%3)\n"
29998+ "13: "__copyuser_seg" movl %%eax, 16(%3)\n"
29999+ "14: "__copyuser_seg" movl %%edx, 20(%3)\n"
30000 "15: movl 24(%4), %%eax\n"
30001 "16: movl 28(%4), %%edx\n"
30002- "17: movl %%eax, 24(%3)\n"
30003- "18: movl %%edx, 28(%3)\n"
30004+ "17: "__copyuser_seg" movl %%eax, 24(%3)\n"
30005+ "18: "__copyuser_seg" movl %%edx, 28(%3)\n"
30006 "19: movl 32(%4), %%eax\n"
30007 "20: movl 36(%4), %%edx\n"
30008- "21: movl %%eax, 32(%3)\n"
30009- "22: movl %%edx, 36(%3)\n"
30010+ "21: "__copyuser_seg" movl %%eax, 32(%3)\n"
30011+ "22: "__copyuser_seg" movl %%edx, 36(%3)\n"
30012 "23: movl 40(%4), %%eax\n"
30013 "24: movl 44(%4), %%edx\n"
30014- "25: movl %%eax, 40(%3)\n"
30015- "26: movl %%edx, 44(%3)\n"
30016+ "25: "__copyuser_seg" movl %%eax, 40(%3)\n"
30017+ "26: "__copyuser_seg" movl %%edx, 44(%3)\n"
30018 "27: movl 48(%4), %%eax\n"
30019 "28: movl 52(%4), %%edx\n"
30020- "29: movl %%eax, 48(%3)\n"
30021- "30: movl %%edx, 52(%3)\n"
30022+ "29: "__copyuser_seg" movl %%eax, 48(%3)\n"
30023+ "30: "__copyuser_seg" movl %%edx, 52(%3)\n"
30024 "31: movl 56(%4), %%eax\n"
30025 "32: movl 60(%4), %%edx\n"
30026- "33: movl %%eax, 56(%3)\n"
30027- "34: movl %%edx, 60(%3)\n"
30028+ "33: "__copyuser_seg" movl %%eax, 56(%3)\n"
30029+ "34: "__copyuser_seg" movl %%edx, 60(%3)\n"
30030 " addl $-64, %0\n"
30031 " addl $64, %4\n"
30032 " addl $64, %3\n"
30033@@ -149,10 +151,116 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
30034 " shrl $2, %0\n"
30035 " andl $3, %%eax\n"
30036 " cld\n"
30037+ __COPYUSER_SET_ES
30038 "99: rep; movsl\n"
30039 "36: movl %%eax, %0\n"
30040 "37: rep; movsb\n"
30041 "100:\n"
30042+ __COPYUSER_RESTORE_ES
30043+ ".section .fixup,\"ax\"\n"
30044+ "101: lea 0(%%eax,%0,4),%0\n"
30045+ " jmp 100b\n"
30046+ ".previous\n"
30047+ _ASM_EXTABLE(1b,100b)
30048+ _ASM_EXTABLE(2b,100b)
30049+ _ASM_EXTABLE(3b,100b)
30050+ _ASM_EXTABLE(4b,100b)
30051+ _ASM_EXTABLE(5b,100b)
30052+ _ASM_EXTABLE(6b,100b)
30053+ _ASM_EXTABLE(7b,100b)
30054+ _ASM_EXTABLE(8b,100b)
30055+ _ASM_EXTABLE(9b,100b)
30056+ _ASM_EXTABLE(10b,100b)
30057+ _ASM_EXTABLE(11b,100b)
30058+ _ASM_EXTABLE(12b,100b)
30059+ _ASM_EXTABLE(13b,100b)
30060+ _ASM_EXTABLE(14b,100b)
30061+ _ASM_EXTABLE(15b,100b)
30062+ _ASM_EXTABLE(16b,100b)
30063+ _ASM_EXTABLE(17b,100b)
30064+ _ASM_EXTABLE(18b,100b)
30065+ _ASM_EXTABLE(19b,100b)
30066+ _ASM_EXTABLE(20b,100b)
30067+ _ASM_EXTABLE(21b,100b)
30068+ _ASM_EXTABLE(22b,100b)
30069+ _ASM_EXTABLE(23b,100b)
30070+ _ASM_EXTABLE(24b,100b)
30071+ _ASM_EXTABLE(25b,100b)
30072+ _ASM_EXTABLE(26b,100b)
30073+ _ASM_EXTABLE(27b,100b)
30074+ _ASM_EXTABLE(28b,100b)
30075+ _ASM_EXTABLE(29b,100b)
30076+ _ASM_EXTABLE(30b,100b)
30077+ _ASM_EXTABLE(31b,100b)
30078+ _ASM_EXTABLE(32b,100b)
30079+ _ASM_EXTABLE(33b,100b)
30080+ _ASM_EXTABLE(34b,100b)
30081+ _ASM_EXTABLE(35b,100b)
30082+ _ASM_EXTABLE(36b,100b)
30083+ _ASM_EXTABLE(37b,100b)
30084+ _ASM_EXTABLE(99b,101b)
30085+ : "=&c"(size), "=&D" (d0), "=&S" (d1)
30086+ : "1"(to), "2"(from), "0"(size)
30087+ : "eax", "edx", "memory");
30088+ return size;
30089+}
30090+
30091+static unsigned long
30092+__generic_copy_from_user_intel(void *to, const void __user *from, unsigned long size)
30093+{
30094+ int d0, d1;
30095+ __asm__ __volatile__(
30096+ " .align 2,0x90\n"
30097+ "1: "__copyuser_seg" movl 32(%4), %%eax\n"
30098+ " cmpl $67, %0\n"
30099+ " jbe 3f\n"
30100+ "2: "__copyuser_seg" movl 64(%4), %%eax\n"
30101+ " .align 2,0x90\n"
30102+ "3: "__copyuser_seg" movl 0(%4), %%eax\n"
30103+ "4: "__copyuser_seg" movl 4(%4), %%edx\n"
30104+ "5: movl %%eax, 0(%3)\n"
30105+ "6: movl %%edx, 4(%3)\n"
30106+ "7: "__copyuser_seg" movl 8(%4), %%eax\n"
30107+ "8: "__copyuser_seg" movl 12(%4),%%edx\n"
30108+ "9: movl %%eax, 8(%3)\n"
30109+ "10: movl %%edx, 12(%3)\n"
30110+ "11: "__copyuser_seg" movl 16(%4), %%eax\n"
30111+ "12: "__copyuser_seg" movl 20(%4), %%edx\n"
30112+ "13: movl %%eax, 16(%3)\n"
30113+ "14: movl %%edx, 20(%3)\n"
30114+ "15: "__copyuser_seg" movl 24(%4), %%eax\n"
30115+ "16: "__copyuser_seg" movl 28(%4), %%edx\n"
30116+ "17: movl %%eax, 24(%3)\n"
30117+ "18: movl %%edx, 28(%3)\n"
30118+ "19: "__copyuser_seg" movl 32(%4), %%eax\n"
30119+ "20: "__copyuser_seg" movl 36(%4), %%edx\n"
30120+ "21: movl %%eax, 32(%3)\n"
30121+ "22: movl %%edx, 36(%3)\n"
30122+ "23: "__copyuser_seg" movl 40(%4), %%eax\n"
30123+ "24: "__copyuser_seg" movl 44(%4), %%edx\n"
30124+ "25: movl %%eax, 40(%3)\n"
30125+ "26: movl %%edx, 44(%3)\n"
30126+ "27: "__copyuser_seg" movl 48(%4), %%eax\n"
30127+ "28: "__copyuser_seg" movl 52(%4), %%edx\n"
30128+ "29: movl %%eax, 48(%3)\n"
30129+ "30: movl %%edx, 52(%3)\n"
30130+ "31: "__copyuser_seg" movl 56(%4), %%eax\n"
30131+ "32: "__copyuser_seg" movl 60(%4), %%edx\n"
30132+ "33: movl %%eax, 56(%3)\n"
30133+ "34: movl %%edx, 60(%3)\n"
30134+ " addl $-64, %0\n"
30135+ " addl $64, %4\n"
30136+ " addl $64, %3\n"
30137+ " cmpl $63, %0\n"
30138+ " ja 1b\n"
30139+ "35: movl %0, %%eax\n"
30140+ " shrl $2, %0\n"
30141+ " andl $3, %%eax\n"
30142+ " cld\n"
30143+ "99: rep; "__copyuser_seg" movsl\n"
30144+ "36: movl %%eax, %0\n"
30145+ "37: rep; "__copyuser_seg" movsb\n"
30146+ "100:\n"
30147 ".section .fixup,\"ax\"\n"
30148 "101: lea 0(%%eax,%0,4),%0\n"
30149 " jmp 100b\n"
30150@@ -207,41 +315,41 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
30151 int d0, d1;
30152 __asm__ __volatile__(
30153 " .align 2,0x90\n"
30154- "0: movl 32(%4), %%eax\n"
30155+ "0: "__copyuser_seg" movl 32(%4), %%eax\n"
30156 " cmpl $67, %0\n"
30157 " jbe 2f\n"
30158- "1: movl 64(%4), %%eax\n"
30159+ "1: "__copyuser_seg" movl 64(%4), %%eax\n"
30160 " .align 2,0x90\n"
30161- "2: movl 0(%4), %%eax\n"
30162- "21: movl 4(%4), %%edx\n"
30163+ "2: "__copyuser_seg" movl 0(%4), %%eax\n"
30164+ "21: "__copyuser_seg" movl 4(%4), %%edx\n"
30165 " movl %%eax, 0(%3)\n"
30166 " movl %%edx, 4(%3)\n"
30167- "3: movl 8(%4), %%eax\n"
30168- "31: movl 12(%4),%%edx\n"
30169+ "3: "__copyuser_seg" movl 8(%4), %%eax\n"
30170+ "31: "__copyuser_seg" movl 12(%4),%%edx\n"
30171 " movl %%eax, 8(%3)\n"
30172 " movl %%edx, 12(%3)\n"
30173- "4: movl 16(%4), %%eax\n"
30174- "41: movl 20(%4), %%edx\n"
30175+ "4: "__copyuser_seg" movl 16(%4), %%eax\n"
30176+ "41: "__copyuser_seg" movl 20(%4), %%edx\n"
30177 " movl %%eax, 16(%3)\n"
30178 " movl %%edx, 20(%3)\n"
30179- "10: movl 24(%4), %%eax\n"
30180- "51: movl 28(%4), %%edx\n"
30181+ "10: "__copyuser_seg" movl 24(%4), %%eax\n"
30182+ "51: "__copyuser_seg" movl 28(%4), %%edx\n"
30183 " movl %%eax, 24(%3)\n"
30184 " movl %%edx, 28(%3)\n"
30185- "11: movl 32(%4), %%eax\n"
30186- "61: movl 36(%4), %%edx\n"
30187+ "11: "__copyuser_seg" movl 32(%4), %%eax\n"
30188+ "61: "__copyuser_seg" movl 36(%4), %%edx\n"
30189 " movl %%eax, 32(%3)\n"
30190 " movl %%edx, 36(%3)\n"
30191- "12: movl 40(%4), %%eax\n"
30192- "71: movl 44(%4), %%edx\n"
30193+ "12: "__copyuser_seg" movl 40(%4), %%eax\n"
30194+ "71: "__copyuser_seg" movl 44(%4), %%edx\n"
30195 " movl %%eax, 40(%3)\n"
30196 " movl %%edx, 44(%3)\n"
30197- "13: movl 48(%4), %%eax\n"
30198- "81: movl 52(%4), %%edx\n"
30199+ "13: "__copyuser_seg" movl 48(%4), %%eax\n"
30200+ "81: "__copyuser_seg" movl 52(%4), %%edx\n"
30201 " movl %%eax, 48(%3)\n"
30202 " movl %%edx, 52(%3)\n"
30203- "14: movl 56(%4), %%eax\n"
30204- "91: movl 60(%4), %%edx\n"
30205+ "14: "__copyuser_seg" movl 56(%4), %%eax\n"
30206+ "91: "__copyuser_seg" movl 60(%4), %%edx\n"
30207 " movl %%eax, 56(%3)\n"
30208 " movl %%edx, 60(%3)\n"
30209 " addl $-64, %0\n"
30210@@ -253,9 +361,9 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
30211 " shrl $2, %0\n"
30212 " andl $3, %%eax\n"
30213 " cld\n"
30214- "6: rep; movsl\n"
30215+ "6: rep; "__copyuser_seg" movsl\n"
30216 " movl %%eax,%0\n"
30217- "7: rep; movsb\n"
30218+ "7: rep; "__copyuser_seg" movsb\n"
30219 "8:\n"
30220 ".section .fixup,\"ax\"\n"
30221 "9: lea 0(%%eax,%0,4),%0\n"
30222@@ -305,41 +413,41 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
30223
30224 __asm__ __volatile__(
30225 " .align 2,0x90\n"
30226- "0: movl 32(%4), %%eax\n"
30227+ "0: "__copyuser_seg" movl 32(%4), %%eax\n"
30228 " cmpl $67, %0\n"
30229 " jbe 2f\n"
30230- "1: movl 64(%4), %%eax\n"
30231+ "1: "__copyuser_seg" movl 64(%4), %%eax\n"
30232 " .align 2,0x90\n"
30233- "2: movl 0(%4), %%eax\n"
30234- "21: movl 4(%4), %%edx\n"
30235+ "2: "__copyuser_seg" movl 0(%4), %%eax\n"
30236+ "21: "__copyuser_seg" movl 4(%4), %%edx\n"
30237 " movnti %%eax, 0(%3)\n"
30238 " movnti %%edx, 4(%3)\n"
30239- "3: movl 8(%4), %%eax\n"
30240- "31: movl 12(%4),%%edx\n"
30241+ "3: "__copyuser_seg" movl 8(%4), %%eax\n"
30242+ "31: "__copyuser_seg" movl 12(%4),%%edx\n"
30243 " movnti %%eax, 8(%3)\n"
30244 " movnti %%edx, 12(%3)\n"
30245- "4: movl 16(%4), %%eax\n"
30246- "41: movl 20(%4), %%edx\n"
30247+ "4: "__copyuser_seg" movl 16(%4), %%eax\n"
30248+ "41: "__copyuser_seg" movl 20(%4), %%edx\n"
30249 " movnti %%eax, 16(%3)\n"
30250 " movnti %%edx, 20(%3)\n"
30251- "10: movl 24(%4), %%eax\n"
30252- "51: movl 28(%4), %%edx\n"
30253+ "10: "__copyuser_seg" movl 24(%4), %%eax\n"
30254+ "51: "__copyuser_seg" movl 28(%4), %%edx\n"
30255 " movnti %%eax, 24(%3)\n"
30256 " movnti %%edx, 28(%3)\n"
30257- "11: movl 32(%4), %%eax\n"
30258- "61: movl 36(%4), %%edx\n"
30259+ "11: "__copyuser_seg" movl 32(%4), %%eax\n"
30260+ "61: "__copyuser_seg" movl 36(%4), %%edx\n"
30261 " movnti %%eax, 32(%3)\n"
30262 " movnti %%edx, 36(%3)\n"
30263- "12: movl 40(%4), %%eax\n"
30264- "71: movl 44(%4), %%edx\n"
30265+ "12: "__copyuser_seg" movl 40(%4), %%eax\n"
30266+ "71: "__copyuser_seg" movl 44(%4), %%edx\n"
30267 " movnti %%eax, 40(%3)\n"
30268 " movnti %%edx, 44(%3)\n"
30269- "13: movl 48(%4), %%eax\n"
30270- "81: movl 52(%4), %%edx\n"
30271+ "13: "__copyuser_seg" movl 48(%4), %%eax\n"
30272+ "81: "__copyuser_seg" movl 52(%4), %%edx\n"
30273 " movnti %%eax, 48(%3)\n"
30274 " movnti %%edx, 52(%3)\n"
30275- "14: movl 56(%4), %%eax\n"
30276- "91: movl 60(%4), %%edx\n"
30277+ "14: "__copyuser_seg" movl 56(%4), %%eax\n"
30278+ "91: "__copyuser_seg" movl 60(%4), %%edx\n"
30279 " movnti %%eax, 56(%3)\n"
30280 " movnti %%edx, 60(%3)\n"
30281 " addl $-64, %0\n"
30282@@ -352,9 +460,9 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
30283 " shrl $2, %0\n"
30284 " andl $3, %%eax\n"
30285 " cld\n"
30286- "6: rep; movsl\n"
30287+ "6: rep; "__copyuser_seg" movsl\n"
30288 " movl %%eax,%0\n"
30289- "7: rep; movsb\n"
30290+ "7: rep; "__copyuser_seg" movsb\n"
30291 "8:\n"
30292 ".section .fixup,\"ax\"\n"
30293 "9: lea 0(%%eax,%0,4),%0\n"
30294@@ -399,41 +507,41 @@ static unsigned long __copy_user_intel_nocache(void *to,
30295
30296 __asm__ __volatile__(
30297 " .align 2,0x90\n"
30298- "0: movl 32(%4), %%eax\n"
30299+ "0: "__copyuser_seg" movl 32(%4), %%eax\n"
30300 " cmpl $67, %0\n"
30301 " jbe 2f\n"
30302- "1: movl 64(%4), %%eax\n"
30303+ "1: "__copyuser_seg" movl 64(%4), %%eax\n"
30304 " .align 2,0x90\n"
30305- "2: movl 0(%4), %%eax\n"
30306- "21: movl 4(%4), %%edx\n"
30307+ "2: "__copyuser_seg" movl 0(%4), %%eax\n"
30308+ "21: "__copyuser_seg" movl 4(%4), %%edx\n"
30309 " movnti %%eax, 0(%3)\n"
30310 " movnti %%edx, 4(%3)\n"
30311- "3: movl 8(%4), %%eax\n"
30312- "31: movl 12(%4),%%edx\n"
30313+ "3: "__copyuser_seg" movl 8(%4), %%eax\n"
30314+ "31: "__copyuser_seg" movl 12(%4),%%edx\n"
30315 " movnti %%eax, 8(%3)\n"
30316 " movnti %%edx, 12(%3)\n"
30317- "4: movl 16(%4), %%eax\n"
30318- "41: movl 20(%4), %%edx\n"
30319+ "4: "__copyuser_seg" movl 16(%4), %%eax\n"
30320+ "41: "__copyuser_seg" movl 20(%4), %%edx\n"
30321 " movnti %%eax, 16(%3)\n"
30322 " movnti %%edx, 20(%3)\n"
30323- "10: movl 24(%4), %%eax\n"
30324- "51: movl 28(%4), %%edx\n"
30325+ "10: "__copyuser_seg" movl 24(%4), %%eax\n"
30326+ "51: "__copyuser_seg" movl 28(%4), %%edx\n"
30327 " movnti %%eax, 24(%3)\n"
30328 " movnti %%edx, 28(%3)\n"
30329- "11: movl 32(%4), %%eax\n"
30330- "61: movl 36(%4), %%edx\n"
30331+ "11: "__copyuser_seg" movl 32(%4), %%eax\n"
30332+ "61: "__copyuser_seg" movl 36(%4), %%edx\n"
30333 " movnti %%eax, 32(%3)\n"
30334 " movnti %%edx, 36(%3)\n"
30335- "12: movl 40(%4), %%eax\n"
30336- "71: movl 44(%4), %%edx\n"
30337+ "12: "__copyuser_seg" movl 40(%4), %%eax\n"
30338+ "71: "__copyuser_seg" movl 44(%4), %%edx\n"
30339 " movnti %%eax, 40(%3)\n"
30340 " movnti %%edx, 44(%3)\n"
30341- "13: movl 48(%4), %%eax\n"
30342- "81: movl 52(%4), %%edx\n"
30343+ "13: "__copyuser_seg" movl 48(%4), %%eax\n"
30344+ "81: "__copyuser_seg" movl 52(%4), %%edx\n"
30345 " movnti %%eax, 48(%3)\n"
30346 " movnti %%edx, 52(%3)\n"
30347- "14: movl 56(%4), %%eax\n"
30348- "91: movl 60(%4), %%edx\n"
30349+ "14: "__copyuser_seg" movl 56(%4), %%eax\n"
30350+ "91: "__copyuser_seg" movl 60(%4), %%edx\n"
30351 " movnti %%eax, 56(%3)\n"
30352 " movnti %%edx, 60(%3)\n"
30353 " addl $-64, %0\n"
30354@@ -446,9 +554,9 @@ static unsigned long __copy_user_intel_nocache(void *to,
30355 " shrl $2, %0\n"
30356 " andl $3, %%eax\n"
30357 " cld\n"
30358- "6: rep; movsl\n"
30359+ "6: rep; "__copyuser_seg" movsl\n"
30360 " movl %%eax,%0\n"
30361- "7: rep; movsb\n"
30362+ "7: rep; "__copyuser_seg" movsb\n"
30363 "8:\n"
30364 ".section .fixup,\"ax\"\n"
30365 "9: lea 0(%%eax,%0,4),%0\n"
30366@@ -488,32 +596,36 @@ static unsigned long __copy_user_intel_nocache(void *to,
30367 */
30368 unsigned long __copy_user_zeroing_intel(void *to, const void __user *from,
30369 unsigned long size);
30370-unsigned long __copy_user_intel(void __user *to, const void *from,
30371+unsigned long __generic_copy_to_user_intel(void __user *to, const void *from,
30372+ unsigned long size);
30373+unsigned long __generic_copy_from_user_intel(void *to, const void __user *from,
30374 unsigned long size);
30375 unsigned long __copy_user_zeroing_intel_nocache(void *to,
30376 const void __user *from, unsigned long size);
30377 #endif /* CONFIG_X86_INTEL_USERCOPY */
30378
30379 /* Generic arbitrary sized copy. */
30380-#define __copy_user(to, from, size) \
30381+#define __copy_user(to, from, size, prefix, set, restore) \
30382 do { \
30383 int __d0, __d1, __d2; \
30384 __asm__ __volatile__( \
30385+ set \
30386 " cmp $7,%0\n" \
30387 " jbe 1f\n" \
30388 " movl %1,%0\n" \
30389 " negl %0\n" \
30390 " andl $7,%0\n" \
30391 " subl %0,%3\n" \
30392- "4: rep; movsb\n" \
30393+ "4: rep; "prefix"movsb\n" \
30394 " movl %3,%0\n" \
30395 " shrl $2,%0\n" \
30396 " andl $3,%3\n" \
30397 " .align 2,0x90\n" \
30398- "0: rep; movsl\n" \
30399+ "0: rep; "prefix"movsl\n" \
30400 " movl %3,%0\n" \
30401- "1: rep; movsb\n" \
30402+ "1: rep; "prefix"movsb\n" \
30403 "2:\n" \
30404+ restore \
30405 ".section .fixup,\"ax\"\n" \
30406 "5: addl %3,%0\n" \
30407 " jmp 2b\n" \
30408@@ -538,14 +650,14 @@ do { \
30409 " negl %0\n" \
30410 " andl $7,%0\n" \
30411 " subl %0,%3\n" \
30412- "4: rep; movsb\n" \
30413+ "4: rep; "__copyuser_seg"movsb\n" \
30414 " movl %3,%0\n" \
30415 " shrl $2,%0\n" \
30416 " andl $3,%3\n" \
30417 " .align 2,0x90\n" \
30418- "0: rep; movsl\n" \
30419+ "0: rep; "__copyuser_seg"movsl\n" \
30420 " movl %3,%0\n" \
30421- "1: rep; movsb\n" \
30422+ "1: rep; "__copyuser_seg"movsb\n" \
30423 "2:\n" \
30424 ".section .fixup,\"ax\"\n" \
30425 "5: addl %3,%0\n" \
30426@@ -572,9 +684,9 @@ unsigned long __copy_to_user_ll(void __user *to, const void *from,
30427 {
30428 stac();
30429 if (movsl_is_ok(to, from, n))
30430- __copy_user(to, from, n);
30431+ __copy_user(to, from, n, "", __COPYUSER_SET_ES, __COPYUSER_RESTORE_ES);
30432 else
30433- n = __copy_user_intel(to, from, n);
30434+ n = __generic_copy_to_user_intel(to, from, n);
30435 clac();
30436 return n;
30437 }
30438@@ -598,10 +710,9 @@ unsigned long __copy_from_user_ll_nozero(void *to, const void __user *from,
30439 {
30440 stac();
30441 if (movsl_is_ok(to, from, n))
30442- __copy_user(to, from, n);
30443+ __copy_user(to, from, n, __copyuser_seg, "", "");
30444 else
30445- n = __copy_user_intel((void __user *)to,
30446- (const void *)from, n);
30447+ n = __generic_copy_from_user_intel(to, from, n);
30448 clac();
30449 return n;
30450 }
30451@@ -632,60 +743,38 @@ unsigned long __copy_from_user_ll_nocache_nozero(void *to, const void __user *fr
30452 if (n > 64 && cpu_has_xmm2)
30453 n = __copy_user_intel_nocache(to, from, n);
30454 else
30455- __copy_user(to, from, n);
30456+ __copy_user(to, from, n, __copyuser_seg, "", "");
30457 #else
30458- __copy_user(to, from, n);
30459+ __copy_user(to, from, n, __copyuser_seg, "", "");
30460 #endif
30461 clac();
30462 return n;
30463 }
30464 EXPORT_SYMBOL(__copy_from_user_ll_nocache_nozero);
30465
30466-/**
30467- * copy_to_user: - Copy a block of data into user space.
30468- * @to: Destination address, in user space.
30469- * @from: Source address, in kernel space.
30470- * @n: Number of bytes to copy.
30471- *
30472- * Context: User context only. This function may sleep.
30473- *
30474- * Copy data from kernel space to user space.
30475- *
30476- * Returns number of bytes that could not be copied.
30477- * On success, this will be zero.
30478- */
30479-unsigned long
30480-copy_to_user(void __user *to, const void *from, unsigned long n)
30481+#ifdef CONFIG_PAX_MEMORY_UDEREF
30482+void __set_fs(mm_segment_t x)
30483 {
30484- if (access_ok(VERIFY_WRITE, to, n))
30485- n = __copy_to_user(to, from, n);
30486- return n;
30487+ switch (x.seg) {
30488+ case 0:
30489+ loadsegment(gs, 0);
30490+ break;
30491+ case TASK_SIZE_MAX:
30492+ loadsegment(gs, __USER_DS);
30493+ break;
30494+ case -1UL:
30495+ loadsegment(gs, __KERNEL_DS);
30496+ break;
30497+ default:
30498+ BUG();
30499+ }
30500 }
30501-EXPORT_SYMBOL(copy_to_user);
30502+EXPORT_SYMBOL(__set_fs);
30503
30504-/**
30505- * copy_from_user: - Copy a block of data from user space.
30506- * @to: Destination address, in kernel space.
30507- * @from: Source address, in user space.
30508- * @n: Number of bytes to copy.
30509- *
30510- * Context: User context only. This function may sleep.
30511- *
30512- * Copy data from user space to kernel space.
30513- *
30514- * Returns number of bytes that could not be copied.
30515- * On success, this will be zero.
30516- *
30517- * If some data could not be copied, this function will pad the copied
30518- * data to the requested size using zero bytes.
30519- */
30520-unsigned long
30521-_copy_from_user(void *to, const void __user *from, unsigned long n)
30522+void set_fs(mm_segment_t x)
30523 {
30524- if (access_ok(VERIFY_READ, from, n))
30525- n = __copy_from_user(to, from, n);
30526- else
30527- memset(to, 0, n);
30528- return n;
30529+ current_thread_info()->addr_limit = x;
30530+ __set_fs(x);
30531 }
30532-EXPORT_SYMBOL(_copy_from_user);
30533+EXPORT_SYMBOL(set_fs);
30534+#endif
30535diff --git a/arch/x86/lib/usercopy_64.c b/arch/x86/lib/usercopy_64.c
30536index c905e89..01ab928 100644
30537--- a/arch/x86/lib/usercopy_64.c
30538+++ b/arch/x86/lib/usercopy_64.c
30539@@ -18,6 +18,7 @@ unsigned long __clear_user(void __user *addr, unsigned long size)
30540 might_fault();
30541 /* no memory constraint because it doesn't change any memory gcc knows
30542 about */
30543+ pax_open_userland();
30544 stac();
30545 asm volatile(
30546 " testq %[size8],%[size8]\n"
30547@@ -39,9 +40,10 @@ unsigned long __clear_user(void __user *addr, unsigned long size)
30548 _ASM_EXTABLE(0b,3b)
30549 _ASM_EXTABLE(1b,2b)
30550 : [size8] "=&c"(size), [dst] "=&D" (__d0)
30551- : [size1] "r"(size & 7), "[size8]" (size / 8), "[dst]"(addr),
30552+ : [size1] "r"(size & 7), "[size8]" (size / 8), "[dst]"(____m(addr)),
30553 [zero] "r" (0UL), [eight] "r" (8UL));
30554 clac();
30555+ pax_close_userland();
30556 return size;
30557 }
30558 EXPORT_SYMBOL(__clear_user);
30559@@ -54,12 +56,11 @@ unsigned long clear_user(void __user *to, unsigned long n)
30560 }
30561 EXPORT_SYMBOL(clear_user);
30562
30563-unsigned long copy_in_user(void __user *to, const void __user *from, unsigned len)
30564+unsigned long copy_in_user(void __user *to, const void __user *from, unsigned long len)
30565 {
30566- if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len)) {
30567- return copy_user_generic((__force void *)to, (__force void *)from, len);
30568- }
30569- return len;
30570+ if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len))
30571+ return copy_user_generic((void __force_kernel *)____m(to), (void __force_kernel *)____m(from), len);
30572+ return len;
30573 }
30574 EXPORT_SYMBOL(copy_in_user);
30575
30576@@ -69,11 +70,13 @@ EXPORT_SYMBOL(copy_in_user);
30577 * it is not necessary to optimize tail handling.
30578 */
30579 __visible unsigned long
30580-copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
30581+copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest)
30582 {
30583 char c;
30584 unsigned zero_len;
30585
30586+ clac();
30587+ pax_close_userland();
30588 for (; len; --len, to++) {
30589 if (__get_user_nocheck(c, from++, sizeof(char)))
30590 break;
30591@@ -84,6 +87,5 @@ copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
30592 for (c = 0, zero_len = len; zerorest && zero_len; --zero_len)
30593 if (__put_user_nocheck(c, to++, sizeof(char)))
30594 break;
30595- clac();
30596 return len;
30597 }
30598diff --git a/arch/x86/mm/Makefile b/arch/x86/mm/Makefile
30599index 23d8e5f..9ccc13a 100644
30600--- a/arch/x86/mm/Makefile
30601+++ b/arch/x86/mm/Makefile
30602@@ -28,3 +28,7 @@ obj-$(CONFIG_ACPI_NUMA) += srat.o
30603 obj-$(CONFIG_NUMA_EMU) += numa_emulation.o
30604
30605 obj-$(CONFIG_MEMTEST) += memtest.o
30606+
30607+quote:="
30608+obj-$(CONFIG_X86_64) += uderef_64.o
30609+CFLAGS_uderef_64.o := $(subst $(quote),,$(CONFIG_ARCH_HWEIGHT_CFLAGS))
30610diff --git a/arch/x86/mm/extable.c b/arch/x86/mm/extable.c
30611index 903ec1e..c4166b2 100644
30612--- a/arch/x86/mm/extable.c
30613+++ b/arch/x86/mm/extable.c
30614@@ -6,12 +6,24 @@
30615 static inline unsigned long
30616 ex_insn_addr(const struct exception_table_entry *x)
30617 {
30618- return (unsigned long)&x->insn + x->insn;
30619+ unsigned long reloc = 0;
30620+
30621+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
30622+ reloc = ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
30623+#endif
30624+
30625+ return (unsigned long)&x->insn + x->insn + reloc;
30626 }
30627 static inline unsigned long
30628 ex_fixup_addr(const struct exception_table_entry *x)
30629 {
30630- return (unsigned long)&x->fixup + x->fixup;
30631+ unsigned long reloc = 0;
30632+
30633+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
30634+ reloc = ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
30635+#endif
30636+
30637+ return (unsigned long)&x->fixup + x->fixup + reloc;
30638 }
30639
30640 int fixup_exception(struct pt_regs *regs)
30641@@ -20,7 +32,7 @@ int fixup_exception(struct pt_regs *regs)
30642 unsigned long new_ip;
30643
30644 #ifdef CONFIG_PNPBIOS
30645- if (unlikely(SEGMENT_IS_PNP_CODE(regs->cs))) {
30646+ if (unlikely(!v8086_mode(regs) && SEGMENT_IS_PNP_CODE(regs->cs))) {
30647 extern u32 pnp_bios_fault_eip, pnp_bios_fault_esp;
30648 extern u32 pnp_bios_is_utter_crap;
30649 pnp_bios_is_utter_crap = 1;
30650@@ -145,6 +157,13 @@ void sort_extable(struct exception_table_entry *start,
30651 i += 4;
30652 p->fixup -= i;
30653 i += 4;
30654+
30655+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
30656+ BUILD_BUG_ON(!IS_ENABLED(CONFIG_BUILDTIME_EXTABLE_SORT));
30657+ p->insn -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
30658+ p->fixup -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
30659+#endif
30660+
30661 }
30662 }
30663
30664diff --git a/arch/x86/mm/fault.c b/arch/x86/mm/fault.c
30665index 3aaeffc..42ea9fb 100644
30666--- a/arch/x86/mm/fault.c
30667+++ b/arch/x86/mm/fault.c
30668@@ -14,11 +14,18 @@
30669 #include <linux/hugetlb.h> /* hstate_index_to_shift */
30670 #include <linux/prefetch.h> /* prefetchw */
30671 #include <linux/context_tracking.h> /* exception_enter(), ... */
30672+#include <linux/unistd.h>
30673+#include <linux/compiler.h>
30674
30675 #include <asm/traps.h> /* dotraplinkage, ... */
30676 #include <asm/pgalloc.h> /* pgd_*(), ... */
30677 #include <asm/kmemcheck.h> /* kmemcheck_*(), ... */
30678 #include <asm/fixmap.h> /* VSYSCALL_START */
30679+#include <asm/tlbflush.h>
30680+
30681+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30682+#include <asm/stacktrace.h>
30683+#endif
30684
30685 /*
30686 * Page fault error code bits:
30687@@ -56,7 +63,7 @@ static inline int __kprobes notify_page_fault(struct pt_regs *regs)
30688 int ret = 0;
30689
30690 /* kprobe_running() needs smp_processor_id() */
30691- if (kprobes_built_in() && !user_mode_vm(regs)) {
30692+ if (kprobes_built_in() && !user_mode(regs)) {
30693 preempt_disable();
30694 if (kprobe_running() && kprobe_fault_handler(regs, 14))
30695 ret = 1;
30696@@ -117,7 +124,10 @@ check_prefetch_opcode(struct pt_regs *regs, unsigned char *instr,
30697 return !instr_lo || (instr_lo>>1) == 1;
30698 case 0x00:
30699 /* Prefetch instruction is 0x0F0D or 0x0F18 */
30700- if (probe_kernel_address(instr, opcode))
30701+ if (user_mode(regs)) {
30702+ if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
30703+ return 0;
30704+ } else if (probe_kernel_address(instr, opcode))
30705 return 0;
30706
30707 *prefetch = (instr_lo == 0xF) &&
30708@@ -151,7 +161,10 @@ is_prefetch(struct pt_regs *regs, unsigned long error_code, unsigned long addr)
30709 while (instr < max_instr) {
30710 unsigned char opcode;
30711
30712- if (probe_kernel_address(instr, opcode))
30713+ if (user_mode(regs)) {
30714+ if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
30715+ break;
30716+ } else if (probe_kernel_address(instr, opcode))
30717 break;
30718
30719 instr++;
30720@@ -182,6 +195,34 @@ force_sig_info_fault(int si_signo, int si_code, unsigned long address,
30721 force_sig_info(si_signo, &info, tsk);
30722 }
30723
30724+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
30725+static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address);
30726+#endif
30727+
30728+#ifdef CONFIG_PAX_EMUTRAMP
30729+static int pax_handle_fetch_fault(struct pt_regs *regs);
30730+#endif
30731+
30732+#ifdef CONFIG_PAX_PAGEEXEC
30733+static inline pmd_t * pax_get_pmd(struct mm_struct *mm, unsigned long address)
30734+{
30735+ pgd_t *pgd;
30736+ pud_t *pud;
30737+ pmd_t *pmd;
30738+
30739+ pgd = pgd_offset(mm, address);
30740+ if (!pgd_present(*pgd))
30741+ return NULL;
30742+ pud = pud_offset(pgd, address);
30743+ if (!pud_present(*pud))
30744+ return NULL;
30745+ pmd = pmd_offset(pud, address);
30746+ if (!pmd_present(*pmd))
30747+ return NULL;
30748+ return pmd;
30749+}
30750+#endif
30751+
30752 DEFINE_SPINLOCK(pgd_lock);
30753 LIST_HEAD(pgd_list);
30754
30755@@ -232,10 +273,27 @@ void vmalloc_sync_all(void)
30756 for (address = VMALLOC_START & PMD_MASK;
30757 address >= TASK_SIZE && address < FIXADDR_TOP;
30758 address += PMD_SIZE) {
30759+
30760+#ifdef CONFIG_PAX_PER_CPU_PGD
30761+ unsigned long cpu;
30762+#else
30763 struct page *page;
30764+#endif
30765
30766 spin_lock(&pgd_lock);
30767+
30768+#ifdef CONFIG_PAX_PER_CPU_PGD
30769+ for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
30770+ pgd_t *pgd = get_cpu_pgd(cpu, user);
30771+ pmd_t *ret;
30772+
30773+ ret = vmalloc_sync_one(pgd, address);
30774+ if (!ret)
30775+ break;
30776+ pgd = get_cpu_pgd(cpu, kernel);
30777+#else
30778 list_for_each_entry(page, &pgd_list, lru) {
30779+ pgd_t *pgd;
30780 spinlock_t *pgt_lock;
30781 pmd_t *ret;
30782
30783@@ -243,8 +301,14 @@ void vmalloc_sync_all(void)
30784 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
30785
30786 spin_lock(pgt_lock);
30787- ret = vmalloc_sync_one(page_address(page), address);
30788+ pgd = page_address(page);
30789+#endif
30790+
30791+ ret = vmalloc_sync_one(pgd, address);
30792+
30793+#ifndef CONFIG_PAX_PER_CPU_PGD
30794 spin_unlock(pgt_lock);
30795+#endif
30796
30797 if (!ret)
30798 break;
30799@@ -278,6 +342,12 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
30800 * an interrupt in the middle of a task switch..
30801 */
30802 pgd_paddr = read_cr3();
30803+
30804+#ifdef CONFIG_PAX_PER_CPU_PGD
30805+ BUG_ON(__pa(get_cpu_pgd(smp_processor_id(), kernel)) != (pgd_paddr & __PHYSICAL_MASK));
30806+ vmalloc_sync_one(__va(pgd_paddr + PAGE_SIZE), address);
30807+#endif
30808+
30809 pmd_k = vmalloc_sync_one(__va(pgd_paddr), address);
30810 if (!pmd_k)
30811 return -1;
30812@@ -373,11 +443,25 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
30813 * happen within a race in page table update. In the later
30814 * case just flush:
30815 */
30816- pgd = pgd_offset(current->active_mm, address);
30817+
30818 pgd_ref = pgd_offset_k(address);
30819 if (pgd_none(*pgd_ref))
30820 return -1;
30821
30822+#ifdef CONFIG_PAX_PER_CPU_PGD
30823+ BUG_ON(__pa(get_cpu_pgd(smp_processor_id(), kernel)) != (read_cr3() & __PHYSICAL_MASK));
30824+ pgd = pgd_offset_cpu(smp_processor_id(), user, address);
30825+ if (pgd_none(*pgd)) {
30826+ set_pgd(pgd, *pgd_ref);
30827+ arch_flush_lazy_mmu_mode();
30828+ } else {
30829+ BUG_ON(pgd_page_vaddr(*pgd) != pgd_page_vaddr(*pgd_ref));
30830+ }
30831+ pgd = pgd_offset_cpu(smp_processor_id(), kernel, address);
30832+#else
30833+ pgd = pgd_offset(current->active_mm, address);
30834+#endif
30835+
30836 if (pgd_none(*pgd)) {
30837 set_pgd(pgd, *pgd_ref);
30838 arch_flush_lazy_mmu_mode();
30839@@ -543,7 +627,7 @@ static int is_errata93(struct pt_regs *regs, unsigned long address)
30840 static int is_errata100(struct pt_regs *regs, unsigned long address)
30841 {
30842 #ifdef CONFIG_X86_64
30843- if ((regs->cs == __USER32_CS || (regs->cs & (1<<2))) && (address >> 32))
30844+ if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)) && (address >> 32))
30845 return 1;
30846 #endif
30847 return 0;
30848@@ -570,7 +654,7 @@ static int is_f00f_bug(struct pt_regs *regs, unsigned long address)
30849 }
30850
30851 static const char nx_warning[] = KERN_CRIT
30852-"kernel tried to execute NX-protected page - exploit attempt? (uid: %d)\n";
30853+"kernel tried to execute NX-protected page - exploit attempt? (uid: %d, task: %s, pid: %d)\n";
30854
30855 static void
30856 show_fault_oops(struct pt_regs *regs, unsigned long error_code,
30857@@ -579,15 +663,27 @@ show_fault_oops(struct pt_regs *regs, unsigned long error_code,
30858 if (!oops_may_print())
30859 return;
30860
30861- if (error_code & PF_INSTR) {
30862+ if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR)) {
30863 unsigned int level;
30864
30865 pte_t *pte = lookup_address(address, &level);
30866
30867 if (pte && pte_present(*pte) && !pte_exec(*pte))
30868- printk(nx_warning, from_kuid(&init_user_ns, current_uid()));
30869+ printk(nx_warning, from_kuid_munged(&init_user_ns, current_uid()), current->comm, task_pid_nr(current));
30870 }
30871
30872+#ifdef CONFIG_PAX_KERNEXEC
30873+ if (init_mm.start_code <= address && address < init_mm.end_code) {
30874+ if (current->signal->curr_ip)
30875+ printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
30876+ &current->signal->curr_ip, current->comm, task_pid_nr(current),
30877+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
30878+ else
30879+ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n", current->comm, task_pid_nr(current),
30880+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
30881+ }
30882+#endif
30883+
30884 printk(KERN_ALERT "BUG: unable to handle kernel ");
30885 if (address < PAGE_SIZE)
30886 printk(KERN_CONT "NULL pointer dereference");
30887@@ -750,6 +846,22 @@ __bad_area_nosemaphore(struct pt_regs *regs, unsigned long error_code,
30888 return;
30889 }
30890 #endif
30891+
30892+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
30893+ if (pax_is_fetch_fault(regs, error_code, address)) {
30894+
30895+#ifdef CONFIG_PAX_EMUTRAMP
30896+ switch (pax_handle_fetch_fault(regs)) {
30897+ case 2:
30898+ return;
30899+ }
30900+#endif
30901+
30902+ pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
30903+ do_group_exit(SIGKILL);
30904+ }
30905+#endif
30906+
30907 /* Kernel addresses are always protection faults: */
30908 if (address >= TASK_SIZE)
30909 error_code |= PF_PROT;
30910@@ -835,7 +947,7 @@ do_sigbus(struct pt_regs *regs, unsigned long error_code, unsigned long address,
30911 if (fault & (VM_FAULT_HWPOISON|VM_FAULT_HWPOISON_LARGE)) {
30912 printk(KERN_ERR
30913 "MCE: Killing %s:%d due to hardware memory corruption fault at %lx\n",
30914- tsk->comm, tsk->pid, address);
30915+ tsk->comm, task_pid_nr(tsk), address);
30916 code = BUS_MCEERR_AR;
30917 }
30918 #endif
30919@@ -889,6 +1001,99 @@ static int spurious_fault_check(unsigned long error_code, pte_t *pte)
30920 return 1;
30921 }
30922
30923+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
30924+static int pax_handle_pageexec_fault(struct pt_regs *regs, struct mm_struct *mm, unsigned long address, unsigned long error_code)
30925+{
30926+ pte_t *pte;
30927+ pmd_t *pmd;
30928+ spinlock_t *ptl;
30929+ unsigned char pte_mask;
30930+
30931+ if ((__supported_pte_mask & _PAGE_NX) || (error_code & (PF_PROT|PF_USER)) != (PF_PROT|PF_USER) || v8086_mode(regs) ||
30932+ !(mm->pax_flags & MF_PAX_PAGEEXEC))
30933+ return 0;
30934+
30935+ /* PaX: it's our fault, let's handle it if we can */
30936+
30937+ /* PaX: take a look at read faults before acquiring any locks */
30938+ if (unlikely(!(error_code & PF_WRITE) && (regs->ip == address))) {
30939+ /* instruction fetch attempt from a protected page in user mode */
30940+ up_read(&mm->mmap_sem);
30941+
30942+#ifdef CONFIG_PAX_EMUTRAMP
30943+ switch (pax_handle_fetch_fault(regs)) {
30944+ case 2:
30945+ return 1;
30946+ }
30947+#endif
30948+
30949+ pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
30950+ do_group_exit(SIGKILL);
30951+ }
30952+
30953+ pmd = pax_get_pmd(mm, address);
30954+ if (unlikely(!pmd))
30955+ return 0;
30956+
30957+ pte = pte_offset_map_lock(mm, pmd, address, &ptl);
30958+ if (unlikely(!(pte_val(*pte) & _PAGE_PRESENT) || pte_user(*pte))) {
30959+ pte_unmap_unlock(pte, ptl);
30960+ return 0;
30961+ }
30962+
30963+ if (unlikely((error_code & PF_WRITE) && !pte_write(*pte))) {
30964+ /* write attempt to a protected page in user mode */
30965+ pte_unmap_unlock(pte, ptl);
30966+ return 0;
30967+ }
30968+
30969+#ifdef CONFIG_SMP
30970+ if (likely(address > get_limit(regs->cs) && cpu_isset(smp_processor_id(), mm->context.cpu_user_cs_mask)))
30971+#else
30972+ if (likely(address > get_limit(regs->cs)))
30973+#endif
30974+ {
30975+ set_pte(pte, pte_mkread(*pte));
30976+ __flush_tlb_one(address);
30977+ pte_unmap_unlock(pte, ptl);
30978+ up_read(&mm->mmap_sem);
30979+ return 1;
30980+ }
30981+
30982+ pte_mask = _PAGE_ACCESSED | _PAGE_USER | ((error_code & PF_WRITE) << (_PAGE_BIT_DIRTY-1));
30983+
30984+ /*
30985+ * PaX: fill DTLB with user rights and retry
30986+ */
30987+ __asm__ __volatile__ (
30988+ "orb %2,(%1)\n"
30989+#if defined(CONFIG_M586) || defined(CONFIG_M586TSC)
30990+/*
30991+ * PaX: let this uncommented 'invlpg' remind us on the behaviour of Intel's
30992+ * (and AMD's) TLBs. namely, they do not cache PTEs that would raise *any*
30993+ * page fault when examined during a TLB load attempt. this is true not only
30994+ * for PTEs holding a non-present entry but also present entries that will
30995+ * raise a page fault (such as those set up by PaX, or the copy-on-write
30996+ * mechanism). in effect it means that we do *not* need to flush the TLBs
30997+ * for our target pages since their PTEs are simply not in the TLBs at all.
30998+
30999+ * the best thing in omitting it is that we gain around 15-20% speed in the
31000+ * fast path of the page fault handler and can get rid of tracing since we
31001+ * can no longer flush unintended entries.
31002+ */
31003+ "invlpg (%0)\n"
31004+#endif
31005+ __copyuser_seg"testb $0,(%0)\n"
31006+ "xorb %3,(%1)\n"
31007+ :
31008+ : "r" (address), "r" (pte), "q" (pte_mask), "i" (_PAGE_USER)
31009+ : "memory", "cc");
31010+ pte_unmap_unlock(pte, ptl);
31011+ up_read(&mm->mmap_sem);
31012+ return 1;
31013+}
31014+#endif
31015+
31016 /*
31017 * Handle a spurious fault caused by a stale TLB entry.
31018 *
31019@@ -955,6 +1160,9 @@ int show_unhandled_signals = 1;
31020 static inline int
31021 access_error(unsigned long error_code, struct vm_area_struct *vma)
31022 {
31023+ if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR) && !(vma->vm_flags & VM_EXEC))
31024+ return 1;
31025+
31026 if (error_code & PF_WRITE) {
31027 /* write, present and write, not present: */
31028 if (unlikely(!(vma->vm_flags & VM_WRITE)))
31029@@ -983,7 +1191,7 @@ static inline bool smap_violation(int error_code, struct pt_regs *regs)
31030 if (error_code & PF_USER)
31031 return false;
31032
31033- if (!user_mode_vm(regs) && (regs->flags & X86_EFLAGS_AC))
31034+ if (!user_mode(regs) && (regs->flags & X86_EFLAGS_AC))
31035 return false;
31036
31037 return true;
31038@@ -1010,6 +1218,22 @@ __do_page_fault(struct pt_regs *regs, unsigned long error_code)
31039 /* Get the faulting address: */
31040 address = read_cr2();
31041
31042+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
31043+ if (!user_mode(regs) && address < 2 * pax_user_shadow_base) {
31044+ if (!search_exception_tables(regs->ip)) {
31045+ printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
31046+ bad_area_nosemaphore(regs, error_code, address);
31047+ return;
31048+ }
31049+ if (address < pax_user_shadow_base) {
31050+ printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
31051+ printk(KERN_ERR "PAX: faulting IP: %pS\n", (void *)regs->ip);
31052+ show_trace_log_lvl(NULL, NULL, (void *)regs->sp, regs->bp, KERN_ERR);
31053+ } else
31054+ address -= pax_user_shadow_base;
31055+ }
31056+#endif
31057+
31058 /*
31059 * Detect and handle instructions that would cause a page fault for
31060 * both a tracked kernel page and a userspace page.
31061@@ -1069,7 +1293,7 @@ __do_page_fault(struct pt_regs *regs, unsigned long error_code)
31062 * User-mode registers count as a user access even for any
31063 * potential system fault or CPU buglet:
31064 */
31065- if (user_mode_vm(regs)) {
31066+ if (user_mode(regs)) {
31067 local_irq_enable();
31068 error_code |= PF_USER;
31069 flags |= FAULT_FLAG_USER;
31070@@ -1135,6 +1359,11 @@ retry:
31071 might_sleep();
31072 }
31073
31074+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
31075+ if (pax_handle_pageexec_fault(regs, mm, address, error_code))
31076+ return;
31077+#endif
31078+
31079 vma = find_vma(mm, address);
31080 if (unlikely(!vma)) {
31081 bad_area(regs, error_code, address);
31082@@ -1146,18 +1375,24 @@ retry:
31083 bad_area(regs, error_code, address);
31084 return;
31085 }
31086- if (error_code & PF_USER) {
31087- /*
31088- * Accessing the stack below %sp is always a bug.
31089- * The large cushion allows instructions like enter
31090- * and pusha to work. ("enter $65535, $31" pushes
31091- * 32 pointers and then decrements %sp by 65535.)
31092- */
31093- if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < regs->sp)) {
31094- bad_area(regs, error_code, address);
31095- return;
31096- }
31097+ /*
31098+ * Accessing the stack below %sp is always a bug.
31099+ * The large cushion allows instructions like enter
31100+ * and pusha to work. ("enter $65535, $31" pushes
31101+ * 32 pointers and then decrements %sp by 65535.)
31102+ */
31103+ if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < task_pt_regs(tsk)->sp)) {
31104+ bad_area(regs, error_code, address);
31105+ return;
31106 }
31107+
31108+#ifdef CONFIG_PAX_SEGMEXEC
31109+ if (unlikely((mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end - SEGMEXEC_TASK_SIZE - 1 < address - SEGMEXEC_TASK_SIZE - 1)) {
31110+ bad_area(regs, error_code, address);
31111+ return;
31112+ }
31113+#endif
31114+
31115 if (unlikely(expand_stack(vma, address))) {
31116 bad_area(regs, error_code, address);
31117 return;
31118@@ -1231,3 +1466,292 @@ do_page_fault(struct pt_regs *regs, unsigned long error_code)
31119 __do_page_fault(regs, error_code);
31120 exception_exit(prev_state);
31121 }
31122+
31123+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
31124+static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address)
31125+{
31126+ struct mm_struct *mm = current->mm;
31127+ unsigned long ip = regs->ip;
31128+
31129+ if (v8086_mode(regs))
31130+ ip = ((regs->cs & 0xffff) << 4) + (ip & 0xffff);
31131+
31132+#ifdef CONFIG_PAX_PAGEEXEC
31133+ if (mm->pax_flags & MF_PAX_PAGEEXEC) {
31134+ if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR))
31135+ return true;
31136+ if (!(error_code & (PF_PROT | PF_WRITE)) && ip == address)
31137+ return true;
31138+ return false;
31139+ }
31140+#endif
31141+
31142+#ifdef CONFIG_PAX_SEGMEXEC
31143+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
31144+ if (!(error_code & (PF_PROT | PF_WRITE)) && (ip + SEGMEXEC_TASK_SIZE == address))
31145+ return true;
31146+ return false;
31147+ }
31148+#endif
31149+
31150+ return false;
31151+}
31152+#endif
31153+
31154+#ifdef CONFIG_PAX_EMUTRAMP
31155+static int pax_handle_fetch_fault_32(struct pt_regs *regs)
31156+{
31157+ int err;
31158+
31159+ do { /* PaX: libffi trampoline emulation */
31160+ unsigned char mov, jmp;
31161+ unsigned int addr1, addr2;
31162+
31163+#ifdef CONFIG_X86_64
31164+ if ((regs->ip + 9) >> 32)
31165+ break;
31166+#endif
31167+
31168+ err = get_user(mov, (unsigned char __user *)regs->ip);
31169+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
31170+ err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
31171+ err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
31172+
31173+ if (err)
31174+ break;
31175+
31176+ if (mov == 0xB8 && jmp == 0xE9) {
31177+ regs->ax = addr1;
31178+ regs->ip = (unsigned int)(regs->ip + addr2 + 10);
31179+ return 2;
31180+ }
31181+ } while (0);
31182+
31183+ do { /* PaX: gcc trampoline emulation #1 */
31184+ unsigned char mov1, mov2;
31185+ unsigned short jmp;
31186+ unsigned int addr1, addr2;
31187+
31188+#ifdef CONFIG_X86_64
31189+ if ((regs->ip + 11) >> 32)
31190+ break;
31191+#endif
31192+
31193+ err = get_user(mov1, (unsigned char __user *)regs->ip);
31194+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
31195+ err |= get_user(mov2, (unsigned char __user *)(regs->ip + 5));
31196+ err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
31197+ err |= get_user(jmp, (unsigned short __user *)(regs->ip + 10));
31198+
31199+ if (err)
31200+ break;
31201+
31202+ if (mov1 == 0xB9 && mov2 == 0xB8 && jmp == 0xE0FF) {
31203+ regs->cx = addr1;
31204+ regs->ax = addr2;
31205+ regs->ip = addr2;
31206+ return 2;
31207+ }
31208+ } while (0);
31209+
31210+ do { /* PaX: gcc trampoline emulation #2 */
31211+ unsigned char mov, jmp;
31212+ unsigned int addr1, addr2;
31213+
31214+#ifdef CONFIG_X86_64
31215+ if ((regs->ip + 9) >> 32)
31216+ break;
31217+#endif
31218+
31219+ err = get_user(mov, (unsigned char __user *)regs->ip);
31220+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
31221+ err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
31222+ err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
31223+
31224+ if (err)
31225+ break;
31226+
31227+ if (mov == 0xB9 && jmp == 0xE9) {
31228+ regs->cx = addr1;
31229+ regs->ip = (unsigned int)(regs->ip + addr2 + 10);
31230+ return 2;
31231+ }
31232+ } while (0);
31233+
31234+ return 1; /* PaX in action */
31235+}
31236+
31237+#ifdef CONFIG_X86_64
31238+static int pax_handle_fetch_fault_64(struct pt_regs *regs)
31239+{
31240+ int err;
31241+
31242+ do { /* PaX: libffi trampoline emulation */
31243+ unsigned short mov1, mov2, jmp1;
31244+ unsigned char stcclc, jmp2;
31245+ unsigned long addr1, addr2;
31246+
31247+ err = get_user(mov1, (unsigned short __user *)regs->ip);
31248+ err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
31249+ err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
31250+ err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
31251+ err |= get_user(stcclc, (unsigned char __user *)(regs->ip + 20));
31252+ err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 21));
31253+ err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 23));
31254+
31255+ if (err)
31256+ break;
31257+
31258+ if (mov1 == 0xBB49 && mov2 == 0xBA49 && (stcclc == 0xF8 || stcclc == 0xF9) && jmp1 == 0xFF49 && jmp2 == 0xE3) {
31259+ regs->r11 = addr1;
31260+ regs->r10 = addr2;
31261+ if (stcclc == 0xF8)
31262+ regs->flags &= ~X86_EFLAGS_CF;
31263+ else
31264+ regs->flags |= X86_EFLAGS_CF;
31265+ regs->ip = addr1;
31266+ return 2;
31267+ }
31268+ } while (0);
31269+
31270+ do { /* PaX: gcc trampoline emulation #1 */
31271+ unsigned short mov1, mov2, jmp1;
31272+ unsigned char jmp2;
31273+ unsigned int addr1;
31274+ unsigned long addr2;
31275+
31276+ err = get_user(mov1, (unsigned short __user *)regs->ip);
31277+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 2));
31278+ err |= get_user(mov2, (unsigned short __user *)(regs->ip + 6));
31279+ err |= get_user(addr2, (unsigned long __user *)(regs->ip + 8));
31280+ err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 16));
31281+ err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 18));
31282+
31283+ if (err)
31284+ break;
31285+
31286+ if (mov1 == 0xBB41 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
31287+ regs->r11 = addr1;
31288+ regs->r10 = addr2;
31289+ regs->ip = addr1;
31290+ return 2;
31291+ }
31292+ } while (0);
31293+
31294+ do { /* PaX: gcc trampoline emulation #2 */
31295+ unsigned short mov1, mov2, jmp1;
31296+ unsigned char jmp2;
31297+ unsigned long addr1, addr2;
31298+
31299+ err = get_user(mov1, (unsigned short __user *)regs->ip);
31300+ err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
31301+ err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
31302+ err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
31303+ err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 20));
31304+ err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 22));
31305+
31306+ if (err)
31307+ break;
31308+
31309+ if (mov1 == 0xBB49 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
31310+ regs->r11 = addr1;
31311+ regs->r10 = addr2;
31312+ regs->ip = addr1;
31313+ return 2;
31314+ }
31315+ } while (0);
31316+
31317+ return 1; /* PaX in action */
31318+}
31319+#endif
31320+
31321+/*
31322+ * PaX: decide what to do with offenders (regs->ip = fault address)
31323+ *
31324+ * returns 1 when task should be killed
31325+ * 2 when gcc trampoline was detected
31326+ */
31327+static int pax_handle_fetch_fault(struct pt_regs *regs)
31328+{
31329+ if (v8086_mode(regs))
31330+ return 1;
31331+
31332+ if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
31333+ return 1;
31334+
31335+#ifdef CONFIG_X86_32
31336+ return pax_handle_fetch_fault_32(regs);
31337+#else
31338+ if (regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))
31339+ return pax_handle_fetch_fault_32(regs);
31340+ else
31341+ return pax_handle_fetch_fault_64(regs);
31342+#endif
31343+}
31344+#endif
31345+
31346+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
31347+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
31348+{
31349+ long i;
31350+
31351+ printk(KERN_ERR "PAX: bytes at PC: ");
31352+ for (i = 0; i < 20; i++) {
31353+ unsigned char c;
31354+ if (get_user(c, (unsigned char __force_user *)pc+i))
31355+ printk(KERN_CONT "?? ");
31356+ else
31357+ printk(KERN_CONT "%02x ", c);
31358+ }
31359+ printk("\n");
31360+
31361+ printk(KERN_ERR "PAX: bytes at SP-%lu: ", (unsigned long)sizeof(long));
31362+ for (i = -1; i < 80 / (long)sizeof(long); i++) {
31363+ unsigned long c;
31364+ if (get_user(c, (unsigned long __force_user *)sp+i)) {
31365+#ifdef CONFIG_X86_32
31366+ printk(KERN_CONT "???????? ");
31367+#else
31368+ if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)))
31369+ printk(KERN_CONT "???????? ???????? ");
31370+ else
31371+ printk(KERN_CONT "???????????????? ");
31372+#endif
31373+ } else {
31374+#ifdef CONFIG_X86_64
31375+ if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))) {
31376+ printk(KERN_CONT "%08x ", (unsigned int)c);
31377+ printk(KERN_CONT "%08x ", (unsigned int)(c >> 32));
31378+ } else
31379+#endif
31380+ printk(KERN_CONT "%0*lx ", 2 * (int)sizeof(long), c);
31381+ }
31382+ }
31383+ printk("\n");
31384+}
31385+#endif
31386+
31387+/**
31388+ * probe_kernel_write(): safely attempt to write to a location
31389+ * @dst: address to write to
31390+ * @src: pointer to the data that shall be written
31391+ * @size: size of the data chunk
31392+ *
31393+ * Safely write to address @dst from the buffer at @src. If a kernel fault
31394+ * happens, handle that and return -EFAULT.
31395+ */
31396+long notrace probe_kernel_write(void *dst, const void *src, size_t size)
31397+{
31398+ long ret;
31399+ mm_segment_t old_fs = get_fs();
31400+
31401+ set_fs(KERNEL_DS);
31402+ pagefault_disable();
31403+ pax_open_kernel();
31404+ ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
31405+ pax_close_kernel();
31406+ pagefault_enable();
31407+ set_fs(old_fs);
31408+
31409+ return ret ? -EFAULT : 0;
31410+}
31411diff --git a/arch/x86/mm/gup.c b/arch/x86/mm/gup.c
31412index 0596e8e..9de0b1c 100644
31413--- a/arch/x86/mm/gup.c
31414+++ b/arch/x86/mm/gup.c
31415@@ -268,7 +268,7 @@ int __get_user_pages_fast(unsigned long start, int nr_pages, int write,
31416 addr = start;
31417 len = (unsigned long) nr_pages << PAGE_SHIFT;
31418 end = start + len;
31419- if (unlikely(!access_ok(write ? VERIFY_WRITE : VERIFY_READ,
31420+ if (unlikely(!__access_ok(write ? VERIFY_WRITE : VERIFY_READ,
31421 (void __user *)start, len)))
31422 return 0;
31423
31424@@ -344,6 +344,10 @@ int get_user_pages_fast(unsigned long start, int nr_pages, int write,
31425 goto slow_irqon;
31426 #endif
31427
31428+ if (unlikely(!__access_ok(write ? VERIFY_WRITE : VERIFY_READ,
31429+ (void __user *)start, len)))
31430+ return 0;
31431+
31432 /*
31433 * XXX: batch / limit 'nr', to avoid large irq off latency
31434 * needs some instrumenting to determine the common sizes used by
31435diff --git a/arch/x86/mm/highmem_32.c b/arch/x86/mm/highmem_32.c
31436index 4500142..53a363c 100644
31437--- a/arch/x86/mm/highmem_32.c
31438+++ b/arch/x86/mm/highmem_32.c
31439@@ -45,7 +45,11 @@ void *kmap_atomic_prot(struct page *page, pgprot_t prot)
31440 idx = type + KM_TYPE_NR*smp_processor_id();
31441 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
31442 BUG_ON(!pte_none(*(kmap_pte-idx)));
31443+
31444+ pax_open_kernel();
31445 set_pte(kmap_pte-idx, mk_pte(page, prot));
31446+ pax_close_kernel();
31447+
31448 arch_flush_lazy_mmu_mode();
31449
31450 return (void *)vaddr;
31451diff --git a/arch/x86/mm/hugetlbpage.c b/arch/x86/mm/hugetlbpage.c
31452index 9d980d8..6bbfacb 100644
31453--- a/arch/x86/mm/hugetlbpage.c
31454+++ b/arch/x86/mm/hugetlbpage.c
31455@@ -92,23 +92,30 @@ int pmd_huge_support(void)
31456 #ifdef HAVE_ARCH_HUGETLB_UNMAPPED_AREA
31457 static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *file,
31458 unsigned long addr, unsigned long len,
31459- unsigned long pgoff, unsigned long flags)
31460+ unsigned long pgoff, unsigned long flags, unsigned long offset)
31461 {
31462 struct hstate *h = hstate_file(file);
31463 struct vm_unmapped_area_info info;
31464-
31465+
31466 info.flags = 0;
31467 info.length = len;
31468 info.low_limit = TASK_UNMAPPED_BASE;
31469+
31470+#ifdef CONFIG_PAX_RANDMMAP
31471+ if (current->mm->pax_flags & MF_PAX_RANDMMAP)
31472+ info.low_limit += current->mm->delta_mmap;
31473+#endif
31474+
31475 info.high_limit = TASK_SIZE;
31476 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
31477 info.align_offset = 0;
31478+ info.threadstack_offset = offset;
31479 return vm_unmapped_area(&info);
31480 }
31481
31482 static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
31483 unsigned long addr0, unsigned long len,
31484- unsigned long pgoff, unsigned long flags)
31485+ unsigned long pgoff, unsigned long flags, unsigned long offset)
31486 {
31487 struct hstate *h = hstate_file(file);
31488 struct vm_unmapped_area_info info;
31489@@ -120,6 +127,7 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
31490 info.high_limit = current->mm->mmap_base;
31491 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
31492 info.align_offset = 0;
31493+ info.threadstack_offset = offset;
31494 addr = vm_unmapped_area(&info);
31495
31496 /*
31497@@ -132,6 +140,12 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
31498 VM_BUG_ON(addr != -ENOMEM);
31499 info.flags = 0;
31500 info.low_limit = TASK_UNMAPPED_BASE;
31501+
31502+#ifdef CONFIG_PAX_RANDMMAP
31503+ if (current->mm->pax_flags & MF_PAX_RANDMMAP)
31504+ info.low_limit += current->mm->delta_mmap;
31505+#endif
31506+
31507 info.high_limit = TASK_SIZE;
31508 addr = vm_unmapped_area(&info);
31509 }
31510@@ -146,10 +160,20 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
31511 struct hstate *h = hstate_file(file);
31512 struct mm_struct *mm = current->mm;
31513 struct vm_area_struct *vma;
31514+ unsigned long pax_task_size = TASK_SIZE;
31515+ unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
31516
31517 if (len & ~huge_page_mask(h))
31518 return -EINVAL;
31519- if (len > TASK_SIZE)
31520+
31521+#ifdef CONFIG_PAX_SEGMEXEC
31522+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
31523+ pax_task_size = SEGMEXEC_TASK_SIZE;
31524+#endif
31525+
31526+ pax_task_size -= PAGE_SIZE;
31527+
31528+ if (len > pax_task_size)
31529 return -ENOMEM;
31530
31531 if (flags & MAP_FIXED) {
31532@@ -158,19 +182,22 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
31533 return addr;
31534 }
31535
31536+#ifdef CONFIG_PAX_RANDMMAP
31537+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
31538+#endif
31539+
31540 if (addr) {
31541 addr = ALIGN(addr, huge_page_size(h));
31542 vma = find_vma(mm, addr);
31543- if (TASK_SIZE - len >= addr &&
31544- (!vma || addr + len <= vma->vm_start))
31545+ if (pax_task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
31546 return addr;
31547 }
31548 if (mm->get_unmapped_area == arch_get_unmapped_area)
31549 return hugetlb_get_unmapped_area_bottomup(file, addr, len,
31550- pgoff, flags);
31551+ pgoff, flags, offset);
31552 else
31553 return hugetlb_get_unmapped_area_topdown(file, addr, len,
31554- pgoff, flags);
31555+ pgoff, flags, offset);
31556 }
31557
31558 #endif /*HAVE_ARCH_HUGETLB_UNMAPPED_AREA*/
31559diff --git a/arch/x86/mm/init.c b/arch/x86/mm/init.c
31560index 04664cd..dae6e5d 100644
31561--- a/arch/x86/mm/init.c
31562+++ b/arch/x86/mm/init.c
31563@@ -4,6 +4,7 @@
31564 #include <linux/swap.h>
31565 #include <linux/memblock.h>
31566 #include <linux/bootmem.h> /* for max_low_pfn */
31567+#include <linux/tboot.h>
31568
31569 #include <asm/cacheflush.h>
31570 #include <asm/e820.h>
31571@@ -17,6 +18,8 @@
31572 #include <asm/proto.h>
31573 #include <asm/dma.h> /* for MAX_DMA_PFN */
31574 #include <asm/microcode.h>
31575+#include <asm/desc.h>
31576+#include <asm/bios_ebda.h>
31577
31578 #include "mm_internal.h"
31579
31580@@ -465,7 +468,18 @@ void __init init_mem_mapping(void)
31581 early_ioremap_page_table_range_init();
31582 #endif
31583
31584+#ifdef CONFIG_PAX_PER_CPU_PGD
31585+ clone_pgd_range(get_cpu_pgd(0, kernel) + KERNEL_PGD_BOUNDARY,
31586+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
31587+ KERNEL_PGD_PTRS);
31588+ clone_pgd_range(get_cpu_pgd(0, user) + KERNEL_PGD_BOUNDARY,
31589+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
31590+ KERNEL_PGD_PTRS);
31591+ load_cr3(get_cpu_pgd(0, kernel));
31592+#else
31593 load_cr3(swapper_pg_dir);
31594+#endif
31595+
31596 __flush_tlb_all();
31597
31598 early_memtest(0, max_pfn_mapped << PAGE_SHIFT);
31599@@ -481,10 +495,40 @@ void __init init_mem_mapping(void)
31600 * Access has to be given to non-kernel-ram areas as well, these contain the PCI
31601 * mmio resources as well as potential bios/acpi data regions.
31602 */
31603+
31604+#ifdef CONFIG_GRKERNSEC_KMEM
31605+static unsigned int ebda_start __read_only;
31606+static unsigned int ebda_end __read_only;
31607+#endif
31608+
31609 int devmem_is_allowed(unsigned long pagenr)
31610 {
31611- if (pagenr < 256)
31612+#ifdef CONFIG_GRKERNSEC_KMEM
31613+ /* allow BDA */
31614+ if (!pagenr)
31615 return 1;
31616+ /* allow EBDA */
31617+ if (pagenr >= ebda_start && pagenr < ebda_end)
31618+ return 1;
31619+ /* if tboot is in use, allow access to its hardcoded serial log range */
31620+ if (tboot_enabled() && ((0x60000 >> PAGE_SHIFT) <= pagenr) && (pagenr < (0x68000 >> PAGE_SHIFT)))
31621+ return 1;
31622+#else
31623+ if (!pagenr)
31624+ return 1;
31625+#ifdef CONFIG_VM86
31626+ if (pagenr < (ISA_START_ADDRESS >> PAGE_SHIFT))
31627+ return 1;
31628+#endif
31629+#endif
31630+
31631+ if ((ISA_START_ADDRESS >> PAGE_SHIFT) <= pagenr && pagenr < (ISA_END_ADDRESS >> PAGE_SHIFT))
31632+ return 1;
31633+#ifdef CONFIG_GRKERNSEC_KMEM
31634+ /* throw out everything else below 1MB */
31635+ if (pagenr <= 256)
31636+ return 0;
31637+#endif
31638 if (iomem_is_exclusive(pagenr << PAGE_SHIFT))
31639 return 0;
31640 if (!page_is_ram(pagenr))
31641@@ -530,8 +574,117 @@ void free_init_pages(char *what, unsigned long begin, unsigned long end)
31642 #endif
31643 }
31644
31645+#ifdef CONFIG_GRKERNSEC_KMEM
31646+static inline void gr_init_ebda(void)
31647+{
31648+ unsigned int ebda_addr;
31649+ unsigned int ebda_size = 0;
31650+
31651+ ebda_addr = get_bios_ebda();
31652+ if (ebda_addr) {
31653+ ebda_size = *(unsigned char *)phys_to_virt(ebda_addr);
31654+ ebda_size <<= 10;
31655+ }
31656+ if (ebda_addr && ebda_size) {
31657+ ebda_start = ebda_addr >> PAGE_SHIFT;
31658+ ebda_end = min((unsigned int)PAGE_ALIGN(ebda_addr + ebda_size), (unsigned int)0xa0000) >> PAGE_SHIFT;
31659+ } else {
31660+ ebda_start = 0x9f000 >> PAGE_SHIFT;
31661+ ebda_end = 0xa0000 >> PAGE_SHIFT;
31662+ }
31663+}
31664+#else
31665+static inline void gr_init_ebda(void) { }
31666+#endif
31667+
31668 void free_initmem(void)
31669 {
31670+#ifdef CONFIG_PAX_KERNEXEC
31671+#ifdef CONFIG_X86_32
31672+ /* PaX: limit KERNEL_CS to actual size */
31673+ unsigned long addr, limit;
31674+ struct desc_struct d;
31675+ int cpu;
31676+#else
31677+ pgd_t *pgd;
31678+ pud_t *pud;
31679+ pmd_t *pmd;
31680+ unsigned long addr, end;
31681+#endif
31682+#endif
31683+
31684+ gr_init_ebda();
31685+
31686+#ifdef CONFIG_PAX_KERNEXEC
31687+#ifdef CONFIG_X86_32
31688+ limit = paravirt_enabled() ? ktva_ktla(0xffffffff) : (unsigned long)&_etext;
31689+ limit = (limit - 1UL) >> PAGE_SHIFT;
31690+
31691+ memset(__LOAD_PHYSICAL_ADDR + PAGE_OFFSET, POISON_FREE_INITMEM, PAGE_SIZE);
31692+ for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
31693+ pack_descriptor(&d, get_desc_base(&get_cpu_gdt_table(cpu)[GDT_ENTRY_KERNEL_CS]), limit, 0x9B, 0xC);
31694+ write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEL_CS, &d, DESCTYPE_S);
31695+ write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEXEC_KERNEL_CS, &d, DESCTYPE_S);
31696+ }
31697+
31698+ /* PaX: make KERNEL_CS read-only */
31699+ addr = PFN_ALIGN(ktla_ktva((unsigned long)&_text));
31700+ if (!paravirt_enabled())
31701+ set_memory_ro(addr, (PFN_ALIGN(_sdata) - addr) >> PAGE_SHIFT);
31702+/*
31703+ for (addr = ktla_ktva((unsigned long)&_text); addr < (unsigned long)&_sdata; addr += PMD_SIZE) {
31704+ pgd = pgd_offset_k(addr);
31705+ pud = pud_offset(pgd, addr);
31706+ pmd = pmd_offset(pud, addr);
31707+ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
31708+ }
31709+*/
31710+#ifdef CONFIG_X86_PAE
31711+ set_memory_nx(PFN_ALIGN(__init_begin), (PFN_ALIGN(__init_end) - PFN_ALIGN(__init_begin)) >> PAGE_SHIFT);
31712+/*
31713+ for (addr = (unsigned long)&__init_begin; addr < (unsigned long)&__init_end; addr += PMD_SIZE) {
31714+ pgd = pgd_offset_k(addr);
31715+ pud = pud_offset(pgd, addr);
31716+ pmd = pmd_offset(pud, addr);
31717+ set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
31718+ }
31719+*/
31720+#endif
31721+
31722+#ifdef CONFIG_MODULES
31723+ set_memory_4k((unsigned long)MODULES_EXEC_VADDR, (MODULES_EXEC_END - MODULES_EXEC_VADDR) >> PAGE_SHIFT);
31724+#endif
31725+
31726+#else
31727+ /* PaX: make kernel code/rodata read-only, rest non-executable */
31728+ for (addr = __START_KERNEL_map; addr < __START_KERNEL_map + KERNEL_IMAGE_SIZE; addr += PMD_SIZE) {
31729+ pgd = pgd_offset_k(addr);
31730+ pud = pud_offset(pgd, addr);
31731+ pmd = pmd_offset(pud, addr);
31732+ if (!pmd_present(*pmd))
31733+ continue;
31734+ if ((unsigned long)_text <= addr && addr < (unsigned long)_sdata)
31735+ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
31736+ else
31737+ set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
31738+ }
31739+
31740+ addr = (unsigned long)__va(__pa(__START_KERNEL_map));
31741+ end = addr + KERNEL_IMAGE_SIZE;
31742+ for (; addr < end; addr += PMD_SIZE) {
31743+ pgd = pgd_offset_k(addr);
31744+ pud = pud_offset(pgd, addr);
31745+ pmd = pmd_offset(pud, addr);
31746+ if (!pmd_present(*pmd))
31747+ continue;
31748+ if ((unsigned long)__va(__pa(_text)) <= addr && addr < (unsigned long)__va(__pa(_sdata)))
31749+ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
31750+ }
31751+#endif
31752+
31753+ flush_tlb_all();
31754+#endif
31755+
31756 free_init_pages("unused kernel",
31757 (unsigned long)(&__init_begin),
31758 (unsigned long)(&__init_end));
31759diff --git a/arch/x86/mm/init_32.c b/arch/x86/mm/init_32.c
31760index 4287f1f..3b99c71 100644
31761--- a/arch/x86/mm/init_32.c
31762+++ b/arch/x86/mm/init_32.c
31763@@ -62,33 +62,6 @@ static noinline int do_test_wp_bit(void);
31764 bool __read_mostly __vmalloc_start_set = false;
31765
31766 /*
31767- * Creates a middle page table and puts a pointer to it in the
31768- * given global directory entry. This only returns the gd entry
31769- * in non-PAE compilation mode, since the middle layer is folded.
31770- */
31771-static pmd_t * __init one_md_table_init(pgd_t *pgd)
31772-{
31773- pud_t *pud;
31774- pmd_t *pmd_table;
31775-
31776-#ifdef CONFIG_X86_PAE
31777- if (!(pgd_val(*pgd) & _PAGE_PRESENT)) {
31778- pmd_table = (pmd_t *)alloc_low_page();
31779- paravirt_alloc_pmd(&init_mm, __pa(pmd_table) >> PAGE_SHIFT);
31780- set_pgd(pgd, __pgd(__pa(pmd_table) | _PAGE_PRESENT));
31781- pud = pud_offset(pgd, 0);
31782- BUG_ON(pmd_table != pmd_offset(pud, 0));
31783-
31784- return pmd_table;
31785- }
31786-#endif
31787- pud = pud_offset(pgd, 0);
31788- pmd_table = pmd_offset(pud, 0);
31789-
31790- return pmd_table;
31791-}
31792-
31793-/*
31794 * Create a page table and place a pointer to it in a middle page
31795 * directory entry:
31796 */
31797@@ -98,13 +71,28 @@ static pte_t * __init one_page_table_init(pmd_t *pmd)
31798 pte_t *page_table = (pte_t *)alloc_low_page();
31799
31800 paravirt_alloc_pte(&init_mm, __pa(page_table) >> PAGE_SHIFT);
31801+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
31802+ set_pmd(pmd, __pmd(__pa(page_table) | _KERNPG_TABLE));
31803+#else
31804 set_pmd(pmd, __pmd(__pa(page_table) | _PAGE_TABLE));
31805+#endif
31806 BUG_ON(page_table != pte_offset_kernel(pmd, 0));
31807 }
31808
31809 return pte_offset_kernel(pmd, 0);
31810 }
31811
31812+static pmd_t * __init one_md_table_init(pgd_t *pgd)
31813+{
31814+ pud_t *pud;
31815+ pmd_t *pmd_table;
31816+
31817+ pud = pud_offset(pgd, 0);
31818+ pmd_table = pmd_offset(pud, 0);
31819+
31820+ return pmd_table;
31821+}
31822+
31823 pmd_t * __init populate_extra_pmd(unsigned long vaddr)
31824 {
31825 int pgd_idx = pgd_index(vaddr);
31826@@ -208,6 +196,7 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
31827 int pgd_idx, pmd_idx;
31828 unsigned long vaddr;
31829 pgd_t *pgd;
31830+ pud_t *pud;
31831 pmd_t *pmd;
31832 pte_t *pte = NULL;
31833 unsigned long count = page_table_range_init_count(start, end);
31834@@ -222,8 +211,13 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
31835 pgd = pgd_base + pgd_idx;
31836
31837 for ( ; (pgd_idx < PTRS_PER_PGD) && (vaddr != end); pgd++, pgd_idx++) {
31838- pmd = one_md_table_init(pgd);
31839- pmd = pmd + pmd_index(vaddr);
31840+ pud = pud_offset(pgd, vaddr);
31841+ pmd = pmd_offset(pud, vaddr);
31842+
31843+#ifdef CONFIG_X86_PAE
31844+ paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
31845+#endif
31846+
31847 for (; (pmd_idx < PTRS_PER_PMD) && (vaddr != end);
31848 pmd++, pmd_idx++) {
31849 pte = page_table_kmap_check(one_page_table_init(pmd),
31850@@ -235,11 +229,20 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
31851 }
31852 }
31853
31854-static inline int is_kernel_text(unsigned long addr)
31855+static inline int is_kernel_text(unsigned long start, unsigned long end)
31856 {
31857- if (addr >= (unsigned long)_text && addr <= (unsigned long)__init_end)
31858- return 1;
31859- return 0;
31860+ if ((start > ktla_ktva((unsigned long)_etext) ||
31861+ end <= ktla_ktva((unsigned long)_stext)) &&
31862+ (start > ktla_ktva((unsigned long)_einittext) ||
31863+ end <= ktla_ktva((unsigned long)_sinittext)) &&
31864+
31865+#ifdef CONFIG_ACPI_SLEEP
31866+ (start > (unsigned long)__va(acpi_wakeup_address) + 0x4000 || end <= (unsigned long)__va(acpi_wakeup_address)) &&
31867+#endif
31868+
31869+ (start > (unsigned long)__va(0xfffff) || end <= (unsigned long)__va(0xc0000)))
31870+ return 0;
31871+ return 1;
31872 }
31873
31874 /*
31875@@ -256,9 +259,10 @@ kernel_physical_mapping_init(unsigned long start,
31876 unsigned long last_map_addr = end;
31877 unsigned long start_pfn, end_pfn;
31878 pgd_t *pgd_base = swapper_pg_dir;
31879- int pgd_idx, pmd_idx, pte_ofs;
31880+ unsigned int pgd_idx, pmd_idx, pte_ofs;
31881 unsigned long pfn;
31882 pgd_t *pgd;
31883+ pud_t *pud;
31884 pmd_t *pmd;
31885 pte_t *pte;
31886 unsigned pages_2m, pages_4k;
31887@@ -291,8 +295,13 @@ repeat:
31888 pfn = start_pfn;
31889 pgd_idx = pgd_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
31890 pgd = pgd_base + pgd_idx;
31891- for (; pgd_idx < PTRS_PER_PGD; pgd++, pgd_idx++) {
31892- pmd = one_md_table_init(pgd);
31893+ for (; pgd_idx < PTRS_PER_PGD && pfn < max_low_pfn; pgd++, pgd_idx++) {
31894+ pud = pud_offset(pgd, 0);
31895+ pmd = pmd_offset(pud, 0);
31896+
31897+#ifdef CONFIG_X86_PAE
31898+ paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
31899+#endif
31900
31901 if (pfn >= end_pfn)
31902 continue;
31903@@ -304,14 +313,13 @@ repeat:
31904 #endif
31905 for (; pmd_idx < PTRS_PER_PMD && pfn < end_pfn;
31906 pmd++, pmd_idx++) {
31907- unsigned int addr = pfn * PAGE_SIZE + PAGE_OFFSET;
31908+ unsigned long address = pfn * PAGE_SIZE + PAGE_OFFSET;
31909
31910 /*
31911 * Map with big pages if possible, otherwise
31912 * create normal page tables:
31913 */
31914 if (use_pse) {
31915- unsigned int addr2;
31916 pgprot_t prot = PAGE_KERNEL_LARGE;
31917 /*
31918 * first pass will use the same initial
31919@@ -322,11 +330,7 @@ repeat:
31920 _PAGE_PSE);
31921
31922 pfn &= PMD_MASK >> PAGE_SHIFT;
31923- addr2 = (pfn + PTRS_PER_PTE-1) * PAGE_SIZE +
31924- PAGE_OFFSET + PAGE_SIZE-1;
31925-
31926- if (is_kernel_text(addr) ||
31927- is_kernel_text(addr2))
31928+ if (is_kernel_text(address, address + PMD_SIZE))
31929 prot = PAGE_KERNEL_LARGE_EXEC;
31930
31931 pages_2m++;
31932@@ -343,7 +347,7 @@ repeat:
31933 pte_ofs = pte_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
31934 pte += pte_ofs;
31935 for (; pte_ofs < PTRS_PER_PTE && pfn < end_pfn;
31936- pte++, pfn++, pte_ofs++, addr += PAGE_SIZE) {
31937+ pte++, pfn++, pte_ofs++, address += PAGE_SIZE) {
31938 pgprot_t prot = PAGE_KERNEL;
31939 /*
31940 * first pass will use the same initial
31941@@ -351,7 +355,7 @@ repeat:
31942 */
31943 pgprot_t init_prot = __pgprot(PTE_IDENT_ATTR);
31944
31945- if (is_kernel_text(addr))
31946+ if (is_kernel_text(address, address + PAGE_SIZE))
31947 prot = PAGE_KERNEL_EXEC;
31948
31949 pages_4k++;
31950@@ -474,7 +478,7 @@ void __init native_pagetable_init(void)
31951
31952 pud = pud_offset(pgd, va);
31953 pmd = pmd_offset(pud, va);
31954- if (!pmd_present(*pmd))
31955+ if (!pmd_present(*pmd)) // PAX TODO || pmd_large(*pmd))
31956 break;
31957
31958 /* should not be large page here */
31959@@ -532,12 +536,10 @@ void __init early_ioremap_page_table_range_init(void)
31960
31961 static void __init pagetable_init(void)
31962 {
31963- pgd_t *pgd_base = swapper_pg_dir;
31964-
31965- permanent_kmaps_init(pgd_base);
31966+ permanent_kmaps_init(swapper_pg_dir);
31967 }
31968
31969-pteval_t __supported_pte_mask __read_mostly = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
31970+pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
31971 EXPORT_SYMBOL_GPL(__supported_pte_mask);
31972
31973 /* user-defined highmem size */
31974@@ -787,10 +789,10 @@ void __init mem_init(void)
31975 ((unsigned long)&__init_end -
31976 (unsigned long)&__init_begin) >> 10,
31977
31978- (unsigned long)&_etext, (unsigned long)&_edata,
31979- ((unsigned long)&_edata - (unsigned long)&_etext) >> 10,
31980+ (unsigned long)&_sdata, (unsigned long)&_edata,
31981+ ((unsigned long)&_edata - (unsigned long)&_sdata) >> 10,
31982
31983- (unsigned long)&_text, (unsigned long)&_etext,
31984+ ktla_ktva((unsigned long)&_text), ktla_ktva((unsigned long)&_etext),
31985 ((unsigned long)&_etext - (unsigned long)&_text) >> 10);
31986
31987 /*
31988@@ -880,6 +882,7 @@ void set_kernel_text_rw(void)
31989 if (!kernel_set_to_readonly)
31990 return;
31991
31992+ start = ktla_ktva(start);
31993 pr_debug("Set kernel text: %lx - %lx for read write\n",
31994 start, start+size);
31995
31996@@ -894,6 +897,7 @@ void set_kernel_text_ro(void)
31997 if (!kernel_set_to_readonly)
31998 return;
31999
32000+ start = ktla_ktva(start);
32001 pr_debug("Set kernel text: %lx - %lx for read only\n",
32002 start, start+size);
32003
32004@@ -922,6 +926,7 @@ void mark_rodata_ro(void)
32005 unsigned long start = PFN_ALIGN(_text);
32006 unsigned long size = PFN_ALIGN(_etext) - start;
32007
32008+ start = ktla_ktva(start);
32009 set_pages_ro(virt_to_page(start), size >> PAGE_SHIFT);
32010 printk(KERN_INFO "Write protecting the kernel text: %luk\n",
32011 size >> 10);
32012diff --git a/arch/x86/mm/init_64.c b/arch/x86/mm/init_64.c
32013index 104d56a..62ba13f1 100644
32014--- a/arch/x86/mm/init_64.c
32015+++ b/arch/x86/mm/init_64.c
32016@@ -151,7 +151,7 @@ early_param("gbpages", parse_direct_gbpages_on);
32017 * around without checking the pgd every time.
32018 */
32019
32020-pteval_t __supported_pte_mask __read_mostly = ~_PAGE_IOMAP;
32021+pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_IOMAP);
32022 EXPORT_SYMBOL_GPL(__supported_pte_mask);
32023
32024 int force_personality32;
32025@@ -184,12 +184,29 @@ void sync_global_pgds(unsigned long start, unsigned long end)
32026
32027 for (address = start; address <= end; address += PGDIR_SIZE) {
32028 const pgd_t *pgd_ref = pgd_offset_k(address);
32029+
32030+#ifdef CONFIG_PAX_PER_CPU_PGD
32031+ unsigned long cpu;
32032+#else
32033 struct page *page;
32034+#endif
32035
32036 if (pgd_none(*pgd_ref))
32037 continue;
32038
32039 spin_lock(&pgd_lock);
32040+
32041+#ifdef CONFIG_PAX_PER_CPU_PGD
32042+ for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
32043+ pgd_t *pgd = pgd_offset_cpu(cpu, user, address);
32044+
32045+ if (pgd_none(*pgd))
32046+ set_pgd(pgd, *pgd_ref);
32047+ else
32048+ BUG_ON(pgd_page_vaddr(*pgd)
32049+ != pgd_page_vaddr(*pgd_ref));
32050+ pgd = pgd_offset_cpu(cpu, kernel, address);
32051+#else
32052 list_for_each_entry(page, &pgd_list, lru) {
32053 pgd_t *pgd;
32054 spinlock_t *pgt_lock;
32055@@ -198,6 +215,7 @@ void sync_global_pgds(unsigned long start, unsigned long end)
32056 /* the pgt_lock only for Xen */
32057 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
32058 spin_lock(pgt_lock);
32059+#endif
32060
32061 if (pgd_none(*pgd))
32062 set_pgd(pgd, *pgd_ref);
32063@@ -205,7 +223,10 @@ void sync_global_pgds(unsigned long start, unsigned long end)
32064 BUG_ON(pgd_page_vaddr(*pgd)
32065 != pgd_page_vaddr(*pgd_ref));
32066
32067+#ifndef CONFIG_PAX_PER_CPU_PGD
32068 spin_unlock(pgt_lock);
32069+#endif
32070+
32071 }
32072 spin_unlock(&pgd_lock);
32073 }
32074@@ -238,7 +259,7 @@ static pud_t *fill_pud(pgd_t *pgd, unsigned long vaddr)
32075 {
32076 if (pgd_none(*pgd)) {
32077 pud_t *pud = (pud_t *)spp_getpage();
32078- pgd_populate(&init_mm, pgd, pud);
32079+ pgd_populate_kernel(&init_mm, pgd, pud);
32080 if (pud != pud_offset(pgd, 0))
32081 printk(KERN_ERR "PAGETABLE BUG #00! %p <-> %p\n",
32082 pud, pud_offset(pgd, 0));
32083@@ -250,7 +271,7 @@ static pmd_t *fill_pmd(pud_t *pud, unsigned long vaddr)
32084 {
32085 if (pud_none(*pud)) {
32086 pmd_t *pmd = (pmd_t *) spp_getpage();
32087- pud_populate(&init_mm, pud, pmd);
32088+ pud_populate_kernel(&init_mm, pud, pmd);
32089 if (pmd != pmd_offset(pud, 0))
32090 printk(KERN_ERR "PAGETABLE BUG #01! %p <-> %p\n",
32091 pmd, pmd_offset(pud, 0));
32092@@ -279,7 +300,9 @@ void set_pte_vaddr_pud(pud_t *pud_page, unsigned long vaddr, pte_t new_pte)
32093 pmd = fill_pmd(pud, vaddr);
32094 pte = fill_pte(pmd, vaddr);
32095
32096+ pax_open_kernel();
32097 set_pte(pte, new_pte);
32098+ pax_close_kernel();
32099
32100 /*
32101 * It's enough to flush this one mapping.
32102@@ -338,14 +361,12 @@ static void __init __init_extra_mapping(unsigned long phys, unsigned long size,
32103 pgd = pgd_offset_k((unsigned long)__va(phys));
32104 if (pgd_none(*pgd)) {
32105 pud = (pud_t *) spp_getpage();
32106- set_pgd(pgd, __pgd(__pa(pud) | _KERNPG_TABLE |
32107- _PAGE_USER));
32108+ set_pgd(pgd, __pgd(__pa(pud) | _PAGE_TABLE));
32109 }
32110 pud = pud_offset(pgd, (unsigned long)__va(phys));
32111 if (pud_none(*pud)) {
32112 pmd = (pmd_t *) spp_getpage();
32113- set_pud(pud, __pud(__pa(pmd) | _KERNPG_TABLE |
32114- _PAGE_USER));
32115+ set_pud(pud, __pud(__pa(pmd) | _PAGE_TABLE));
32116 }
32117 pmd = pmd_offset(pud, phys);
32118 BUG_ON(!pmd_none(*pmd));
32119@@ -586,7 +607,7 @@ phys_pud_init(pud_t *pud_page, unsigned long addr, unsigned long end,
32120 prot);
32121
32122 spin_lock(&init_mm.page_table_lock);
32123- pud_populate(&init_mm, pud, pmd);
32124+ pud_populate_kernel(&init_mm, pud, pmd);
32125 spin_unlock(&init_mm.page_table_lock);
32126 }
32127 __flush_tlb_all();
32128@@ -627,7 +648,7 @@ kernel_physical_mapping_init(unsigned long start,
32129 page_size_mask);
32130
32131 spin_lock(&init_mm.page_table_lock);
32132- pgd_populate(&init_mm, pgd, pud);
32133+ pgd_populate_kernel(&init_mm, pgd, pud);
32134 spin_unlock(&init_mm.page_table_lock);
32135 pgd_changed = true;
32136 }
32137@@ -1188,8 +1209,8 @@ int kern_addr_valid(unsigned long addr)
32138 static struct vm_area_struct gate_vma = {
32139 .vm_start = VSYSCALL_START,
32140 .vm_end = VSYSCALL_START + (VSYSCALL_MAPPED_PAGES * PAGE_SIZE),
32141- .vm_page_prot = PAGE_READONLY_EXEC,
32142- .vm_flags = VM_READ | VM_EXEC
32143+ .vm_page_prot = PAGE_READONLY,
32144+ .vm_flags = VM_READ
32145 };
32146
32147 struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
32148@@ -1223,7 +1244,7 @@ int in_gate_area_no_mm(unsigned long addr)
32149
32150 const char *arch_vma_name(struct vm_area_struct *vma)
32151 {
32152- if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
32153+ if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
32154 return "[vdso]";
32155 if (vma == &gate_vma)
32156 return "[vsyscall]";
32157diff --git a/arch/x86/mm/iomap_32.c b/arch/x86/mm/iomap_32.c
32158index 7b179b4..6bd17777 100644
32159--- a/arch/x86/mm/iomap_32.c
32160+++ b/arch/x86/mm/iomap_32.c
32161@@ -64,7 +64,11 @@ void *kmap_atomic_prot_pfn(unsigned long pfn, pgprot_t prot)
32162 type = kmap_atomic_idx_push();
32163 idx = type + KM_TYPE_NR * smp_processor_id();
32164 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
32165+
32166+ pax_open_kernel();
32167 set_pte(kmap_pte - idx, pfn_pte(pfn, prot));
32168+ pax_close_kernel();
32169+
32170 arch_flush_lazy_mmu_mode();
32171
32172 return (void *)vaddr;
32173diff --git a/arch/x86/mm/ioremap.c b/arch/x86/mm/ioremap.c
32174index 799580c..72f9fe0 100644
32175--- a/arch/x86/mm/ioremap.c
32176+++ b/arch/x86/mm/ioremap.c
32177@@ -97,7 +97,7 @@ static void __iomem *__ioremap_caller(resource_size_t phys_addr,
32178 for (pfn = phys_addr >> PAGE_SHIFT; pfn <= last_pfn; pfn++) {
32179 int is_ram = page_is_ram(pfn);
32180
32181- if (is_ram && pfn_valid(pfn) && !PageReserved(pfn_to_page(pfn)))
32182+ if (is_ram && pfn_valid(pfn) && (pfn >= 0x100 || !PageReserved(pfn_to_page(pfn))))
32183 return NULL;
32184 WARN_ON_ONCE(is_ram);
32185 }
32186@@ -256,7 +256,7 @@ EXPORT_SYMBOL(ioremap_prot);
32187 *
32188 * Caller must ensure there is only one unmapping for the same pointer.
32189 */
32190-void iounmap(volatile void __iomem *addr)
32191+void iounmap(const volatile void __iomem *addr)
32192 {
32193 struct vm_struct *p, *o;
32194
32195@@ -310,6 +310,9 @@ void *xlate_dev_mem_ptr(unsigned long phys)
32196
32197 /* If page is RAM, we can use __va. Otherwise ioremap and unmap. */
32198 if (page_is_ram(start >> PAGE_SHIFT))
32199+#ifdef CONFIG_HIGHMEM
32200+ if ((start >> PAGE_SHIFT) < max_low_pfn)
32201+#endif
32202 return __va(phys);
32203
32204 addr = (void __force *)ioremap_cache(start, PAGE_SIZE);
32205@@ -322,6 +325,9 @@ void *xlate_dev_mem_ptr(unsigned long phys)
32206 void unxlate_dev_mem_ptr(unsigned long phys, void *addr)
32207 {
32208 if (page_is_ram(phys >> PAGE_SHIFT))
32209+#ifdef CONFIG_HIGHMEM
32210+ if ((phys >> PAGE_SHIFT) < max_low_pfn)
32211+#endif
32212 return;
32213
32214 iounmap((void __iomem *)((unsigned long)addr & PAGE_MASK));
32215@@ -339,7 +345,7 @@ static int __init early_ioremap_debug_setup(char *str)
32216 early_param("early_ioremap_debug", early_ioremap_debug_setup);
32217
32218 static __initdata int after_paging_init;
32219-static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __page_aligned_bss;
32220+static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __read_only __aligned(PAGE_SIZE);
32221
32222 static inline pmd_t * __init early_ioremap_pmd(unsigned long addr)
32223 {
32224@@ -376,8 +382,7 @@ void __init early_ioremap_init(void)
32225 slot_virt[i] = __fix_to_virt(FIX_BTMAP_BEGIN - NR_FIX_BTMAPS*i);
32226
32227 pmd = early_ioremap_pmd(fix_to_virt(FIX_BTMAP_BEGIN));
32228- memset(bm_pte, 0, sizeof(bm_pte));
32229- pmd_populate_kernel(&init_mm, pmd, bm_pte);
32230+ pmd_populate_user(&init_mm, pmd, bm_pte);
32231
32232 /*
32233 * The boot-ioremap range spans multiple pmds, for which
32234diff --git a/arch/x86/mm/kmemcheck/kmemcheck.c b/arch/x86/mm/kmemcheck/kmemcheck.c
32235index d87dd6d..bf3fa66 100644
32236--- a/arch/x86/mm/kmemcheck/kmemcheck.c
32237+++ b/arch/x86/mm/kmemcheck/kmemcheck.c
32238@@ -622,9 +622,9 @@ bool kmemcheck_fault(struct pt_regs *regs, unsigned long address,
32239 * memory (e.g. tracked pages)? For now, we need this to avoid
32240 * invoking kmemcheck for PnP BIOS calls.
32241 */
32242- if (regs->flags & X86_VM_MASK)
32243+ if (v8086_mode(regs))
32244 return false;
32245- if (regs->cs != __KERNEL_CS)
32246+ if (regs->cs != __KERNEL_CS && regs->cs != __KERNEXEC_KERNEL_CS)
32247 return false;
32248
32249 pte = kmemcheck_pte_lookup(address);
32250diff --git a/arch/x86/mm/mmap.c b/arch/x86/mm/mmap.c
32251index 25e7e13..1964579 100644
32252--- a/arch/x86/mm/mmap.c
32253+++ b/arch/x86/mm/mmap.c
32254@@ -52,7 +52,7 @@ static unsigned int stack_maxrandom_size(void)
32255 * Leave an at least ~128 MB hole with possible stack randomization.
32256 */
32257 #define MIN_GAP (128*1024*1024UL + stack_maxrandom_size())
32258-#define MAX_GAP (TASK_SIZE/6*5)
32259+#define MAX_GAP (pax_task_size/6*5)
32260
32261 static int mmap_is_legacy(void)
32262 {
32263@@ -82,27 +82,40 @@ static unsigned long mmap_rnd(void)
32264 return rnd << PAGE_SHIFT;
32265 }
32266
32267-static unsigned long mmap_base(void)
32268+static unsigned long mmap_base(struct mm_struct *mm)
32269 {
32270 unsigned long gap = rlimit(RLIMIT_STACK);
32271+ unsigned long pax_task_size = TASK_SIZE;
32272+
32273+#ifdef CONFIG_PAX_SEGMEXEC
32274+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
32275+ pax_task_size = SEGMEXEC_TASK_SIZE;
32276+#endif
32277
32278 if (gap < MIN_GAP)
32279 gap = MIN_GAP;
32280 else if (gap > MAX_GAP)
32281 gap = MAX_GAP;
32282
32283- return PAGE_ALIGN(TASK_SIZE - gap - mmap_rnd());
32284+ return PAGE_ALIGN(pax_task_size - gap - mmap_rnd());
32285 }
32286
32287 /*
32288 * Bottom-up (legacy) layout on X86_32 did not support randomization, X86_64
32289 * does, but not when emulating X86_32
32290 */
32291-static unsigned long mmap_legacy_base(void)
32292+static unsigned long mmap_legacy_base(struct mm_struct *mm)
32293 {
32294- if (mmap_is_ia32())
32295+ if (mmap_is_ia32()) {
32296+
32297+#ifdef CONFIG_PAX_SEGMEXEC
32298+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
32299+ return SEGMEXEC_TASK_UNMAPPED_BASE;
32300+ else
32301+#endif
32302+
32303 return TASK_UNMAPPED_BASE;
32304- else
32305+ } else
32306 return TASK_UNMAPPED_BASE + mmap_rnd();
32307 }
32308
32309@@ -112,8 +125,15 @@ static unsigned long mmap_legacy_base(void)
32310 */
32311 void arch_pick_mmap_layout(struct mm_struct *mm)
32312 {
32313- mm->mmap_legacy_base = mmap_legacy_base();
32314- mm->mmap_base = mmap_base();
32315+ mm->mmap_legacy_base = mmap_legacy_base(mm);
32316+ mm->mmap_base = mmap_base(mm);
32317+
32318+#ifdef CONFIG_PAX_RANDMMAP
32319+ if (mm->pax_flags & MF_PAX_RANDMMAP) {
32320+ mm->mmap_legacy_base += mm->delta_mmap;
32321+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
32322+ }
32323+#endif
32324
32325 if (mmap_is_legacy()) {
32326 mm->mmap_base = mm->mmap_legacy_base;
32327diff --git a/arch/x86/mm/mmio-mod.c b/arch/x86/mm/mmio-mod.c
32328index 0057a7a..95c7edd 100644
32329--- a/arch/x86/mm/mmio-mod.c
32330+++ b/arch/x86/mm/mmio-mod.c
32331@@ -194,7 +194,7 @@ static void pre(struct kmmio_probe *p, struct pt_regs *regs,
32332 break;
32333 default:
32334 {
32335- unsigned char *ip = (unsigned char *)instptr;
32336+ unsigned char *ip = (unsigned char *)ktla_ktva(instptr);
32337 my_trace->opcode = MMIO_UNKNOWN_OP;
32338 my_trace->width = 0;
32339 my_trace->value = (*ip) << 16 | *(ip + 1) << 8 |
32340@@ -234,7 +234,7 @@ static void post(struct kmmio_probe *p, unsigned long condition,
32341 static void ioremap_trace_core(resource_size_t offset, unsigned long size,
32342 void __iomem *addr)
32343 {
32344- static atomic_t next_id;
32345+ static atomic_unchecked_t next_id;
32346 struct remap_trace *trace = kmalloc(sizeof(*trace), GFP_KERNEL);
32347 /* These are page-unaligned. */
32348 struct mmiotrace_map map = {
32349@@ -258,7 +258,7 @@ static void ioremap_trace_core(resource_size_t offset, unsigned long size,
32350 .private = trace
32351 },
32352 .phys = offset,
32353- .id = atomic_inc_return(&next_id)
32354+ .id = atomic_inc_return_unchecked(&next_id)
32355 };
32356 map.map_id = trace->id;
32357
32358@@ -290,7 +290,7 @@ void mmiotrace_ioremap(resource_size_t offset, unsigned long size,
32359 ioremap_trace_core(offset, size, addr);
32360 }
32361
32362-static void iounmap_trace_core(volatile void __iomem *addr)
32363+static void iounmap_trace_core(const volatile void __iomem *addr)
32364 {
32365 struct mmiotrace_map map = {
32366 .phys = 0,
32367@@ -328,7 +328,7 @@ not_enabled:
32368 }
32369 }
32370
32371-void mmiotrace_iounmap(volatile void __iomem *addr)
32372+void mmiotrace_iounmap(const volatile void __iomem *addr)
32373 {
32374 might_sleep();
32375 if (is_enabled()) /* recheck and proper locking in *_core() */
32376diff --git a/arch/x86/mm/numa.c b/arch/x86/mm/numa.c
32377index 8bf93ba..dbcd670 100644
32378--- a/arch/x86/mm/numa.c
32379+++ b/arch/x86/mm/numa.c
32380@@ -474,7 +474,7 @@ static bool __init numa_meminfo_cover_memory(const struct numa_meminfo *mi)
32381 return true;
32382 }
32383
32384-static int __init numa_register_memblks(struct numa_meminfo *mi)
32385+static int __init __intentional_overflow(-1) numa_register_memblks(struct numa_meminfo *mi)
32386 {
32387 unsigned long uninitialized_var(pfn_align);
32388 int i, nid;
32389diff --git a/arch/x86/mm/pageattr-test.c b/arch/x86/mm/pageattr-test.c
32390index d0b1773..4c3327c 100644
32391--- a/arch/x86/mm/pageattr-test.c
32392+++ b/arch/x86/mm/pageattr-test.c
32393@@ -36,7 +36,7 @@ enum {
32394
32395 static int pte_testbit(pte_t pte)
32396 {
32397- return pte_flags(pte) & _PAGE_UNUSED1;
32398+ return pte_flags(pte) & _PAGE_CPA_TEST;
32399 }
32400
32401 struct split_state {
32402diff --git a/arch/x86/mm/pageattr.c b/arch/x86/mm/pageattr.c
32403index bb32480..75f2f5e 100644
32404--- a/arch/x86/mm/pageattr.c
32405+++ b/arch/x86/mm/pageattr.c
32406@@ -261,7 +261,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
32407 */
32408 #ifdef CONFIG_PCI_BIOS
32409 if (pcibios_enabled && within(pfn, BIOS_BEGIN >> PAGE_SHIFT, BIOS_END >> PAGE_SHIFT))
32410- pgprot_val(forbidden) |= _PAGE_NX;
32411+ pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
32412 #endif
32413
32414 /*
32415@@ -269,9 +269,10 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
32416 * Does not cover __inittext since that is gone later on. On
32417 * 64bit we do not enforce !NX on the low mapping
32418 */
32419- if (within(address, (unsigned long)_text, (unsigned long)_etext))
32420- pgprot_val(forbidden) |= _PAGE_NX;
32421+ if (within(address, ktla_ktva((unsigned long)_text), ktla_ktva((unsigned long)_etext)))
32422+ pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
32423
32424+#ifdef CONFIG_DEBUG_RODATA
32425 /*
32426 * The .rodata section needs to be read-only. Using the pfn
32427 * catches all aliases.
32428@@ -279,6 +280,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
32429 if (within(pfn, __pa_symbol(__start_rodata) >> PAGE_SHIFT,
32430 __pa_symbol(__end_rodata) >> PAGE_SHIFT))
32431 pgprot_val(forbidden) |= _PAGE_RW;
32432+#endif
32433
32434 #if defined(CONFIG_X86_64) && defined(CONFIG_DEBUG_RODATA)
32435 /*
32436@@ -317,6 +319,13 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
32437 }
32438 #endif
32439
32440+#ifdef CONFIG_PAX_KERNEXEC
32441+ if (within(pfn, __pa(ktla_ktva((unsigned long)&_text)), __pa((unsigned long)&_sdata))) {
32442+ pgprot_val(forbidden) |= _PAGE_RW;
32443+ pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
32444+ }
32445+#endif
32446+
32447 prot = __pgprot(pgprot_val(prot) & ~pgprot_val(forbidden));
32448
32449 return prot;
32450@@ -400,23 +409,37 @@ EXPORT_SYMBOL_GPL(slow_virt_to_phys);
32451 static void __set_pmd_pte(pte_t *kpte, unsigned long address, pte_t pte)
32452 {
32453 /* change init_mm */
32454+ pax_open_kernel();
32455 set_pte_atomic(kpte, pte);
32456+
32457 #ifdef CONFIG_X86_32
32458 if (!SHARED_KERNEL_PMD) {
32459+
32460+#ifdef CONFIG_PAX_PER_CPU_PGD
32461+ unsigned long cpu;
32462+#else
32463 struct page *page;
32464+#endif
32465
32466+#ifdef CONFIG_PAX_PER_CPU_PGD
32467+ for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
32468+ pgd_t *pgd = get_cpu_pgd(cpu, kernel);
32469+#else
32470 list_for_each_entry(page, &pgd_list, lru) {
32471- pgd_t *pgd;
32472+ pgd_t *pgd = (pgd_t *)page_address(page);
32473+#endif
32474+
32475 pud_t *pud;
32476 pmd_t *pmd;
32477
32478- pgd = (pgd_t *)page_address(page) + pgd_index(address);
32479+ pgd += pgd_index(address);
32480 pud = pud_offset(pgd, address);
32481 pmd = pmd_offset(pud, address);
32482 set_pte_atomic((pte_t *)pmd, pte);
32483 }
32484 }
32485 #endif
32486+ pax_close_kernel();
32487 }
32488
32489 static int
32490diff --git a/arch/x86/mm/pat.c b/arch/x86/mm/pat.c
32491index 6574388..87e9bef 100644
32492--- a/arch/x86/mm/pat.c
32493+++ b/arch/x86/mm/pat.c
32494@@ -376,7 +376,7 @@ int free_memtype(u64 start, u64 end)
32495
32496 if (!entry) {
32497 printk(KERN_INFO "%s:%d freeing invalid memtype [mem %#010Lx-%#010Lx]\n",
32498- current->comm, current->pid, start, end - 1);
32499+ current->comm, task_pid_nr(current), start, end - 1);
32500 return -EINVAL;
32501 }
32502
32503@@ -506,8 +506,8 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
32504
32505 while (cursor < to) {
32506 if (!devmem_is_allowed(pfn)) {
32507- printk(KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx]\n",
32508- current->comm, from, to - 1);
32509+ printk(KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx] (%#010Lx)\n",
32510+ current->comm, from, to - 1, cursor);
32511 return 0;
32512 }
32513 cursor += PAGE_SIZE;
32514@@ -577,7 +577,7 @@ int kernel_map_sync_memtype(u64 base, unsigned long size, unsigned long flags)
32515 if (ioremap_change_attr((unsigned long)__va(base), id_sz, flags) < 0) {
32516 printk(KERN_INFO "%s:%d ioremap_change_attr failed %s "
32517 "for [mem %#010Lx-%#010Lx]\n",
32518- current->comm, current->pid,
32519+ current->comm, task_pid_nr(current),
32520 cattr_name(flags),
32521 base, (unsigned long long)(base + size-1));
32522 return -EINVAL;
32523@@ -612,7 +612,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
32524 flags = lookup_memtype(paddr);
32525 if (want_flags != flags) {
32526 printk(KERN_WARNING "%s:%d map pfn RAM range req %s for [mem %#010Lx-%#010Lx], got %s\n",
32527- current->comm, current->pid,
32528+ current->comm, task_pid_nr(current),
32529 cattr_name(want_flags),
32530 (unsigned long long)paddr,
32531 (unsigned long long)(paddr + size - 1),
32532@@ -634,7 +634,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
32533 free_memtype(paddr, paddr + size);
32534 printk(KERN_ERR "%s:%d map pfn expected mapping type %s"
32535 " for [mem %#010Lx-%#010Lx], got %s\n",
32536- current->comm, current->pid,
32537+ current->comm, task_pid_nr(current),
32538 cattr_name(want_flags),
32539 (unsigned long long)paddr,
32540 (unsigned long long)(paddr + size - 1),
32541diff --git a/arch/x86/mm/pat_rbtree.c b/arch/x86/mm/pat_rbtree.c
32542index 415f6c4..d319983 100644
32543--- a/arch/x86/mm/pat_rbtree.c
32544+++ b/arch/x86/mm/pat_rbtree.c
32545@@ -160,7 +160,7 @@ success:
32546
32547 failure:
32548 printk(KERN_INFO "%s:%d conflicting memory types "
32549- "%Lx-%Lx %s<->%s\n", current->comm, current->pid, start,
32550+ "%Lx-%Lx %s<->%s\n", current->comm, task_pid_nr(current), start,
32551 end, cattr_name(found_type), cattr_name(match->type));
32552 return -EBUSY;
32553 }
32554diff --git a/arch/x86/mm/pf_in.c b/arch/x86/mm/pf_in.c
32555index 9f0614d..92ae64a 100644
32556--- a/arch/x86/mm/pf_in.c
32557+++ b/arch/x86/mm/pf_in.c
32558@@ -148,7 +148,7 @@ enum reason_type get_ins_type(unsigned long ins_addr)
32559 int i;
32560 enum reason_type rv = OTHERS;
32561
32562- p = (unsigned char *)ins_addr;
32563+ p = (unsigned char *)ktla_ktva(ins_addr);
32564 p += skip_prefix(p, &prf);
32565 p += get_opcode(p, &opcode);
32566
32567@@ -168,7 +168,7 @@ static unsigned int get_ins_reg_width(unsigned long ins_addr)
32568 struct prefix_bits prf;
32569 int i;
32570
32571- p = (unsigned char *)ins_addr;
32572+ p = (unsigned char *)ktla_ktva(ins_addr);
32573 p += skip_prefix(p, &prf);
32574 p += get_opcode(p, &opcode);
32575
32576@@ -191,7 +191,7 @@ unsigned int get_ins_mem_width(unsigned long ins_addr)
32577 struct prefix_bits prf;
32578 int i;
32579
32580- p = (unsigned char *)ins_addr;
32581+ p = (unsigned char *)ktla_ktva(ins_addr);
32582 p += skip_prefix(p, &prf);
32583 p += get_opcode(p, &opcode);
32584
32585@@ -415,7 +415,7 @@ unsigned long get_ins_reg_val(unsigned long ins_addr, struct pt_regs *regs)
32586 struct prefix_bits prf;
32587 int i;
32588
32589- p = (unsigned char *)ins_addr;
32590+ p = (unsigned char *)ktla_ktva(ins_addr);
32591 p += skip_prefix(p, &prf);
32592 p += get_opcode(p, &opcode);
32593 for (i = 0; i < ARRAY_SIZE(reg_rop); i++)
32594@@ -470,7 +470,7 @@ unsigned long get_ins_imm_val(unsigned long ins_addr)
32595 struct prefix_bits prf;
32596 int i;
32597
32598- p = (unsigned char *)ins_addr;
32599+ p = (unsigned char *)ktla_ktva(ins_addr);
32600 p += skip_prefix(p, &prf);
32601 p += get_opcode(p, &opcode);
32602 for (i = 0; i < ARRAY_SIZE(imm_wop); i++)
32603diff --git a/arch/x86/mm/pgtable.c b/arch/x86/mm/pgtable.c
32604index dfa537a..fd45c64 100644
32605--- a/arch/x86/mm/pgtable.c
32606+++ b/arch/x86/mm/pgtable.c
32607@@ -91,10 +91,67 @@ static inline void pgd_list_del(pgd_t *pgd)
32608 list_del(&page->lru);
32609 }
32610
32611-#define UNSHARED_PTRS_PER_PGD \
32612- (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
32613+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
32614+pgdval_t clone_pgd_mask __read_only = ~_PAGE_PRESENT;
32615
32616+void __shadow_user_pgds(pgd_t *dst, const pgd_t *src)
32617+{
32618+ unsigned int count = USER_PGD_PTRS;
32619
32620+ if (!pax_user_shadow_base)
32621+ return;
32622+
32623+ while (count--)
32624+ *dst++ = __pgd((pgd_val(*src++) | (_PAGE_NX & __supported_pte_mask)) & ~_PAGE_USER);
32625+}
32626+#endif
32627+
32628+#ifdef CONFIG_PAX_PER_CPU_PGD
32629+void __clone_user_pgds(pgd_t *dst, const pgd_t *src)
32630+{
32631+ unsigned int count = USER_PGD_PTRS;
32632+
32633+ while (count--) {
32634+ pgd_t pgd;
32635+
32636+#ifdef CONFIG_X86_64
32637+ pgd = __pgd(pgd_val(*src++) | _PAGE_USER);
32638+#else
32639+ pgd = *src++;
32640+#endif
32641+
32642+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
32643+ pgd = __pgd(pgd_val(pgd) & clone_pgd_mask);
32644+#endif
32645+
32646+ *dst++ = pgd;
32647+ }
32648+
32649+}
32650+#endif
32651+
32652+#ifdef CONFIG_X86_64
32653+#define pxd_t pud_t
32654+#define pyd_t pgd_t
32655+#define paravirt_release_pxd(pfn) paravirt_release_pud(pfn)
32656+#define pxd_free(mm, pud) pud_free((mm), (pud))
32657+#define pyd_populate(mm, pgd, pud) pgd_populate((mm), (pgd), (pud))
32658+#define pyd_offset(mm, address) pgd_offset((mm), (address))
32659+#define PYD_SIZE PGDIR_SIZE
32660+#else
32661+#define pxd_t pmd_t
32662+#define pyd_t pud_t
32663+#define paravirt_release_pxd(pfn) paravirt_release_pmd(pfn)
32664+#define pxd_free(mm, pud) pmd_free((mm), (pud))
32665+#define pyd_populate(mm, pgd, pud) pud_populate((mm), (pgd), (pud))
32666+#define pyd_offset(mm, address) pud_offset((mm), (address))
32667+#define PYD_SIZE PUD_SIZE
32668+#endif
32669+
32670+#ifdef CONFIG_PAX_PER_CPU_PGD
32671+static inline void pgd_ctor(struct mm_struct *mm, pgd_t *pgd) {}
32672+static inline void pgd_dtor(pgd_t *pgd) {}
32673+#else
32674 static void pgd_set_mm(pgd_t *pgd, struct mm_struct *mm)
32675 {
32676 BUILD_BUG_ON(sizeof(virt_to_page(pgd)->index) < sizeof(mm));
32677@@ -135,6 +192,7 @@ static void pgd_dtor(pgd_t *pgd)
32678 pgd_list_del(pgd);
32679 spin_unlock(&pgd_lock);
32680 }
32681+#endif
32682
32683 /*
32684 * List of all pgd's needed for non-PAE so it can invalidate entries
32685@@ -147,7 +205,7 @@ static void pgd_dtor(pgd_t *pgd)
32686 * -- nyc
32687 */
32688
32689-#ifdef CONFIG_X86_PAE
32690+#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
32691 /*
32692 * In PAE mode, we need to do a cr3 reload (=tlb flush) when
32693 * updating the top-level pagetable entries to guarantee the
32694@@ -159,7 +217,7 @@ static void pgd_dtor(pgd_t *pgd)
32695 * not shared between pagetables (!SHARED_KERNEL_PMDS), we allocate
32696 * and initialize the kernel pmds here.
32697 */
32698-#define PREALLOCATED_PMDS UNSHARED_PTRS_PER_PGD
32699+#define PREALLOCATED_PXDS (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
32700
32701 void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
32702 {
32703@@ -177,36 +235,38 @@ void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
32704 */
32705 flush_tlb_mm(mm);
32706 }
32707+#elif defined(CONFIG_X86_64) && defined(CONFIG_PAX_PER_CPU_PGD)
32708+#define PREALLOCATED_PXDS USER_PGD_PTRS
32709 #else /* !CONFIG_X86_PAE */
32710
32711 /* No need to prepopulate any pagetable entries in non-PAE modes. */
32712-#define PREALLOCATED_PMDS 0
32713+#define PREALLOCATED_PXDS 0
32714
32715 #endif /* CONFIG_X86_PAE */
32716
32717-static void free_pmds(pmd_t *pmds[])
32718+static void free_pxds(pxd_t *pxds[])
32719 {
32720 int i;
32721
32722- for(i = 0; i < PREALLOCATED_PMDS; i++)
32723- if (pmds[i])
32724- free_page((unsigned long)pmds[i]);
32725+ for(i = 0; i < PREALLOCATED_PXDS; i++)
32726+ if (pxds[i])
32727+ free_page((unsigned long)pxds[i]);
32728 }
32729
32730-static int preallocate_pmds(pmd_t *pmds[])
32731+static int preallocate_pxds(pxd_t *pxds[])
32732 {
32733 int i;
32734 bool failed = false;
32735
32736- for(i = 0; i < PREALLOCATED_PMDS; i++) {
32737- pmd_t *pmd = (pmd_t *)__get_free_page(PGALLOC_GFP);
32738- if (pmd == NULL)
32739+ for(i = 0; i < PREALLOCATED_PXDS; i++) {
32740+ pxd_t *pxd = (pxd_t *)__get_free_page(PGALLOC_GFP);
32741+ if (pxd == NULL)
32742 failed = true;
32743- pmds[i] = pmd;
32744+ pxds[i] = pxd;
32745 }
32746
32747 if (failed) {
32748- free_pmds(pmds);
32749+ free_pxds(pxds);
32750 return -ENOMEM;
32751 }
32752
32753@@ -219,49 +279,52 @@ static int preallocate_pmds(pmd_t *pmds[])
32754 * preallocate which never got a corresponding vma will need to be
32755 * freed manually.
32756 */
32757-static void pgd_mop_up_pmds(struct mm_struct *mm, pgd_t *pgdp)
32758+static void pgd_mop_up_pxds(struct mm_struct *mm, pgd_t *pgdp)
32759 {
32760 int i;
32761
32762- for(i = 0; i < PREALLOCATED_PMDS; i++) {
32763+ for(i = 0; i < PREALLOCATED_PXDS; i++) {
32764 pgd_t pgd = pgdp[i];
32765
32766 if (pgd_val(pgd) != 0) {
32767- pmd_t *pmd = (pmd_t *)pgd_page_vaddr(pgd);
32768+ pxd_t *pxd = (pxd_t *)pgd_page_vaddr(pgd);
32769
32770- pgdp[i] = native_make_pgd(0);
32771+ set_pgd(pgdp + i, native_make_pgd(0));
32772
32773- paravirt_release_pmd(pgd_val(pgd) >> PAGE_SHIFT);
32774- pmd_free(mm, pmd);
32775+ paravirt_release_pxd(pgd_val(pgd) >> PAGE_SHIFT);
32776+ pxd_free(mm, pxd);
32777 }
32778 }
32779 }
32780
32781-static void pgd_prepopulate_pmd(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmds[])
32782+static void pgd_prepopulate_pxd(struct mm_struct *mm, pgd_t *pgd, pxd_t *pxds[])
32783 {
32784- pud_t *pud;
32785+ pyd_t *pyd;
32786 int i;
32787
32788- if (PREALLOCATED_PMDS == 0) /* Work around gcc-3.4.x bug */
32789+ if (PREALLOCATED_PXDS == 0) /* Work around gcc-3.4.x bug */
32790 return;
32791
32792- pud = pud_offset(pgd, 0);
32793-
32794- for (i = 0; i < PREALLOCATED_PMDS; i++, pud++) {
32795- pmd_t *pmd = pmds[i];
32796+#ifdef CONFIG_X86_64
32797+ pyd = pyd_offset(mm, 0L);
32798+#else
32799+ pyd = pyd_offset(pgd, 0L);
32800+#endif
32801
32802+ for (i = 0; i < PREALLOCATED_PXDS; i++, pyd++) {
32803+ pxd_t *pxd = pxds[i];
32804 if (i >= KERNEL_PGD_BOUNDARY)
32805- memcpy(pmd, (pmd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
32806- sizeof(pmd_t) * PTRS_PER_PMD);
32807+ memcpy(pxd, (pxd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
32808+ sizeof(pxd_t) * PTRS_PER_PMD);
32809
32810- pud_populate(mm, pud, pmd);
32811+ pyd_populate(mm, pyd, pxd);
32812 }
32813 }
32814
32815 pgd_t *pgd_alloc(struct mm_struct *mm)
32816 {
32817 pgd_t *pgd;
32818- pmd_t *pmds[PREALLOCATED_PMDS];
32819+ pxd_t *pxds[PREALLOCATED_PXDS];
32820
32821 pgd = (pgd_t *)__get_free_page(PGALLOC_GFP);
32822
32823@@ -270,11 +333,11 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
32824
32825 mm->pgd = pgd;
32826
32827- if (preallocate_pmds(pmds) != 0)
32828+ if (preallocate_pxds(pxds) != 0)
32829 goto out_free_pgd;
32830
32831 if (paravirt_pgd_alloc(mm) != 0)
32832- goto out_free_pmds;
32833+ goto out_free_pxds;
32834
32835 /*
32836 * Make sure that pre-populating the pmds is atomic with
32837@@ -284,14 +347,14 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
32838 spin_lock(&pgd_lock);
32839
32840 pgd_ctor(mm, pgd);
32841- pgd_prepopulate_pmd(mm, pgd, pmds);
32842+ pgd_prepopulate_pxd(mm, pgd, pxds);
32843
32844 spin_unlock(&pgd_lock);
32845
32846 return pgd;
32847
32848-out_free_pmds:
32849- free_pmds(pmds);
32850+out_free_pxds:
32851+ free_pxds(pxds);
32852 out_free_pgd:
32853 free_page((unsigned long)pgd);
32854 out:
32855@@ -300,7 +363,7 @@ out:
32856
32857 void pgd_free(struct mm_struct *mm, pgd_t *pgd)
32858 {
32859- pgd_mop_up_pmds(mm, pgd);
32860+ pgd_mop_up_pxds(mm, pgd);
32861 pgd_dtor(pgd);
32862 paravirt_pgd_free(mm, pgd);
32863 free_page((unsigned long)pgd);
32864diff --git a/arch/x86/mm/pgtable_32.c b/arch/x86/mm/pgtable_32.c
32865index a69bcb8..19068ab 100644
32866--- a/arch/x86/mm/pgtable_32.c
32867+++ b/arch/x86/mm/pgtable_32.c
32868@@ -47,10 +47,13 @@ void set_pte_vaddr(unsigned long vaddr, pte_t pteval)
32869 return;
32870 }
32871 pte = pte_offset_kernel(pmd, vaddr);
32872+
32873+ pax_open_kernel();
32874 if (pte_val(pteval))
32875 set_pte_at(&init_mm, vaddr, pte, pteval);
32876 else
32877 pte_clear(&init_mm, vaddr, pte);
32878+ pax_close_kernel();
32879
32880 /*
32881 * It's enough to flush this one mapping.
32882diff --git a/arch/x86/mm/physaddr.c b/arch/x86/mm/physaddr.c
32883index e666cbb..61788c45 100644
32884--- a/arch/x86/mm/physaddr.c
32885+++ b/arch/x86/mm/physaddr.c
32886@@ -10,7 +10,7 @@
32887 #ifdef CONFIG_X86_64
32888
32889 #ifdef CONFIG_DEBUG_VIRTUAL
32890-unsigned long __phys_addr(unsigned long x)
32891+unsigned long __intentional_overflow(-1) __phys_addr(unsigned long x)
32892 {
32893 unsigned long y = x - __START_KERNEL_map;
32894
32895@@ -67,7 +67,7 @@ EXPORT_SYMBOL(__virt_addr_valid);
32896 #else
32897
32898 #ifdef CONFIG_DEBUG_VIRTUAL
32899-unsigned long __phys_addr(unsigned long x)
32900+unsigned long __intentional_overflow(-1) __phys_addr(unsigned long x)
32901 {
32902 unsigned long phys_addr = x - PAGE_OFFSET;
32903 /* VMALLOC_* aren't constants */
32904diff --git a/arch/x86/mm/setup_nx.c b/arch/x86/mm/setup_nx.c
32905index 90555bf..f5f1828 100644
32906--- a/arch/x86/mm/setup_nx.c
32907+++ b/arch/x86/mm/setup_nx.c
32908@@ -5,8 +5,10 @@
32909 #include <asm/pgtable.h>
32910 #include <asm/proto.h>
32911
32912+#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
32913 static int disable_nx;
32914
32915+#ifndef CONFIG_PAX_PAGEEXEC
32916 /*
32917 * noexec = on|off
32918 *
32919@@ -28,12 +30,17 @@ static int __init noexec_setup(char *str)
32920 return 0;
32921 }
32922 early_param("noexec", noexec_setup);
32923+#endif
32924+
32925+#endif
32926
32927 void x86_configure_nx(void)
32928 {
32929+#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
32930 if (cpu_has_nx && !disable_nx)
32931 __supported_pte_mask |= _PAGE_NX;
32932 else
32933+#endif
32934 __supported_pte_mask &= ~_PAGE_NX;
32935 }
32936
32937diff --git a/arch/x86/mm/tlb.c b/arch/x86/mm/tlb.c
32938index ae699b3..f1b2ad2 100644
32939--- a/arch/x86/mm/tlb.c
32940+++ b/arch/x86/mm/tlb.c
32941@@ -48,7 +48,11 @@ void leave_mm(int cpu)
32942 BUG();
32943 if (cpumask_test_cpu(cpu, mm_cpumask(active_mm))) {
32944 cpumask_clear_cpu(cpu, mm_cpumask(active_mm));
32945+
32946+#ifndef CONFIG_PAX_PER_CPU_PGD
32947 load_cr3(swapper_pg_dir);
32948+#endif
32949+
32950 }
32951 }
32952 EXPORT_SYMBOL_GPL(leave_mm);
32953diff --git a/arch/x86/mm/uderef_64.c b/arch/x86/mm/uderef_64.c
32954new file mode 100644
32955index 0000000..dace51c
32956--- /dev/null
32957+++ b/arch/x86/mm/uderef_64.c
32958@@ -0,0 +1,37 @@
32959+#include <linux/mm.h>
32960+#include <asm/pgtable.h>
32961+#include <asm/uaccess.h>
32962+
32963+#ifdef CONFIG_PAX_MEMORY_UDEREF
32964+/* PaX: due to the special call convention these functions must
32965+ * - remain leaf functions under all configurations,
32966+ * - never be called directly, only dereferenced from the wrappers.
32967+ */
32968+void __pax_open_userland(void)
32969+{
32970+ unsigned int cpu;
32971+
32972+ if (unlikely(!segment_eq(get_fs(), USER_DS)))
32973+ return;
32974+
32975+ cpu = raw_get_cpu();
32976+ BUG_ON((read_cr3() & ~PAGE_MASK) != PCID_KERNEL);
32977+ write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER | PCID_NOFLUSH);
32978+ raw_put_cpu_no_resched();
32979+}
32980+EXPORT_SYMBOL(__pax_open_userland);
32981+
32982+void __pax_close_userland(void)
32983+{
32984+ unsigned int cpu;
32985+
32986+ if (unlikely(!segment_eq(get_fs(), USER_DS)))
32987+ return;
32988+
32989+ cpu = raw_get_cpu();
32990+ BUG_ON((read_cr3() & ~PAGE_MASK) != PCID_USER);
32991+ write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL | PCID_NOFLUSH);
32992+ raw_put_cpu_no_resched();
32993+}
32994+EXPORT_SYMBOL(__pax_close_userland);
32995+#endif
32996diff --git a/arch/x86/net/bpf_jit.S b/arch/x86/net/bpf_jit.S
32997index 877b9a1..a8ecf42 100644
32998--- a/arch/x86/net/bpf_jit.S
32999+++ b/arch/x86/net/bpf_jit.S
33000@@ -9,6 +9,7 @@
33001 */
33002 #include <linux/linkage.h>
33003 #include <asm/dwarf2.h>
33004+#include <asm/alternative-asm.h>
33005
33006 /*
33007 * Calling convention :
33008@@ -35,6 +36,7 @@ sk_load_word_positive_offset:
33009 jle bpf_slow_path_word
33010 mov (SKBDATA,%rsi),%eax
33011 bswap %eax /* ntohl() */
33012+ pax_force_retaddr
33013 ret
33014
33015 sk_load_half:
33016@@ -52,6 +54,7 @@ sk_load_half_positive_offset:
33017 jle bpf_slow_path_half
33018 movzwl (SKBDATA,%rsi),%eax
33019 rol $8,%ax # ntohs()
33020+ pax_force_retaddr
33021 ret
33022
33023 sk_load_byte:
33024@@ -66,6 +69,7 @@ sk_load_byte_positive_offset:
33025 cmp %esi,%r9d /* if (offset >= hlen) goto bpf_slow_path_byte */
33026 jle bpf_slow_path_byte
33027 movzbl (SKBDATA,%rsi),%eax
33028+ pax_force_retaddr
33029 ret
33030
33031 /**
33032@@ -87,6 +91,7 @@ sk_load_byte_msh_positive_offset:
33033 movzbl (SKBDATA,%rsi),%ebx
33034 and $15,%bl
33035 shl $2,%bl
33036+ pax_force_retaddr
33037 ret
33038
33039 /* rsi contains offset and can be scratched */
33040@@ -109,6 +114,7 @@ bpf_slow_path_word:
33041 js bpf_error
33042 mov -12(%rbp),%eax
33043 bswap %eax
33044+ pax_force_retaddr
33045 ret
33046
33047 bpf_slow_path_half:
33048@@ -117,12 +123,14 @@ bpf_slow_path_half:
33049 mov -12(%rbp),%ax
33050 rol $8,%ax
33051 movzwl %ax,%eax
33052+ pax_force_retaddr
33053 ret
33054
33055 bpf_slow_path_byte:
33056 bpf_slow_path_common(1)
33057 js bpf_error
33058 movzbl -12(%rbp),%eax
33059+ pax_force_retaddr
33060 ret
33061
33062 bpf_slow_path_byte_msh:
33063@@ -133,6 +141,7 @@ bpf_slow_path_byte_msh:
33064 and $15,%al
33065 shl $2,%al
33066 xchg %eax,%ebx
33067+ pax_force_retaddr
33068 ret
33069
33070 #define sk_negative_common(SIZE) \
33071@@ -157,6 +166,7 @@ sk_load_word_negative_offset:
33072 sk_negative_common(4)
33073 mov (%rax), %eax
33074 bswap %eax
33075+ pax_force_retaddr
33076 ret
33077
33078 bpf_slow_path_half_neg:
33079@@ -168,6 +178,7 @@ sk_load_half_negative_offset:
33080 mov (%rax),%ax
33081 rol $8,%ax
33082 movzwl %ax,%eax
33083+ pax_force_retaddr
33084 ret
33085
33086 bpf_slow_path_byte_neg:
33087@@ -177,6 +188,7 @@ sk_load_byte_negative_offset:
33088 .globl sk_load_byte_negative_offset
33089 sk_negative_common(1)
33090 movzbl (%rax), %eax
33091+ pax_force_retaddr
33092 ret
33093
33094 bpf_slow_path_byte_msh_neg:
33095@@ -190,6 +202,7 @@ sk_load_byte_msh_negative_offset:
33096 and $15,%al
33097 shl $2,%al
33098 xchg %eax,%ebx
33099+ pax_force_retaddr
33100 ret
33101
33102 bpf_error:
33103@@ -197,4 +210,5 @@ bpf_error:
33104 xor %eax,%eax
33105 mov -8(%rbp),%rbx
33106 leaveq
33107+ pax_force_retaddr
33108 ret
33109diff --git a/arch/x86/net/bpf_jit_comp.c b/arch/x86/net/bpf_jit_comp.c
33110index 26328e8..8dfe0d5 100644
33111--- a/arch/x86/net/bpf_jit_comp.c
33112+++ b/arch/x86/net/bpf_jit_comp.c
33113@@ -50,13 +50,90 @@ static inline u8 *emit_code(u8 *ptr, u32 bytes, unsigned int len)
33114 return ptr + len;
33115 }
33116
33117+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
33118+#define MAX_INSTR_CODE_SIZE 96
33119+#else
33120+#define MAX_INSTR_CODE_SIZE 64
33121+#endif
33122+
33123 #define EMIT(bytes, len) do { prog = emit_code(prog, bytes, len); } while (0)
33124
33125 #define EMIT1(b1) EMIT(b1, 1)
33126 #define EMIT2(b1, b2) EMIT((b1) + ((b2) << 8), 2)
33127 #define EMIT3(b1, b2, b3) EMIT((b1) + ((b2) << 8) + ((b3) << 16), 3)
33128 #define EMIT4(b1, b2, b3, b4) EMIT((b1) + ((b2) << 8) + ((b3) << 16) + ((b4) << 24), 4)
33129+
33130+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
33131+/* original constant will appear in ecx */
33132+#define DILUTE_CONST_SEQUENCE(_off, _key) \
33133+do { \
33134+ /* mov ecx, randkey */ \
33135+ EMIT1(0xb9); \
33136+ EMIT(_key, 4); \
33137+ /* xor ecx, randkey ^ off */ \
33138+ EMIT2(0x81, 0xf1); \
33139+ EMIT((_key) ^ (_off), 4); \
33140+} while (0)
33141+
33142+#define EMIT1_off32(b1, _off) \
33143+do { \
33144+ switch (b1) { \
33145+ case 0x05: /* add eax, imm32 */ \
33146+ case 0x2d: /* sub eax, imm32 */ \
33147+ case 0x25: /* and eax, imm32 */ \
33148+ case 0x0d: /* or eax, imm32 */ \
33149+ case 0xb8: /* mov eax, imm32 */ \
33150+ case 0x35: /* xor eax, imm32 */ \
33151+ case 0x3d: /* cmp eax, imm32 */ \
33152+ case 0xa9: /* test eax, imm32 */ \
33153+ DILUTE_CONST_SEQUENCE(_off, randkey); \
33154+ EMIT2((b1) - 4, 0xc8); /* convert imm instruction to eax, ecx */\
33155+ break; \
33156+ case 0xbb: /* mov ebx, imm32 */ \
33157+ DILUTE_CONST_SEQUENCE(_off, randkey); \
33158+ /* mov ebx, ecx */ \
33159+ EMIT2(0x89, 0xcb); \
33160+ break; \
33161+ case 0xbe: /* mov esi, imm32 */ \
33162+ DILUTE_CONST_SEQUENCE(_off, randkey); \
33163+ /* mov esi, ecx */ \
33164+ EMIT2(0x89, 0xce); \
33165+ break; \
33166+ case 0xe8: /* call rel imm32, always to known funcs */ \
33167+ EMIT1(b1); \
33168+ EMIT(_off, 4); \
33169+ break; \
33170+ case 0xe9: /* jmp rel imm32 */ \
33171+ EMIT1(b1); \
33172+ EMIT(_off, 4); \
33173+ /* prevent fall-through, we're not called if off = 0 */ \
33174+ EMIT(0xcccccccc, 4); \
33175+ EMIT(0xcccccccc, 4); \
33176+ break; \
33177+ default: \
33178+ BUILD_BUG(); \
33179+ } \
33180+} while (0)
33181+
33182+#define EMIT2_off32(b1, b2, _off) \
33183+do { \
33184+ if ((b1) == 0x8d && (b2) == 0xb3) { /* lea esi, [rbx+imm32] */ \
33185+ EMIT2(0x8d, 0xb3); /* lea esi, [rbx+randkey] */ \
33186+ EMIT(randkey, 4); \
33187+ EMIT2(0x8d, 0xb6); /* lea esi, [esi+off-randkey] */ \
33188+ EMIT((_off) - randkey, 4); \
33189+ } else if ((b1) == 0x69 && (b2) == 0xc0) { /* imul eax, imm32 */\
33190+ DILUTE_CONST_SEQUENCE(_off, randkey); \
33191+ /* imul eax, ecx */ \
33192+ EMIT3(0x0f, 0xaf, 0xc1); \
33193+ } else { \
33194+ BUILD_BUG(); \
33195+ } \
33196+} while (0)
33197+#else
33198 #define EMIT1_off32(b1, off) do { EMIT1(b1); EMIT(off, 4);} while (0)
33199+#define EMIT2_off32(b1, b2, off) do { EMIT2(b1, b2); EMIT(off, 4);} while (0)
33200+#endif
33201
33202 #define CLEAR_A() EMIT2(0x31, 0xc0) /* xor %eax,%eax */
33203 #define CLEAR_X() EMIT2(0x31, 0xdb) /* xor %ebx,%ebx */
33204@@ -91,6 +168,24 @@ do { \
33205 #define X86_JBE 0x76
33206 #define X86_JA 0x77
33207
33208+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
33209+#define APPEND_FLOW_VERIFY() \
33210+do { \
33211+ /* mov ecx, randkey */ \
33212+ EMIT1(0xb9); \
33213+ EMIT(randkey, 4); \
33214+ /* cmp ecx, randkey */ \
33215+ EMIT2(0x81, 0xf9); \
33216+ EMIT(randkey, 4); \
33217+ /* jz after 8 int 3s */ \
33218+ EMIT2(0x74, 0x08); \
33219+ EMIT(0xcccccccc, 4); \
33220+ EMIT(0xcccccccc, 4); \
33221+} while (0)
33222+#else
33223+#define APPEND_FLOW_VERIFY() do { } while (0)
33224+#endif
33225+
33226 #define EMIT_COND_JMP(op, offset) \
33227 do { \
33228 if (is_near(offset)) \
33229@@ -98,6 +193,7 @@ do { \
33230 else { \
33231 EMIT2(0x0f, op + 0x10); \
33232 EMIT(offset, 4); /* jxx .+off32 */ \
33233+ APPEND_FLOW_VERIFY(); \
33234 } \
33235 } while (0)
33236
33237@@ -145,55 +241,54 @@ static int pkt_type_offset(void)
33238 return -1;
33239 }
33240
33241-struct bpf_binary_header {
33242- unsigned int pages;
33243- /* Note : for security reasons, bpf code will follow a randomly
33244- * sized amount of int3 instructions
33245- */
33246- u8 image[];
33247-};
33248-
33249-static struct bpf_binary_header *bpf_alloc_binary(unsigned int proglen,
33250+/* Note : for security reasons, bpf code will follow a randomly
33251+ * sized amount of int3 instructions
33252+ */
33253+static u8 *bpf_alloc_binary(unsigned int proglen,
33254 u8 **image_ptr)
33255 {
33256 unsigned int sz, hole;
33257- struct bpf_binary_header *header;
33258+ u8 *header;
33259
33260 /* Most of BPF filters are really small,
33261 * but if some of them fill a page, allow at least
33262 * 128 extra bytes to insert a random section of int3
33263 */
33264- sz = round_up(proglen + sizeof(*header) + 128, PAGE_SIZE);
33265- header = module_alloc(sz);
33266+ sz = round_up(proglen + 128, PAGE_SIZE);
33267+ header = module_alloc_exec(sz);
33268 if (!header)
33269 return NULL;
33270
33271+ pax_open_kernel();
33272 memset(header, 0xcc, sz); /* fill whole space with int3 instructions */
33273+ pax_close_kernel();
33274
33275- header->pages = sz / PAGE_SIZE;
33276- hole = sz - (proglen + sizeof(*header));
33277+ hole = PAGE_SIZE - (proglen & ~PAGE_MASK);
33278
33279 /* insert a random number of int3 instructions before BPF code */
33280- *image_ptr = &header->image[prandom_u32() % hole];
33281+ *image_ptr = &header[prandom_u32() % hole];
33282 return header;
33283 }
33284
33285 void bpf_jit_compile(struct sk_filter *fp)
33286 {
33287- u8 temp[64];
33288+ u8 temp[MAX_INSTR_CODE_SIZE];
33289 u8 *prog;
33290 unsigned int proglen, oldproglen = 0;
33291 int ilen, i;
33292 int t_offset, f_offset;
33293 u8 t_op, f_op, seen = 0, pass;
33294 u8 *image = NULL;
33295- struct bpf_binary_header *header = NULL;
33296+ u8 *header = NULL;
33297 u8 *func;
33298 int pc_ret0 = -1; /* bpf index of first RET #0 instruction (if any) */
33299 unsigned int cleanup_addr; /* epilogue code offset */
33300 unsigned int *addrs;
33301 const struct sock_filter *filter = fp->insns;
33302 int flen = fp->len;
33303+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
33304+ unsigned int randkey;
33305+#endif
33306
33307 if (!bpf_jit_enable)
33308 return;
33309@@ -202,11 +297,15 @@ void bpf_jit_compile(struct sk_filter *fp)
33310 if (addrs == NULL)
33311 return;
33312
33313+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
33314+ randkey = get_random_int();
33315+#endif
33316+
33317 /* Before first pass, make a rough estimation of addrs[]
33318- * each bpf instruction is translated to less than 64 bytes
33319+ * each bpf instruction is translated to less than MAX_INSTR_CODE_SIZE bytes
33320 */
33321 for (proglen = 0, i = 0; i < flen; i++) {
33322- proglen += 64;
33323+ proglen += MAX_INSTR_CODE_SIZE;
33324 addrs[i] = proglen;
33325 }
33326 cleanup_addr = proglen; /* epilogue address */
33327@@ -317,10 +416,8 @@ void bpf_jit_compile(struct sk_filter *fp)
33328 case BPF_S_ALU_MUL_K: /* A *= K */
33329 if (is_imm8(K))
33330 EMIT3(0x6b, 0xc0, K); /* imul imm8,%eax,%eax */
33331- else {
33332- EMIT2(0x69, 0xc0); /* imul imm32,%eax */
33333- EMIT(K, 4);
33334- }
33335+ else
33336+ EMIT2_off32(0x69, 0xc0, K); /* imul imm32,%eax */
33337 break;
33338 case BPF_S_ALU_DIV_X: /* A /= X; */
33339 seen |= SEEN_XREG;
33340@@ -359,15 +456,29 @@ void bpf_jit_compile(struct sk_filter *fp)
33341 EMIT2(0x89, 0xd0); /* mov %edx,%eax */
33342 break;
33343 case BPF_S_ALU_MOD_K: /* A %= K; */
33344+ if (K == 1) {
33345+ CLEAR_A();
33346+ break;
33347+ }
33348 EMIT2(0x31, 0xd2); /* xor %edx,%edx */
33349+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
33350+ DILUTE_CONST_SEQUENCE(K, randkey);
33351+#else
33352 EMIT1(0xb9);EMIT(K, 4); /* mov imm32,%ecx */
33353+#endif
33354 EMIT2(0xf7, 0xf1); /* div %ecx */
33355 EMIT2(0x89, 0xd0); /* mov %edx,%eax */
33356 break;
33357- case BPF_S_ALU_DIV_K: /* A = reciprocal_divide(A, K); */
33358- EMIT3(0x48, 0x69, 0xc0); /* imul imm32,%rax,%rax */
33359- EMIT(K, 4);
33360- EMIT4(0x48, 0xc1, 0xe8, 0x20); /* shr $0x20,%rax */
33361+ case BPF_S_ALU_DIV_K: /* A /= K */
33362+ if (K == 1)
33363+ break;
33364+ EMIT2(0x31, 0xd2); /* xor %edx,%edx */
33365+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
33366+ DILUTE_CONST_SEQUENCE(K, randkey);
33367+#else
33368+ EMIT1(0xb9);EMIT(K, 4); /* mov imm32,%ecx */
33369+#endif
33370+ EMIT2(0xf7, 0xf1); /* div %ecx */
33371 break;
33372 case BPF_S_ALU_AND_X:
33373 seen |= SEEN_XREG;
33374@@ -637,8 +748,7 @@ common_load_ind: seen |= SEEN_DATAREF | SEEN_XREG;
33375 if (is_imm8(K)) {
33376 EMIT3(0x8d, 0x73, K); /* lea imm8(%rbx), %esi */
33377 } else {
33378- EMIT2(0x8d, 0xb3); /* lea imm32(%rbx),%esi */
33379- EMIT(K, 4);
33380+ EMIT2_off32(0x8d, 0xb3, K); /* lea imm32(%rbx),%esi */
33381 }
33382 } else {
33383 EMIT2(0x89,0xde); /* mov %ebx,%esi */
33384@@ -728,10 +838,12 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
33385 if (unlikely(proglen + ilen > oldproglen)) {
33386 pr_err("bpb_jit_compile fatal error\n");
33387 kfree(addrs);
33388- module_free(NULL, header);
33389+ module_free_exec(NULL, image);
33390 return;
33391 }
33392+ pax_open_kernel();
33393 memcpy(image + proglen, temp, ilen);
33394+ pax_close_kernel();
33395 }
33396 proglen += ilen;
33397 addrs[i] = proglen;
33398@@ -764,7 +876,6 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
33399
33400 if (image) {
33401 bpf_flush_icache(header, image + proglen);
33402- set_memory_ro((unsigned long)header, header->pages);
33403 fp->bpf_func = (void *)image;
33404 }
33405 out:
33406@@ -776,10 +887,9 @@ static void bpf_jit_free_deferred(struct work_struct *work)
33407 {
33408 struct sk_filter *fp = container_of(work, struct sk_filter, work);
33409 unsigned long addr = (unsigned long)fp->bpf_func & PAGE_MASK;
33410- struct bpf_binary_header *header = (void *)addr;
33411
33412- set_memory_rw(addr, header->pages);
33413- module_free(NULL, header);
33414+ set_memory_rw(addr, 1);
33415+ module_free_exec(NULL, (void *)addr);
33416 kfree(fp);
33417 }
33418
33419diff --git a/arch/x86/oprofile/backtrace.c b/arch/x86/oprofile/backtrace.c
33420index d6aa6e8..266395a 100644
33421--- a/arch/x86/oprofile/backtrace.c
33422+++ b/arch/x86/oprofile/backtrace.c
33423@@ -46,11 +46,11 @@ dump_user_backtrace_32(struct stack_frame_ia32 *head)
33424 struct stack_frame_ia32 *fp;
33425 unsigned long bytes;
33426
33427- bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
33428+ bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
33429 if (bytes != sizeof(bufhead))
33430 return NULL;
33431
33432- fp = (struct stack_frame_ia32 *) compat_ptr(bufhead[0].next_frame);
33433+ fp = (struct stack_frame_ia32 __force_kernel *) compat_ptr(bufhead[0].next_frame);
33434
33435 oprofile_add_trace(bufhead[0].return_address);
33436
33437@@ -92,7 +92,7 @@ static struct stack_frame *dump_user_backtrace(struct stack_frame *head)
33438 struct stack_frame bufhead[2];
33439 unsigned long bytes;
33440
33441- bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
33442+ bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
33443 if (bytes != sizeof(bufhead))
33444 return NULL;
33445
33446@@ -111,7 +111,7 @@ x86_backtrace(struct pt_regs * const regs, unsigned int depth)
33447 {
33448 struct stack_frame *head = (struct stack_frame *)frame_pointer(regs);
33449
33450- if (!user_mode_vm(regs)) {
33451+ if (!user_mode(regs)) {
33452 unsigned long stack = kernel_stack_pointer(regs);
33453 if (depth)
33454 dump_trace(NULL, regs, (unsigned long *)stack, 0,
33455diff --git a/arch/x86/oprofile/nmi_int.c b/arch/x86/oprofile/nmi_int.c
33456index 6890d84..1dad1f1 100644
33457--- a/arch/x86/oprofile/nmi_int.c
33458+++ b/arch/x86/oprofile/nmi_int.c
33459@@ -23,6 +23,7 @@
33460 #include <asm/nmi.h>
33461 #include <asm/msr.h>
33462 #include <asm/apic.h>
33463+#include <asm/pgtable.h>
33464
33465 #include "op_counter.h"
33466 #include "op_x86_model.h"
33467@@ -774,8 +775,11 @@ int __init op_nmi_init(struct oprofile_operations *ops)
33468 if (ret)
33469 return ret;
33470
33471- if (!model->num_virt_counters)
33472- model->num_virt_counters = model->num_counters;
33473+ if (!model->num_virt_counters) {
33474+ pax_open_kernel();
33475+ *(unsigned int *)&model->num_virt_counters = model->num_counters;
33476+ pax_close_kernel();
33477+ }
33478
33479 mux_init(ops);
33480
33481diff --git a/arch/x86/oprofile/op_model_amd.c b/arch/x86/oprofile/op_model_amd.c
33482index 50d86c0..7985318 100644
33483--- a/arch/x86/oprofile/op_model_amd.c
33484+++ b/arch/x86/oprofile/op_model_amd.c
33485@@ -519,9 +519,11 @@ static int op_amd_init(struct oprofile_operations *ops)
33486 num_counters = AMD64_NUM_COUNTERS;
33487 }
33488
33489- op_amd_spec.num_counters = num_counters;
33490- op_amd_spec.num_controls = num_counters;
33491- op_amd_spec.num_virt_counters = max(num_counters, NUM_VIRT_COUNTERS);
33492+ pax_open_kernel();
33493+ *(unsigned int *)&op_amd_spec.num_counters = num_counters;
33494+ *(unsigned int *)&op_amd_spec.num_controls = num_counters;
33495+ *(unsigned int *)&op_amd_spec.num_virt_counters = max(num_counters, NUM_VIRT_COUNTERS);
33496+ pax_close_kernel();
33497
33498 return 0;
33499 }
33500diff --git a/arch/x86/oprofile/op_model_ppro.c b/arch/x86/oprofile/op_model_ppro.c
33501index d90528e..0127e2b 100644
33502--- a/arch/x86/oprofile/op_model_ppro.c
33503+++ b/arch/x86/oprofile/op_model_ppro.c
33504@@ -19,6 +19,7 @@
33505 #include <asm/msr.h>
33506 #include <asm/apic.h>
33507 #include <asm/nmi.h>
33508+#include <asm/pgtable.h>
33509
33510 #include "op_x86_model.h"
33511 #include "op_counter.h"
33512@@ -221,8 +222,10 @@ static void arch_perfmon_setup_counters(void)
33513
33514 num_counters = min((int)eax.split.num_counters, OP_MAX_COUNTER);
33515
33516- op_arch_perfmon_spec.num_counters = num_counters;
33517- op_arch_perfmon_spec.num_controls = num_counters;
33518+ pax_open_kernel();
33519+ *(unsigned int *)&op_arch_perfmon_spec.num_counters = num_counters;
33520+ *(unsigned int *)&op_arch_perfmon_spec.num_controls = num_counters;
33521+ pax_close_kernel();
33522 }
33523
33524 static int arch_perfmon_init(struct oprofile_operations *ignore)
33525diff --git a/arch/x86/oprofile/op_x86_model.h b/arch/x86/oprofile/op_x86_model.h
33526index 71e8a67..6a313bb 100644
33527--- a/arch/x86/oprofile/op_x86_model.h
33528+++ b/arch/x86/oprofile/op_x86_model.h
33529@@ -52,7 +52,7 @@ struct op_x86_model_spec {
33530 void (*switch_ctrl)(struct op_x86_model_spec const *model,
33531 struct op_msrs const * const msrs);
33532 #endif
33533-};
33534+} __do_const;
33535
33536 struct op_counter_config;
33537
33538diff --git a/arch/x86/pci/irq.c b/arch/x86/pci/irq.c
33539index 372e9b8..e775a6c 100644
33540--- a/arch/x86/pci/irq.c
33541+++ b/arch/x86/pci/irq.c
33542@@ -50,7 +50,7 @@ struct irq_router {
33543 struct irq_router_handler {
33544 u16 vendor;
33545 int (*probe)(struct irq_router *r, struct pci_dev *router, u16 device);
33546-};
33547+} __do_const;
33548
33549 int (*pcibios_enable_irq)(struct pci_dev *dev) = pirq_enable_irq;
33550 void (*pcibios_disable_irq)(struct pci_dev *dev) = NULL;
33551@@ -794,7 +794,7 @@ static __init int pico_router_probe(struct irq_router *r, struct pci_dev *router
33552 return 0;
33553 }
33554
33555-static __initdata struct irq_router_handler pirq_routers[] = {
33556+static __initconst const struct irq_router_handler pirq_routers[] = {
33557 { PCI_VENDOR_ID_INTEL, intel_router_probe },
33558 { PCI_VENDOR_ID_AL, ali_router_probe },
33559 { PCI_VENDOR_ID_ITE, ite_router_probe },
33560@@ -821,7 +821,7 @@ static struct pci_dev *pirq_router_dev;
33561 static void __init pirq_find_router(struct irq_router *r)
33562 {
33563 struct irq_routing_table *rt = pirq_table;
33564- struct irq_router_handler *h;
33565+ const struct irq_router_handler *h;
33566
33567 #ifdef CONFIG_PCI_BIOS
33568 if (!rt->signature) {
33569@@ -1094,7 +1094,7 @@ static int __init fix_acer_tm360_irqrouting(const struct dmi_system_id *d)
33570 return 0;
33571 }
33572
33573-static struct dmi_system_id __initdata pciirq_dmi_table[] = {
33574+static const struct dmi_system_id __initconst pciirq_dmi_table[] = {
33575 {
33576 .callback = fix_broken_hp_bios_irq9,
33577 .ident = "HP Pavilion N5400 Series Laptop",
33578diff --git a/arch/x86/pci/mrst.c b/arch/x86/pci/mrst.c
33579index 903fded..94b0d88 100644
33580--- a/arch/x86/pci/mrst.c
33581+++ b/arch/x86/pci/mrst.c
33582@@ -241,7 +241,9 @@ int __init pci_mrst_init(void)
33583 pr_info("Intel MID platform detected, using MID PCI ops\n");
33584 pci_mmcfg_late_init();
33585 pcibios_enable_irq = mrst_pci_irq_enable;
33586- pci_root_ops = pci_mrst_ops;
33587+ pax_open_kernel();
33588+ memcpy((void *)&pci_root_ops, &pci_mrst_ops, sizeof(pci_mrst_ops));
33589+ pax_close_kernel();
33590 pci_soc_mode = 1;
33591 /* Continue with standard init */
33592 return 1;
33593diff --git a/arch/x86/pci/pcbios.c b/arch/x86/pci/pcbios.c
33594index c77b24a..c979855 100644
33595--- a/arch/x86/pci/pcbios.c
33596+++ b/arch/x86/pci/pcbios.c
33597@@ -79,7 +79,7 @@ union bios32 {
33598 static struct {
33599 unsigned long address;
33600 unsigned short segment;
33601-} bios32_indirect = { 0, __KERNEL_CS };
33602+} bios32_indirect __read_only = { 0, __PCIBIOS_CS };
33603
33604 /*
33605 * Returns the entry point for the given service, NULL on error
33606@@ -92,37 +92,80 @@ static unsigned long bios32_service(unsigned long service)
33607 unsigned long length; /* %ecx */
33608 unsigned long entry; /* %edx */
33609 unsigned long flags;
33610+ struct desc_struct d, *gdt;
33611
33612 local_irq_save(flags);
33613- __asm__("lcall *(%%edi); cld"
33614+
33615+ gdt = get_cpu_gdt_table(smp_processor_id());
33616+
33617+ pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x9B, 0xC);
33618+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
33619+ pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x93, 0xC);
33620+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
33621+
33622+ __asm__("movw %w7, %%ds; lcall *(%%edi); push %%ss; pop %%ds; cld"
33623 : "=a" (return_code),
33624 "=b" (address),
33625 "=c" (length),
33626 "=d" (entry)
33627 : "0" (service),
33628 "1" (0),
33629- "D" (&bios32_indirect));
33630+ "D" (&bios32_indirect),
33631+ "r"(__PCIBIOS_DS)
33632+ : "memory");
33633+
33634+ pax_open_kernel();
33635+ gdt[GDT_ENTRY_PCIBIOS_CS].a = 0;
33636+ gdt[GDT_ENTRY_PCIBIOS_CS].b = 0;
33637+ gdt[GDT_ENTRY_PCIBIOS_DS].a = 0;
33638+ gdt[GDT_ENTRY_PCIBIOS_DS].b = 0;
33639+ pax_close_kernel();
33640+
33641 local_irq_restore(flags);
33642
33643 switch (return_code) {
33644- case 0:
33645- return address + entry;
33646- case 0x80: /* Not present */
33647- printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
33648- return 0;
33649- default: /* Shouldn't happen */
33650- printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
33651- service, return_code);
33652+ case 0: {
33653+ int cpu;
33654+ unsigned char flags;
33655+
33656+ printk(KERN_INFO "bios32_service: base:%08lx length:%08lx entry:%08lx\n", address, length, entry);
33657+ if (address >= 0xFFFF0 || length > 0x100000 - address || length <= entry) {
33658+ printk(KERN_WARNING "bios32_service: not valid\n");
33659 return 0;
33660+ }
33661+ address = address + PAGE_OFFSET;
33662+ length += 16UL; /* some BIOSs underreport this... */
33663+ flags = 4;
33664+ if (length >= 64*1024*1024) {
33665+ length >>= PAGE_SHIFT;
33666+ flags |= 8;
33667+ }
33668+
33669+ for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
33670+ gdt = get_cpu_gdt_table(cpu);
33671+ pack_descriptor(&d, address, length, 0x9b, flags);
33672+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
33673+ pack_descriptor(&d, address, length, 0x93, flags);
33674+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
33675+ }
33676+ return entry;
33677+ }
33678+ case 0x80: /* Not present */
33679+ printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
33680+ return 0;
33681+ default: /* Shouldn't happen */
33682+ printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
33683+ service, return_code);
33684+ return 0;
33685 }
33686 }
33687
33688 static struct {
33689 unsigned long address;
33690 unsigned short segment;
33691-} pci_indirect = { 0, __KERNEL_CS };
33692+} pci_indirect __read_only = { 0, __PCIBIOS_CS };
33693
33694-static int pci_bios_present;
33695+static int pci_bios_present __read_only;
33696
33697 static int check_pcibios(void)
33698 {
33699@@ -131,11 +174,13 @@ static int check_pcibios(void)
33700 unsigned long flags, pcibios_entry;
33701
33702 if ((pcibios_entry = bios32_service(PCI_SERVICE))) {
33703- pci_indirect.address = pcibios_entry + PAGE_OFFSET;
33704+ pci_indirect.address = pcibios_entry;
33705
33706 local_irq_save(flags);
33707- __asm__(
33708- "lcall *(%%edi); cld\n\t"
33709+ __asm__("movw %w6, %%ds\n\t"
33710+ "lcall *%%ss:(%%edi); cld\n\t"
33711+ "push %%ss\n\t"
33712+ "pop %%ds\n\t"
33713 "jc 1f\n\t"
33714 "xor %%ah, %%ah\n"
33715 "1:"
33716@@ -144,7 +189,8 @@ static int check_pcibios(void)
33717 "=b" (ebx),
33718 "=c" (ecx)
33719 : "1" (PCIBIOS_PCI_BIOS_PRESENT),
33720- "D" (&pci_indirect)
33721+ "D" (&pci_indirect),
33722+ "r" (__PCIBIOS_DS)
33723 : "memory");
33724 local_irq_restore(flags);
33725
33726@@ -189,7 +235,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
33727
33728 switch (len) {
33729 case 1:
33730- __asm__("lcall *(%%esi); cld\n\t"
33731+ __asm__("movw %w6, %%ds\n\t"
33732+ "lcall *%%ss:(%%esi); cld\n\t"
33733+ "push %%ss\n\t"
33734+ "pop %%ds\n\t"
33735 "jc 1f\n\t"
33736 "xor %%ah, %%ah\n"
33737 "1:"
33738@@ -198,7 +247,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
33739 : "1" (PCIBIOS_READ_CONFIG_BYTE),
33740 "b" (bx),
33741 "D" ((long)reg),
33742- "S" (&pci_indirect));
33743+ "S" (&pci_indirect),
33744+ "r" (__PCIBIOS_DS));
33745 /*
33746 * Zero-extend the result beyond 8 bits, do not trust the
33747 * BIOS having done it:
33748@@ -206,7 +256,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
33749 *value &= 0xff;
33750 break;
33751 case 2:
33752- __asm__("lcall *(%%esi); cld\n\t"
33753+ __asm__("movw %w6, %%ds\n\t"
33754+ "lcall *%%ss:(%%esi); cld\n\t"
33755+ "push %%ss\n\t"
33756+ "pop %%ds\n\t"
33757 "jc 1f\n\t"
33758 "xor %%ah, %%ah\n"
33759 "1:"
33760@@ -215,7 +268,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
33761 : "1" (PCIBIOS_READ_CONFIG_WORD),
33762 "b" (bx),
33763 "D" ((long)reg),
33764- "S" (&pci_indirect));
33765+ "S" (&pci_indirect),
33766+ "r" (__PCIBIOS_DS));
33767 /*
33768 * Zero-extend the result beyond 16 bits, do not trust the
33769 * BIOS having done it:
33770@@ -223,7 +277,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
33771 *value &= 0xffff;
33772 break;
33773 case 4:
33774- __asm__("lcall *(%%esi); cld\n\t"
33775+ __asm__("movw %w6, %%ds\n\t"
33776+ "lcall *%%ss:(%%esi); cld\n\t"
33777+ "push %%ss\n\t"
33778+ "pop %%ds\n\t"
33779 "jc 1f\n\t"
33780 "xor %%ah, %%ah\n"
33781 "1:"
33782@@ -232,7 +289,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
33783 : "1" (PCIBIOS_READ_CONFIG_DWORD),
33784 "b" (bx),
33785 "D" ((long)reg),
33786- "S" (&pci_indirect));
33787+ "S" (&pci_indirect),
33788+ "r" (__PCIBIOS_DS));
33789 break;
33790 }
33791
33792@@ -256,7 +314,10 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
33793
33794 switch (len) {
33795 case 1:
33796- __asm__("lcall *(%%esi); cld\n\t"
33797+ __asm__("movw %w6, %%ds\n\t"
33798+ "lcall *%%ss:(%%esi); cld\n\t"
33799+ "push %%ss\n\t"
33800+ "pop %%ds\n\t"
33801 "jc 1f\n\t"
33802 "xor %%ah, %%ah\n"
33803 "1:"
33804@@ -265,10 +326,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
33805 "c" (value),
33806 "b" (bx),
33807 "D" ((long)reg),
33808- "S" (&pci_indirect));
33809+ "S" (&pci_indirect),
33810+ "r" (__PCIBIOS_DS));
33811 break;
33812 case 2:
33813- __asm__("lcall *(%%esi); cld\n\t"
33814+ __asm__("movw %w6, %%ds\n\t"
33815+ "lcall *%%ss:(%%esi); cld\n\t"
33816+ "push %%ss\n\t"
33817+ "pop %%ds\n\t"
33818 "jc 1f\n\t"
33819 "xor %%ah, %%ah\n"
33820 "1:"
33821@@ -277,10 +342,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
33822 "c" (value),
33823 "b" (bx),
33824 "D" ((long)reg),
33825- "S" (&pci_indirect));
33826+ "S" (&pci_indirect),
33827+ "r" (__PCIBIOS_DS));
33828 break;
33829 case 4:
33830- __asm__("lcall *(%%esi); cld\n\t"
33831+ __asm__("movw %w6, %%ds\n\t"
33832+ "lcall *%%ss:(%%esi); cld\n\t"
33833+ "push %%ss\n\t"
33834+ "pop %%ds\n\t"
33835 "jc 1f\n\t"
33836 "xor %%ah, %%ah\n"
33837 "1:"
33838@@ -289,7 +358,8 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
33839 "c" (value),
33840 "b" (bx),
33841 "D" ((long)reg),
33842- "S" (&pci_indirect));
33843+ "S" (&pci_indirect),
33844+ "r" (__PCIBIOS_DS));
33845 break;
33846 }
33847
33848@@ -394,10 +464,13 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
33849
33850 DBG("PCI: Fetching IRQ routing table... ");
33851 __asm__("push %%es\n\t"
33852+ "movw %w8, %%ds\n\t"
33853 "push %%ds\n\t"
33854 "pop %%es\n\t"
33855- "lcall *(%%esi); cld\n\t"
33856+ "lcall *%%ss:(%%esi); cld\n\t"
33857 "pop %%es\n\t"
33858+ "push %%ss\n\t"
33859+ "pop %%ds\n"
33860 "jc 1f\n\t"
33861 "xor %%ah, %%ah\n"
33862 "1:"
33863@@ -408,7 +481,8 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
33864 "1" (0),
33865 "D" ((long) &opt),
33866 "S" (&pci_indirect),
33867- "m" (opt)
33868+ "m" (opt),
33869+ "r" (__PCIBIOS_DS)
33870 : "memory");
33871 DBG("OK ret=%d, size=%d, map=%x\n", ret, opt.size, map);
33872 if (ret & 0xff00)
33873@@ -432,7 +506,10 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
33874 {
33875 int ret;
33876
33877- __asm__("lcall *(%%esi); cld\n\t"
33878+ __asm__("movw %w5, %%ds\n\t"
33879+ "lcall *%%ss:(%%esi); cld\n\t"
33880+ "push %%ss\n\t"
33881+ "pop %%ds\n"
33882 "jc 1f\n\t"
33883 "xor %%ah, %%ah\n"
33884 "1:"
33885@@ -440,7 +517,8 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
33886 : "0" (PCIBIOS_SET_PCI_HW_INT),
33887 "b" ((dev->bus->number << 8) | dev->devfn),
33888 "c" ((irq << 8) | (pin + 10)),
33889- "S" (&pci_indirect));
33890+ "S" (&pci_indirect),
33891+ "r" (__PCIBIOS_DS));
33892 return !(ret & 0xff00);
33893 }
33894 EXPORT_SYMBOL(pcibios_set_irq_routing);
33895diff --git a/arch/x86/platform/efi/efi_32.c b/arch/x86/platform/efi/efi_32.c
33896index 40e4469..d915bf9 100644
33897--- a/arch/x86/platform/efi/efi_32.c
33898+++ b/arch/x86/platform/efi/efi_32.c
33899@@ -44,11 +44,22 @@ void efi_call_phys_prelog(void)
33900 {
33901 struct desc_ptr gdt_descr;
33902
33903+#ifdef CONFIG_PAX_KERNEXEC
33904+ struct desc_struct d;
33905+#endif
33906+
33907 local_irq_save(efi_rt_eflags);
33908
33909 load_cr3(initial_page_table);
33910 __flush_tlb_all();
33911
33912+#ifdef CONFIG_PAX_KERNEXEC
33913+ pack_descriptor(&d, 0, 0xFFFFF, 0x9B, 0xC);
33914+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
33915+ pack_descriptor(&d, 0, 0xFFFFF, 0x93, 0xC);
33916+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
33917+#endif
33918+
33919 gdt_descr.address = __pa(get_cpu_gdt_table(0));
33920 gdt_descr.size = GDT_SIZE - 1;
33921 load_gdt(&gdt_descr);
33922@@ -58,11 +69,24 @@ void efi_call_phys_epilog(void)
33923 {
33924 struct desc_ptr gdt_descr;
33925
33926+#ifdef CONFIG_PAX_KERNEXEC
33927+ struct desc_struct d;
33928+
33929+ memset(&d, 0, sizeof d);
33930+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
33931+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
33932+#endif
33933+
33934 gdt_descr.address = (unsigned long)get_cpu_gdt_table(0);
33935 gdt_descr.size = GDT_SIZE - 1;
33936 load_gdt(&gdt_descr);
33937
33938+#ifdef CONFIG_PAX_PER_CPU_PGD
33939+ load_cr3(get_cpu_pgd(smp_processor_id(), kernel));
33940+#else
33941 load_cr3(swapper_pg_dir);
33942+#endif
33943+
33944 __flush_tlb_all();
33945
33946 local_irq_restore(efi_rt_eflags);
33947diff --git a/arch/x86/platform/efi/efi_64.c b/arch/x86/platform/efi/efi_64.c
33948index 39a0e7f1..872396e 100644
33949--- a/arch/x86/platform/efi/efi_64.c
33950+++ b/arch/x86/platform/efi/efi_64.c
33951@@ -76,6 +76,11 @@ void __init efi_call_phys_prelog(void)
33952 vaddress = (unsigned long)__va(pgd * PGDIR_SIZE);
33953 set_pgd(pgd_offset_k(pgd * PGDIR_SIZE), *pgd_offset_k(vaddress));
33954 }
33955+
33956+#ifdef CONFIG_PAX_PER_CPU_PGD
33957+ load_cr3(swapper_pg_dir);
33958+#endif
33959+
33960 __flush_tlb_all();
33961 }
33962
33963@@ -89,6 +94,11 @@ void __init efi_call_phys_epilog(void)
33964 for (pgd = 0; pgd < n_pgds; pgd++)
33965 set_pgd(pgd_offset_k(pgd * PGDIR_SIZE), save_pgd[pgd]);
33966 kfree(save_pgd);
33967+
33968+#ifdef CONFIG_PAX_PER_CPU_PGD
33969+ load_cr3(get_cpu_pgd(smp_processor_id(), kernel));
33970+#endif
33971+
33972 __flush_tlb_all();
33973 local_irq_restore(efi_flags);
33974 early_code_mapping_set_exec(0);
33975diff --git a/arch/x86/platform/efi/efi_stub_32.S b/arch/x86/platform/efi/efi_stub_32.S
33976index fbe66e6..eae5e38 100644
33977--- a/arch/x86/platform/efi/efi_stub_32.S
33978+++ b/arch/x86/platform/efi/efi_stub_32.S
33979@@ -6,7 +6,9 @@
33980 */
33981
33982 #include <linux/linkage.h>
33983+#include <linux/init.h>
33984 #include <asm/page_types.h>
33985+#include <asm/segment.h>
33986
33987 /*
33988 * efi_call_phys(void *, ...) is a function with variable parameters.
33989@@ -20,7 +22,7 @@
33990 * service functions will comply with gcc calling convention, too.
33991 */
33992
33993-.text
33994+__INIT
33995 ENTRY(efi_call_phys)
33996 /*
33997 * 0. The function can only be called in Linux kernel. So CS has been
33998@@ -36,10 +38,24 @@ ENTRY(efi_call_phys)
33999 * The mapping of lower virtual memory has been created in prelog and
34000 * epilog.
34001 */
34002- movl $1f, %edx
34003- subl $__PAGE_OFFSET, %edx
34004- jmp *%edx
34005+#ifdef CONFIG_PAX_KERNEXEC
34006+ movl $(__KERNEXEC_EFI_DS), %edx
34007+ mov %edx, %ds
34008+ mov %edx, %es
34009+ mov %edx, %ss
34010+ addl $2f,(1f)
34011+ ljmp *(1f)
34012+
34013+__INITDATA
34014+1: .long __LOAD_PHYSICAL_ADDR, __KERNEXEC_EFI_CS
34015+.previous
34016+
34017+2:
34018+ subl $2b,(1b)
34019+#else
34020+ jmp 1f-__PAGE_OFFSET
34021 1:
34022+#endif
34023
34024 /*
34025 * 2. Now on the top of stack is the return
34026@@ -47,14 +63,8 @@ ENTRY(efi_call_phys)
34027 * parameter 2, ..., param n. To make things easy, we save the return
34028 * address of efi_call_phys in a global variable.
34029 */
34030- popl %edx
34031- movl %edx, saved_return_addr
34032- /* get the function pointer into ECX*/
34033- popl %ecx
34034- movl %ecx, efi_rt_function_ptr
34035- movl $2f, %edx
34036- subl $__PAGE_OFFSET, %edx
34037- pushl %edx
34038+ popl (saved_return_addr)
34039+ popl (efi_rt_function_ptr)
34040
34041 /*
34042 * 3. Clear PG bit in %CR0.
34043@@ -73,9 +83,8 @@ ENTRY(efi_call_phys)
34044 /*
34045 * 5. Call the physical function.
34046 */
34047- jmp *%ecx
34048+ call *(efi_rt_function_ptr-__PAGE_OFFSET)
34049
34050-2:
34051 /*
34052 * 6. After EFI runtime service returns, control will return to
34053 * following instruction. We'd better readjust stack pointer first.
34054@@ -88,35 +97,36 @@ ENTRY(efi_call_phys)
34055 movl %cr0, %edx
34056 orl $0x80000000, %edx
34057 movl %edx, %cr0
34058- jmp 1f
34059-1:
34060+
34061 /*
34062 * 8. Now restore the virtual mode from flat mode by
34063 * adding EIP with PAGE_OFFSET.
34064 */
34065- movl $1f, %edx
34066- jmp *%edx
34067+#ifdef CONFIG_PAX_KERNEXEC
34068+ movl $(__KERNEL_DS), %edx
34069+ mov %edx, %ds
34070+ mov %edx, %es
34071+ mov %edx, %ss
34072+ ljmp $(__KERNEL_CS),$1f
34073+#else
34074+ jmp 1f+__PAGE_OFFSET
34075+#endif
34076 1:
34077
34078 /*
34079 * 9. Balance the stack. And because EAX contain the return value,
34080 * we'd better not clobber it.
34081 */
34082- leal efi_rt_function_ptr, %edx
34083- movl (%edx), %ecx
34084- pushl %ecx
34085+ pushl (efi_rt_function_ptr)
34086
34087 /*
34088- * 10. Push the saved return address onto the stack and return.
34089+ * 10. Return to the saved return address.
34090 */
34091- leal saved_return_addr, %edx
34092- movl (%edx), %ecx
34093- pushl %ecx
34094- ret
34095+ jmpl *(saved_return_addr)
34096 ENDPROC(efi_call_phys)
34097 .previous
34098
34099-.data
34100+__INITDATA
34101 saved_return_addr:
34102 .long 0
34103 efi_rt_function_ptr:
34104diff --git a/arch/x86/platform/efi/efi_stub_64.S b/arch/x86/platform/efi/efi_stub_64.S
34105index 4c07cca..2c8427d 100644
34106--- a/arch/x86/platform/efi/efi_stub_64.S
34107+++ b/arch/x86/platform/efi/efi_stub_64.S
34108@@ -7,6 +7,7 @@
34109 */
34110
34111 #include <linux/linkage.h>
34112+#include <asm/alternative-asm.h>
34113
34114 #define SAVE_XMM \
34115 mov %rsp, %rax; \
34116@@ -40,6 +41,7 @@ ENTRY(efi_call0)
34117 call *%rdi
34118 addq $32, %rsp
34119 RESTORE_XMM
34120+ pax_force_retaddr 0, 1
34121 ret
34122 ENDPROC(efi_call0)
34123
34124@@ -50,6 +52,7 @@ ENTRY(efi_call1)
34125 call *%rdi
34126 addq $32, %rsp
34127 RESTORE_XMM
34128+ pax_force_retaddr 0, 1
34129 ret
34130 ENDPROC(efi_call1)
34131
34132@@ -60,6 +63,7 @@ ENTRY(efi_call2)
34133 call *%rdi
34134 addq $32, %rsp
34135 RESTORE_XMM
34136+ pax_force_retaddr 0, 1
34137 ret
34138 ENDPROC(efi_call2)
34139
34140@@ -71,6 +75,7 @@ ENTRY(efi_call3)
34141 call *%rdi
34142 addq $32, %rsp
34143 RESTORE_XMM
34144+ pax_force_retaddr 0, 1
34145 ret
34146 ENDPROC(efi_call3)
34147
34148@@ -83,6 +88,7 @@ ENTRY(efi_call4)
34149 call *%rdi
34150 addq $32, %rsp
34151 RESTORE_XMM
34152+ pax_force_retaddr 0, 1
34153 ret
34154 ENDPROC(efi_call4)
34155
34156@@ -96,6 +102,7 @@ ENTRY(efi_call5)
34157 call *%rdi
34158 addq $48, %rsp
34159 RESTORE_XMM
34160+ pax_force_retaddr 0, 1
34161 ret
34162 ENDPROC(efi_call5)
34163
34164@@ -112,5 +119,6 @@ ENTRY(efi_call6)
34165 call *%rdi
34166 addq $48, %rsp
34167 RESTORE_XMM
34168+ pax_force_retaddr 0, 1
34169 ret
34170 ENDPROC(efi_call6)
34171diff --git a/arch/x86/platform/mrst/mrst.c b/arch/x86/platform/mrst/mrst.c
34172index 3ca5957..7909c18 100644
34173--- a/arch/x86/platform/mrst/mrst.c
34174+++ b/arch/x86/platform/mrst/mrst.c
34175@@ -78,13 +78,15 @@ struct sfi_rtc_table_entry sfi_mrtc_array[SFI_MRTC_MAX];
34176 EXPORT_SYMBOL_GPL(sfi_mrtc_array);
34177 int sfi_mrtc_num;
34178
34179-static void mrst_power_off(void)
34180+static __noreturn void mrst_power_off(void)
34181 {
34182+ BUG();
34183 }
34184
34185-static void mrst_reboot(void)
34186+static __noreturn void mrst_reboot(void)
34187 {
34188 intel_scu_ipc_simple_command(IPCMSG_COLD_BOOT, 0);
34189+ BUG();
34190 }
34191
34192 /* parse all the mtimer info to a static mtimer array */
34193diff --git a/arch/x86/platform/olpc/olpc_dt.c b/arch/x86/platform/olpc/olpc_dt.c
34194index d6ee929..3637cb5 100644
34195--- a/arch/x86/platform/olpc/olpc_dt.c
34196+++ b/arch/x86/platform/olpc/olpc_dt.c
34197@@ -156,7 +156,7 @@ void * __init prom_early_alloc(unsigned long size)
34198 return res;
34199 }
34200
34201-static struct of_pdt_ops prom_olpc_ops __initdata = {
34202+static struct of_pdt_ops prom_olpc_ops __initconst = {
34203 .nextprop = olpc_dt_nextprop,
34204 .getproplen = olpc_dt_getproplen,
34205 .getproperty = olpc_dt_getproperty,
34206diff --git a/arch/x86/power/cpu.c b/arch/x86/power/cpu.c
34207index 424f4c9..f2a2988 100644
34208--- a/arch/x86/power/cpu.c
34209+++ b/arch/x86/power/cpu.c
34210@@ -137,11 +137,8 @@ static void do_fpu_end(void)
34211 static void fix_processor_context(void)
34212 {
34213 int cpu = smp_processor_id();
34214- struct tss_struct *t = &per_cpu(init_tss, cpu);
34215-#ifdef CONFIG_X86_64
34216- struct desc_struct *desc = get_cpu_gdt_table(cpu);
34217- tss_desc tss;
34218-#endif
34219+ struct tss_struct *t = init_tss + cpu;
34220+
34221 set_tss_desc(cpu, t); /*
34222 * This just modifies memory; should not be
34223 * necessary. But... This is necessary, because
34224@@ -150,10 +147,6 @@ static void fix_processor_context(void)
34225 */
34226
34227 #ifdef CONFIG_X86_64
34228- memcpy(&tss, &desc[GDT_ENTRY_TSS], sizeof(tss_desc));
34229- tss.type = 0x9; /* The available 64-bit TSS (see AMD vol 2, pg 91 */
34230- write_gdt_entry(desc, GDT_ENTRY_TSS, &tss, DESC_TSS);
34231-
34232 syscall_init(); /* This sets MSR_*STAR and related */
34233 #endif
34234 load_TR_desc(); /* This does ltr */
34235diff --git a/arch/x86/realmode/init.c b/arch/x86/realmode/init.c
34236index a44f457..9140171 100644
34237--- a/arch/x86/realmode/init.c
34238+++ b/arch/x86/realmode/init.c
34239@@ -70,7 +70,13 @@ void __init setup_real_mode(void)
34240 __va(real_mode_header->trampoline_header);
34241
34242 #ifdef CONFIG_X86_32
34243- trampoline_header->start = __pa_symbol(startup_32_smp);
34244+ trampoline_header->start = __pa_symbol(ktla_ktva(startup_32_smp));
34245+
34246+#ifdef CONFIG_PAX_KERNEXEC
34247+ trampoline_header->start -= LOAD_PHYSICAL_ADDR;
34248+#endif
34249+
34250+ trampoline_header->boot_cs = __BOOT_CS;
34251 trampoline_header->gdt_limit = __BOOT_DS + 7;
34252 trampoline_header->gdt_base = __pa_symbol(boot_gdt);
34253 #else
34254@@ -86,7 +92,7 @@ void __init setup_real_mode(void)
34255 *trampoline_cr4_features = read_cr4();
34256
34257 trampoline_pgd = (u64 *) __va(real_mode_header->trampoline_pgd);
34258- trampoline_pgd[0] = init_level4_pgt[pgd_index(__PAGE_OFFSET)].pgd;
34259+ trampoline_pgd[0] = init_level4_pgt[pgd_index(__PAGE_OFFSET)].pgd & ~_PAGE_NX;
34260 trampoline_pgd[511] = init_level4_pgt[511].pgd;
34261 #endif
34262 }
34263diff --git a/arch/x86/realmode/rm/Makefile b/arch/x86/realmode/rm/Makefile
34264index 9cac825..4890b25 100644
34265--- a/arch/x86/realmode/rm/Makefile
34266+++ b/arch/x86/realmode/rm/Makefile
34267@@ -79,5 +79,8 @@ KBUILD_CFLAGS := $(LINUXINCLUDE) -m32 -g -Os -D_SETUP -D__KERNEL__ -D_WAKEUP \
34268 $(call cc-option, -fno-unit-at-a-time)) \
34269 $(call cc-option, -fno-stack-protector) \
34270 $(call cc-option, -mpreferred-stack-boundary=2)
34271+ifdef CONSTIFY_PLUGIN
34272+KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
34273+endif
34274 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
34275 GCOV_PROFILE := n
34276diff --git a/arch/x86/realmode/rm/header.S b/arch/x86/realmode/rm/header.S
34277index a28221d..93c40f1 100644
34278--- a/arch/x86/realmode/rm/header.S
34279+++ b/arch/x86/realmode/rm/header.S
34280@@ -30,7 +30,9 @@ GLOBAL(real_mode_header)
34281 #endif
34282 /* APM/BIOS reboot */
34283 .long pa_machine_real_restart_asm
34284-#ifdef CONFIG_X86_64
34285+#ifdef CONFIG_X86_32
34286+ .long __KERNEL_CS
34287+#else
34288 .long __KERNEL32_CS
34289 #endif
34290 END(real_mode_header)
34291diff --git a/arch/x86/realmode/rm/trampoline_32.S b/arch/x86/realmode/rm/trampoline_32.S
34292index c1b2791..f9e31c7 100644
34293--- a/arch/x86/realmode/rm/trampoline_32.S
34294+++ b/arch/x86/realmode/rm/trampoline_32.S
34295@@ -25,6 +25,12 @@
34296 #include <asm/page_types.h>
34297 #include "realmode.h"
34298
34299+#ifdef CONFIG_PAX_KERNEXEC
34300+#define ta(X) (X)
34301+#else
34302+#define ta(X) (pa_ ## X)
34303+#endif
34304+
34305 .text
34306 .code16
34307
34308@@ -39,8 +45,6 @@ ENTRY(trampoline_start)
34309
34310 cli # We should be safe anyway
34311
34312- movl tr_start, %eax # where we need to go
34313-
34314 movl $0xA5A5A5A5, trampoline_status
34315 # write marker for master knows we're running
34316
34317@@ -56,7 +60,7 @@ ENTRY(trampoline_start)
34318 movw $1, %dx # protected mode (PE) bit
34319 lmsw %dx # into protected mode
34320
34321- ljmpl $__BOOT_CS, $pa_startup_32
34322+ ljmpl *(trampoline_header)
34323
34324 .section ".text32","ax"
34325 .code32
34326@@ -67,7 +71,7 @@ ENTRY(startup_32) # note: also used from wakeup_asm.S
34327 .balign 8
34328 GLOBAL(trampoline_header)
34329 tr_start: .space 4
34330- tr_gdt_pad: .space 2
34331+ tr_boot_cs: .space 2
34332 tr_gdt: .space 6
34333 END(trampoline_header)
34334
34335diff --git a/arch/x86/realmode/rm/trampoline_64.S b/arch/x86/realmode/rm/trampoline_64.S
34336index bb360dc..d0fd8f8 100644
34337--- a/arch/x86/realmode/rm/trampoline_64.S
34338+++ b/arch/x86/realmode/rm/trampoline_64.S
34339@@ -94,6 +94,7 @@ ENTRY(startup_32)
34340 movl %edx, %gs
34341
34342 movl pa_tr_cr4, %eax
34343+ andl $~X86_CR4_PCIDE, %eax
34344 movl %eax, %cr4 # Enable PAE mode
34345
34346 # Setup trampoline 4 level pagetables
34347@@ -107,7 +108,7 @@ ENTRY(startup_32)
34348 wrmsr
34349
34350 # Enable paging and in turn activate Long Mode
34351- movl $(X86_CR0_PG | X86_CR0_WP | X86_CR0_PE), %eax
34352+ movl $(X86_CR0_PG | X86_CR0_PE), %eax
34353 movl %eax, %cr0
34354
34355 /*
34356diff --git a/arch/x86/tools/Makefile b/arch/x86/tools/Makefile
34357index e812034..c747134 100644
34358--- a/arch/x86/tools/Makefile
34359+++ b/arch/x86/tools/Makefile
34360@@ -37,7 +37,7 @@ $(obj)/test_get_len.o: $(srctree)/arch/x86/lib/insn.c $(srctree)/arch/x86/lib/in
34361
34362 $(obj)/insn_sanity.o: $(srctree)/arch/x86/lib/insn.c $(srctree)/arch/x86/lib/inat.c $(srctree)/arch/x86/include/asm/inat_types.h $(srctree)/arch/x86/include/asm/inat.h $(srctree)/arch/x86/include/asm/insn.h $(objtree)/arch/x86/lib/inat-tables.c
34363
34364-HOST_EXTRACFLAGS += -I$(srctree)/tools/include
34365+HOST_EXTRACFLAGS += -I$(srctree)/tools/include -ggdb
34366 hostprogs-y += relocs
34367 relocs-objs := relocs_32.o relocs_64.o relocs_common.o
34368 relocs: $(obj)/relocs
34369diff --git a/arch/x86/tools/relocs.c b/arch/x86/tools/relocs.c
34370index f7bab68..b6d9886 100644
34371--- a/arch/x86/tools/relocs.c
34372+++ b/arch/x86/tools/relocs.c
34373@@ -1,5 +1,7 @@
34374 /* This is included from relocs_32/64.c */
34375
34376+#include "../../../include/generated/autoconf.h"
34377+
34378 #define ElfW(type) _ElfW(ELF_BITS, type)
34379 #define _ElfW(bits, type) __ElfW(bits, type)
34380 #define __ElfW(bits, type) Elf##bits##_##type
34381@@ -11,6 +13,7 @@
34382 #define Elf_Sym ElfW(Sym)
34383
34384 static Elf_Ehdr ehdr;
34385+static Elf_Phdr *phdr;
34386
34387 struct relocs {
34388 uint32_t *offset;
34389@@ -383,9 +386,39 @@ static void read_ehdr(FILE *fp)
34390 }
34391 }
34392
34393+static void read_phdrs(FILE *fp)
34394+{
34395+ unsigned int i;
34396+
34397+ phdr = calloc(ehdr.e_phnum, sizeof(Elf_Phdr));
34398+ if (!phdr) {
34399+ die("Unable to allocate %d program headers\n",
34400+ ehdr.e_phnum);
34401+ }
34402+ if (fseek(fp, ehdr.e_phoff, SEEK_SET) < 0) {
34403+ die("Seek to %d failed: %s\n",
34404+ ehdr.e_phoff, strerror(errno));
34405+ }
34406+ if (fread(phdr, sizeof(*phdr), ehdr.e_phnum, fp) != ehdr.e_phnum) {
34407+ die("Cannot read ELF program headers: %s\n",
34408+ strerror(errno));
34409+ }
34410+ for(i = 0; i < ehdr.e_phnum; i++) {
34411+ phdr[i].p_type = elf_word_to_cpu(phdr[i].p_type);
34412+ phdr[i].p_offset = elf_off_to_cpu(phdr[i].p_offset);
34413+ phdr[i].p_vaddr = elf_addr_to_cpu(phdr[i].p_vaddr);
34414+ phdr[i].p_paddr = elf_addr_to_cpu(phdr[i].p_paddr);
34415+ phdr[i].p_filesz = elf_word_to_cpu(phdr[i].p_filesz);
34416+ phdr[i].p_memsz = elf_word_to_cpu(phdr[i].p_memsz);
34417+ phdr[i].p_flags = elf_word_to_cpu(phdr[i].p_flags);
34418+ phdr[i].p_align = elf_word_to_cpu(phdr[i].p_align);
34419+ }
34420+
34421+}
34422+
34423 static void read_shdrs(FILE *fp)
34424 {
34425- int i;
34426+ unsigned int i;
34427 Elf_Shdr shdr;
34428
34429 secs = calloc(ehdr.e_shnum, sizeof(struct section));
34430@@ -420,7 +453,7 @@ static void read_shdrs(FILE *fp)
34431
34432 static void read_strtabs(FILE *fp)
34433 {
34434- int i;
34435+ unsigned int i;
34436 for (i = 0; i < ehdr.e_shnum; i++) {
34437 struct section *sec = &secs[i];
34438 if (sec->shdr.sh_type != SHT_STRTAB) {
34439@@ -445,7 +478,7 @@ static void read_strtabs(FILE *fp)
34440
34441 static void read_symtabs(FILE *fp)
34442 {
34443- int i,j;
34444+ unsigned int i,j;
34445 for (i = 0; i < ehdr.e_shnum; i++) {
34446 struct section *sec = &secs[i];
34447 if (sec->shdr.sh_type != SHT_SYMTAB) {
34448@@ -476,9 +509,11 @@ static void read_symtabs(FILE *fp)
34449 }
34450
34451
34452-static void read_relocs(FILE *fp)
34453+static void read_relocs(FILE *fp, int use_real_mode)
34454 {
34455- int i,j;
34456+ unsigned int i,j;
34457+ uint32_t base;
34458+
34459 for (i = 0; i < ehdr.e_shnum; i++) {
34460 struct section *sec = &secs[i];
34461 if (sec->shdr.sh_type != SHT_REL_TYPE) {
34462@@ -498,9 +533,22 @@ static void read_relocs(FILE *fp)
34463 die("Cannot read symbol table: %s\n",
34464 strerror(errno));
34465 }
34466+ base = 0;
34467+
34468+#ifdef CONFIG_X86_32
34469+ for (j = 0; !use_real_mode && j < ehdr.e_phnum; j++) {
34470+ if (phdr[j].p_type != PT_LOAD )
34471+ continue;
34472+ 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)
34473+ continue;
34474+ base = CONFIG_PAGE_OFFSET + phdr[j].p_paddr - phdr[j].p_vaddr;
34475+ break;
34476+ }
34477+#endif
34478+
34479 for (j = 0; j < sec->shdr.sh_size/sizeof(Elf_Rel); j++) {
34480 Elf_Rel *rel = &sec->reltab[j];
34481- rel->r_offset = elf_addr_to_cpu(rel->r_offset);
34482+ rel->r_offset = elf_addr_to_cpu(rel->r_offset) + base;
34483 rel->r_info = elf_xword_to_cpu(rel->r_info);
34484 #if (SHT_REL_TYPE == SHT_RELA)
34485 rel->r_addend = elf_xword_to_cpu(rel->r_addend);
34486@@ -512,7 +560,7 @@ static void read_relocs(FILE *fp)
34487
34488 static void print_absolute_symbols(void)
34489 {
34490- int i;
34491+ unsigned int i;
34492 const char *format;
34493
34494 if (ELF_BITS == 64)
34495@@ -525,7 +573,7 @@ static void print_absolute_symbols(void)
34496 for (i = 0; i < ehdr.e_shnum; i++) {
34497 struct section *sec = &secs[i];
34498 char *sym_strtab;
34499- int j;
34500+ unsigned int j;
34501
34502 if (sec->shdr.sh_type != SHT_SYMTAB) {
34503 continue;
34504@@ -552,7 +600,7 @@ static void print_absolute_symbols(void)
34505
34506 static void print_absolute_relocs(void)
34507 {
34508- int i, printed = 0;
34509+ unsigned int i, printed = 0;
34510 const char *format;
34511
34512 if (ELF_BITS == 64)
34513@@ -565,7 +613,7 @@ static void print_absolute_relocs(void)
34514 struct section *sec_applies, *sec_symtab;
34515 char *sym_strtab;
34516 Elf_Sym *sh_symtab;
34517- int j;
34518+ unsigned int j;
34519 if (sec->shdr.sh_type != SHT_REL_TYPE) {
34520 continue;
34521 }
34522@@ -642,13 +690,13 @@ static void add_reloc(struct relocs *r, uint32_t offset)
34523 static void walk_relocs(int (*process)(struct section *sec, Elf_Rel *rel,
34524 Elf_Sym *sym, const char *symname))
34525 {
34526- int i;
34527+ unsigned int i;
34528 /* Walk through the relocations */
34529 for (i = 0; i < ehdr.e_shnum; i++) {
34530 char *sym_strtab;
34531 Elf_Sym *sh_symtab;
34532 struct section *sec_applies, *sec_symtab;
34533- int j;
34534+ unsigned int j;
34535 struct section *sec = &secs[i];
34536
34537 if (sec->shdr.sh_type != SHT_REL_TYPE) {
34538@@ -812,6 +860,23 @@ static int do_reloc32(struct section *sec, Elf_Rel *rel, Elf_Sym *sym,
34539 {
34540 unsigned r_type = ELF32_R_TYPE(rel->r_info);
34541 int shn_abs = (sym->st_shndx == SHN_ABS) && !is_reloc(S_REL, symname);
34542+ char *sym_strtab = sec->link->link->strtab;
34543+
34544+ /* Don't relocate actual per-cpu variables, they are absolute indices, not addresses */
34545+ if (!strcmp(sec_name(sym->st_shndx), ".data..percpu") && strcmp(sym_name(sym_strtab, sym), "__per_cpu_load"))
34546+ return 0;
34547+
34548+#ifdef CONFIG_PAX_KERNEXEC
34549+ /* Don't relocate actual code, they are relocated implicitly by the base address of KERNEL_CS */
34550+ if (!strcmp(sec_name(sym->st_shndx), ".text.end") && !strcmp(sym_name(sym_strtab, sym), "_etext"))
34551+ return 0;
34552+ if (!strcmp(sec_name(sym->st_shndx), ".init.text"))
34553+ return 0;
34554+ if (!strcmp(sec_name(sym->st_shndx), ".exit.text"))
34555+ return 0;
34556+ if (!strcmp(sec_name(sym->st_shndx), ".text") && strcmp(sym_name(sym_strtab, sym), "__LOAD_PHYSICAL_ADDR"))
34557+ return 0;
34558+#endif
34559
34560 switch (r_type) {
34561 case R_386_NONE:
34562@@ -950,7 +1015,7 @@ static int write32_as_text(uint32_t v, FILE *f)
34563
34564 static void emit_relocs(int as_text, int use_real_mode)
34565 {
34566- int i;
34567+ unsigned int i;
34568 int (*write_reloc)(uint32_t, FILE *) = write32;
34569 int (*do_reloc)(struct section *sec, Elf_Rel *rel, Elf_Sym *sym,
34570 const char *symname);
34571@@ -1026,10 +1091,11 @@ void process(FILE *fp, int use_real_mode, int as_text,
34572 {
34573 regex_init(use_real_mode);
34574 read_ehdr(fp);
34575+ read_phdrs(fp);
34576 read_shdrs(fp);
34577 read_strtabs(fp);
34578 read_symtabs(fp);
34579- read_relocs(fp);
34580+ read_relocs(fp, use_real_mode);
34581 if (ELF_BITS == 64)
34582 percpu_init();
34583 if (show_absolute_syms) {
34584diff --git a/arch/x86/um/tls_32.c b/arch/x86/um/tls_32.c
34585index 80ffa5b..a33bd15 100644
34586--- a/arch/x86/um/tls_32.c
34587+++ b/arch/x86/um/tls_32.c
34588@@ -260,7 +260,7 @@ out:
34589 if (unlikely(task == current &&
34590 !t->arch.tls_array[idx - GDT_ENTRY_TLS_MIN].flushed)) {
34591 printk(KERN_ERR "get_tls_entry: task with pid %d got here "
34592- "without flushed TLS.", current->pid);
34593+ "without flushed TLS.", task_pid_nr(current));
34594 }
34595
34596 return 0;
34597diff --git a/arch/x86/vdso/Makefile b/arch/x86/vdso/Makefile
34598index fd14be1..e3c79c0 100644
34599--- a/arch/x86/vdso/Makefile
34600+++ b/arch/x86/vdso/Makefile
34601@@ -181,7 +181,7 @@ quiet_cmd_vdso = VDSO $@
34602 -Wl,-T,$(filter %.lds,$^) $(filter %.o,$^) && \
34603 sh $(srctree)/$(src)/checkundef.sh '$(NM)' '$@'
34604
34605-VDSO_LDFLAGS = -fPIC -shared $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
34606+VDSO_LDFLAGS = -fPIC -shared -Wl,--no-undefined $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
34607 GCOV_PROFILE := n
34608
34609 #
34610diff --git a/arch/x86/vdso/vdso32-setup.c b/arch/x86/vdso/vdso32-setup.c
34611index d6bfb87..876ee18 100644
34612--- a/arch/x86/vdso/vdso32-setup.c
34613+++ b/arch/x86/vdso/vdso32-setup.c
34614@@ -25,6 +25,7 @@
34615 #include <asm/tlbflush.h>
34616 #include <asm/vdso.h>
34617 #include <asm/proto.h>
34618+#include <asm/mman.h>
34619
34620 enum {
34621 VDSO_DISABLED = 0,
34622@@ -226,7 +227,7 @@ static inline void map_compat_vdso(int map)
34623 void enable_sep_cpu(void)
34624 {
34625 int cpu = get_cpu();
34626- struct tss_struct *tss = &per_cpu(init_tss, cpu);
34627+ struct tss_struct *tss = init_tss + cpu;
34628
34629 if (!boot_cpu_has(X86_FEATURE_SEP)) {
34630 put_cpu();
34631@@ -249,7 +250,7 @@ static int __init gate_vma_init(void)
34632 gate_vma.vm_start = FIXADDR_USER_START;
34633 gate_vma.vm_end = FIXADDR_USER_END;
34634 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
34635- gate_vma.vm_page_prot = __P101;
34636+ gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
34637
34638 return 0;
34639 }
34640@@ -330,14 +331,14 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
34641 if (compat)
34642 addr = VDSO_HIGH_BASE;
34643 else {
34644- addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, 0);
34645+ addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, MAP_EXECUTABLE);
34646 if (IS_ERR_VALUE(addr)) {
34647 ret = addr;
34648 goto up_fail;
34649 }
34650 }
34651
34652- current->mm->context.vdso = (void *)addr;
34653+ current->mm->context.vdso = addr;
34654
34655 if (compat_uses_vma || !compat) {
34656 /*
34657@@ -353,11 +354,11 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
34658 }
34659
34660 current_thread_info()->sysenter_return =
34661- VDSO32_SYMBOL(addr, SYSENTER_RETURN);
34662+ (__force void __user *)VDSO32_SYMBOL(addr, SYSENTER_RETURN);
34663
34664 up_fail:
34665 if (ret)
34666- current->mm->context.vdso = NULL;
34667+ current->mm->context.vdso = 0;
34668
34669 up_write(&mm->mmap_sem);
34670
34671@@ -404,8 +405,14 @@ __initcall(ia32_binfmt_init);
34672
34673 const char *arch_vma_name(struct vm_area_struct *vma)
34674 {
34675- if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
34676+ if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
34677 return "[vdso]";
34678+
34679+#ifdef CONFIG_PAX_SEGMEXEC
34680+ if (vma->vm_mm && vma->vm_mirror && vma->vm_mirror->vm_start == vma->vm_mm->context.vdso)
34681+ return "[vdso]";
34682+#endif
34683+
34684 return NULL;
34685 }
34686
34687@@ -415,7 +422,7 @@ struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
34688 * Check to see if the corresponding task was created in compat vdso
34689 * mode.
34690 */
34691- if (mm && mm->context.vdso == (void *)VDSO_HIGH_BASE)
34692+ if (mm && mm->context.vdso == VDSO_HIGH_BASE)
34693 return &gate_vma;
34694 return NULL;
34695 }
34696diff --git a/arch/x86/vdso/vma.c b/arch/x86/vdso/vma.c
34697index 431e875..cbb23f3 100644
34698--- a/arch/x86/vdso/vma.c
34699+++ b/arch/x86/vdso/vma.c
34700@@ -16,8 +16,6 @@
34701 #include <asm/vdso.h>
34702 #include <asm/page.h>
34703
34704-unsigned int __read_mostly vdso_enabled = 1;
34705-
34706 extern char vdso_start[], vdso_end[];
34707 extern unsigned short vdso_sync_cpuid;
34708
34709@@ -141,7 +139,6 @@ static unsigned long vdso_addr(unsigned long start, unsigned len)
34710 * unaligned here as a result of stack start randomization.
34711 */
34712 addr = PAGE_ALIGN(addr);
34713- addr = align_vdso_addr(addr);
34714
34715 return addr;
34716 }
34717@@ -154,30 +151,31 @@ static int setup_additional_pages(struct linux_binprm *bprm,
34718 unsigned size)
34719 {
34720 struct mm_struct *mm = current->mm;
34721- unsigned long addr;
34722+ unsigned long addr = 0;
34723 int ret;
34724
34725- if (!vdso_enabled)
34726- return 0;
34727-
34728 down_write(&mm->mmap_sem);
34729+
34730+#ifdef CONFIG_PAX_RANDMMAP
34731+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
34732+#endif
34733+
34734 addr = vdso_addr(mm->start_stack, size);
34735+ addr = align_vdso_addr(addr);
34736 addr = get_unmapped_area(NULL, addr, size, 0, 0);
34737 if (IS_ERR_VALUE(addr)) {
34738 ret = addr;
34739 goto up_fail;
34740 }
34741
34742- current->mm->context.vdso = (void *)addr;
34743+ mm->context.vdso = addr;
34744
34745 ret = install_special_mapping(mm, addr, size,
34746 VM_READ|VM_EXEC|
34747 VM_MAYREAD|VM_MAYWRITE|VM_MAYEXEC,
34748 pages);
34749- if (ret) {
34750- current->mm->context.vdso = NULL;
34751- goto up_fail;
34752- }
34753+ if (ret)
34754+ mm->context.vdso = 0;
34755
34756 up_fail:
34757 up_write(&mm->mmap_sem);
34758@@ -197,10 +195,3 @@ int x32_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
34759 vdsox32_size);
34760 }
34761 #endif
34762-
34763-static __init int vdso_setup(char *s)
34764-{
34765- vdso_enabled = simple_strtoul(s, NULL, 0);
34766- return 0;
34767-}
34768-__setup("vdso=", vdso_setup);
34769diff --git a/arch/x86/xen/enlighten.c b/arch/x86/xen/enlighten.c
34770index fa6ade7..73da73a5 100644
34771--- a/arch/x86/xen/enlighten.c
34772+++ b/arch/x86/xen/enlighten.c
34773@@ -123,8 +123,6 @@ EXPORT_SYMBOL_GPL(xen_start_info);
34774
34775 struct shared_info xen_dummy_shared_info;
34776
34777-void *xen_initial_gdt;
34778-
34779 RESERVE_BRK(shared_info_page_brk, PAGE_SIZE);
34780 __read_mostly int xen_have_vector_callback;
34781 EXPORT_SYMBOL_GPL(xen_have_vector_callback);
34782@@ -541,8 +539,7 @@ static void xen_load_gdt(const struct desc_ptr *dtr)
34783 {
34784 unsigned long va = dtr->address;
34785 unsigned int size = dtr->size + 1;
34786- unsigned pages = (size + PAGE_SIZE - 1) / PAGE_SIZE;
34787- unsigned long frames[pages];
34788+ unsigned long frames[65536 / PAGE_SIZE];
34789 int f;
34790
34791 /*
34792@@ -590,8 +587,7 @@ static void __init xen_load_gdt_boot(const struct desc_ptr *dtr)
34793 {
34794 unsigned long va = dtr->address;
34795 unsigned int size = dtr->size + 1;
34796- unsigned pages = (size + PAGE_SIZE - 1) / PAGE_SIZE;
34797- unsigned long frames[pages];
34798+ unsigned long frames[(GDT_SIZE + PAGE_SIZE - 1) / PAGE_SIZE];
34799 int f;
34800
34801 /*
34802@@ -599,7 +595,7 @@ static void __init xen_load_gdt_boot(const struct desc_ptr *dtr)
34803 * 8-byte entries, or 16 4k pages..
34804 */
34805
34806- BUG_ON(size > 65536);
34807+ BUG_ON(size > GDT_SIZE);
34808 BUG_ON(va & ~PAGE_MASK);
34809
34810 for (f = 0; va < dtr->address + size; va += PAGE_SIZE, f++) {
34811@@ -988,7 +984,7 @@ static u32 xen_safe_apic_wait_icr_idle(void)
34812 return 0;
34813 }
34814
34815-static void set_xen_basic_apic_ops(void)
34816+static void __init set_xen_basic_apic_ops(void)
34817 {
34818 apic->read = xen_apic_read;
34819 apic->write = xen_apic_write;
34820@@ -1293,30 +1289,30 @@ static const struct pv_apic_ops xen_apic_ops __initconst = {
34821 #endif
34822 };
34823
34824-static void xen_reboot(int reason)
34825+static __noreturn void xen_reboot(int reason)
34826 {
34827 struct sched_shutdown r = { .reason = reason };
34828
34829- if (HYPERVISOR_sched_op(SCHEDOP_shutdown, &r))
34830- BUG();
34831+ HYPERVISOR_sched_op(SCHEDOP_shutdown, &r);
34832+ BUG();
34833 }
34834
34835-static void xen_restart(char *msg)
34836+static __noreturn void xen_restart(char *msg)
34837 {
34838 xen_reboot(SHUTDOWN_reboot);
34839 }
34840
34841-static void xen_emergency_restart(void)
34842+static __noreturn void xen_emergency_restart(void)
34843 {
34844 xen_reboot(SHUTDOWN_reboot);
34845 }
34846
34847-static void xen_machine_halt(void)
34848+static __noreturn void xen_machine_halt(void)
34849 {
34850 xen_reboot(SHUTDOWN_poweroff);
34851 }
34852
34853-static void xen_machine_power_off(void)
34854+static __noreturn void xen_machine_power_off(void)
34855 {
34856 if (pm_power_off)
34857 pm_power_off();
34858@@ -1467,7 +1463,17 @@ asmlinkage void __init xen_start_kernel(void)
34859 __userpte_alloc_gfp &= ~__GFP_HIGHMEM;
34860
34861 /* Work out if we support NX */
34862- x86_configure_nx();
34863+#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
34864+ if ((cpuid_eax(0x80000000) & 0xffff0000) == 0x80000000 &&
34865+ (cpuid_edx(0x80000001) & (1U << (X86_FEATURE_NX & 31)))) {
34866+ unsigned l, h;
34867+
34868+ __supported_pte_mask |= _PAGE_NX;
34869+ rdmsr(MSR_EFER, l, h);
34870+ l |= EFER_NX;
34871+ wrmsr(MSR_EFER, l, h);
34872+ }
34873+#endif
34874
34875 xen_setup_features();
34876
34877@@ -1498,13 +1504,6 @@ asmlinkage void __init xen_start_kernel(void)
34878
34879 machine_ops = xen_machine_ops;
34880
34881- /*
34882- * The only reliable way to retain the initial address of the
34883- * percpu gdt_page is to remember it here, so we can go and
34884- * mark it RW later, when the initial percpu area is freed.
34885- */
34886- xen_initial_gdt = &per_cpu(gdt_page, 0);
34887-
34888 xen_smp_init();
34889
34890 #ifdef CONFIG_ACPI_NUMA
34891diff --git a/arch/x86/xen/mmu.c b/arch/x86/xen/mmu.c
34892index fdc3ba2..23cae00 100644
34893--- a/arch/x86/xen/mmu.c
34894+++ b/arch/x86/xen/mmu.c
34895@@ -379,7 +379,7 @@ static pteval_t pte_mfn_to_pfn(pteval_t val)
34896 return val;
34897 }
34898
34899-static pteval_t pte_pfn_to_mfn(pteval_t val)
34900+static pteval_t __intentional_overflow(-1) pte_pfn_to_mfn(pteval_t val)
34901 {
34902 if (val & _PAGE_PRESENT) {
34903 unsigned long pfn = (val & PTE_PFN_MASK) >> PAGE_SHIFT;
34904@@ -1894,6 +1894,9 @@ void __init xen_setup_kernel_pagetable(pgd_t *pgd, unsigned long max_pfn)
34905 /* L3_k[510] -> level2_kernel_pgt
34906 * L3_i[511] -> level2_fixmap_pgt */
34907 convert_pfn_mfn(level3_kernel_pgt);
34908+ convert_pfn_mfn(level3_vmalloc_start_pgt);
34909+ convert_pfn_mfn(level3_vmalloc_end_pgt);
34910+ convert_pfn_mfn(level3_vmemmap_pgt);
34911
34912 /* We get [511][511] and have Xen's version of level2_kernel_pgt */
34913 l3 = m2v(pgd[pgd_index(__START_KERNEL_map)].pgd);
34914@@ -1923,8 +1926,12 @@ void __init xen_setup_kernel_pagetable(pgd_t *pgd, unsigned long max_pfn)
34915 set_page_prot(init_level4_pgt, PAGE_KERNEL_RO);
34916 set_page_prot(level3_ident_pgt, PAGE_KERNEL_RO);
34917 set_page_prot(level3_kernel_pgt, PAGE_KERNEL_RO);
34918+ set_page_prot(level3_vmalloc_start_pgt, PAGE_KERNEL_RO);
34919+ set_page_prot(level3_vmalloc_end_pgt, PAGE_KERNEL_RO);
34920+ set_page_prot(level3_vmemmap_pgt, PAGE_KERNEL_RO);
34921 set_page_prot(level3_user_vsyscall, PAGE_KERNEL_RO);
34922 set_page_prot(level2_ident_pgt, PAGE_KERNEL_RO);
34923+ set_page_prot(level2_vmemmap_pgt, PAGE_KERNEL_RO);
34924 set_page_prot(level2_kernel_pgt, PAGE_KERNEL_RO);
34925 set_page_prot(level2_fixmap_pgt, PAGE_KERNEL_RO);
34926
34927@@ -2108,6 +2115,7 @@ static void __init xen_post_allocator_init(void)
34928 pv_mmu_ops.set_pud = xen_set_pud;
34929 #if PAGETABLE_LEVELS == 4
34930 pv_mmu_ops.set_pgd = xen_set_pgd;
34931+ pv_mmu_ops.set_pgd_batched = xen_set_pgd;
34932 #endif
34933
34934 /* This will work as long as patching hasn't happened yet
34935@@ -2186,6 +2194,7 @@ static const struct pv_mmu_ops xen_mmu_ops __initconst = {
34936 .pud_val = PV_CALLEE_SAVE(xen_pud_val),
34937 .make_pud = PV_CALLEE_SAVE(xen_make_pud),
34938 .set_pgd = xen_set_pgd_hyper,
34939+ .set_pgd_batched = xen_set_pgd_hyper,
34940
34941 .alloc_pud = xen_alloc_pmd_init,
34942 .release_pud = xen_release_pmd_init,
34943diff --git a/arch/x86/xen/smp.c b/arch/x86/xen/smp.c
34944index 31d0475..51af671 100644
34945--- a/arch/x86/xen/smp.c
34946+++ b/arch/x86/xen/smp.c
34947@@ -274,17 +274,13 @@ static void __init xen_smp_prepare_boot_cpu(void)
34948 native_smp_prepare_boot_cpu();
34949
34950 if (xen_pv_domain()) {
34951- /* We've switched to the "real" per-cpu gdt, so make sure the
34952- old memory can be recycled */
34953- make_lowmem_page_readwrite(xen_initial_gdt);
34954-
34955 #ifdef CONFIG_X86_32
34956 /*
34957 * Xen starts us with XEN_FLAT_RING1_DS, but linux code
34958 * expects __USER_DS
34959 */
34960- loadsegment(ds, __USER_DS);
34961- loadsegment(es, __USER_DS);
34962+ loadsegment(ds, __KERNEL_DS);
34963+ loadsegment(es, __KERNEL_DS);
34964 #endif
34965
34966 xen_filter_cpu_maps();
34967@@ -364,7 +360,7 @@ cpu_initialize_context(unsigned int cpu, struct task_struct *idle)
34968 ctxt->user_regs.ss = __KERNEL_DS;
34969 #ifdef CONFIG_X86_32
34970 ctxt->user_regs.fs = __KERNEL_PERCPU;
34971- ctxt->user_regs.gs = __KERNEL_STACK_CANARY;
34972+ savesegment(gs, ctxt->user_regs.gs);
34973 #else
34974 ctxt->gs_base_kernel = per_cpu_offset(cpu);
34975 #endif
34976@@ -374,8 +370,8 @@ cpu_initialize_context(unsigned int cpu, struct task_struct *idle)
34977
34978 {
34979 ctxt->user_regs.eflags = 0x1000; /* IOPL_RING1 */
34980- ctxt->user_regs.ds = __USER_DS;
34981- ctxt->user_regs.es = __USER_DS;
34982+ ctxt->user_regs.ds = __KERNEL_DS;
34983+ ctxt->user_regs.es = __KERNEL_DS;
34984
34985 xen_copy_trap_info(ctxt->trap_ctxt);
34986
34987@@ -420,13 +416,12 @@ static int xen_cpu_up(unsigned int cpu, struct task_struct *idle)
34988 int rc;
34989
34990 per_cpu(current_task, cpu) = idle;
34991+ per_cpu(current_tinfo, cpu) = &idle->tinfo;
34992 #ifdef CONFIG_X86_32
34993 irq_ctx_init(cpu);
34994 #else
34995 clear_tsk_thread_flag(idle, TIF_FORK);
34996- per_cpu(kernel_stack, cpu) =
34997- (unsigned long)task_stack_page(idle) -
34998- KERNEL_STACK_OFFSET + THREAD_SIZE;
34999+ per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
35000 #endif
35001 xen_setup_runstate_info(cpu);
35002 xen_setup_timer(cpu);
35003@@ -702,7 +697,7 @@ static const struct smp_ops xen_smp_ops __initconst = {
35004
35005 void __init xen_smp_init(void)
35006 {
35007- smp_ops = xen_smp_ops;
35008+ memcpy((void *)&smp_ops, &xen_smp_ops, sizeof smp_ops);
35009 xen_fill_possible_map();
35010 }
35011
35012diff --git a/arch/x86/xen/xen-asm_32.S b/arch/x86/xen/xen-asm_32.S
35013index 33ca6e4..0ded929 100644
35014--- a/arch/x86/xen/xen-asm_32.S
35015+++ b/arch/x86/xen/xen-asm_32.S
35016@@ -84,14 +84,14 @@ ENTRY(xen_iret)
35017 ESP_OFFSET=4 # bytes pushed onto stack
35018
35019 /*
35020- * Store vcpu_info pointer for easy access. Do it this way to
35021- * avoid having to reload %fs
35022+ * Store vcpu_info pointer for easy access.
35023 */
35024 #ifdef CONFIG_SMP
35025- GET_THREAD_INFO(%eax)
35026- movl %ss:TI_cpu(%eax), %eax
35027- movl %ss:__per_cpu_offset(,%eax,4), %eax
35028- mov %ss:xen_vcpu(%eax), %eax
35029+ push %fs
35030+ mov $(__KERNEL_PERCPU), %eax
35031+ mov %eax, %fs
35032+ mov PER_CPU_VAR(xen_vcpu), %eax
35033+ pop %fs
35034 #else
35035 movl %ss:xen_vcpu, %eax
35036 #endif
35037diff --git a/arch/x86/xen/xen-head.S b/arch/x86/xen/xen-head.S
35038index 7faed58..ba4427c 100644
35039--- a/arch/x86/xen/xen-head.S
35040+++ b/arch/x86/xen/xen-head.S
35041@@ -19,6 +19,17 @@ ENTRY(startup_xen)
35042 #ifdef CONFIG_X86_32
35043 mov %esi,xen_start_info
35044 mov $init_thread_union+THREAD_SIZE,%esp
35045+#ifdef CONFIG_SMP
35046+ movl $cpu_gdt_table,%edi
35047+ movl $__per_cpu_load,%eax
35048+ movw %ax,__KERNEL_PERCPU + 2(%edi)
35049+ rorl $16,%eax
35050+ movb %al,__KERNEL_PERCPU + 4(%edi)
35051+ movb %ah,__KERNEL_PERCPU + 7(%edi)
35052+ movl $__per_cpu_end - 1,%eax
35053+ subl $__per_cpu_start,%eax
35054+ movw %ax,__KERNEL_PERCPU + 0(%edi)
35055+#endif
35056 #else
35057 mov %rsi,xen_start_info
35058 mov $init_thread_union+THREAD_SIZE,%rsp
35059diff --git a/arch/x86/xen/xen-ops.h b/arch/x86/xen/xen-ops.h
35060index 95f8c61..611d6e8 100644
35061--- a/arch/x86/xen/xen-ops.h
35062+++ b/arch/x86/xen/xen-ops.h
35063@@ -10,8 +10,6 @@
35064 extern const char xen_hypervisor_callback[];
35065 extern const char xen_failsafe_callback[];
35066
35067-extern void *xen_initial_gdt;
35068-
35069 struct trap_info;
35070 void xen_copy_trap_info(struct trap_info *traps);
35071
35072diff --git a/arch/xtensa/variants/dc232b/include/variant/core.h b/arch/xtensa/variants/dc232b/include/variant/core.h
35073index 525bd3d..ef888b1 100644
35074--- a/arch/xtensa/variants/dc232b/include/variant/core.h
35075+++ b/arch/xtensa/variants/dc232b/include/variant/core.h
35076@@ -119,9 +119,9 @@
35077 ----------------------------------------------------------------------*/
35078
35079 #define XCHAL_ICACHE_LINESIZE 32 /* I-cache line size in bytes */
35080-#define XCHAL_DCACHE_LINESIZE 32 /* D-cache line size in bytes */
35081 #define XCHAL_ICACHE_LINEWIDTH 5 /* log2(I line size in bytes) */
35082 #define XCHAL_DCACHE_LINEWIDTH 5 /* log2(D line size in bytes) */
35083+#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
35084
35085 #define XCHAL_ICACHE_SIZE 16384 /* I-cache size in bytes or 0 */
35086 #define XCHAL_DCACHE_SIZE 16384 /* D-cache size in bytes or 0 */
35087diff --git a/arch/xtensa/variants/fsf/include/variant/core.h b/arch/xtensa/variants/fsf/include/variant/core.h
35088index 2f33760..835e50a 100644
35089--- a/arch/xtensa/variants/fsf/include/variant/core.h
35090+++ b/arch/xtensa/variants/fsf/include/variant/core.h
35091@@ -11,6 +11,7 @@
35092 #ifndef _XTENSA_CORE_H
35093 #define _XTENSA_CORE_H
35094
35095+#include <linux/const.h>
35096
35097 /****************************************************************************
35098 Parameters Useful for Any Code, USER or PRIVILEGED
35099@@ -112,9 +113,9 @@
35100 ----------------------------------------------------------------------*/
35101
35102 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
35103-#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
35104 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
35105 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
35106+#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
35107
35108 #define XCHAL_ICACHE_SIZE 8192 /* I-cache size in bytes or 0 */
35109 #define XCHAL_DCACHE_SIZE 8192 /* D-cache size in bytes or 0 */
35110diff --git a/arch/xtensa/variants/s6000/include/variant/core.h b/arch/xtensa/variants/s6000/include/variant/core.h
35111index af00795..2bb8105 100644
35112--- a/arch/xtensa/variants/s6000/include/variant/core.h
35113+++ b/arch/xtensa/variants/s6000/include/variant/core.h
35114@@ -11,6 +11,7 @@
35115 #ifndef _XTENSA_CORE_CONFIGURATION_H
35116 #define _XTENSA_CORE_CONFIGURATION_H
35117
35118+#include <linux/const.h>
35119
35120 /****************************************************************************
35121 Parameters Useful for Any Code, USER or PRIVILEGED
35122@@ -118,9 +119,9 @@
35123 ----------------------------------------------------------------------*/
35124
35125 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
35126-#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
35127 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
35128 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
35129+#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
35130
35131 #define XCHAL_ICACHE_SIZE 32768 /* I-cache size in bytes or 0 */
35132 #define XCHAL_DCACHE_SIZE 32768 /* D-cache size in bytes or 0 */
35133diff --git a/block/blk-cgroup.c b/block/blk-cgroup.c
35134index 4e491d9..c8e18e4 100644
35135--- a/block/blk-cgroup.c
35136+++ b/block/blk-cgroup.c
35137@@ -812,7 +812,7 @@ static void blkcg_css_free(struct cgroup_subsys_state *css)
35138 static struct cgroup_subsys_state *
35139 blkcg_css_alloc(struct cgroup_subsys_state *parent_css)
35140 {
35141- static atomic64_t id_seq = ATOMIC64_INIT(0);
35142+ static atomic64_unchecked_t id_seq = ATOMIC64_INIT(0);
35143 struct blkcg *blkcg;
35144
35145 if (!parent_css) {
35146@@ -826,7 +826,7 @@ blkcg_css_alloc(struct cgroup_subsys_state *parent_css)
35147
35148 blkcg->cfq_weight = CFQ_WEIGHT_DEFAULT;
35149 blkcg->cfq_leaf_weight = CFQ_WEIGHT_DEFAULT;
35150- blkcg->id = atomic64_inc_return(&id_seq); /* root is 0, start from 1 */
35151+ blkcg->id = atomic64_inc_return_unchecked(&id_seq); /* root is 0, start from 1 */
35152 done:
35153 spin_lock_init(&blkcg->lock);
35154 INIT_RADIX_TREE(&blkcg->blkg_tree, GFP_ATOMIC);
35155diff --git a/block/blk-iopoll.c b/block/blk-iopoll.c
35156index 4b8d9b54..a7178c0 100644
35157--- a/block/blk-iopoll.c
35158+++ b/block/blk-iopoll.c
35159@@ -77,7 +77,7 @@ void blk_iopoll_complete(struct blk_iopoll *iopoll)
35160 }
35161 EXPORT_SYMBOL(blk_iopoll_complete);
35162
35163-static void blk_iopoll_softirq(struct softirq_action *h)
35164+static __latent_entropy void blk_iopoll_softirq(void)
35165 {
35166 struct list_head *list = &__get_cpu_var(blk_cpu_iopoll);
35167 int rearm = 0, budget = blk_iopoll_budget;
35168diff --git a/block/blk-map.c b/block/blk-map.c
35169index 623e1cd..ca1e109 100644
35170--- a/block/blk-map.c
35171+++ b/block/blk-map.c
35172@@ -302,7 +302,7 @@ int blk_rq_map_kern(struct request_queue *q, struct request *rq, void *kbuf,
35173 if (!len || !kbuf)
35174 return -EINVAL;
35175
35176- do_copy = !blk_rq_aligned(q, addr, len) || object_is_on_stack(kbuf);
35177+ do_copy = !blk_rq_aligned(q, addr, len) || object_starts_on_stack(kbuf);
35178 if (do_copy)
35179 bio = bio_copy_kern(q, kbuf, len, gfp_mask, reading);
35180 else
35181diff --git a/block/blk-softirq.c b/block/blk-softirq.c
35182index ec9e606..3f38839 100644
35183--- a/block/blk-softirq.c
35184+++ b/block/blk-softirq.c
35185@@ -18,7 +18,7 @@ static DEFINE_PER_CPU(struct list_head, blk_cpu_done);
35186 * Softirq action handler - move entries to local list and loop over them
35187 * while passing them to the queue registered handler.
35188 */
35189-static void blk_done_softirq(struct softirq_action *h)
35190+static __latent_entropy void blk_done_softirq(void)
35191 {
35192 struct list_head *cpu_list, local_list;
35193
35194diff --git a/block/bsg.c b/block/bsg.c
35195index 420a5a9..23834aa 100644
35196--- a/block/bsg.c
35197+++ b/block/bsg.c
35198@@ -176,16 +176,24 @@ static int blk_fill_sgv4_hdr_rq(struct request_queue *q, struct request *rq,
35199 struct sg_io_v4 *hdr, struct bsg_device *bd,
35200 fmode_t has_write_perm)
35201 {
35202+ unsigned char tmpcmd[sizeof(rq->__cmd)];
35203+ unsigned char *cmdptr;
35204+
35205 if (hdr->request_len > BLK_MAX_CDB) {
35206 rq->cmd = kzalloc(hdr->request_len, GFP_KERNEL);
35207 if (!rq->cmd)
35208 return -ENOMEM;
35209- }
35210+ cmdptr = rq->cmd;
35211+ } else
35212+ cmdptr = tmpcmd;
35213
35214- if (copy_from_user(rq->cmd, (void __user *)(unsigned long)hdr->request,
35215+ if (copy_from_user(cmdptr, (void __user *)(unsigned long)hdr->request,
35216 hdr->request_len))
35217 return -EFAULT;
35218
35219+ if (cmdptr != rq->cmd)
35220+ memcpy(rq->cmd, cmdptr, hdr->request_len);
35221+
35222 if (hdr->subprotocol == BSG_SUB_PROTOCOL_SCSI_CMD) {
35223 if (blk_verify_command(rq->cmd, has_write_perm))
35224 return -EPERM;
35225diff --git a/block/compat_ioctl.c b/block/compat_ioctl.c
35226index fbd5a67..5d631b5 100644
35227--- a/block/compat_ioctl.c
35228+++ b/block/compat_ioctl.c
35229@@ -341,7 +341,7 @@ static int compat_fd_ioctl(struct block_device *bdev, fmode_t mode,
35230 err |= __get_user(f->spec1, &uf->spec1);
35231 err |= __get_user(f->fmt_gap, &uf->fmt_gap);
35232 err |= __get_user(name, &uf->name);
35233- f->name = compat_ptr(name);
35234+ f->name = (void __force_kernel *)compat_ptr(name);
35235 if (err) {
35236 err = -EFAULT;
35237 goto out;
35238diff --git a/block/genhd.c b/block/genhd.c
35239index 791f419..89f21c4 100644
35240--- a/block/genhd.c
35241+++ b/block/genhd.c
35242@@ -467,21 +467,24 @@ static char *bdevt_str(dev_t devt, char *buf)
35243
35244 /*
35245 * Register device numbers dev..(dev+range-1)
35246- * range must be nonzero
35247+ * Noop if @range is zero.
35248 * The hash chain is sorted on range, so that subranges can override.
35249 */
35250 void blk_register_region(dev_t devt, unsigned long range, struct module *module,
35251 struct kobject *(*probe)(dev_t, int *, void *),
35252 int (*lock)(dev_t, void *), void *data)
35253 {
35254- kobj_map(bdev_map, devt, range, module, probe, lock, data);
35255+ if (range)
35256+ kobj_map(bdev_map, devt, range, module, probe, lock, data);
35257 }
35258
35259 EXPORT_SYMBOL(blk_register_region);
35260
35261+/* undo blk_register_region(), noop if @range is zero */
35262 void blk_unregister_region(dev_t devt, unsigned long range)
35263 {
35264- kobj_unmap(bdev_map, devt, range);
35265+ if (range)
35266+ kobj_unmap(bdev_map, devt, range);
35267 }
35268
35269 EXPORT_SYMBOL(blk_unregister_region);
35270diff --git a/block/partitions/efi.c b/block/partitions/efi.c
35271index a8287b4..241a48e 100644
35272--- a/block/partitions/efi.c
35273+++ b/block/partitions/efi.c
35274@@ -292,14 +292,14 @@ static gpt_entry *alloc_read_gpt_entries(struct parsed_partitions *state,
35275 if (!gpt)
35276 return NULL;
35277
35278+ if (!le32_to_cpu(gpt->num_partition_entries))
35279+ return NULL;
35280+ pte = kcalloc(le32_to_cpu(gpt->num_partition_entries), le32_to_cpu(gpt->sizeof_partition_entry), GFP_KERNEL);
35281+ if (!pte)
35282+ return NULL;
35283+
35284 count = le32_to_cpu(gpt->num_partition_entries) *
35285 le32_to_cpu(gpt->sizeof_partition_entry);
35286- if (!count)
35287- return NULL;
35288- pte = kmalloc(count, GFP_KERNEL);
35289- if (!pte)
35290- return NULL;
35291-
35292 if (read_lba(state, le64_to_cpu(gpt->partition_entry_lba),
35293 (u8 *) pte, count) < count) {
35294 kfree(pte);
35295diff --git a/block/scsi_ioctl.c b/block/scsi_ioctl.c
35296index a5ffcc9..e057498 100644
35297--- a/block/scsi_ioctl.c
35298+++ b/block/scsi_ioctl.c
35299@@ -67,7 +67,7 @@ static int scsi_get_bus(struct request_queue *q, int __user *p)
35300 return put_user(0, p);
35301 }
35302
35303-static int sg_get_timeout(struct request_queue *q)
35304+static int __intentional_overflow(-1) sg_get_timeout(struct request_queue *q)
35305 {
35306 return jiffies_to_clock_t(q->sg_timeout);
35307 }
35308@@ -224,8 +224,20 @@ EXPORT_SYMBOL(blk_verify_command);
35309 static int blk_fill_sghdr_rq(struct request_queue *q, struct request *rq,
35310 struct sg_io_hdr *hdr, fmode_t mode)
35311 {
35312- if (copy_from_user(rq->cmd, hdr->cmdp, hdr->cmd_len))
35313+ unsigned char tmpcmd[sizeof(rq->__cmd)];
35314+ unsigned char *cmdptr;
35315+
35316+ if (rq->cmd != rq->__cmd)
35317+ cmdptr = rq->cmd;
35318+ else
35319+ cmdptr = tmpcmd;
35320+
35321+ if (copy_from_user(cmdptr, hdr->cmdp, hdr->cmd_len))
35322 return -EFAULT;
35323+
35324+ if (cmdptr != rq->cmd)
35325+ memcpy(rq->cmd, cmdptr, hdr->cmd_len);
35326+
35327 if (blk_verify_command(rq->cmd, mode & FMODE_WRITE))
35328 return -EPERM;
35329
35330@@ -434,6 +446,8 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
35331 int err;
35332 unsigned int in_len, out_len, bytes, opcode, cmdlen;
35333 char *buffer = NULL, sense[SCSI_SENSE_BUFFERSIZE];
35334+ unsigned char tmpcmd[sizeof(rq->__cmd)];
35335+ unsigned char *cmdptr;
35336
35337 if (!sic)
35338 return -EINVAL;
35339@@ -467,9 +481,18 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
35340 */
35341 err = -EFAULT;
35342 rq->cmd_len = cmdlen;
35343- if (copy_from_user(rq->cmd, sic->data, cmdlen))
35344+
35345+ if (rq->cmd != rq->__cmd)
35346+ cmdptr = rq->cmd;
35347+ else
35348+ cmdptr = tmpcmd;
35349+
35350+ if (copy_from_user(cmdptr, sic->data, cmdlen))
35351 goto error;
35352
35353+ if (rq->cmd != cmdptr)
35354+ memcpy(rq->cmd, cmdptr, cmdlen);
35355+
35356 if (in_len && copy_from_user(buffer, sic->data + cmdlen, in_len))
35357 goto error;
35358
35359diff --git a/crypto/cryptd.c b/crypto/cryptd.c
35360index 7bdd61b..afec999 100644
35361--- a/crypto/cryptd.c
35362+++ b/crypto/cryptd.c
35363@@ -63,7 +63,7 @@ struct cryptd_blkcipher_ctx {
35364
35365 struct cryptd_blkcipher_request_ctx {
35366 crypto_completion_t complete;
35367-};
35368+} __no_const;
35369
35370 struct cryptd_hash_ctx {
35371 struct crypto_shash *child;
35372@@ -80,7 +80,7 @@ struct cryptd_aead_ctx {
35373
35374 struct cryptd_aead_request_ctx {
35375 crypto_completion_t complete;
35376-};
35377+} __no_const;
35378
35379 static void cryptd_queue_worker(struct work_struct *work);
35380
35381diff --git a/crypto/pcrypt.c b/crypto/pcrypt.c
35382index f8c920c..ab2cb5a 100644
35383--- a/crypto/pcrypt.c
35384+++ b/crypto/pcrypt.c
35385@@ -440,7 +440,7 @@ static int pcrypt_sysfs_add(struct padata_instance *pinst, const char *name)
35386 int ret;
35387
35388 pinst->kobj.kset = pcrypt_kset;
35389- ret = kobject_add(&pinst->kobj, NULL, name);
35390+ ret = kobject_add(&pinst->kobj, NULL, "%s", name);
35391 if (!ret)
35392 kobject_uevent(&pinst->kobj, KOBJ_ADD);
35393
35394diff --git a/drivers/acpi/acpica/hwxfsleep.c b/drivers/acpi/acpica/hwxfsleep.c
35395index f2e669d..349cb1c 100644
35396--- a/drivers/acpi/acpica/hwxfsleep.c
35397+++ b/drivers/acpi/acpica/hwxfsleep.c
35398@@ -62,11 +62,12 @@ static acpi_status acpi_hw_sleep_dispatch(u8 sleep_state, u32 function_id);
35399 /* Legacy functions are optional, based upon ACPI_REDUCED_HARDWARE */
35400
35401 static struct acpi_sleep_functions acpi_sleep_dispatch[] = {
35402- {ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_sleep),
35403- acpi_hw_extended_sleep},
35404- {ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_wake_prep),
35405- acpi_hw_extended_wake_prep},
35406- {ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_wake), acpi_hw_extended_wake}
35407+ {.legacy_function = ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_sleep),
35408+ .extended_function = acpi_hw_extended_sleep},
35409+ {.legacy_function = ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_wake_prep),
35410+ .extended_function = acpi_hw_extended_wake_prep},
35411+ {.legacy_function = ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_wake),
35412+ .extended_function = acpi_hw_extended_wake}
35413 };
35414
35415 /*
35416diff --git a/drivers/acpi/apei/apei-internal.h b/drivers/acpi/apei/apei-internal.h
35417index f220d64..d359ad6 100644
35418--- a/drivers/acpi/apei/apei-internal.h
35419+++ b/drivers/acpi/apei/apei-internal.h
35420@@ -20,7 +20,7 @@ typedef int (*apei_exec_ins_func_t)(struct apei_exec_context *ctx,
35421 struct apei_exec_ins_type {
35422 u32 flags;
35423 apei_exec_ins_func_t run;
35424-};
35425+} __do_const;
35426
35427 struct apei_exec_context {
35428 u32 ip;
35429diff --git a/drivers/acpi/apei/cper.c b/drivers/acpi/apei/cper.c
35430index 33dc6a0..4b24b47 100644
35431--- a/drivers/acpi/apei/cper.c
35432+++ b/drivers/acpi/apei/cper.c
35433@@ -39,12 +39,12 @@
35434 */
35435 u64 cper_next_record_id(void)
35436 {
35437- static atomic64_t seq;
35438+ static atomic64_unchecked_t seq;
35439
35440- if (!atomic64_read(&seq))
35441- atomic64_set(&seq, ((u64)get_seconds()) << 32);
35442+ if (!atomic64_read_unchecked(&seq))
35443+ atomic64_set_unchecked(&seq, ((u64)get_seconds()) << 32);
35444
35445- return atomic64_inc_return(&seq);
35446+ return atomic64_inc_return_unchecked(&seq);
35447 }
35448 EXPORT_SYMBOL_GPL(cper_next_record_id);
35449
35450diff --git a/drivers/acpi/apei/ghes.c b/drivers/acpi/apei/ghes.c
35451index 8ec37bb..b0716e5 100644
35452--- a/drivers/acpi/apei/ghes.c
35453+++ b/drivers/acpi/apei/ghes.c
35454@@ -498,7 +498,7 @@ static void __ghes_print_estatus(const char *pfx,
35455 const struct acpi_hest_generic *generic,
35456 const struct acpi_hest_generic_status *estatus)
35457 {
35458- static atomic_t seqno;
35459+ static atomic_unchecked_t seqno;
35460 unsigned int curr_seqno;
35461 char pfx_seq[64];
35462
35463@@ -509,7 +509,7 @@ static void __ghes_print_estatus(const char *pfx,
35464 else
35465 pfx = KERN_ERR;
35466 }
35467- curr_seqno = atomic_inc_return(&seqno);
35468+ curr_seqno = atomic_inc_return_unchecked(&seqno);
35469 snprintf(pfx_seq, sizeof(pfx_seq), "%s{%u}" HW_ERR, pfx, curr_seqno);
35470 printk("%s""Hardware error from APEI Generic Hardware Error Source: %d\n",
35471 pfx_seq, generic->header.source_id);
35472diff --git a/drivers/acpi/bgrt.c b/drivers/acpi/bgrt.c
35473index a83e3c6..c3d617f 100644
35474--- a/drivers/acpi/bgrt.c
35475+++ b/drivers/acpi/bgrt.c
35476@@ -86,8 +86,10 @@ static int __init bgrt_init(void)
35477 if (!bgrt_image)
35478 return -ENODEV;
35479
35480- bin_attr_image.private = bgrt_image;
35481- bin_attr_image.size = bgrt_image_size;
35482+ pax_open_kernel();
35483+ *(void **)&bin_attr_image.private = bgrt_image;
35484+ *(size_t *)&bin_attr_image.size = bgrt_image_size;
35485+ pax_close_kernel();
35486
35487 bgrt_kobj = kobject_create_and_add("bgrt", acpi_kobj);
35488 if (!bgrt_kobj)
35489diff --git a/drivers/acpi/blacklist.c b/drivers/acpi/blacklist.c
35490index 9515f18..4b149c9 100644
35491--- a/drivers/acpi/blacklist.c
35492+++ b/drivers/acpi/blacklist.c
35493@@ -52,7 +52,7 @@ struct acpi_blacklist_item {
35494 u32 is_critical_error;
35495 };
35496
35497-static struct dmi_system_id acpi_osi_dmi_table[] __initdata;
35498+static const struct dmi_system_id acpi_osi_dmi_table[] __initconst;
35499
35500 /*
35501 * POLICY: If *anything* doesn't work, put it on the blacklist.
35502@@ -199,7 +199,7 @@ static int __init dmi_disable_osi_win8(const struct dmi_system_id *d)
35503 return 0;
35504 }
35505
35506-static struct dmi_system_id acpi_osi_dmi_table[] __initdata = {
35507+static const struct dmi_system_id acpi_osi_dmi_table[] __initconst = {
35508 {
35509 .callback = dmi_disable_osi_vista,
35510 .ident = "Fujitsu Siemens",
35511diff --git a/drivers/acpi/custom_method.c b/drivers/acpi/custom_method.c
35512index 12b62f2..dc2aac8 100644
35513--- a/drivers/acpi/custom_method.c
35514+++ b/drivers/acpi/custom_method.c
35515@@ -29,6 +29,10 @@ static ssize_t cm_write(struct file *file, const char __user * user_buf,
35516 struct acpi_table_header table;
35517 acpi_status status;
35518
35519+#ifdef CONFIG_GRKERNSEC_KMEM
35520+ return -EPERM;
35521+#endif
35522+
35523 if (!(*ppos)) {
35524 /* parse the table header to get the table length */
35525 if (count <= sizeof(struct acpi_table_header))
35526diff --git a/drivers/acpi/processor_idle.c b/drivers/acpi/processor_idle.c
35527index c7414a5..d5afd71 100644
35528--- a/drivers/acpi/processor_idle.c
35529+++ b/drivers/acpi/processor_idle.c
35530@@ -966,7 +966,7 @@ static int acpi_processor_setup_cpuidle_states(struct acpi_processor *pr)
35531 {
35532 int i, count = CPUIDLE_DRIVER_STATE_START;
35533 struct acpi_processor_cx *cx;
35534- struct cpuidle_state *state;
35535+ cpuidle_state_no_const *state;
35536 struct cpuidle_driver *drv = &acpi_idle_driver;
35537
35538 if (!pr->flags.power_setup_done)
35539diff --git a/drivers/acpi/sysfs.c b/drivers/acpi/sysfs.c
35540index 05306a5..733d1f0 100644
35541--- a/drivers/acpi/sysfs.c
35542+++ b/drivers/acpi/sysfs.c
35543@@ -423,11 +423,11 @@ static u32 num_counters;
35544 static struct attribute **all_attrs;
35545 static u32 acpi_gpe_count;
35546
35547-static struct attribute_group interrupt_stats_attr_group = {
35548+static attribute_group_no_const interrupt_stats_attr_group = {
35549 .name = "interrupts",
35550 };
35551
35552-static struct kobj_attribute *counter_attrs;
35553+static kobj_attribute_no_const *counter_attrs;
35554
35555 static void delete_gpe_attr_array(void)
35556 {
35557diff --git a/drivers/ata/libahci.c b/drivers/ata/libahci.c
35558index cfb7447..98f2149 100644
35559--- a/drivers/ata/libahci.c
35560+++ b/drivers/ata/libahci.c
35561@@ -1239,7 +1239,7 @@ int ahci_kick_engine(struct ata_port *ap)
35562 }
35563 EXPORT_SYMBOL_GPL(ahci_kick_engine);
35564
35565-static int ahci_exec_polled_cmd(struct ata_port *ap, int pmp,
35566+static int __intentional_overflow(-1) ahci_exec_polled_cmd(struct ata_port *ap, int pmp,
35567 struct ata_taskfile *tf, int is_cmd, u16 flags,
35568 unsigned long timeout_msec)
35569 {
35570diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c
35571index 2c2780a..5ebc310 100644
35572--- a/drivers/ata/libata-core.c
35573+++ b/drivers/ata/libata-core.c
35574@@ -98,7 +98,7 @@ static unsigned int ata_dev_set_xfermode(struct ata_device *dev);
35575 static void ata_dev_xfermask(struct ata_device *dev);
35576 static unsigned long ata_dev_blacklisted(const struct ata_device *dev);
35577
35578-atomic_t ata_print_id = ATOMIC_INIT(0);
35579+atomic_unchecked_t ata_print_id = ATOMIC_INIT(0);
35580
35581 struct ata_force_param {
35582 const char *name;
35583@@ -4823,7 +4823,7 @@ void ata_qc_free(struct ata_queued_cmd *qc)
35584 struct ata_port *ap;
35585 unsigned int tag;
35586
35587- WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
35588+ BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
35589 ap = qc->ap;
35590
35591 qc->flags = 0;
35592@@ -4839,7 +4839,7 @@ void __ata_qc_complete(struct ata_queued_cmd *qc)
35593 struct ata_port *ap;
35594 struct ata_link *link;
35595
35596- WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
35597+ BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
35598 WARN_ON_ONCE(!(qc->flags & ATA_QCFLAG_ACTIVE));
35599 ap = qc->ap;
35600 link = qc->dev->link;
35601@@ -5958,6 +5958,7 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
35602 return;
35603
35604 spin_lock(&lock);
35605+ pax_open_kernel();
35606
35607 for (cur = ops->inherits; cur; cur = cur->inherits) {
35608 void **inherit = (void **)cur;
35609@@ -5971,8 +5972,9 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
35610 if (IS_ERR(*pp))
35611 *pp = NULL;
35612
35613- ops->inherits = NULL;
35614+ *(struct ata_port_operations **)&ops->inherits = NULL;
35615
35616+ pax_close_kernel();
35617 spin_unlock(&lock);
35618 }
35619
35620@@ -6165,7 +6167,7 @@ int ata_host_register(struct ata_host *host, struct scsi_host_template *sht)
35621
35622 /* give ports names and add SCSI hosts */
35623 for (i = 0; i < host->n_ports; i++) {
35624- host->ports[i]->print_id = atomic_inc_return(&ata_print_id);
35625+ host->ports[i]->print_id = atomic_inc_return_unchecked(&ata_print_id);
35626 host->ports[i]->local_port_no = i + 1;
35627 }
35628
35629diff --git a/drivers/ata/libata-scsi.c b/drivers/ata/libata-scsi.c
35630index 377eb88..8591b44 100644
35631--- a/drivers/ata/libata-scsi.c
35632+++ b/drivers/ata/libata-scsi.c
35633@@ -4135,7 +4135,7 @@ int ata_sas_port_init(struct ata_port *ap)
35634
35635 if (rc)
35636 return rc;
35637- ap->print_id = atomic_inc_return(&ata_print_id);
35638+ ap->print_id = atomic_inc_return_unchecked(&ata_print_id);
35639 return 0;
35640 }
35641 EXPORT_SYMBOL_GPL(ata_sas_port_init);
35642diff --git a/drivers/ata/libata.h b/drivers/ata/libata.h
35643index 45b5ab3..98446b8 100644
35644--- a/drivers/ata/libata.h
35645+++ b/drivers/ata/libata.h
35646@@ -53,7 +53,7 @@ enum {
35647 ATA_DNXFER_QUIET = (1 << 31),
35648 };
35649
35650-extern atomic_t ata_print_id;
35651+extern atomic_unchecked_t ata_print_id;
35652 extern int atapi_passthru16;
35653 extern int libata_fua;
35654 extern int libata_noacpi;
35655diff --git a/drivers/ata/pata_arasan_cf.c b/drivers/ata/pata_arasan_cf.c
35656index 853f610..97d24da 100644
35657--- a/drivers/ata/pata_arasan_cf.c
35658+++ b/drivers/ata/pata_arasan_cf.c
35659@@ -865,7 +865,9 @@ static int arasan_cf_probe(struct platform_device *pdev)
35660 /* Handle platform specific quirks */
35661 if (quirk) {
35662 if (quirk & CF_BROKEN_PIO) {
35663- ap->ops->set_piomode = NULL;
35664+ pax_open_kernel();
35665+ *(void **)&ap->ops->set_piomode = NULL;
35666+ pax_close_kernel();
35667 ap->pio_mask = 0;
35668 }
35669 if (quirk & CF_BROKEN_MWDMA)
35670diff --git a/drivers/atm/adummy.c b/drivers/atm/adummy.c
35671index f9b983a..887b9d8 100644
35672--- a/drivers/atm/adummy.c
35673+++ b/drivers/atm/adummy.c
35674@@ -114,7 +114,7 @@ adummy_send(struct atm_vcc *vcc, struct sk_buff *skb)
35675 vcc->pop(vcc, skb);
35676 else
35677 dev_kfree_skb_any(skb);
35678- atomic_inc(&vcc->stats->tx);
35679+ atomic_inc_unchecked(&vcc->stats->tx);
35680
35681 return 0;
35682 }
35683diff --git a/drivers/atm/ambassador.c b/drivers/atm/ambassador.c
35684index 62a7607..cc4be104 100644
35685--- a/drivers/atm/ambassador.c
35686+++ b/drivers/atm/ambassador.c
35687@@ -454,7 +454,7 @@ static void tx_complete (amb_dev * dev, tx_out * tx) {
35688 PRINTD (DBG_FLOW|DBG_TX, "tx_complete %p %p", dev, tx);
35689
35690 // VC layer stats
35691- atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
35692+ atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
35693
35694 // free the descriptor
35695 kfree (tx_descr);
35696@@ -495,7 +495,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
35697 dump_skb ("<<<", vc, skb);
35698
35699 // VC layer stats
35700- atomic_inc(&atm_vcc->stats->rx);
35701+ atomic_inc_unchecked(&atm_vcc->stats->rx);
35702 __net_timestamp(skb);
35703 // end of our responsibility
35704 atm_vcc->push (atm_vcc, skb);
35705@@ -510,7 +510,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
35706 } else {
35707 PRINTK (KERN_INFO, "dropped over-size frame");
35708 // should we count this?
35709- atomic_inc(&atm_vcc->stats->rx_drop);
35710+ atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
35711 }
35712
35713 } else {
35714@@ -1338,7 +1338,7 @@ static int amb_send (struct atm_vcc * atm_vcc, struct sk_buff * skb) {
35715 }
35716
35717 if (check_area (skb->data, skb->len)) {
35718- atomic_inc(&atm_vcc->stats->tx_err);
35719+ atomic_inc_unchecked(&atm_vcc->stats->tx_err);
35720 return -ENOMEM; // ?
35721 }
35722
35723diff --git a/drivers/atm/atmtcp.c b/drivers/atm/atmtcp.c
35724index 0e3f8f9..765a7a5 100644
35725--- a/drivers/atm/atmtcp.c
35726+++ b/drivers/atm/atmtcp.c
35727@@ -206,7 +206,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
35728 if (vcc->pop) vcc->pop(vcc,skb);
35729 else dev_kfree_skb(skb);
35730 if (dev_data) return 0;
35731- atomic_inc(&vcc->stats->tx_err);
35732+ atomic_inc_unchecked(&vcc->stats->tx_err);
35733 return -ENOLINK;
35734 }
35735 size = skb->len+sizeof(struct atmtcp_hdr);
35736@@ -214,7 +214,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
35737 if (!new_skb) {
35738 if (vcc->pop) vcc->pop(vcc,skb);
35739 else dev_kfree_skb(skb);
35740- atomic_inc(&vcc->stats->tx_err);
35741+ atomic_inc_unchecked(&vcc->stats->tx_err);
35742 return -ENOBUFS;
35743 }
35744 hdr = (void *) skb_put(new_skb,sizeof(struct atmtcp_hdr));
35745@@ -225,8 +225,8 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
35746 if (vcc->pop) vcc->pop(vcc,skb);
35747 else dev_kfree_skb(skb);
35748 out_vcc->push(out_vcc,new_skb);
35749- atomic_inc(&vcc->stats->tx);
35750- atomic_inc(&out_vcc->stats->rx);
35751+ atomic_inc_unchecked(&vcc->stats->tx);
35752+ atomic_inc_unchecked(&out_vcc->stats->rx);
35753 return 0;
35754 }
35755
35756@@ -299,7 +299,7 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
35757 out_vcc = find_vcc(dev, ntohs(hdr->vpi), ntohs(hdr->vci));
35758 read_unlock(&vcc_sklist_lock);
35759 if (!out_vcc) {
35760- atomic_inc(&vcc->stats->tx_err);
35761+ atomic_inc_unchecked(&vcc->stats->tx_err);
35762 goto done;
35763 }
35764 skb_pull(skb,sizeof(struct atmtcp_hdr));
35765@@ -311,8 +311,8 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
35766 __net_timestamp(new_skb);
35767 skb_copy_from_linear_data(skb, skb_put(new_skb, skb->len), skb->len);
35768 out_vcc->push(out_vcc,new_skb);
35769- atomic_inc(&vcc->stats->tx);
35770- atomic_inc(&out_vcc->stats->rx);
35771+ atomic_inc_unchecked(&vcc->stats->tx);
35772+ atomic_inc_unchecked(&out_vcc->stats->rx);
35773 done:
35774 if (vcc->pop) vcc->pop(vcc,skb);
35775 else dev_kfree_skb(skb);
35776diff --git a/drivers/atm/eni.c b/drivers/atm/eni.c
35777index b1955ba..b179940 100644
35778--- a/drivers/atm/eni.c
35779+++ b/drivers/atm/eni.c
35780@@ -522,7 +522,7 @@ static int rx_aal0(struct atm_vcc *vcc)
35781 DPRINTK(DEV_LABEL "(itf %d): trashing empty cell\n",
35782 vcc->dev->number);
35783 length = 0;
35784- atomic_inc(&vcc->stats->rx_err);
35785+ atomic_inc_unchecked(&vcc->stats->rx_err);
35786 }
35787 else {
35788 length = ATM_CELL_SIZE-1; /* no HEC */
35789@@ -577,7 +577,7 @@ static int rx_aal5(struct atm_vcc *vcc)
35790 size);
35791 }
35792 eff = length = 0;
35793- atomic_inc(&vcc->stats->rx_err);
35794+ atomic_inc_unchecked(&vcc->stats->rx_err);
35795 }
35796 else {
35797 size = (descr & MID_RED_COUNT)*(ATM_CELL_PAYLOAD >> 2);
35798@@ -594,7 +594,7 @@ static int rx_aal5(struct atm_vcc *vcc)
35799 "(VCI=%d,length=%ld,size=%ld (descr 0x%lx))\n",
35800 vcc->dev->number,vcc->vci,length,size << 2,descr);
35801 length = eff = 0;
35802- atomic_inc(&vcc->stats->rx_err);
35803+ atomic_inc_unchecked(&vcc->stats->rx_err);
35804 }
35805 }
35806 skb = eff ? atm_alloc_charge(vcc,eff << 2,GFP_ATOMIC) : NULL;
35807@@ -767,7 +767,7 @@ rx_dequeued++;
35808 vcc->push(vcc,skb);
35809 pushed++;
35810 }
35811- atomic_inc(&vcc->stats->rx);
35812+ atomic_inc_unchecked(&vcc->stats->rx);
35813 }
35814 wake_up(&eni_dev->rx_wait);
35815 }
35816@@ -1227,7 +1227,7 @@ static void dequeue_tx(struct atm_dev *dev)
35817 PCI_DMA_TODEVICE);
35818 if (vcc->pop) vcc->pop(vcc,skb);
35819 else dev_kfree_skb_irq(skb);
35820- atomic_inc(&vcc->stats->tx);
35821+ atomic_inc_unchecked(&vcc->stats->tx);
35822 wake_up(&eni_dev->tx_wait);
35823 dma_complete++;
35824 }
35825diff --git a/drivers/atm/firestream.c b/drivers/atm/firestream.c
35826index b41c948..a002b17 100644
35827--- a/drivers/atm/firestream.c
35828+++ b/drivers/atm/firestream.c
35829@@ -749,7 +749,7 @@ static void process_txdone_queue (struct fs_dev *dev, struct queue *q)
35830 }
35831 }
35832
35833- atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
35834+ atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
35835
35836 fs_dprintk (FS_DEBUG_TXMEM, "i");
35837 fs_dprintk (FS_DEBUG_ALLOC, "Free t-skb: %p\n", skb);
35838@@ -816,7 +816,7 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
35839 #endif
35840 skb_put (skb, qe->p1 & 0xffff);
35841 ATM_SKB(skb)->vcc = atm_vcc;
35842- atomic_inc(&atm_vcc->stats->rx);
35843+ atomic_inc_unchecked(&atm_vcc->stats->rx);
35844 __net_timestamp(skb);
35845 fs_dprintk (FS_DEBUG_ALLOC, "Free rec-skb: %p (pushed)\n", skb);
35846 atm_vcc->push (atm_vcc, skb);
35847@@ -837,12 +837,12 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
35848 kfree (pe);
35849 }
35850 if (atm_vcc)
35851- atomic_inc(&atm_vcc->stats->rx_drop);
35852+ atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
35853 break;
35854 case 0x1f: /* Reassembly abort: no buffers. */
35855 /* Silently increment error counter. */
35856 if (atm_vcc)
35857- atomic_inc(&atm_vcc->stats->rx_drop);
35858+ atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
35859 break;
35860 default: /* Hmm. Haven't written the code to handle the others yet... -- REW */
35861 printk (KERN_WARNING "Don't know what to do with RX status %x: %s.\n",
35862diff --git a/drivers/atm/fore200e.c b/drivers/atm/fore200e.c
35863index 204814e..cede831 100644
35864--- a/drivers/atm/fore200e.c
35865+++ b/drivers/atm/fore200e.c
35866@@ -931,9 +931,9 @@ fore200e_tx_irq(struct fore200e* fore200e)
35867 #endif
35868 /* check error condition */
35869 if (*entry->status & STATUS_ERROR)
35870- atomic_inc(&vcc->stats->tx_err);
35871+ atomic_inc_unchecked(&vcc->stats->tx_err);
35872 else
35873- atomic_inc(&vcc->stats->tx);
35874+ atomic_inc_unchecked(&vcc->stats->tx);
35875 }
35876 }
35877
35878@@ -1082,7 +1082,7 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
35879 if (skb == NULL) {
35880 DPRINTK(2, "unable to alloc new skb, rx PDU length = %d\n", pdu_len);
35881
35882- atomic_inc(&vcc->stats->rx_drop);
35883+ atomic_inc_unchecked(&vcc->stats->rx_drop);
35884 return -ENOMEM;
35885 }
35886
35887@@ -1125,14 +1125,14 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
35888
35889 dev_kfree_skb_any(skb);
35890
35891- atomic_inc(&vcc->stats->rx_drop);
35892+ atomic_inc_unchecked(&vcc->stats->rx_drop);
35893 return -ENOMEM;
35894 }
35895
35896 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
35897
35898 vcc->push(vcc, skb);
35899- atomic_inc(&vcc->stats->rx);
35900+ atomic_inc_unchecked(&vcc->stats->rx);
35901
35902 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
35903
35904@@ -1210,7 +1210,7 @@ fore200e_rx_irq(struct fore200e* fore200e)
35905 DPRINTK(2, "damaged PDU on %d.%d.%d\n",
35906 fore200e->atm_dev->number,
35907 entry->rpd->atm_header.vpi, entry->rpd->atm_header.vci);
35908- atomic_inc(&vcc->stats->rx_err);
35909+ atomic_inc_unchecked(&vcc->stats->rx_err);
35910 }
35911 }
35912
35913@@ -1655,7 +1655,7 @@ fore200e_send(struct atm_vcc *vcc, struct sk_buff *skb)
35914 goto retry_here;
35915 }
35916
35917- atomic_inc(&vcc->stats->tx_err);
35918+ atomic_inc_unchecked(&vcc->stats->tx_err);
35919
35920 fore200e->tx_sat++;
35921 DPRINTK(2, "tx queue of device %s is saturated, PDU dropped - heartbeat is %08x\n",
35922diff --git a/drivers/atm/he.c b/drivers/atm/he.c
35923index 8557adc..3fb5d55 100644
35924--- a/drivers/atm/he.c
35925+++ b/drivers/atm/he.c
35926@@ -1691,7 +1691,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
35927
35928 if (RBRQ_HBUF_ERR(he_dev->rbrq_head)) {
35929 hprintk("HBUF_ERR! (cid 0x%x)\n", cid);
35930- atomic_inc(&vcc->stats->rx_drop);
35931+ atomic_inc_unchecked(&vcc->stats->rx_drop);
35932 goto return_host_buffers;
35933 }
35934
35935@@ -1718,7 +1718,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
35936 RBRQ_LEN_ERR(he_dev->rbrq_head)
35937 ? "LEN_ERR" : "",
35938 vcc->vpi, vcc->vci);
35939- atomic_inc(&vcc->stats->rx_err);
35940+ atomic_inc_unchecked(&vcc->stats->rx_err);
35941 goto return_host_buffers;
35942 }
35943
35944@@ -1770,7 +1770,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
35945 vcc->push(vcc, skb);
35946 spin_lock(&he_dev->global_lock);
35947
35948- atomic_inc(&vcc->stats->rx);
35949+ atomic_inc_unchecked(&vcc->stats->rx);
35950
35951 return_host_buffers:
35952 ++pdus_assembled;
35953@@ -2096,7 +2096,7 @@ __enqueue_tpd(struct he_dev *he_dev, struct he_tpd *tpd, unsigned cid)
35954 tpd->vcc->pop(tpd->vcc, tpd->skb);
35955 else
35956 dev_kfree_skb_any(tpd->skb);
35957- atomic_inc(&tpd->vcc->stats->tx_err);
35958+ atomic_inc_unchecked(&tpd->vcc->stats->tx_err);
35959 }
35960 pci_pool_free(he_dev->tpd_pool, tpd, TPD_ADDR(tpd->status));
35961 return;
35962@@ -2508,7 +2508,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
35963 vcc->pop(vcc, skb);
35964 else
35965 dev_kfree_skb_any(skb);
35966- atomic_inc(&vcc->stats->tx_err);
35967+ atomic_inc_unchecked(&vcc->stats->tx_err);
35968 return -EINVAL;
35969 }
35970
35971@@ -2519,7 +2519,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
35972 vcc->pop(vcc, skb);
35973 else
35974 dev_kfree_skb_any(skb);
35975- atomic_inc(&vcc->stats->tx_err);
35976+ atomic_inc_unchecked(&vcc->stats->tx_err);
35977 return -EINVAL;
35978 }
35979 #endif
35980@@ -2531,7 +2531,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
35981 vcc->pop(vcc, skb);
35982 else
35983 dev_kfree_skb_any(skb);
35984- atomic_inc(&vcc->stats->tx_err);
35985+ atomic_inc_unchecked(&vcc->stats->tx_err);
35986 spin_unlock_irqrestore(&he_dev->global_lock, flags);
35987 return -ENOMEM;
35988 }
35989@@ -2573,7 +2573,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
35990 vcc->pop(vcc, skb);
35991 else
35992 dev_kfree_skb_any(skb);
35993- atomic_inc(&vcc->stats->tx_err);
35994+ atomic_inc_unchecked(&vcc->stats->tx_err);
35995 spin_unlock_irqrestore(&he_dev->global_lock, flags);
35996 return -ENOMEM;
35997 }
35998@@ -2604,7 +2604,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
35999 __enqueue_tpd(he_dev, tpd, cid);
36000 spin_unlock_irqrestore(&he_dev->global_lock, flags);
36001
36002- atomic_inc(&vcc->stats->tx);
36003+ atomic_inc_unchecked(&vcc->stats->tx);
36004
36005 return 0;
36006 }
36007diff --git a/drivers/atm/horizon.c b/drivers/atm/horizon.c
36008index 1dc0519..1aadaf7 100644
36009--- a/drivers/atm/horizon.c
36010+++ b/drivers/atm/horizon.c
36011@@ -1034,7 +1034,7 @@ static void rx_schedule (hrz_dev * dev, int irq) {
36012 {
36013 struct atm_vcc * vcc = ATM_SKB(skb)->vcc;
36014 // VC layer stats
36015- atomic_inc(&vcc->stats->rx);
36016+ atomic_inc_unchecked(&vcc->stats->rx);
36017 __net_timestamp(skb);
36018 // end of our responsibility
36019 vcc->push (vcc, skb);
36020@@ -1186,7 +1186,7 @@ static void tx_schedule (hrz_dev * const dev, int irq) {
36021 dev->tx_iovec = NULL;
36022
36023 // VC layer stats
36024- atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
36025+ atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
36026
36027 // free the skb
36028 hrz_kfree_skb (skb);
36029diff --git a/drivers/atm/idt77252.c b/drivers/atm/idt77252.c
36030index 1bdf104..9dc44b1 100644
36031--- a/drivers/atm/idt77252.c
36032+++ b/drivers/atm/idt77252.c
36033@@ -812,7 +812,7 @@ drain_scq(struct idt77252_dev *card, struct vc_map *vc)
36034 else
36035 dev_kfree_skb(skb);
36036
36037- atomic_inc(&vcc->stats->tx);
36038+ atomic_inc_unchecked(&vcc->stats->tx);
36039 }
36040
36041 atomic_dec(&scq->used);
36042@@ -1075,13 +1075,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
36043 if ((sb = dev_alloc_skb(64)) == NULL) {
36044 printk("%s: Can't allocate buffers for aal0.\n",
36045 card->name);
36046- atomic_add(i, &vcc->stats->rx_drop);
36047+ atomic_add_unchecked(i, &vcc->stats->rx_drop);
36048 break;
36049 }
36050 if (!atm_charge(vcc, sb->truesize)) {
36051 RXPRINTK("%s: atm_charge() dropped aal0 packets.\n",
36052 card->name);
36053- atomic_add(i - 1, &vcc->stats->rx_drop);
36054+ atomic_add_unchecked(i - 1, &vcc->stats->rx_drop);
36055 dev_kfree_skb(sb);
36056 break;
36057 }
36058@@ -1098,7 +1098,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
36059 ATM_SKB(sb)->vcc = vcc;
36060 __net_timestamp(sb);
36061 vcc->push(vcc, sb);
36062- atomic_inc(&vcc->stats->rx);
36063+ atomic_inc_unchecked(&vcc->stats->rx);
36064
36065 cell += ATM_CELL_PAYLOAD;
36066 }
36067@@ -1135,13 +1135,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
36068 "(CDC: %08x)\n",
36069 card->name, len, rpp->len, readl(SAR_REG_CDC));
36070 recycle_rx_pool_skb(card, rpp);
36071- atomic_inc(&vcc->stats->rx_err);
36072+ atomic_inc_unchecked(&vcc->stats->rx_err);
36073 return;
36074 }
36075 if (stat & SAR_RSQE_CRC) {
36076 RXPRINTK("%s: AAL5 CRC error.\n", card->name);
36077 recycle_rx_pool_skb(card, rpp);
36078- atomic_inc(&vcc->stats->rx_err);
36079+ atomic_inc_unchecked(&vcc->stats->rx_err);
36080 return;
36081 }
36082 if (skb_queue_len(&rpp->queue) > 1) {
36083@@ -1152,7 +1152,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
36084 RXPRINTK("%s: Can't alloc RX skb.\n",
36085 card->name);
36086 recycle_rx_pool_skb(card, rpp);
36087- atomic_inc(&vcc->stats->rx_err);
36088+ atomic_inc_unchecked(&vcc->stats->rx_err);
36089 return;
36090 }
36091 if (!atm_charge(vcc, skb->truesize)) {
36092@@ -1171,7 +1171,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
36093 __net_timestamp(skb);
36094
36095 vcc->push(vcc, skb);
36096- atomic_inc(&vcc->stats->rx);
36097+ atomic_inc_unchecked(&vcc->stats->rx);
36098
36099 return;
36100 }
36101@@ -1193,7 +1193,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
36102 __net_timestamp(skb);
36103
36104 vcc->push(vcc, skb);
36105- atomic_inc(&vcc->stats->rx);
36106+ atomic_inc_unchecked(&vcc->stats->rx);
36107
36108 if (skb->truesize > SAR_FB_SIZE_3)
36109 add_rx_skb(card, 3, SAR_FB_SIZE_3, 1);
36110@@ -1304,14 +1304,14 @@ idt77252_rx_raw(struct idt77252_dev *card)
36111 if (vcc->qos.aal != ATM_AAL0) {
36112 RPRINTK("%s: raw cell for non AAL0 vc %u.%u\n",
36113 card->name, vpi, vci);
36114- atomic_inc(&vcc->stats->rx_drop);
36115+ atomic_inc_unchecked(&vcc->stats->rx_drop);
36116 goto drop;
36117 }
36118
36119 if ((sb = dev_alloc_skb(64)) == NULL) {
36120 printk("%s: Can't allocate buffers for AAL0.\n",
36121 card->name);
36122- atomic_inc(&vcc->stats->rx_err);
36123+ atomic_inc_unchecked(&vcc->stats->rx_err);
36124 goto drop;
36125 }
36126
36127@@ -1330,7 +1330,7 @@ idt77252_rx_raw(struct idt77252_dev *card)
36128 ATM_SKB(sb)->vcc = vcc;
36129 __net_timestamp(sb);
36130 vcc->push(vcc, sb);
36131- atomic_inc(&vcc->stats->rx);
36132+ atomic_inc_unchecked(&vcc->stats->rx);
36133
36134 drop:
36135 skb_pull(queue, 64);
36136@@ -1955,13 +1955,13 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
36137
36138 if (vc == NULL) {
36139 printk("%s: NULL connection in send().\n", card->name);
36140- atomic_inc(&vcc->stats->tx_err);
36141+ atomic_inc_unchecked(&vcc->stats->tx_err);
36142 dev_kfree_skb(skb);
36143 return -EINVAL;
36144 }
36145 if (!test_bit(VCF_TX, &vc->flags)) {
36146 printk("%s: Trying to transmit on a non-tx VC.\n", card->name);
36147- atomic_inc(&vcc->stats->tx_err);
36148+ atomic_inc_unchecked(&vcc->stats->tx_err);
36149 dev_kfree_skb(skb);
36150 return -EINVAL;
36151 }
36152@@ -1973,14 +1973,14 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
36153 break;
36154 default:
36155 printk("%s: Unsupported AAL: %d\n", card->name, vcc->qos.aal);
36156- atomic_inc(&vcc->stats->tx_err);
36157+ atomic_inc_unchecked(&vcc->stats->tx_err);
36158 dev_kfree_skb(skb);
36159 return -EINVAL;
36160 }
36161
36162 if (skb_shinfo(skb)->nr_frags != 0) {
36163 printk("%s: No scatter-gather yet.\n", card->name);
36164- atomic_inc(&vcc->stats->tx_err);
36165+ atomic_inc_unchecked(&vcc->stats->tx_err);
36166 dev_kfree_skb(skb);
36167 return -EINVAL;
36168 }
36169@@ -1988,7 +1988,7 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
36170
36171 err = queue_skb(card, vc, skb, oam);
36172 if (err) {
36173- atomic_inc(&vcc->stats->tx_err);
36174+ atomic_inc_unchecked(&vcc->stats->tx_err);
36175 dev_kfree_skb(skb);
36176 return err;
36177 }
36178@@ -2011,7 +2011,7 @@ idt77252_send_oam(struct atm_vcc *vcc, void *cell, int flags)
36179 skb = dev_alloc_skb(64);
36180 if (!skb) {
36181 printk("%s: Out of memory in send_oam().\n", card->name);
36182- atomic_inc(&vcc->stats->tx_err);
36183+ atomic_inc_unchecked(&vcc->stats->tx_err);
36184 return -ENOMEM;
36185 }
36186 atomic_add(skb->truesize, &sk_atm(vcc)->sk_wmem_alloc);
36187diff --git a/drivers/atm/iphase.c b/drivers/atm/iphase.c
36188index 4217f29..88f547a 100644
36189--- a/drivers/atm/iphase.c
36190+++ b/drivers/atm/iphase.c
36191@@ -1145,7 +1145,7 @@ static int rx_pkt(struct atm_dev *dev)
36192 status = (u_short) (buf_desc_ptr->desc_mode);
36193 if (status & (RX_CER | RX_PTE | RX_OFL))
36194 {
36195- atomic_inc(&vcc->stats->rx_err);
36196+ atomic_inc_unchecked(&vcc->stats->rx_err);
36197 IF_ERR(printk("IA: bad packet, dropping it");)
36198 if (status & RX_CER) {
36199 IF_ERR(printk(" cause: packet CRC error\n");)
36200@@ -1168,7 +1168,7 @@ static int rx_pkt(struct atm_dev *dev)
36201 len = dma_addr - buf_addr;
36202 if (len > iadev->rx_buf_sz) {
36203 printk("Over %d bytes sdu received, dropped!!!\n", iadev->rx_buf_sz);
36204- atomic_inc(&vcc->stats->rx_err);
36205+ atomic_inc_unchecked(&vcc->stats->rx_err);
36206 goto out_free_desc;
36207 }
36208
36209@@ -1318,7 +1318,7 @@ static void rx_dle_intr(struct atm_dev *dev)
36210 ia_vcc = INPH_IA_VCC(vcc);
36211 if (ia_vcc == NULL)
36212 {
36213- atomic_inc(&vcc->stats->rx_err);
36214+ atomic_inc_unchecked(&vcc->stats->rx_err);
36215 atm_return(vcc, skb->truesize);
36216 dev_kfree_skb_any(skb);
36217 goto INCR_DLE;
36218@@ -1330,7 +1330,7 @@ static void rx_dle_intr(struct atm_dev *dev)
36219 if ((length > iadev->rx_buf_sz) || (length >
36220 (skb->len - sizeof(struct cpcs_trailer))))
36221 {
36222- atomic_inc(&vcc->stats->rx_err);
36223+ atomic_inc_unchecked(&vcc->stats->rx_err);
36224 IF_ERR(printk("rx_dle_intr: Bad AAL5 trailer %d (skb len %d)",
36225 length, skb->len);)
36226 atm_return(vcc, skb->truesize);
36227@@ -1346,7 +1346,7 @@ static void rx_dle_intr(struct atm_dev *dev)
36228
36229 IF_RX(printk("rx_dle_intr: skb push");)
36230 vcc->push(vcc,skb);
36231- atomic_inc(&vcc->stats->rx);
36232+ atomic_inc_unchecked(&vcc->stats->rx);
36233 iadev->rx_pkt_cnt++;
36234 }
36235 INCR_DLE:
36236@@ -2826,15 +2826,15 @@ static int ia_ioctl(struct atm_dev *dev, unsigned int cmd, void __user *arg)
36237 {
36238 struct k_sonet_stats *stats;
36239 stats = &PRIV(_ia_dev[board])->sonet_stats;
36240- printk("section_bip: %d\n", atomic_read(&stats->section_bip));
36241- printk("line_bip : %d\n", atomic_read(&stats->line_bip));
36242- printk("path_bip : %d\n", atomic_read(&stats->path_bip));
36243- printk("line_febe : %d\n", atomic_read(&stats->line_febe));
36244- printk("path_febe : %d\n", atomic_read(&stats->path_febe));
36245- printk("corr_hcs : %d\n", atomic_read(&stats->corr_hcs));
36246- printk("uncorr_hcs : %d\n", atomic_read(&stats->uncorr_hcs));
36247- printk("tx_cells : %d\n", atomic_read(&stats->tx_cells));
36248- printk("rx_cells : %d\n", atomic_read(&stats->rx_cells));
36249+ printk("section_bip: %d\n", atomic_read_unchecked(&stats->section_bip));
36250+ printk("line_bip : %d\n", atomic_read_unchecked(&stats->line_bip));
36251+ printk("path_bip : %d\n", atomic_read_unchecked(&stats->path_bip));
36252+ printk("line_febe : %d\n", atomic_read_unchecked(&stats->line_febe));
36253+ printk("path_febe : %d\n", atomic_read_unchecked(&stats->path_febe));
36254+ printk("corr_hcs : %d\n", atomic_read_unchecked(&stats->corr_hcs));
36255+ printk("uncorr_hcs : %d\n", atomic_read_unchecked(&stats->uncorr_hcs));
36256+ printk("tx_cells : %d\n", atomic_read_unchecked(&stats->tx_cells));
36257+ printk("rx_cells : %d\n", atomic_read_unchecked(&stats->rx_cells));
36258 }
36259 ia_cmds.status = 0;
36260 break;
36261@@ -2939,7 +2939,7 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
36262 if ((desc == 0) || (desc > iadev->num_tx_desc))
36263 {
36264 IF_ERR(printk(DEV_LABEL "invalid desc for send: %d\n", desc);)
36265- atomic_inc(&vcc->stats->tx);
36266+ atomic_inc_unchecked(&vcc->stats->tx);
36267 if (vcc->pop)
36268 vcc->pop(vcc, skb);
36269 else
36270@@ -3044,14 +3044,14 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
36271 ATM_DESC(skb) = vcc->vci;
36272 skb_queue_tail(&iadev->tx_dma_q, skb);
36273
36274- atomic_inc(&vcc->stats->tx);
36275+ atomic_inc_unchecked(&vcc->stats->tx);
36276 iadev->tx_pkt_cnt++;
36277 /* Increment transaction counter */
36278 writel(2, iadev->dma+IPHASE5575_TX_COUNTER);
36279
36280 #if 0
36281 /* add flow control logic */
36282- if (atomic_read(&vcc->stats->tx) % 20 == 0) {
36283+ if (atomic_read_unchecked(&vcc->stats->tx) % 20 == 0) {
36284 if (iavcc->vc_desc_cnt > 10) {
36285 vcc->tx_quota = vcc->tx_quota * 3 / 4;
36286 printk("Tx1: vcc->tx_quota = %d \n", (u32)vcc->tx_quota );
36287diff --git a/drivers/atm/lanai.c b/drivers/atm/lanai.c
36288index fa7d701..1e404c7 100644
36289--- a/drivers/atm/lanai.c
36290+++ b/drivers/atm/lanai.c
36291@@ -1303,7 +1303,7 @@ static void lanai_send_one_aal5(struct lanai_dev *lanai,
36292 vcc_tx_add_aal5_trailer(lvcc, skb->len, 0, 0);
36293 lanai_endtx(lanai, lvcc);
36294 lanai_free_skb(lvcc->tx.atmvcc, skb);
36295- atomic_inc(&lvcc->tx.atmvcc->stats->tx);
36296+ atomic_inc_unchecked(&lvcc->tx.atmvcc->stats->tx);
36297 }
36298
36299 /* Try to fill the buffer - don't call unless there is backlog */
36300@@ -1426,7 +1426,7 @@ static void vcc_rx_aal5(struct lanai_vcc *lvcc, int endptr)
36301 ATM_SKB(skb)->vcc = lvcc->rx.atmvcc;
36302 __net_timestamp(skb);
36303 lvcc->rx.atmvcc->push(lvcc->rx.atmvcc, skb);
36304- atomic_inc(&lvcc->rx.atmvcc->stats->rx);
36305+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx);
36306 out:
36307 lvcc->rx.buf.ptr = end;
36308 cardvcc_write(lvcc, endptr, vcc_rxreadptr);
36309@@ -1667,7 +1667,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
36310 DPRINTK("(itf %d) got RX service entry 0x%X for non-AAL5 "
36311 "vcc %d\n", lanai->number, (unsigned int) s, vci);
36312 lanai->stats.service_rxnotaal5++;
36313- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
36314+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
36315 return 0;
36316 }
36317 if (likely(!(s & (SERVICE_TRASH | SERVICE_STREAM | SERVICE_CRCERR)))) {
36318@@ -1679,7 +1679,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
36319 int bytes;
36320 read_unlock(&vcc_sklist_lock);
36321 DPRINTK("got trashed rx pdu on vci %d\n", vci);
36322- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
36323+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
36324 lvcc->stats.x.aal5.service_trash++;
36325 bytes = (SERVICE_GET_END(s) * 16) -
36326 (((unsigned long) lvcc->rx.buf.ptr) -
36327@@ -1691,7 +1691,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
36328 }
36329 if (s & SERVICE_STREAM) {
36330 read_unlock(&vcc_sklist_lock);
36331- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
36332+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
36333 lvcc->stats.x.aal5.service_stream++;
36334 printk(KERN_ERR DEV_LABEL "(itf %d): Got AAL5 stream "
36335 "PDU on VCI %d!\n", lanai->number, vci);
36336@@ -1699,7 +1699,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
36337 return 0;
36338 }
36339 DPRINTK("got rx crc error on vci %d\n", vci);
36340- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
36341+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
36342 lvcc->stats.x.aal5.service_rxcrc++;
36343 lvcc->rx.buf.ptr = &lvcc->rx.buf.start[SERVICE_GET_END(s) * 4];
36344 cardvcc_write(lvcc, SERVICE_GET_END(s), vcc_rxreadptr);
36345diff --git a/drivers/atm/nicstar.c b/drivers/atm/nicstar.c
36346index 5aca5f4..ce3a6b0 100644
36347--- a/drivers/atm/nicstar.c
36348+++ b/drivers/atm/nicstar.c
36349@@ -1640,7 +1640,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
36350 if ((vc = (vc_map *) vcc->dev_data) == NULL) {
36351 printk("nicstar%d: vcc->dev_data == NULL on ns_send().\n",
36352 card->index);
36353- atomic_inc(&vcc->stats->tx_err);
36354+ atomic_inc_unchecked(&vcc->stats->tx_err);
36355 dev_kfree_skb_any(skb);
36356 return -EINVAL;
36357 }
36358@@ -1648,7 +1648,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
36359 if (!vc->tx) {
36360 printk("nicstar%d: Trying to transmit on a non-tx VC.\n",
36361 card->index);
36362- atomic_inc(&vcc->stats->tx_err);
36363+ atomic_inc_unchecked(&vcc->stats->tx_err);
36364 dev_kfree_skb_any(skb);
36365 return -EINVAL;
36366 }
36367@@ -1656,14 +1656,14 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
36368 if (vcc->qos.aal != ATM_AAL5 && vcc->qos.aal != ATM_AAL0) {
36369 printk("nicstar%d: Only AAL0 and AAL5 are supported.\n",
36370 card->index);
36371- atomic_inc(&vcc->stats->tx_err);
36372+ atomic_inc_unchecked(&vcc->stats->tx_err);
36373 dev_kfree_skb_any(skb);
36374 return -EINVAL;
36375 }
36376
36377 if (skb_shinfo(skb)->nr_frags != 0) {
36378 printk("nicstar%d: No scatter-gather yet.\n", card->index);
36379- atomic_inc(&vcc->stats->tx_err);
36380+ atomic_inc_unchecked(&vcc->stats->tx_err);
36381 dev_kfree_skb_any(skb);
36382 return -EINVAL;
36383 }
36384@@ -1711,11 +1711,11 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
36385 }
36386
36387 if (push_scqe(card, vc, scq, &scqe, skb) != 0) {
36388- atomic_inc(&vcc->stats->tx_err);
36389+ atomic_inc_unchecked(&vcc->stats->tx_err);
36390 dev_kfree_skb_any(skb);
36391 return -EIO;
36392 }
36393- atomic_inc(&vcc->stats->tx);
36394+ atomic_inc_unchecked(&vcc->stats->tx);
36395
36396 return 0;
36397 }
36398@@ -2032,14 +2032,14 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
36399 printk
36400 ("nicstar%d: Can't allocate buffers for aal0.\n",
36401 card->index);
36402- atomic_add(i, &vcc->stats->rx_drop);
36403+ atomic_add_unchecked(i, &vcc->stats->rx_drop);
36404 break;
36405 }
36406 if (!atm_charge(vcc, sb->truesize)) {
36407 RXPRINTK
36408 ("nicstar%d: atm_charge() dropped aal0 packets.\n",
36409 card->index);
36410- atomic_add(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
36411+ atomic_add_unchecked(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
36412 dev_kfree_skb_any(sb);
36413 break;
36414 }
36415@@ -2054,7 +2054,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
36416 ATM_SKB(sb)->vcc = vcc;
36417 __net_timestamp(sb);
36418 vcc->push(vcc, sb);
36419- atomic_inc(&vcc->stats->rx);
36420+ atomic_inc_unchecked(&vcc->stats->rx);
36421 cell += ATM_CELL_PAYLOAD;
36422 }
36423
36424@@ -2071,7 +2071,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
36425 if (iovb == NULL) {
36426 printk("nicstar%d: Out of iovec buffers.\n",
36427 card->index);
36428- atomic_inc(&vcc->stats->rx_drop);
36429+ atomic_inc_unchecked(&vcc->stats->rx_drop);
36430 recycle_rx_buf(card, skb);
36431 return;
36432 }
36433@@ -2095,7 +2095,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
36434 small or large buffer itself. */
36435 } else if (NS_PRV_IOVCNT(iovb) >= NS_MAX_IOVECS) {
36436 printk("nicstar%d: received too big AAL5 SDU.\n", card->index);
36437- atomic_inc(&vcc->stats->rx_err);
36438+ atomic_inc_unchecked(&vcc->stats->rx_err);
36439 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
36440 NS_MAX_IOVECS);
36441 NS_PRV_IOVCNT(iovb) = 0;
36442@@ -2115,7 +2115,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
36443 ("nicstar%d: Expected a small buffer, and this is not one.\n",
36444 card->index);
36445 which_list(card, skb);
36446- atomic_inc(&vcc->stats->rx_err);
36447+ atomic_inc_unchecked(&vcc->stats->rx_err);
36448 recycle_rx_buf(card, skb);
36449 vc->rx_iov = NULL;
36450 recycle_iov_buf(card, iovb);
36451@@ -2128,7 +2128,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
36452 ("nicstar%d: Expected a large buffer, and this is not one.\n",
36453 card->index);
36454 which_list(card, skb);
36455- atomic_inc(&vcc->stats->rx_err);
36456+ atomic_inc_unchecked(&vcc->stats->rx_err);
36457 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
36458 NS_PRV_IOVCNT(iovb));
36459 vc->rx_iov = NULL;
36460@@ -2151,7 +2151,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
36461 printk(" - PDU size mismatch.\n");
36462 else
36463 printk(".\n");
36464- atomic_inc(&vcc->stats->rx_err);
36465+ atomic_inc_unchecked(&vcc->stats->rx_err);
36466 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
36467 NS_PRV_IOVCNT(iovb));
36468 vc->rx_iov = NULL;
36469@@ -2165,7 +2165,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
36470 /* skb points to a small buffer */
36471 if (!atm_charge(vcc, skb->truesize)) {
36472 push_rxbufs(card, skb);
36473- atomic_inc(&vcc->stats->rx_drop);
36474+ atomic_inc_unchecked(&vcc->stats->rx_drop);
36475 } else {
36476 skb_put(skb, len);
36477 dequeue_sm_buf(card, skb);
36478@@ -2175,7 +2175,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
36479 ATM_SKB(skb)->vcc = vcc;
36480 __net_timestamp(skb);
36481 vcc->push(vcc, skb);
36482- atomic_inc(&vcc->stats->rx);
36483+ atomic_inc_unchecked(&vcc->stats->rx);
36484 }
36485 } else if (NS_PRV_IOVCNT(iovb) == 2) { /* One small plus one large buffer */
36486 struct sk_buff *sb;
36487@@ -2186,7 +2186,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
36488 if (len <= NS_SMBUFSIZE) {
36489 if (!atm_charge(vcc, sb->truesize)) {
36490 push_rxbufs(card, sb);
36491- atomic_inc(&vcc->stats->rx_drop);
36492+ atomic_inc_unchecked(&vcc->stats->rx_drop);
36493 } else {
36494 skb_put(sb, len);
36495 dequeue_sm_buf(card, sb);
36496@@ -2196,7 +2196,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
36497 ATM_SKB(sb)->vcc = vcc;
36498 __net_timestamp(sb);
36499 vcc->push(vcc, sb);
36500- atomic_inc(&vcc->stats->rx);
36501+ atomic_inc_unchecked(&vcc->stats->rx);
36502 }
36503
36504 push_rxbufs(card, skb);
36505@@ -2205,7 +2205,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
36506
36507 if (!atm_charge(vcc, skb->truesize)) {
36508 push_rxbufs(card, skb);
36509- atomic_inc(&vcc->stats->rx_drop);
36510+ atomic_inc_unchecked(&vcc->stats->rx_drop);
36511 } else {
36512 dequeue_lg_buf(card, skb);
36513 #ifdef NS_USE_DESTRUCTORS
36514@@ -2218,7 +2218,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
36515 ATM_SKB(skb)->vcc = vcc;
36516 __net_timestamp(skb);
36517 vcc->push(vcc, skb);
36518- atomic_inc(&vcc->stats->rx);
36519+ atomic_inc_unchecked(&vcc->stats->rx);
36520 }
36521
36522 push_rxbufs(card, sb);
36523@@ -2239,7 +2239,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
36524 printk
36525 ("nicstar%d: Out of huge buffers.\n",
36526 card->index);
36527- atomic_inc(&vcc->stats->rx_drop);
36528+ atomic_inc_unchecked(&vcc->stats->rx_drop);
36529 recycle_iovec_rx_bufs(card,
36530 (struct iovec *)
36531 iovb->data,
36532@@ -2290,7 +2290,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
36533 card->hbpool.count++;
36534 } else
36535 dev_kfree_skb_any(hb);
36536- atomic_inc(&vcc->stats->rx_drop);
36537+ atomic_inc_unchecked(&vcc->stats->rx_drop);
36538 } else {
36539 /* Copy the small buffer to the huge buffer */
36540 sb = (struct sk_buff *)iov->iov_base;
36541@@ -2327,7 +2327,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
36542 #endif /* NS_USE_DESTRUCTORS */
36543 __net_timestamp(hb);
36544 vcc->push(vcc, hb);
36545- atomic_inc(&vcc->stats->rx);
36546+ atomic_inc_unchecked(&vcc->stats->rx);
36547 }
36548 }
36549
36550diff --git a/drivers/atm/solos-pci.c b/drivers/atm/solos-pci.c
36551index 32784d1..4a8434a 100644
36552--- a/drivers/atm/solos-pci.c
36553+++ b/drivers/atm/solos-pci.c
36554@@ -838,7 +838,7 @@ void solos_bh(unsigned long card_arg)
36555 }
36556 atm_charge(vcc, skb->truesize);
36557 vcc->push(vcc, skb);
36558- atomic_inc(&vcc->stats->rx);
36559+ atomic_inc_unchecked(&vcc->stats->rx);
36560 break;
36561
36562 case PKT_STATUS:
36563@@ -1116,7 +1116,7 @@ static uint32_t fpga_tx(struct solos_card *card)
36564 vcc = SKB_CB(oldskb)->vcc;
36565
36566 if (vcc) {
36567- atomic_inc(&vcc->stats->tx);
36568+ atomic_inc_unchecked(&vcc->stats->tx);
36569 solos_pop(vcc, oldskb);
36570 } else {
36571 dev_kfree_skb_irq(oldskb);
36572diff --git a/drivers/atm/suni.c b/drivers/atm/suni.c
36573index 0215934..ce9f5b1 100644
36574--- a/drivers/atm/suni.c
36575+++ b/drivers/atm/suni.c
36576@@ -49,8 +49,8 @@ static DEFINE_SPINLOCK(sunis_lock);
36577
36578
36579 #define ADD_LIMITED(s,v) \
36580- atomic_add((v),&stats->s); \
36581- if (atomic_read(&stats->s) < 0) atomic_set(&stats->s,INT_MAX);
36582+ atomic_add_unchecked((v),&stats->s); \
36583+ if (atomic_read_unchecked(&stats->s) < 0) atomic_set_unchecked(&stats->s,INT_MAX);
36584
36585
36586 static void suni_hz(unsigned long from_timer)
36587diff --git a/drivers/atm/uPD98402.c b/drivers/atm/uPD98402.c
36588index 5120a96..e2572bd 100644
36589--- a/drivers/atm/uPD98402.c
36590+++ b/drivers/atm/uPD98402.c
36591@@ -42,7 +42,7 @@ static int fetch_stats(struct atm_dev *dev,struct sonet_stats __user *arg,int ze
36592 struct sonet_stats tmp;
36593 int error = 0;
36594
36595- atomic_add(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
36596+ atomic_add_unchecked(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
36597 sonet_copy_stats(&PRIV(dev)->sonet_stats,&tmp);
36598 if (arg) error = copy_to_user(arg,&tmp,sizeof(tmp));
36599 if (zero && !error) {
36600@@ -161,9 +161,9 @@ static int uPD98402_ioctl(struct atm_dev *dev,unsigned int cmd,void __user *arg)
36601
36602
36603 #define ADD_LIMITED(s,v) \
36604- { atomic_add(GET(v),&PRIV(dev)->sonet_stats.s); \
36605- if (atomic_read(&PRIV(dev)->sonet_stats.s) < 0) \
36606- atomic_set(&PRIV(dev)->sonet_stats.s,INT_MAX); }
36607+ { atomic_add_unchecked(GET(v),&PRIV(dev)->sonet_stats.s); \
36608+ if (atomic_read_unchecked(&PRIV(dev)->sonet_stats.s) < 0) \
36609+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.s,INT_MAX); }
36610
36611
36612 static void stat_event(struct atm_dev *dev)
36613@@ -194,7 +194,7 @@ static void uPD98402_int(struct atm_dev *dev)
36614 if (reason & uPD98402_INT_PFM) stat_event(dev);
36615 if (reason & uPD98402_INT_PCO) {
36616 (void) GET(PCOCR); /* clear interrupt cause */
36617- atomic_add(GET(HECCT),
36618+ atomic_add_unchecked(GET(HECCT),
36619 &PRIV(dev)->sonet_stats.uncorr_hcs);
36620 }
36621 if ((reason & uPD98402_INT_RFO) &&
36622@@ -222,9 +222,9 @@ static int uPD98402_start(struct atm_dev *dev)
36623 PUT(~(uPD98402_INT_PFM | uPD98402_INT_ALM | uPD98402_INT_RFO |
36624 uPD98402_INT_LOS),PIMR); /* enable them */
36625 (void) fetch_stats(dev,NULL,1); /* clear kernel counters */
36626- atomic_set(&PRIV(dev)->sonet_stats.corr_hcs,-1);
36627- atomic_set(&PRIV(dev)->sonet_stats.tx_cells,-1);
36628- atomic_set(&PRIV(dev)->sonet_stats.rx_cells,-1);
36629+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.corr_hcs,-1);
36630+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.tx_cells,-1);
36631+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.rx_cells,-1);
36632 return 0;
36633 }
36634
36635diff --git a/drivers/atm/zatm.c b/drivers/atm/zatm.c
36636index 969c3c2..9b72956 100644
36637--- a/drivers/atm/zatm.c
36638+++ b/drivers/atm/zatm.c
36639@@ -459,7 +459,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
36640 }
36641 if (!size) {
36642 dev_kfree_skb_irq(skb);
36643- if (vcc) atomic_inc(&vcc->stats->rx_err);
36644+ if (vcc) atomic_inc_unchecked(&vcc->stats->rx_err);
36645 continue;
36646 }
36647 if (!atm_charge(vcc,skb->truesize)) {
36648@@ -469,7 +469,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
36649 skb->len = size;
36650 ATM_SKB(skb)->vcc = vcc;
36651 vcc->push(vcc,skb);
36652- atomic_inc(&vcc->stats->rx);
36653+ atomic_inc_unchecked(&vcc->stats->rx);
36654 }
36655 zout(pos & 0xffff,MTA(mbx));
36656 #if 0 /* probably a stupid idea */
36657@@ -733,7 +733,7 @@ if (*ZATM_PRV_DSC(skb) != (uPD98401_TXPD_V | uPD98401_TXPD_DP |
36658 skb_queue_head(&zatm_vcc->backlog,skb);
36659 break;
36660 }
36661- atomic_inc(&vcc->stats->tx);
36662+ atomic_inc_unchecked(&vcc->stats->tx);
36663 wake_up(&zatm_vcc->tx_wait);
36664 }
36665
36666diff --git a/drivers/base/bus.c b/drivers/base/bus.c
36667index 4c289ab..de1c333 100644
36668--- a/drivers/base/bus.c
36669+++ b/drivers/base/bus.c
36670@@ -1193,7 +1193,7 @@ int subsys_interface_register(struct subsys_interface *sif)
36671 return -EINVAL;
36672
36673 mutex_lock(&subsys->p->mutex);
36674- list_add_tail(&sif->node, &subsys->p->interfaces);
36675+ pax_list_add_tail((struct list_head *)&sif->node, &subsys->p->interfaces);
36676 if (sif->add_dev) {
36677 subsys_dev_iter_init(&iter, subsys, NULL, NULL);
36678 while ((dev = subsys_dev_iter_next(&iter)))
36679@@ -1218,7 +1218,7 @@ void subsys_interface_unregister(struct subsys_interface *sif)
36680 subsys = sif->subsys;
36681
36682 mutex_lock(&subsys->p->mutex);
36683- list_del_init(&sif->node);
36684+ pax_list_del_init((struct list_head *)&sif->node);
36685 if (sif->remove_dev) {
36686 subsys_dev_iter_init(&iter, subsys, NULL, NULL);
36687 while ((dev = subsys_dev_iter_next(&iter)))
36688diff --git a/drivers/base/devtmpfs.c b/drivers/base/devtmpfs.c
36689index 7413d06..79155fa 100644
36690--- a/drivers/base/devtmpfs.c
36691+++ b/drivers/base/devtmpfs.c
36692@@ -354,7 +354,7 @@ int devtmpfs_mount(const char *mntdir)
36693 if (!thread)
36694 return 0;
36695
36696- err = sys_mount("devtmpfs", (char *)mntdir, "devtmpfs", MS_SILENT, NULL);
36697+ err = sys_mount((char __force_user *)"devtmpfs", (char __force_user *)mntdir, (char __force_user *)"devtmpfs", MS_SILENT, NULL);
36698 if (err)
36699 printk(KERN_INFO "devtmpfs: error mounting %i\n", err);
36700 else
36701@@ -380,11 +380,11 @@ static int devtmpfsd(void *p)
36702 *err = sys_unshare(CLONE_NEWNS);
36703 if (*err)
36704 goto out;
36705- *err = sys_mount("devtmpfs", "/", "devtmpfs", MS_SILENT, options);
36706+ *err = sys_mount((char __force_user *)"devtmpfs", (char __force_user *)"/", (char __force_user *)"devtmpfs", MS_SILENT, (char __force_user *)options);
36707 if (*err)
36708 goto out;
36709- sys_chdir("/.."); /* will traverse into overmounted root */
36710- sys_chroot(".");
36711+ sys_chdir((char __force_user *)"/.."); /* will traverse into overmounted root */
36712+ sys_chroot((char __force_user *)".");
36713 complete(&setup_done);
36714 while (1) {
36715 spin_lock(&req_lock);
36716diff --git a/drivers/base/node.c b/drivers/base/node.c
36717index bc9f43b..29703b8 100644
36718--- a/drivers/base/node.c
36719+++ b/drivers/base/node.c
36720@@ -620,7 +620,7 @@ static ssize_t print_nodes_state(enum node_states state, char *buf)
36721 struct node_attr {
36722 struct device_attribute attr;
36723 enum node_states state;
36724-};
36725+} __do_const;
36726
36727 static ssize_t show_node_state(struct device *dev,
36728 struct device_attribute *attr, char *buf)
36729diff --git a/drivers/base/power/domain.c b/drivers/base/power/domain.c
36730index bfb8955..42c9b9a 100644
36731--- a/drivers/base/power/domain.c
36732+++ b/drivers/base/power/domain.c
36733@@ -1850,7 +1850,7 @@ int pm_genpd_attach_cpuidle(struct generic_pm_domain *genpd, int state)
36734 {
36735 struct cpuidle_driver *cpuidle_drv;
36736 struct gpd_cpu_data *cpu_data;
36737- struct cpuidle_state *idle_state;
36738+ cpuidle_state_no_const *idle_state;
36739 int ret = 0;
36740
36741 if (IS_ERR_OR_NULL(genpd) || state < 0)
36742@@ -1918,7 +1918,7 @@ int pm_genpd_name_attach_cpuidle(const char *name, int state)
36743 int pm_genpd_detach_cpuidle(struct generic_pm_domain *genpd)
36744 {
36745 struct gpd_cpu_data *cpu_data;
36746- struct cpuidle_state *idle_state;
36747+ cpuidle_state_no_const *idle_state;
36748 int ret = 0;
36749
36750 if (IS_ERR_OR_NULL(genpd))
36751diff --git a/drivers/base/power/sysfs.c b/drivers/base/power/sysfs.c
36752index 03e089a..0e9560c 100644
36753--- a/drivers/base/power/sysfs.c
36754+++ b/drivers/base/power/sysfs.c
36755@@ -185,7 +185,7 @@ static ssize_t rtpm_status_show(struct device *dev,
36756 return -EIO;
36757 }
36758 }
36759- return sprintf(buf, p);
36760+ return sprintf(buf, "%s", p);
36761 }
36762
36763 static DEVICE_ATTR(runtime_status, 0444, rtpm_status_show, NULL);
36764diff --git a/drivers/base/power/wakeup.c b/drivers/base/power/wakeup.c
36765index 2d56f41..8830f19 100644
36766--- a/drivers/base/power/wakeup.c
36767+++ b/drivers/base/power/wakeup.c
36768@@ -29,14 +29,14 @@ bool events_check_enabled __read_mostly;
36769 * They need to be modified together atomically, so it's better to use one
36770 * atomic variable to hold them both.
36771 */
36772-static atomic_t combined_event_count = ATOMIC_INIT(0);
36773+static atomic_unchecked_t combined_event_count = ATOMIC_INIT(0);
36774
36775 #define IN_PROGRESS_BITS (sizeof(int) * 4)
36776 #define MAX_IN_PROGRESS ((1 << IN_PROGRESS_BITS) - 1)
36777
36778 static void split_counters(unsigned int *cnt, unsigned int *inpr)
36779 {
36780- unsigned int comb = atomic_read(&combined_event_count);
36781+ unsigned int comb = atomic_read_unchecked(&combined_event_count);
36782
36783 *cnt = (comb >> IN_PROGRESS_BITS);
36784 *inpr = comb & MAX_IN_PROGRESS;
36785@@ -395,7 +395,7 @@ static void wakeup_source_activate(struct wakeup_source *ws)
36786 ws->start_prevent_time = ws->last_time;
36787
36788 /* Increment the counter of events in progress. */
36789- cec = atomic_inc_return(&combined_event_count);
36790+ cec = atomic_inc_return_unchecked(&combined_event_count);
36791
36792 trace_wakeup_source_activate(ws->name, cec);
36793 }
36794@@ -521,7 +521,7 @@ static void wakeup_source_deactivate(struct wakeup_source *ws)
36795 * Increment the counter of registered wakeup events and decrement the
36796 * couter of wakeup events in progress simultaneously.
36797 */
36798- cec = atomic_add_return(MAX_IN_PROGRESS, &combined_event_count);
36799+ cec = atomic_add_return_unchecked(MAX_IN_PROGRESS, &combined_event_count);
36800 trace_wakeup_source_deactivate(ws->name, cec);
36801
36802 split_counters(&cnt, &inpr);
36803diff --git a/drivers/base/syscore.c b/drivers/base/syscore.c
36804index e8d11b6..7b1b36f 100644
36805--- a/drivers/base/syscore.c
36806+++ b/drivers/base/syscore.c
36807@@ -21,7 +21,7 @@ static DEFINE_MUTEX(syscore_ops_lock);
36808 void register_syscore_ops(struct syscore_ops *ops)
36809 {
36810 mutex_lock(&syscore_ops_lock);
36811- list_add_tail(&ops->node, &syscore_ops_list);
36812+ pax_list_add_tail((struct list_head *)&ops->node, &syscore_ops_list);
36813 mutex_unlock(&syscore_ops_lock);
36814 }
36815 EXPORT_SYMBOL_GPL(register_syscore_ops);
36816@@ -33,7 +33,7 @@ EXPORT_SYMBOL_GPL(register_syscore_ops);
36817 void unregister_syscore_ops(struct syscore_ops *ops)
36818 {
36819 mutex_lock(&syscore_ops_lock);
36820- list_del(&ops->node);
36821+ pax_list_del((struct list_head *)&ops->node);
36822 mutex_unlock(&syscore_ops_lock);
36823 }
36824 EXPORT_SYMBOL_GPL(unregister_syscore_ops);
36825diff --git a/drivers/block/cciss.c b/drivers/block/cciss.c
36826index edfa251..1734d4d 100644
36827--- a/drivers/block/cciss.c
36828+++ b/drivers/block/cciss.c
36829@@ -3011,7 +3011,7 @@ static void start_io(ctlr_info_t *h)
36830 while (!list_empty(&h->reqQ)) {
36831 c = list_entry(h->reqQ.next, CommandList_struct, list);
36832 /* can't do anything if fifo is full */
36833- if ((h->access.fifo_full(h))) {
36834+ if ((h->access->fifo_full(h))) {
36835 dev_warn(&h->pdev->dev, "fifo full\n");
36836 break;
36837 }
36838@@ -3021,7 +3021,7 @@ static void start_io(ctlr_info_t *h)
36839 h->Qdepth--;
36840
36841 /* Tell the controller execute command */
36842- h->access.submit_command(h, c);
36843+ h->access->submit_command(h, c);
36844
36845 /* Put job onto the completed Q */
36846 addQ(&h->cmpQ, c);
36847@@ -3447,17 +3447,17 @@ startio:
36848
36849 static inline unsigned long get_next_completion(ctlr_info_t *h)
36850 {
36851- return h->access.command_completed(h);
36852+ return h->access->command_completed(h);
36853 }
36854
36855 static inline int interrupt_pending(ctlr_info_t *h)
36856 {
36857- return h->access.intr_pending(h);
36858+ return h->access->intr_pending(h);
36859 }
36860
36861 static inline long interrupt_not_for_us(ctlr_info_t *h)
36862 {
36863- return ((h->access.intr_pending(h) == 0) ||
36864+ return ((h->access->intr_pending(h) == 0) ||
36865 (h->interrupts_enabled == 0));
36866 }
36867
36868@@ -3490,7 +3490,7 @@ static inline u32 next_command(ctlr_info_t *h)
36869 u32 a;
36870
36871 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
36872- return h->access.command_completed(h);
36873+ return h->access->command_completed(h);
36874
36875 if ((*(h->reply_pool_head) & 1) == (h->reply_pool_wraparound)) {
36876 a = *(h->reply_pool_head); /* Next cmd in ring buffer */
36877@@ -4047,7 +4047,7 @@ static void cciss_put_controller_into_performant_mode(ctlr_info_t *h)
36878 trans_support & CFGTBL_Trans_use_short_tags);
36879
36880 /* Change the access methods to the performant access methods */
36881- h->access = SA5_performant_access;
36882+ h->access = &SA5_performant_access;
36883 h->transMethod = CFGTBL_Trans_Performant;
36884
36885 return;
36886@@ -4327,7 +4327,7 @@ static int cciss_pci_init(ctlr_info_t *h)
36887 if (prod_index < 0)
36888 return -ENODEV;
36889 h->product_name = products[prod_index].product_name;
36890- h->access = *(products[prod_index].access);
36891+ h->access = products[prod_index].access;
36892
36893 if (cciss_board_disabled(h)) {
36894 dev_warn(&h->pdev->dev, "controller appears to be disabled\n");
36895@@ -5059,7 +5059,7 @@ reinit_after_soft_reset:
36896 }
36897
36898 /* make sure the board interrupts are off */
36899- h->access.set_intr_mask(h, CCISS_INTR_OFF);
36900+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
36901 rc = cciss_request_irq(h, do_cciss_msix_intr, do_cciss_intx);
36902 if (rc)
36903 goto clean2;
36904@@ -5109,7 +5109,7 @@ reinit_after_soft_reset:
36905 * fake ones to scoop up any residual completions.
36906 */
36907 spin_lock_irqsave(&h->lock, flags);
36908- h->access.set_intr_mask(h, CCISS_INTR_OFF);
36909+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
36910 spin_unlock_irqrestore(&h->lock, flags);
36911 free_irq(h->intr[h->intr_mode], h);
36912 rc = cciss_request_irq(h, cciss_msix_discard_completions,
36913@@ -5129,9 +5129,9 @@ reinit_after_soft_reset:
36914 dev_info(&h->pdev->dev, "Board READY.\n");
36915 dev_info(&h->pdev->dev,
36916 "Waiting for stale completions to drain.\n");
36917- h->access.set_intr_mask(h, CCISS_INTR_ON);
36918+ h->access->set_intr_mask(h, CCISS_INTR_ON);
36919 msleep(10000);
36920- h->access.set_intr_mask(h, CCISS_INTR_OFF);
36921+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
36922
36923 rc = controller_reset_failed(h->cfgtable);
36924 if (rc)
36925@@ -5154,7 +5154,7 @@ reinit_after_soft_reset:
36926 cciss_scsi_setup(h);
36927
36928 /* Turn the interrupts on so we can service requests */
36929- h->access.set_intr_mask(h, CCISS_INTR_ON);
36930+ h->access->set_intr_mask(h, CCISS_INTR_ON);
36931
36932 /* Get the firmware version */
36933 inq_buff = kzalloc(sizeof(InquiryData_struct), GFP_KERNEL);
36934@@ -5226,7 +5226,7 @@ static void cciss_shutdown(struct pci_dev *pdev)
36935 kfree(flush_buf);
36936 if (return_code != IO_OK)
36937 dev_warn(&h->pdev->dev, "Error flushing cache\n");
36938- h->access.set_intr_mask(h, CCISS_INTR_OFF);
36939+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
36940 free_irq(h->intr[h->intr_mode], h);
36941 }
36942
36943diff --git a/drivers/block/cciss.h b/drivers/block/cciss.h
36944index 7fda30e..2f27946 100644
36945--- a/drivers/block/cciss.h
36946+++ b/drivers/block/cciss.h
36947@@ -101,7 +101,7 @@ struct ctlr_info
36948 /* information about each logical volume */
36949 drive_info_struct *drv[CISS_MAX_LUN];
36950
36951- struct access_method access;
36952+ struct access_method *access;
36953
36954 /* queue and queue Info */
36955 struct list_head reqQ;
36956@@ -402,27 +402,27 @@ static bool SA5_performant_intr_pending(ctlr_info_t *h)
36957 }
36958
36959 static struct access_method SA5_access = {
36960- SA5_submit_command,
36961- SA5_intr_mask,
36962- SA5_fifo_full,
36963- SA5_intr_pending,
36964- SA5_completed,
36965+ .submit_command = SA5_submit_command,
36966+ .set_intr_mask = SA5_intr_mask,
36967+ .fifo_full = SA5_fifo_full,
36968+ .intr_pending = SA5_intr_pending,
36969+ .command_completed = SA5_completed,
36970 };
36971
36972 static struct access_method SA5B_access = {
36973- SA5_submit_command,
36974- SA5B_intr_mask,
36975- SA5_fifo_full,
36976- SA5B_intr_pending,
36977- SA5_completed,
36978+ .submit_command = SA5_submit_command,
36979+ .set_intr_mask = SA5B_intr_mask,
36980+ .fifo_full = SA5_fifo_full,
36981+ .intr_pending = SA5B_intr_pending,
36982+ .command_completed = SA5_completed,
36983 };
36984
36985 static struct access_method SA5_performant_access = {
36986- SA5_submit_command,
36987- SA5_performant_intr_mask,
36988- SA5_fifo_full,
36989- SA5_performant_intr_pending,
36990- SA5_performant_completed,
36991+ .submit_command = SA5_submit_command,
36992+ .set_intr_mask = SA5_performant_intr_mask,
36993+ .fifo_full = SA5_fifo_full,
36994+ .intr_pending = SA5_performant_intr_pending,
36995+ .command_completed = SA5_performant_completed,
36996 };
36997
36998 struct board_type {
36999diff --git a/drivers/block/cpqarray.c b/drivers/block/cpqarray.c
37000index 2b94403..fd6ad1f 100644
37001--- a/drivers/block/cpqarray.c
37002+++ b/drivers/block/cpqarray.c
37003@@ -404,7 +404,7 @@ static int cpqarray_register_ctlr(int i, struct pci_dev *pdev)
37004 if (register_blkdev(COMPAQ_SMART2_MAJOR+i, hba[i]->devname)) {
37005 goto Enomem4;
37006 }
37007- hba[i]->access.set_intr_mask(hba[i], 0);
37008+ hba[i]->access->set_intr_mask(hba[i], 0);
37009 if (request_irq(hba[i]->intr, do_ida_intr,
37010 IRQF_DISABLED|IRQF_SHARED, hba[i]->devname, hba[i]))
37011 {
37012@@ -459,7 +459,7 @@ static int cpqarray_register_ctlr(int i, struct pci_dev *pdev)
37013 add_timer(&hba[i]->timer);
37014
37015 /* Enable IRQ now that spinlock and rate limit timer are set up */
37016- hba[i]->access.set_intr_mask(hba[i], FIFO_NOT_EMPTY);
37017+ hba[i]->access->set_intr_mask(hba[i], FIFO_NOT_EMPTY);
37018
37019 for(j=0; j<NWD; j++) {
37020 struct gendisk *disk = ida_gendisk[i][j];
37021@@ -694,7 +694,7 @@ DBGINFO(
37022 for(i=0; i<NR_PRODUCTS; i++) {
37023 if (board_id == products[i].board_id) {
37024 c->product_name = products[i].product_name;
37025- c->access = *(products[i].access);
37026+ c->access = products[i].access;
37027 break;
37028 }
37029 }
37030@@ -792,7 +792,7 @@ static int cpqarray_eisa_detect(void)
37031 hba[ctlr]->intr = intr;
37032 sprintf(hba[ctlr]->devname, "ida%d", nr_ctlr);
37033 hba[ctlr]->product_name = products[j].product_name;
37034- hba[ctlr]->access = *(products[j].access);
37035+ hba[ctlr]->access = products[j].access;
37036 hba[ctlr]->ctlr = ctlr;
37037 hba[ctlr]->board_id = board_id;
37038 hba[ctlr]->pci_dev = NULL; /* not PCI */
37039@@ -978,7 +978,7 @@ static void start_io(ctlr_info_t *h)
37040
37041 while((c = h->reqQ) != NULL) {
37042 /* Can't do anything if we're busy */
37043- if (h->access.fifo_full(h) == 0)
37044+ if (h->access->fifo_full(h) == 0)
37045 return;
37046
37047 /* Get the first entry from the request Q */
37048@@ -986,7 +986,7 @@ static void start_io(ctlr_info_t *h)
37049 h->Qdepth--;
37050
37051 /* Tell the controller to do our bidding */
37052- h->access.submit_command(h, c);
37053+ h->access->submit_command(h, c);
37054
37055 /* Get onto the completion Q */
37056 addQ(&h->cmpQ, c);
37057@@ -1048,7 +1048,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
37058 unsigned long flags;
37059 __u32 a,a1;
37060
37061- istat = h->access.intr_pending(h);
37062+ istat = h->access->intr_pending(h);
37063 /* Is this interrupt for us? */
37064 if (istat == 0)
37065 return IRQ_NONE;
37066@@ -1059,7 +1059,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
37067 */
37068 spin_lock_irqsave(IDA_LOCK(h->ctlr), flags);
37069 if (istat & FIFO_NOT_EMPTY) {
37070- while((a = h->access.command_completed(h))) {
37071+ while((a = h->access->command_completed(h))) {
37072 a1 = a; a &= ~3;
37073 if ((c = h->cmpQ) == NULL)
37074 {
37075@@ -1448,11 +1448,11 @@ static int sendcmd(
37076 /*
37077 * Disable interrupt
37078 */
37079- info_p->access.set_intr_mask(info_p, 0);
37080+ info_p->access->set_intr_mask(info_p, 0);
37081 /* Make sure there is room in the command FIFO */
37082 /* Actually it should be completely empty at this time. */
37083 for (i = 200000; i > 0; i--) {
37084- temp = info_p->access.fifo_full(info_p);
37085+ temp = info_p->access->fifo_full(info_p);
37086 if (temp != 0) {
37087 break;
37088 }
37089@@ -1465,7 +1465,7 @@ DBG(
37090 /*
37091 * Send the cmd
37092 */
37093- info_p->access.submit_command(info_p, c);
37094+ info_p->access->submit_command(info_p, c);
37095 complete = pollcomplete(ctlr);
37096
37097 pci_unmap_single(info_p->pci_dev, (dma_addr_t) c->req.sg[0].addr,
37098@@ -1548,9 +1548,9 @@ static int revalidate_allvol(ctlr_info_t *host)
37099 * we check the new geometry. Then turn interrupts back on when
37100 * we're done.
37101 */
37102- host->access.set_intr_mask(host, 0);
37103+ host->access->set_intr_mask(host, 0);
37104 getgeometry(ctlr);
37105- host->access.set_intr_mask(host, FIFO_NOT_EMPTY);
37106+ host->access->set_intr_mask(host, FIFO_NOT_EMPTY);
37107
37108 for(i=0; i<NWD; i++) {
37109 struct gendisk *disk = ida_gendisk[ctlr][i];
37110@@ -1590,7 +1590,7 @@ static int pollcomplete(int ctlr)
37111 /* Wait (up to 2 seconds) for a command to complete */
37112
37113 for (i = 200000; i > 0; i--) {
37114- done = hba[ctlr]->access.command_completed(hba[ctlr]);
37115+ done = hba[ctlr]->access->command_completed(hba[ctlr]);
37116 if (done == 0) {
37117 udelay(10); /* a short fixed delay */
37118 } else
37119diff --git a/drivers/block/cpqarray.h b/drivers/block/cpqarray.h
37120index be73e9d..7fbf140 100644
37121--- a/drivers/block/cpqarray.h
37122+++ b/drivers/block/cpqarray.h
37123@@ -99,7 +99,7 @@ struct ctlr_info {
37124 drv_info_t drv[NWD];
37125 struct proc_dir_entry *proc;
37126
37127- struct access_method access;
37128+ struct access_method *access;
37129
37130 cmdlist_t *reqQ;
37131 cmdlist_t *cmpQ;
37132diff --git a/drivers/block/drbd/drbd_int.h b/drivers/block/drbd/drbd_int.h
37133index 2d7f608..11245fe 100644
37134--- a/drivers/block/drbd/drbd_int.h
37135+++ b/drivers/block/drbd/drbd_int.h
37136@@ -582,7 +582,7 @@ struct drbd_epoch {
37137 struct drbd_tconn *tconn;
37138 struct list_head list;
37139 unsigned int barrier_nr;
37140- atomic_t epoch_size; /* increased on every request added. */
37141+ atomic_unchecked_t epoch_size; /* increased on every request added. */
37142 atomic_t active; /* increased on every req. added, and dec on every finished. */
37143 unsigned long flags;
37144 };
37145@@ -1022,7 +1022,7 @@ struct drbd_conf {
37146 unsigned int al_tr_number;
37147 int al_tr_cycle;
37148 wait_queue_head_t seq_wait;
37149- atomic_t packet_seq;
37150+ atomic_unchecked_t packet_seq;
37151 unsigned int peer_seq;
37152 spinlock_t peer_seq_lock;
37153 unsigned int minor;
37154@@ -1572,7 +1572,7 @@ static inline int drbd_setsockopt(struct socket *sock, int level, int optname,
37155 char __user *uoptval;
37156 int err;
37157
37158- uoptval = (char __user __force *)optval;
37159+ uoptval = (char __force_user *)optval;
37160
37161 set_fs(KERNEL_DS);
37162 if (level == SOL_SOCKET)
37163diff --git a/drivers/block/drbd/drbd_interval.c b/drivers/block/drbd/drbd_interval.c
37164index 89c497c..9c736ae 100644
37165--- a/drivers/block/drbd/drbd_interval.c
37166+++ b/drivers/block/drbd/drbd_interval.c
37167@@ -67,9 +67,9 @@ static void augment_rotate(struct rb_node *rb_old, struct rb_node *rb_new)
37168 }
37169
37170 static const struct rb_augment_callbacks augment_callbacks = {
37171- augment_propagate,
37172- augment_copy,
37173- augment_rotate,
37174+ .propagate = augment_propagate,
37175+ .copy = augment_copy,
37176+ .rotate = augment_rotate,
37177 };
37178
37179 /**
37180diff --git a/drivers/block/drbd/drbd_main.c b/drivers/block/drbd/drbd_main.c
37181index 55635ed..40e837c 100644
37182--- a/drivers/block/drbd/drbd_main.c
37183+++ b/drivers/block/drbd/drbd_main.c
37184@@ -1317,7 +1317,7 @@ static int _drbd_send_ack(struct drbd_conf *mdev, enum drbd_packet cmd,
37185 p->sector = sector;
37186 p->block_id = block_id;
37187 p->blksize = blksize;
37188- p->seq_num = cpu_to_be32(atomic_inc_return(&mdev->packet_seq));
37189+ p->seq_num = cpu_to_be32(atomic_inc_return_unchecked(&mdev->packet_seq));
37190 return drbd_send_command(mdev, sock, cmd, sizeof(*p), NULL, 0);
37191 }
37192
37193@@ -1619,7 +1619,7 @@ int drbd_send_dblock(struct drbd_conf *mdev, struct drbd_request *req)
37194 return -EIO;
37195 p->sector = cpu_to_be64(req->i.sector);
37196 p->block_id = (unsigned long)req;
37197- p->seq_num = cpu_to_be32(atomic_inc_return(&mdev->packet_seq));
37198+ p->seq_num = cpu_to_be32(atomic_inc_return_unchecked(&mdev->packet_seq));
37199 dp_flags = bio_flags_to_wire(mdev, req->master_bio->bi_rw);
37200 if (mdev->state.conn >= C_SYNC_SOURCE &&
37201 mdev->state.conn <= C_PAUSED_SYNC_T)
37202@@ -2574,8 +2574,8 @@ void conn_destroy(struct kref *kref)
37203 {
37204 struct drbd_tconn *tconn = container_of(kref, struct drbd_tconn, kref);
37205
37206- if (atomic_read(&tconn->current_epoch->epoch_size) != 0)
37207- conn_err(tconn, "epoch_size:%d\n", atomic_read(&tconn->current_epoch->epoch_size));
37208+ if (atomic_read_unchecked(&tconn->current_epoch->epoch_size) != 0)
37209+ conn_err(tconn, "epoch_size:%d\n", atomic_read_unchecked(&tconn->current_epoch->epoch_size));
37210 kfree(tconn->current_epoch);
37211
37212 idr_destroy(&tconn->volumes);
37213diff --git a/drivers/block/drbd/drbd_nl.c b/drivers/block/drbd/drbd_nl.c
37214index 8cc1e64..ba7ffa9 100644
37215--- a/drivers/block/drbd/drbd_nl.c
37216+++ b/drivers/block/drbd/drbd_nl.c
37217@@ -3440,7 +3440,7 @@ out:
37218
37219 void drbd_bcast_event(struct drbd_conf *mdev, const struct sib_info *sib)
37220 {
37221- static atomic_t drbd_genl_seq = ATOMIC_INIT(2); /* two. */
37222+ static atomic_unchecked_t drbd_genl_seq = ATOMIC_INIT(2); /* two. */
37223 struct sk_buff *msg;
37224 struct drbd_genlmsghdr *d_out;
37225 unsigned seq;
37226@@ -3453,7 +3453,7 @@ void drbd_bcast_event(struct drbd_conf *mdev, const struct sib_info *sib)
37227 return;
37228 }
37229
37230- seq = atomic_inc_return(&drbd_genl_seq);
37231+ seq = atomic_inc_return_unchecked(&drbd_genl_seq);
37232 msg = genlmsg_new(NLMSG_GOODSIZE, GFP_NOIO);
37233 if (!msg)
37234 goto failed;
37235diff --git a/drivers/block/drbd/drbd_receiver.c b/drivers/block/drbd/drbd_receiver.c
37236index cc29cd3..d4b058b 100644
37237--- a/drivers/block/drbd/drbd_receiver.c
37238+++ b/drivers/block/drbd/drbd_receiver.c
37239@@ -834,7 +834,7 @@ int drbd_connected(struct drbd_conf *mdev)
37240 {
37241 int err;
37242
37243- atomic_set(&mdev->packet_seq, 0);
37244+ atomic_set_unchecked(&mdev->packet_seq, 0);
37245 mdev->peer_seq = 0;
37246
37247 mdev->state_mutex = mdev->tconn->agreed_pro_version < 100 ?
37248@@ -1193,7 +1193,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_tconn *tconn,
37249 do {
37250 next_epoch = NULL;
37251
37252- epoch_size = atomic_read(&epoch->epoch_size);
37253+ epoch_size = atomic_read_unchecked(&epoch->epoch_size);
37254
37255 switch (ev & ~EV_CLEANUP) {
37256 case EV_PUT:
37257@@ -1233,7 +1233,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_tconn *tconn,
37258 rv = FE_DESTROYED;
37259 } else {
37260 epoch->flags = 0;
37261- atomic_set(&epoch->epoch_size, 0);
37262+ atomic_set_unchecked(&epoch->epoch_size, 0);
37263 /* atomic_set(&epoch->active, 0); is already zero */
37264 if (rv == FE_STILL_LIVE)
37265 rv = FE_RECYCLED;
37266@@ -1451,7 +1451,7 @@ static int receive_Barrier(struct drbd_tconn *tconn, struct packet_info *pi)
37267 conn_wait_active_ee_empty(tconn);
37268 drbd_flush(tconn);
37269
37270- if (atomic_read(&tconn->current_epoch->epoch_size)) {
37271+ if (atomic_read_unchecked(&tconn->current_epoch->epoch_size)) {
37272 epoch = kmalloc(sizeof(struct drbd_epoch), GFP_NOIO);
37273 if (epoch)
37274 break;
37275@@ -1464,11 +1464,11 @@ static int receive_Barrier(struct drbd_tconn *tconn, struct packet_info *pi)
37276 }
37277
37278 epoch->flags = 0;
37279- atomic_set(&epoch->epoch_size, 0);
37280+ atomic_set_unchecked(&epoch->epoch_size, 0);
37281 atomic_set(&epoch->active, 0);
37282
37283 spin_lock(&tconn->epoch_lock);
37284- if (atomic_read(&tconn->current_epoch->epoch_size)) {
37285+ if (atomic_read_unchecked(&tconn->current_epoch->epoch_size)) {
37286 list_add(&epoch->list, &tconn->current_epoch->list);
37287 tconn->current_epoch = epoch;
37288 tconn->epochs++;
37289@@ -2172,7 +2172,7 @@ static int receive_Data(struct drbd_tconn *tconn, struct packet_info *pi)
37290
37291 err = wait_for_and_update_peer_seq(mdev, peer_seq);
37292 drbd_send_ack_dp(mdev, P_NEG_ACK, p, pi->size);
37293- atomic_inc(&tconn->current_epoch->epoch_size);
37294+ atomic_inc_unchecked(&tconn->current_epoch->epoch_size);
37295 err2 = drbd_drain_block(mdev, pi->size);
37296 if (!err)
37297 err = err2;
37298@@ -2206,7 +2206,7 @@ static int receive_Data(struct drbd_tconn *tconn, struct packet_info *pi)
37299
37300 spin_lock(&tconn->epoch_lock);
37301 peer_req->epoch = tconn->current_epoch;
37302- atomic_inc(&peer_req->epoch->epoch_size);
37303+ atomic_inc_unchecked(&peer_req->epoch->epoch_size);
37304 atomic_inc(&peer_req->epoch->active);
37305 spin_unlock(&tconn->epoch_lock);
37306
37307@@ -4347,7 +4347,7 @@ struct data_cmd {
37308 int expect_payload;
37309 size_t pkt_size;
37310 int (*fn)(struct drbd_tconn *, struct packet_info *);
37311-};
37312+} __do_const;
37313
37314 static struct data_cmd drbd_cmd_handler[] = {
37315 [P_DATA] = { 1, sizeof(struct p_data), receive_Data },
37316@@ -4467,7 +4467,7 @@ static void conn_disconnect(struct drbd_tconn *tconn)
37317 if (!list_empty(&tconn->current_epoch->list))
37318 conn_err(tconn, "ASSERTION FAILED: tconn->current_epoch->list not empty\n");
37319 /* ok, no more ee's on the fly, it is safe to reset the epoch_size */
37320- atomic_set(&tconn->current_epoch->epoch_size, 0);
37321+ atomic_set_unchecked(&tconn->current_epoch->epoch_size, 0);
37322 tconn->send.seen_any_write_yet = false;
37323
37324 conn_info(tconn, "Connection closed\n");
37325@@ -5223,7 +5223,7 @@ static int tconn_finish_peer_reqs(struct drbd_tconn *tconn)
37326 struct asender_cmd {
37327 size_t pkt_size;
37328 int (*fn)(struct drbd_tconn *tconn, struct packet_info *);
37329-};
37330+} __do_const;
37331
37332 static struct asender_cmd asender_tbl[] = {
37333 [P_PING] = { 0, got_Ping },
37334diff --git a/drivers/block/loop.c b/drivers/block/loop.c
37335index c8dac73..1800093 100644
37336--- a/drivers/block/loop.c
37337+++ b/drivers/block/loop.c
37338@@ -232,7 +232,7 @@ static int __do_lo_send_write(struct file *file,
37339
37340 file_start_write(file);
37341 set_fs(get_ds());
37342- bw = file->f_op->write(file, buf, len, &pos);
37343+ bw = file->f_op->write(file, (const char __force_user *)buf, len, &pos);
37344 set_fs(old_fs);
37345 file_end_write(file);
37346 if (likely(bw == len))
37347diff --git a/drivers/block/pktcdvd.c b/drivers/block/pktcdvd.c
37348index 5618847..5a46f3b 100644
37349--- a/drivers/block/pktcdvd.c
37350+++ b/drivers/block/pktcdvd.c
37351@@ -108,7 +108,7 @@ static int pkt_seq_show(struct seq_file *m, void *p);
37352
37353 static sector_t get_zone(sector_t sector, struct pktcdvd_device *pd)
37354 {
37355- return (sector + pd->offset) & ~(sector_t)(pd->settings.size - 1);
37356+ return (sector + pd->offset) & ~(sector_t)(pd->settings.size - 1UL);
37357 }
37358
37359 /*
37360@@ -1897,7 +1897,7 @@ static noinline_for_stack int pkt_probe_settings(struct pktcdvd_device *pd)
37361 return -EROFS;
37362 }
37363 pd->settings.fp = ti.fp;
37364- pd->offset = (be32_to_cpu(ti.track_start) << 2) & (pd->settings.size - 1);
37365+ pd->offset = (be32_to_cpu(ti.track_start) << 2) & (pd->settings.size - 1UL);
37366
37367 if (ti.nwa_v) {
37368 pd->nwa = be32_to_cpu(ti.next_writable);
37369diff --git a/drivers/block/smart1,2.h b/drivers/block/smart1,2.h
37370index e5565fb..71be10b4 100644
37371--- a/drivers/block/smart1,2.h
37372+++ b/drivers/block/smart1,2.h
37373@@ -108,11 +108,11 @@ static unsigned long smart4_intr_pending(ctlr_info_t *h)
37374 }
37375
37376 static struct access_method smart4_access = {
37377- smart4_submit_command,
37378- smart4_intr_mask,
37379- smart4_fifo_full,
37380- smart4_intr_pending,
37381- smart4_completed,
37382+ .submit_command = smart4_submit_command,
37383+ .set_intr_mask = smart4_intr_mask,
37384+ .fifo_full = smart4_fifo_full,
37385+ .intr_pending = smart4_intr_pending,
37386+ .command_completed = smart4_completed,
37387 };
37388
37389 /*
37390@@ -144,11 +144,11 @@ static unsigned long smart2_intr_pending(ctlr_info_t *h)
37391 }
37392
37393 static struct access_method smart2_access = {
37394- smart2_submit_command,
37395- smart2_intr_mask,
37396- smart2_fifo_full,
37397- smart2_intr_pending,
37398- smart2_completed,
37399+ .submit_command = smart2_submit_command,
37400+ .set_intr_mask = smart2_intr_mask,
37401+ .fifo_full = smart2_fifo_full,
37402+ .intr_pending = smart2_intr_pending,
37403+ .command_completed = smart2_completed,
37404 };
37405
37406 /*
37407@@ -180,11 +180,11 @@ static unsigned long smart2e_intr_pending(ctlr_info_t *h)
37408 }
37409
37410 static struct access_method smart2e_access = {
37411- smart2e_submit_command,
37412- smart2e_intr_mask,
37413- smart2e_fifo_full,
37414- smart2e_intr_pending,
37415- smart2e_completed,
37416+ .submit_command = smart2e_submit_command,
37417+ .set_intr_mask = smart2e_intr_mask,
37418+ .fifo_full = smart2e_fifo_full,
37419+ .intr_pending = smart2e_intr_pending,
37420+ .command_completed = smart2e_completed,
37421 };
37422
37423 /*
37424@@ -270,9 +270,9 @@ static unsigned long smart1_intr_pending(ctlr_info_t *h)
37425 }
37426
37427 static struct access_method smart1_access = {
37428- smart1_submit_command,
37429- smart1_intr_mask,
37430- smart1_fifo_full,
37431- smart1_intr_pending,
37432- smart1_completed,
37433+ .submit_command = smart1_submit_command,
37434+ .set_intr_mask = smart1_intr_mask,
37435+ .fifo_full = smart1_fifo_full,
37436+ .intr_pending = smart1_intr_pending,
37437+ .command_completed = smart1_completed,
37438 };
37439diff --git a/drivers/bluetooth/btwilink.c b/drivers/bluetooth/btwilink.c
37440index 60abf59..80789e1 100644
37441--- a/drivers/bluetooth/btwilink.c
37442+++ b/drivers/bluetooth/btwilink.c
37443@@ -293,7 +293,7 @@ static int ti_st_send_frame(struct sk_buff *skb)
37444
37445 static int bt_ti_probe(struct platform_device *pdev)
37446 {
37447- static struct ti_st *hst;
37448+ struct ti_st *hst;
37449 struct hci_dev *hdev;
37450 int err;
37451
37452diff --git a/drivers/bus/arm-cci.c b/drivers/bus/arm-cci.c
37453index 2009266..7be9ca2 100644
37454--- a/drivers/bus/arm-cci.c
37455+++ b/drivers/bus/arm-cci.c
37456@@ -405,7 +405,7 @@ static int __init cci_probe(void)
37457
37458 nb_cci_ports = cci_config->nb_ace + cci_config->nb_ace_lite;
37459
37460- ports = kcalloc(sizeof(*ports), nb_cci_ports, GFP_KERNEL);
37461+ ports = kcalloc(nb_cci_ports, sizeof(*ports), GFP_KERNEL);
37462 if (!ports)
37463 return -ENOMEM;
37464
37465diff --git a/drivers/cdrom/cdrom.c b/drivers/cdrom/cdrom.c
37466index 8a3aff7..d7538c2 100644
37467--- a/drivers/cdrom/cdrom.c
37468+++ b/drivers/cdrom/cdrom.c
37469@@ -416,7 +416,6 @@ int register_cdrom(struct cdrom_device_info *cdi)
37470 ENSURE(reset, CDC_RESET);
37471 ENSURE(generic_packet, CDC_GENERIC_PACKET);
37472 cdi->mc_flags = 0;
37473- cdo->n_minors = 0;
37474 cdi->options = CDO_USE_FFLAGS;
37475
37476 if (autoclose==1 && CDROM_CAN(CDC_CLOSE_TRAY))
37477@@ -436,8 +435,11 @@ int register_cdrom(struct cdrom_device_info *cdi)
37478 else
37479 cdi->cdda_method = CDDA_OLD;
37480
37481- if (!cdo->generic_packet)
37482- cdo->generic_packet = cdrom_dummy_generic_packet;
37483+ if (!cdo->generic_packet) {
37484+ pax_open_kernel();
37485+ *(void **)&cdo->generic_packet = cdrom_dummy_generic_packet;
37486+ pax_close_kernel();
37487+ }
37488
37489 cdinfo(CD_REG_UNREG, "drive \"/dev/%s\" registered\n", cdi->name);
37490 mutex_lock(&cdrom_mutex);
37491@@ -458,7 +460,6 @@ void unregister_cdrom(struct cdrom_device_info *cdi)
37492 if (cdi->exit)
37493 cdi->exit(cdi);
37494
37495- cdi->ops->n_minors--;
37496 cdinfo(CD_REG_UNREG, "drive \"/dev/%s\" unregistered\n", cdi->name);
37497 }
37498
37499@@ -2107,7 +2108,7 @@ static int cdrom_read_cdda_old(struct cdrom_device_info *cdi, __u8 __user *ubuf,
37500 */
37501 nr = nframes;
37502 do {
37503- cgc.buffer = kmalloc(CD_FRAMESIZE_RAW * nr, GFP_KERNEL);
37504+ cgc.buffer = kzalloc(CD_FRAMESIZE_RAW * nr, GFP_KERNEL);
37505 if (cgc.buffer)
37506 break;
37507
37508@@ -3429,7 +3430,7 @@ static int cdrom_print_info(const char *header, int val, char *info,
37509 struct cdrom_device_info *cdi;
37510 int ret;
37511
37512- ret = scnprintf(info + *pos, max_size - *pos, header);
37513+ ret = scnprintf(info + *pos, max_size - *pos, "%s", header);
37514 if (!ret)
37515 return 1;
37516
37517diff --git a/drivers/cdrom/gdrom.c b/drivers/cdrom/gdrom.c
37518index 5980cb9..6d7bd7e 100644
37519--- a/drivers/cdrom/gdrom.c
37520+++ b/drivers/cdrom/gdrom.c
37521@@ -491,7 +491,6 @@ static struct cdrom_device_ops gdrom_ops = {
37522 .audio_ioctl = gdrom_audio_ioctl,
37523 .capability = CDC_MULTI_SESSION | CDC_MEDIA_CHANGED |
37524 CDC_RESET | CDC_DRIVE_STATUS | CDC_CD_R,
37525- .n_minors = 1,
37526 };
37527
37528 static int gdrom_bdops_open(struct block_device *bdev, fmode_t mode)
37529diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig
37530index 1421997..33f5d6d 100644
37531--- a/drivers/char/Kconfig
37532+++ b/drivers/char/Kconfig
37533@@ -8,7 +8,8 @@ source "drivers/tty/Kconfig"
37534
37535 config DEVKMEM
37536 bool "/dev/kmem virtual device support"
37537- default y
37538+ default n
37539+ depends on !GRKERNSEC_KMEM
37540 help
37541 Say Y here if you want to support the /dev/kmem device. The
37542 /dev/kmem device is rarely used, but can be used for certain
37543@@ -570,6 +571,7 @@ config DEVPORT
37544 bool
37545 depends on !M68K
37546 depends on ISA || PCI
37547+ depends on !GRKERNSEC_KMEM
37548 default y
37549
37550 source "drivers/s390/char/Kconfig"
37551diff --git a/drivers/char/agp/compat_ioctl.c b/drivers/char/agp/compat_ioctl.c
37552index a48e05b..6bac831 100644
37553--- a/drivers/char/agp/compat_ioctl.c
37554+++ b/drivers/char/agp/compat_ioctl.c
37555@@ -108,7 +108,7 @@ static int compat_agpioc_reserve_wrap(struct agp_file_private *priv, void __user
37556 return -ENOMEM;
37557 }
37558
37559- if (copy_from_user(usegment, (void __user *) ureserve.seg_list,
37560+ if (copy_from_user(usegment, (void __force_user *) ureserve.seg_list,
37561 sizeof(*usegment) * ureserve.seg_count)) {
37562 kfree(usegment);
37563 kfree(ksegment);
37564diff --git a/drivers/char/agp/frontend.c b/drivers/char/agp/frontend.c
37565index 1b19239..b87b143 100644
37566--- a/drivers/char/agp/frontend.c
37567+++ b/drivers/char/agp/frontend.c
37568@@ -819,7 +819,7 @@ static int agpioc_reserve_wrap(struct agp_file_private *priv, void __user *arg)
37569 if (copy_from_user(&reserve, arg, sizeof(struct agp_region)))
37570 return -EFAULT;
37571
37572- if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment))
37573+ if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment_priv))
37574 return -EFAULT;
37575
37576 client = agp_find_client_by_pid(reserve.pid);
37577@@ -849,7 +849,7 @@ static int agpioc_reserve_wrap(struct agp_file_private *priv, void __user *arg)
37578 if (segment == NULL)
37579 return -ENOMEM;
37580
37581- if (copy_from_user(segment, (void __user *) reserve.seg_list,
37582+ if (copy_from_user(segment, (void __force_user *) reserve.seg_list,
37583 sizeof(struct agp_segment) * reserve.seg_count)) {
37584 kfree(segment);
37585 return -EFAULT;
37586diff --git a/drivers/char/genrtc.c b/drivers/char/genrtc.c
37587index 4f94375..413694e 100644
37588--- a/drivers/char/genrtc.c
37589+++ b/drivers/char/genrtc.c
37590@@ -273,6 +273,7 @@ static int gen_rtc_ioctl(struct file *file,
37591 switch (cmd) {
37592
37593 case RTC_PLL_GET:
37594+ memset(&pll, 0, sizeof(pll));
37595 if (get_rtc_pll(&pll))
37596 return -EINVAL;
37597 else
37598diff --git a/drivers/char/hpet.c b/drivers/char/hpet.c
37599index 448ce5e..3a76625 100644
37600--- a/drivers/char/hpet.c
37601+++ b/drivers/char/hpet.c
37602@@ -559,7 +559,7 @@ static inline unsigned long hpet_time_div(struct hpets *hpets,
37603 }
37604
37605 static int
37606-hpet_ioctl_common(struct hpet_dev *devp, int cmd, unsigned long arg,
37607+hpet_ioctl_common(struct hpet_dev *devp, unsigned int cmd, unsigned long arg,
37608 struct hpet_info *info)
37609 {
37610 struct hpet_timer __iomem *timer;
37611diff --git a/drivers/char/hw_random/intel-rng.c b/drivers/char/hw_random/intel-rng.c
37612index 86fe45c..c0ea948 100644
37613--- a/drivers/char/hw_random/intel-rng.c
37614+++ b/drivers/char/hw_random/intel-rng.c
37615@@ -314,7 +314,7 @@ PFX "RNG, try using the 'no_fwh_detect' option.\n";
37616
37617 if (no_fwh_detect)
37618 return -ENODEV;
37619- printk(warning);
37620+ printk("%s", warning);
37621 return -EBUSY;
37622 }
37623
37624diff --git a/drivers/char/ipmi/ipmi_msghandler.c b/drivers/char/ipmi/ipmi_msghandler.c
37625index ec4e10f..f2a763b 100644
37626--- a/drivers/char/ipmi/ipmi_msghandler.c
37627+++ b/drivers/char/ipmi/ipmi_msghandler.c
37628@@ -420,7 +420,7 @@ struct ipmi_smi {
37629 struct proc_dir_entry *proc_dir;
37630 char proc_dir_name[10];
37631
37632- atomic_t stats[IPMI_NUM_STATS];
37633+ atomic_unchecked_t stats[IPMI_NUM_STATS];
37634
37635 /*
37636 * run_to_completion duplicate of smb_info, smi_info
37637@@ -453,9 +453,9 @@ static DEFINE_MUTEX(smi_watchers_mutex);
37638
37639
37640 #define ipmi_inc_stat(intf, stat) \
37641- atomic_inc(&(intf)->stats[IPMI_STAT_ ## stat])
37642+ atomic_inc_unchecked(&(intf)->stats[IPMI_STAT_ ## stat])
37643 #define ipmi_get_stat(intf, stat) \
37644- ((unsigned int) atomic_read(&(intf)->stats[IPMI_STAT_ ## stat]))
37645+ ((unsigned int) atomic_read_unchecked(&(intf)->stats[IPMI_STAT_ ## stat]))
37646
37647 static int is_lan_addr(struct ipmi_addr *addr)
37648 {
37649@@ -2883,7 +2883,7 @@ int ipmi_register_smi(struct ipmi_smi_handlers *handlers,
37650 INIT_LIST_HEAD(&intf->cmd_rcvrs);
37651 init_waitqueue_head(&intf->waitq);
37652 for (i = 0; i < IPMI_NUM_STATS; i++)
37653- atomic_set(&intf->stats[i], 0);
37654+ atomic_set_unchecked(&intf->stats[i], 0);
37655
37656 intf->proc_dir = NULL;
37657
37658diff --git a/drivers/char/ipmi/ipmi_si_intf.c b/drivers/char/ipmi/ipmi_si_intf.c
37659index 15e4a60..b046093 100644
37660--- a/drivers/char/ipmi/ipmi_si_intf.c
37661+++ b/drivers/char/ipmi/ipmi_si_intf.c
37662@@ -280,7 +280,7 @@ struct smi_info {
37663 unsigned char slave_addr;
37664
37665 /* Counters and things for the proc filesystem. */
37666- atomic_t stats[SI_NUM_STATS];
37667+ atomic_unchecked_t stats[SI_NUM_STATS];
37668
37669 struct task_struct *thread;
37670
37671@@ -289,9 +289,9 @@ struct smi_info {
37672 };
37673
37674 #define smi_inc_stat(smi, stat) \
37675- atomic_inc(&(smi)->stats[SI_STAT_ ## stat])
37676+ atomic_inc_unchecked(&(smi)->stats[SI_STAT_ ## stat])
37677 #define smi_get_stat(smi, stat) \
37678- ((unsigned int) atomic_read(&(smi)->stats[SI_STAT_ ## stat]))
37679+ ((unsigned int) atomic_read_unchecked(&(smi)->stats[SI_STAT_ ## stat]))
37680
37681 #define SI_MAX_PARMS 4
37682
37683@@ -3324,7 +3324,7 @@ static int try_smi_init(struct smi_info *new_smi)
37684 atomic_set(&new_smi->req_events, 0);
37685 new_smi->run_to_completion = 0;
37686 for (i = 0; i < SI_NUM_STATS; i++)
37687- atomic_set(&new_smi->stats[i], 0);
37688+ atomic_set_unchecked(&new_smi->stats[i], 0);
37689
37690 new_smi->interrupt_disabled = 1;
37691 atomic_set(&new_smi->stop_operation, 0);
37692diff --git a/drivers/char/mem.c b/drivers/char/mem.c
37693index f895a8c..2bc9147 100644
37694--- a/drivers/char/mem.c
37695+++ b/drivers/char/mem.c
37696@@ -18,6 +18,7 @@
37697 #include <linux/raw.h>
37698 #include <linux/tty.h>
37699 #include <linux/capability.h>
37700+#include <linux/security.h>
37701 #include <linux/ptrace.h>
37702 #include <linux/device.h>
37703 #include <linux/highmem.h>
37704@@ -37,6 +38,10 @@
37705
37706 #define DEVPORT_MINOR 4
37707
37708+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
37709+extern const struct file_operations grsec_fops;
37710+#endif
37711+
37712 static inline unsigned long size_inside_page(unsigned long start,
37713 unsigned long size)
37714 {
37715@@ -68,9 +73,13 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
37716
37717 while (cursor < to) {
37718 if (!devmem_is_allowed(pfn)) {
37719+#ifdef CONFIG_GRKERNSEC_KMEM
37720+ gr_handle_mem_readwrite(from, to);
37721+#else
37722 printk(KERN_INFO
37723 "Program %s tried to access /dev/mem between %Lx->%Lx.\n",
37724 current->comm, from, to);
37725+#endif
37726 return 0;
37727 }
37728 cursor += PAGE_SIZE;
37729@@ -78,6 +87,11 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
37730 }
37731 return 1;
37732 }
37733+#elif defined(CONFIG_GRKERNSEC_KMEM)
37734+static inline int range_is_allowed(unsigned long pfn, unsigned long size)
37735+{
37736+ return 0;
37737+}
37738 #else
37739 static inline int range_is_allowed(unsigned long pfn, unsigned long size)
37740 {
37741@@ -120,6 +134,7 @@ static ssize_t read_mem(struct file *file, char __user *buf,
37742
37743 while (count > 0) {
37744 unsigned long remaining;
37745+ char *temp;
37746
37747 sz = size_inside_page(p, count);
37748
37749@@ -135,7 +150,23 @@ static ssize_t read_mem(struct file *file, char __user *buf,
37750 if (!ptr)
37751 return -EFAULT;
37752
37753- remaining = copy_to_user(buf, ptr, sz);
37754+#ifdef CONFIG_PAX_USERCOPY
37755+ temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
37756+ if (!temp) {
37757+ unxlate_dev_mem_ptr(p, ptr);
37758+ return -ENOMEM;
37759+ }
37760+ memcpy(temp, ptr, sz);
37761+#else
37762+ temp = ptr;
37763+#endif
37764+
37765+ remaining = copy_to_user(buf, temp, sz);
37766+
37767+#ifdef CONFIG_PAX_USERCOPY
37768+ kfree(temp);
37769+#endif
37770+
37771 unxlate_dev_mem_ptr(p, ptr);
37772 if (remaining)
37773 return -EFAULT;
37774@@ -364,9 +395,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
37775 size_t count, loff_t *ppos)
37776 {
37777 unsigned long p = *ppos;
37778- ssize_t low_count, read, sz;
37779+ ssize_t low_count, read, sz, err = 0;
37780 char *kbuf; /* k-addr because vread() takes vmlist_lock rwlock */
37781- int err = 0;
37782
37783 read = 0;
37784 if (p < (unsigned long) high_memory) {
37785@@ -388,6 +418,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
37786 }
37787 #endif
37788 while (low_count > 0) {
37789+ char *temp;
37790+
37791 sz = size_inside_page(p, low_count);
37792
37793 /*
37794@@ -397,7 +429,22 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
37795 */
37796 kbuf = xlate_dev_kmem_ptr((char *)p);
37797
37798- if (copy_to_user(buf, kbuf, sz))
37799+#ifdef CONFIG_PAX_USERCOPY
37800+ temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
37801+ if (!temp)
37802+ return -ENOMEM;
37803+ memcpy(temp, kbuf, sz);
37804+#else
37805+ temp = kbuf;
37806+#endif
37807+
37808+ err = copy_to_user(buf, temp, sz);
37809+
37810+#ifdef CONFIG_PAX_USERCOPY
37811+ kfree(temp);
37812+#endif
37813+
37814+ if (err)
37815 return -EFAULT;
37816 buf += sz;
37817 p += sz;
37818@@ -822,6 +869,9 @@ static const struct memdev {
37819 #ifdef CONFIG_PRINTK
37820 [11] = { "kmsg", 0644, &kmsg_fops, NULL },
37821 #endif
37822+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
37823+ [13] = { "grsec",S_IRUSR | S_IWUGO, &grsec_fops, NULL },
37824+#endif
37825 };
37826
37827 static int memory_open(struct inode *inode, struct file *filp)
37828@@ -893,7 +943,7 @@ static int __init chr_dev_init(void)
37829 continue;
37830
37831 device_create(mem_class, NULL, MKDEV(MEM_MAJOR, minor),
37832- NULL, devlist[minor].name);
37833+ NULL, "%s", devlist[minor].name);
37834 }
37835
37836 return tty_init();
37837diff --git a/drivers/char/nvram.c b/drivers/char/nvram.c
37838index 9df78e2..01ba9ae 100644
37839--- a/drivers/char/nvram.c
37840+++ b/drivers/char/nvram.c
37841@@ -247,7 +247,7 @@ static ssize_t nvram_read(struct file *file, char __user *buf,
37842
37843 spin_unlock_irq(&rtc_lock);
37844
37845- if (copy_to_user(buf, contents, tmp - contents))
37846+ if (tmp - contents > sizeof(contents) || copy_to_user(buf, contents, tmp - contents))
37847 return -EFAULT;
37848
37849 *ppos = i;
37850diff --git a/drivers/char/pcmcia/synclink_cs.c b/drivers/char/pcmcia/synclink_cs.c
37851index d39cca6..8c1e269 100644
37852--- a/drivers/char/pcmcia/synclink_cs.c
37853+++ b/drivers/char/pcmcia/synclink_cs.c
37854@@ -2345,9 +2345,9 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
37855
37856 if (debug_level >= DEBUG_LEVEL_INFO)
37857 printk("%s(%d):mgslpc_close(%s) entry, count=%d\n",
37858- __FILE__, __LINE__, info->device_name, port->count);
37859+ __FILE__, __LINE__, info->device_name, atomic_read(&port->count));
37860
37861- WARN_ON(!port->count);
37862+ WARN_ON(!atomic_read(&port->count));
37863
37864 if (tty_port_close_start(port, tty, filp) == 0)
37865 goto cleanup;
37866@@ -2365,7 +2365,7 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
37867 cleanup:
37868 if (debug_level >= DEBUG_LEVEL_INFO)
37869 printk("%s(%d):mgslpc_close(%s) exit, count=%d\n", __FILE__, __LINE__,
37870- tty->driver->name, port->count);
37871+ tty->driver->name, atomic_read(&port->count));
37872 }
37873
37874 /* Wait until the transmitter is empty.
37875@@ -2507,7 +2507,7 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
37876
37877 if (debug_level >= DEBUG_LEVEL_INFO)
37878 printk("%s(%d):mgslpc_open(%s), old ref count = %d\n",
37879- __FILE__, __LINE__, tty->driver->name, port->count);
37880+ __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
37881
37882 /* If port is closing, signal caller to try again */
37883 if (tty_hung_up_p(filp) || port->flags & ASYNC_CLOSING){
37884@@ -2527,11 +2527,11 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
37885 goto cleanup;
37886 }
37887 spin_lock(&port->lock);
37888- port->count++;
37889+ atomic_inc(&port->count);
37890 spin_unlock(&port->lock);
37891 spin_unlock_irqrestore(&info->netlock, flags);
37892
37893- if (port->count == 1) {
37894+ if (atomic_read(&port->count) == 1) {
37895 /* 1st open on this device, init hardware */
37896 retval = startup(info, tty);
37897 if (retval < 0)
37898@@ -3920,7 +3920,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
37899 unsigned short new_crctype;
37900
37901 /* return error if TTY interface open */
37902- if (info->port.count)
37903+ if (atomic_read(&info->port.count))
37904 return -EBUSY;
37905
37906 switch (encoding)
37907@@ -4024,7 +4024,7 @@ static int hdlcdev_open(struct net_device *dev)
37908
37909 /* arbitrate between network and tty opens */
37910 spin_lock_irqsave(&info->netlock, flags);
37911- if (info->port.count != 0 || info->netcount != 0) {
37912+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
37913 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
37914 spin_unlock_irqrestore(&info->netlock, flags);
37915 return -EBUSY;
37916@@ -4114,7 +4114,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
37917 printk("%s:hdlcdev_ioctl(%s)\n", __FILE__, dev->name);
37918
37919 /* return error if TTY interface open */
37920- if (info->port.count)
37921+ if (atomic_read(&info->port.count))
37922 return -EBUSY;
37923
37924 if (cmd != SIOCWANDEV)
37925diff --git a/drivers/char/random.c b/drivers/char/random.c
37926index 7a744d3..895af8f 100644
37927--- a/drivers/char/random.c
37928+++ b/drivers/char/random.c
37929@@ -269,8 +269,13 @@
37930 /*
37931 * Configuration information
37932 */
37933+#ifdef CONFIG_GRKERNSEC_RANDNET
37934+#define INPUT_POOL_WORDS 512
37935+#define OUTPUT_POOL_WORDS 128
37936+#else
37937 #define INPUT_POOL_WORDS 128
37938 #define OUTPUT_POOL_WORDS 32
37939+#endif
37940 #define SEC_XFER_SIZE 512
37941 #define EXTRACT_SIZE 10
37942
37943@@ -310,10 +315,17 @@ static struct poolinfo {
37944 int poolwords;
37945 int tap1, tap2, tap3, tap4, tap5;
37946 } poolinfo_table[] = {
37947+#ifdef CONFIG_GRKERNSEC_RANDNET
37948+ /* x^512 + x^411 + x^308 + x^208 +x^104 + x + 1 -- 225 */
37949+ { 512, 411, 308, 208, 104, 1 },
37950+ /* x^128 + x^103 + x^76 + x^51 + x^25 + x + 1 -- 105 */
37951+ { 128, 103, 76, 51, 25, 1 },
37952+#else
37953 /* x^128 + x^103 + x^76 + x^51 +x^25 + x + 1 -- 105 */
37954 { 128, 103, 76, 51, 25, 1 },
37955 /* x^32 + x^26 + x^20 + x^14 + x^7 + x + 1 -- 15 */
37956 { 32, 26, 20, 14, 7, 1 },
37957+#endif
37958 #if 0
37959 /* x^2048 + x^1638 + x^1231 + x^819 + x^411 + x + 1 -- 115 */
37960 { 2048, 1638, 1231, 819, 411, 1 },
37961@@ -521,8 +533,8 @@ static void _mix_pool_bytes(struct entropy_store *r, const void *in,
37962 input_rotate += i ? 7 : 14;
37963 }
37964
37965- ACCESS_ONCE(r->input_rotate) = input_rotate;
37966- ACCESS_ONCE(r->add_ptr) = i;
37967+ ACCESS_ONCE_RW(r->input_rotate) = input_rotate;
37968+ ACCESS_ONCE_RW(r->add_ptr) = i;
37969 smp_wmb();
37970
37971 if (out)
37972@@ -603,8 +615,11 @@ retry:
37973
37974 if (!r->initialized && nbits > 0) {
37975 r->entropy_total += nbits;
37976- if (r->entropy_total > 128)
37977+ if (r->entropy_total > 128) {
37978 r->initialized = 1;
37979+ if (r == &nonblocking_pool)
37980+ prandom_reseed_late();
37981+ }
37982 }
37983
37984 trace_credit_entropy_bits(r->name, nbits, entropy_count,
37985@@ -1029,7 +1044,7 @@ static ssize_t extract_entropy_user(struct entropy_store *r, void __user *buf,
37986
37987 extract_buf(r, tmp);
37988 i = min_t(int, nbytes, EXTRACT_SIZE);
37989- if (copy_to_user(buf, tmp, i)) {
37990+ if (i > sizeof(tmp) || copy_to_user(buf, tmp, i)) {
37991 ret = -EFAULT;
37992 break;
37993 }
37994@@ -1365,7 +1380,7 @@ EXPORT_SYMBOL(generate_random_uuid);
37995 #include <linux/sysctl.h>
37996
37997 static int min_read_thresh = 8, min_write_thresh;
37998-static int max_read_thresh = INPUT_POOL_WORDS * 32;
37999+static int max_read_thresh = OUTPUT_POOL_WORDS * 32;
38000 static int max_write_thresh = INPUT_POOL_WORDS * 32;
38001 static char sysctl_bootid[16];
38002
38003@@ -1381,7 +1396,7 @@ static char sysctl_bootid[16];
38004 static int proc_do_uuid(struct ctl_table *table, int write,
38005 void __user *buffer, size_t *lenp, loff_t *ppos)
38006 {
38007- struct ctl_table fake_table;
38008+ ctl_table_no_const fake_table;
38009 unsigned char buf[64], tmp_uuid[16], *uuid;
38010
38011 uuid = table->data;
38012diff --git a/drivers/char/sonypi.c b/drivers/char/sonypi.c
38013index 7cc1fe22..b602d6b 100644
38014--- a/drivers/char/sonypi.c
38015+++ b/drivers/char/sonypi.c
38016@@ -54,6 +54,7 @@
38017
38018 #include <asm/uaccess.h>
38019 #include <asm/io.h>
38020+#include <asm/local.h>
38021
38022 #include <linux/sonypi.h>
38023
38024@@ -490,7 +491,7 @@ static struct sonypi_device {
38025 spinlock_t fifo_lock;
38026 wait_queue_head_t fifo_proc_list;
38027 struct fasync_struct *fifo_async;
38028- int open_count;
38029+ local_t open_count;
38030 int model;
38031 struct input_dev *input_jog_dev;
38032 struct input_dev *input_key_dev;
38033@@ -892,7 +893,7 @@ static int sonypi_misc_fasync(int fd, struct file *filp, int on)
38034 static int sonypi_misc_release(struct inode *inode, struct file *file)
38035 {
38036 mutex_lock(&sonypi_device.lock);
38037- sonypi_device.open_count--;
38038+ local_dec(&sonypi_device.open_count);
38039 mutex_unlock(&sonypi_device.lock);
38040 return 0;
38041 }
38042@@ -901,9 +902,9 @@ static int sonypi_misc_open(struct inode *inode, struct file *file)
38043 {
38044 mutex_lock(&sonypi_device.lock);
38045 /* Flush input queue on first open */
38046- if (!sonypi_device.open_count)
38047+ if (!local_read(&sonypi_device.open_count))
38048 kfifo_reset(&sonypi_device.fifo);
38049- sonypi_device.open_count++;
38050+ local_inc(&sonypi_device.open_count);
38051 mutex_unlock(&sonypi_device.lock);
38052
38053 return 0;
38054diff --git a/drivers/char/tpm/tpm_acpi.c b/drivers/char/tpm/tpm_acpi.c
38055index 64420b3..5c40b56 100644
38056--- a/drivers/char/tpm/tpm_acpi.c
38057+++ b/drivers/char/tpm/tpm_acpi.c
38058@@ -98,11 +98,12 @@ int read_log(struct tpm_bios_log *log)
38059 virt = acpi_os_map_memory(start, len);
38060 if (!virt) {
38061 kfree(log->bios_event_log);
38062+ log->bios_event_log = NULL;
38063 printk("%s: ERROR - Unable to map memory\n", __func__);
38064 return -EIO;
38065 }
38066
38067- memcpy_fromio(log->bios_event_log, virt, len);
38068+ memcpy_fromio(log->bios_event_log, (const char __force_kernel *)virt, len);
38069
38070 acpi_os_unmap_memory(virt, len);
38071 return 0;
38072diff --git a/drivers/char/tpm/tpm_eventlog.c b/drivers/char/tpm/tpm_eventlog.c
38073index 84ddc55..1d32f1e 100644
38074--- a/drivers/char/tpm/tpm_eventlog.c
38075+++ b/drivers/char/tpm/tpm_eventlog.c
38076@@ -95,7 +95,7 @@ static void *tpm_bios_measurements_start(struct seq_file *m, loff_t *pos)
38077 event = addr;
38078
38079 if ((event->event_type == 0 && event->event_size == 0) ||
38080- ((addr + sizeof(struct tcpa_event) + event->event_size) >= limit))
38081+ (event->event_size >= limit - addr - sizeof(struct tcpa_event)))
38082 return NULL;
38083
38084 return addr;
38085@@ -120,7 +120,7 @@ static void *tpm_bios_measurements_next(struct seq_file *m, void *v,
38086 return NULL;
38087
38088 if ((event->event_type == 0 && event->event_size == 0) ||
38089- ((v + sizeof(struct tcpa_event) + event->event_size) >= limit))
38090+ (event->event_size >= limit - v - sizeof(struct tcpa_event)))
38091 return NULL;
38092
38093 (*pos)++;
38094@@ -213,7 +213,8 @@ static int tpm_binary_bios_measurements_show(struct seq_file *m, void *v)
38095 int i;
38096
38097 for (i = 0; i < sizeof(struct tcpa_event) + event->event_size; i++)
38098- seq_putc(m, data[i]);
38099+ if (!seq_putc(m, data[i]))
38100+ return -EFAULT;
38101
38102 return 0;
38103 }
38104diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c
38105index b79cf3e..de172d64f 100644
38106--- a/drivers/char/virtio_console.c
38107+++ b/drivers/char/virtio_console.c
38108@@ -682,7 +682,7 @@ static ssize_t fill_readbuf(struct port *port, char *out_buf, size_t out_count,
38109 if (to_user) {
38110 ssize_t ret;
38111
38112- ret = copy_to_user(out_buf, buf->buf + buf->offset, out_count);
38113+ ret = copy_to_user((char __force_user *)out_buf, buf->buf + buf->offset, out_count);
38114 if (ret)
38115 return -EFAULT;
38116 } else {
38117@@ -785,7 +785,7 @@ static ssize_t port_fops_read(struct file *filp, char __user *ubuf,
38118 if (!port_has_data(port) && !port->host_connected)
38119 return 0;
38120
38121- return fill_readbuf(port, ubuf, count, true);
38122+ return fill_readbuf(port, (char __force_kernel *)ubuf, count, true);
38123 }
38124
38125 static int wait_port_writable(struct port *port, bool nonblock)
38126diff --git a/drivers/clk/clk-composite.c b/drivers/clk/clk-composite.c
38127index a33f46f..a720eed 100644
38128--- a/drivers/clk/clk-composite.c
38129+++ b/drivers/clk/clk-composite.c
38130@@ -122,7 +122,7 @@ struct clk *clk_register_composite(struct device *dev, const char *name,
38131 struct clk *clk;
38132 struct clk_init_data init;
38133 struct clk_composite *composite;
38134- struct clk_ops *clk_composite_ops;
38135+ clk_ops_no_const *clk_composite_ops;
38136
38137 composite = kzalloc(sizeof(*composite), GFP_KERNEL);
38138 if (!composite) {
38139diff --git a/drivers/clk/socfpga/clk.c b/drivers/clk/socfpga/clk.c
38140index 81dd31a..ef5c542 100644
38141--- a/drivers/clk/socfpga/clk.c
38142+++ b/drivers/clk/socfpga/clk.c
38143@@ -22,6 +22,7 @@
38144 #include <linux/clk-provider.h>
38145 #include <linux/io.h>
38146 #include <linux/of.h>
38147+#include <asm/pgtable.h>
38148
38149 /* Clock Manager offsets */
38150 #define CLKMGR_CTRL 0x0
38151@@ -152,8 +153,10 @@ static __init struct clk *socfpga_clk_init(struct device_node *node,
38152 streq(clk_name, "periph_pll") ||
38153 streq(clk_name, "sdram_pll")) {
38154 socfpga_clk->hw.bit_idx = SOCFPGA_PLL_EXT_ENA;
38155- clk_pll_ops.enable = clk_gate_ops.enable;
38156- clk_pll_ops.disable = clk_gate_ops.disable;
38157+ pax_open_kernel();
38158+ *(void **)&clk_pll_ops.enable = clk_gate_ops.enable;
38159+ *(void **)&clk_pll_ops.disable = clk_gate_ops.disable;
38160+ pax_close_kernel();
38161 }
38162
38163 clk = clk_register(NULL, &socfpga_clk->hw.hw);
38164@@ -244,7 +247,7 @@ static unsigned long socfpga_clk_recalc_rate(struct clk_hw *hwclk,
38165 return parent_rate / div;
38166 }
38167
38168-static struct clk_ops gateclk_ops = {
38169+static clk_ops_no_const gateclk_ops __read_only = {
38170 .recalc_rate = socfpga_clk_recalc_rate,
38171 .get_parent = socfpga_clk_get_parent,
38172 .set_parent = socfpga_clk_set_parent,
38173diff --git a/drivers/cpufreq/acpi-cpufreq.c b/drivers/cpufreq/acpi-cpufreq.c
38174index 506fd23..01a593f 100644
38175--- a/drivers/cpufreq/acpi-cpufreq.c
38176+++ b/drivers/cpufreq/acpi-cpufreq.c
38177@@ -172,7 +172,7 @@ static ssize_t show_global_boost(struct kobject *kobj,
38178 return sprintf(buf, "%u\n", boost_enabled);
38179 }
38180
38181-static struct global_attr global_boost = __ATTR(boost, 0644,
38182+static global_attr_no_const global_boost = __ATTR(boost, 0644,
38183 show_global_boost,
38184 store_global_boost);
38185
38186@@ -721,8 +721,11 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)
38187 data->acpi_data = per_cpu_ptr(acpi_perf_data, cpu);
38188 per_cpu(acfreq_data, cpu) = data;
38189
38190- if (cpu_has(c, X86_FEATURE_CONSTANT_TSC))
38191- acpi_cpufreq_driver.flags |= CPUFREQ_CONST_LOOPS;
38192+ if (cpu_has(c, X86_FEATURE_CONSTANT_TSC)) {
38193+ pax_open_kernel();
38194+ *(u8 *)&acpi_cpufreq_driver.flags |= CPUFREQ_CONST_LOOPS;
38195+ pax_close_kernel();
38196+ }
38197
38198 result = acpi_processor_register_performance(data->acpi_data, cpu);
38199 if (result)
38200@@ -850,7 +853,9 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)
38201 policy->cur = acpi_cpufreq_guess_freq(data, policy->cpu);
38202 break;
38203 case ACPI_ADR_SPACE_FIXED_HARDWARE:
38204- acpi_cpufreq_driver.get = get_cur_freq_on_cpu;
38205+ pax_open_kernel();
38206+ *(void **)&acpi_cpufreq_driver.get = get_cur_freq_on_cpu;
38207+ pax_close_kernel();
38208 policy->cur = get_cur_freq_on_cpu(cpu);
38209 break;
38210 default:
38211diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
38212index 04548f7..457a342 100644
38213--- a/drivers/cpufreq/cpufreq.c
38214+++ b/drivers/cpufreq/cpufreq.c
38215@@ -2069,7 +2069,7 @@ static int cpufreq_cpu_callback(struct notifier_block *nfb,
38216 return NOTIFY_OK;
38217 }
38218
38219-static struct notifier_block __refdata cpufreq_cpu_notifier = {
38220+static struct notifier_block cpufreq_cpu_notifier = {
38221 .notifier_call = cpufreq_cpu_callback,
38222 };
38223
38224@@ -2101,8 +2101,11 @@ int cpufreq_register_driver(struct cpufreq_driver *driver_data)
38225
38226 pr_debug("trying to register driver %s\n", driver_data->name);
38227
38228- if (driver_data->setpolicy)
38229- driver_data->flags |= CPUFREQ_CONST_LOOPS;
38230+ if (driver_data->setpolicy) {
38231+ pax_open_kernel();
38232+ *(u8 *)&driver_data->flags |= CPUFREQ_CONST_LOOPS;
38233+ pax_close_kernel();
38234+ }
38235
38236 write_lock_irqsave(&cpufreq_driver_lock, flags);
38237 if (cpufreq_driver) {
38238diff --git a/drivers/cpufreq/cpufreq_governor.c b/drivers/cpufreq/cpufreq_governor.c
38239index 0806c31..6a73276 100644
38240--- a/drivers/cpufreq/cpufreq_governor.c
38241+++ b/drivers/cpufreq/cpufreq_governor.c
38242@@ -187,7 +187,7 @@ int cpufreq_governor_dbs(struct cpufreq_policy *policy,
38243 struct dbs_data *dbs_data;
38244 struct od_cpu_dbs_info_s *od_dbs_info = NULL;
38245 struct cs_cpu_dbs_info_s *cs_dbs_info = NULL;
38246- struct od_ops *od_ops = NULL;
38247+ const struct od_ops *od_ops = NULL;
38248 struct od_dbs_tuners *od_tuners = NULL;
38249 struct cs_dbs_tuners *cs_tuners = NULL;
38250 struct cpu_dbs_common_info *cpu_cdbs;
38251@@ -253,7 +253,7 @@ int cpufreq_governor_dbs(struct cpufreq_policy *policy,
38252
38253 if ((cdata->governor == GOV_CONSERVATIVE) &&
38254 (!policy->governor->initialized)) {
38255- struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
38256+ const struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
38257
38258 cpufreq_register_notifier(cs_ops->notifier_block,
38259 CPUFREQ_TRANSITION_NOTIFIER);
38260@@ -273,7 +273,7 @@ int cpufreq_governor_dbs(struct cpufreq_policy *policy,
38261
38262 if ((dbs_data->cdata->governor == GOV_CONSERVATIVE) &&
38263 (policy->governor->initialized == 1)) {
38264- struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
38265+ const struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
38266
38267 cpufreq_unregister_notifier(cs_ops->notifier_block,
38268 CPUFREQ_TRANSITION_NOTIFIER);
38269diff --git a/drivers/cpufreq/cpufreq_governor.h b/drivers/cpufreq/cpufreq_governor.h
38270index 88cd39f..87f0393 100644
38271--- a/drivers/cpufreq/cpufreq_governor.h
38272+++ b/drivers/cpufreq/cpufreq_governor.h
38273@@ -202,7 +202,7 @@ struct common_dbs_data {
38274 void (*exit)(struct dbs_data *dbs_data);
38275
38276 /* Governor specific ops, see below */
38277- void *gov_ops;
38278+ const void *gov_ops;
38279 };
38280
38281 /* Governor Per policy data */
38282@@ -222,7 +222,7 @@ struct od_ops {
38283 unsigned int (*powersave_bias_target)(struct cpufreq_policy *policy,
38284 unsigned int freq_next, unsigned int relation);
38285 void (*freq_increase)(struct cpufreq_policy *policy, unsigned int freq);
38286-};
38287+} __no_const;
38288
38289 struct cs_ops {
38290 struct notifier_block *notifier_block;
38291diff --git a/drivers/cpufreq/cpufreq_ondemand.c b/drivers/cpufreq/cpufreq_ondemand.c
38292index 32f26f6..feb657b 100644
38293--- a/drivers/cpufreq/cpufreq_ondemand.c
38294+++ b/drivers/cpufreq/cpufreq_ondemand.c
38295@@ -522,7 +522,7 @@ static void od_exit(struct dbs_data *dbs_data)
38296
38297 define_get_cpu_dbs_routines(od_cpu_dbs_info);
38298
38299-static struct od_ops od_ops = {
38300+static struct od_ops od_ops __read_only = {
38301 .powersave_bias_init_cpu = ondemand_powersave_bias_init_cpu,
38302 .powersave_bias_target = generic_powersave_bias_target,
38303 .freq_increase = dbs_freq_increase,
38304@@ -577,14 +577,18 @@ void od_register_powersave_bias_handler(unsigned int (*f)
38305 (struct cpufreq_policy *, unsigned int, unsigned int),
38306 unsigned int powersave_bias)
38307 {
38308- od_ops.powersave_bias_target = f;
38309+ pax_open_kernel();
38310+ *(void **)&od_ops.powersave_bias_target = f;
38311+ pax_close_kernel();
38312 od_set_powersave_bias(powersave_bias);
38313 }
38314 EXPORT_SYMBOL_GPL(od_register_powersave_bias_handler);
38315
38316 void od_unregister_powersave_bias_handler(void)
38317 {
38318- od_ops.powersave_bias_target = generic_powersave_bias_target;
38319+ pax_open_kernel();
38320+ *(void **)&od_ops.powersave_bias_target = generic_powersave_bias_target;
38321+ pax_close_kernel();
38322 od_set_powersave_bias(0);
38323 }
38324 EXPORT_SYMBOL_GPL(od_unregister_powersave_bias_handler);
38325diff --git a/drivers/cpufreq/cpufreq_stats.c b/drivers/cpufreq/cpufreq_stats.c
38326index 4cf0d28..5830372 100644
38327--- a/drivers/cpufreq/cpufreq_stats.c
38328+++ b/drivers/cpufreq/cpufreq_stats.c
38329@@ -352,7 +352,7 @@ static int cpufreq_stat_cpu_callback(struct notifier_block *nfb,
38330 }
38331
38332 /* priority=1 so this will get called before cpufreq_remove_dev */
38333-static struct notifier_block cpufreq_stat_cpu_notifier __refdata = {
38334+static struct notifier_block cpufreq_stat_cpu_notifier = {
38335 .notifier_call = cpufreq_stat_cpu_callback,
38336 .priority = 1,
38337 };
38338diff --git a/drivers/cpufreq/p4-clockmod.c b/drivers/cpufreq/p4-clockmod.c
38339index 2f0a2a6..93d728e 100644
38340--- a/drivers/cpufreq/p4-clockmod.c
38341+++ b/drivers/cpufreq/p4-clockmod.c
38342@@ -160,10 +160,14 @@ static unsigned int cpufreq_p4_get_frequency(struct cpuinfo_x86 *c)
38343 case 0x0F: /* Core Duo */
38344 case 0x16: /* Celeron Core */
38345 case 0x1C: /* Atom */
38346- p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
38347+ pax_open_kernel();
38348+ *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
38349+ pax_close_kernel();
38350 return speedstep_get_frequency(SPEEDSTEP_CPU_PCORE);
38351 case 0x0D: /* Pentium M (Dothan) */
38352- p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
38353+ pax_open_kernel();
38354+ *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
38355+ pax_close_kernel();
38356 /* fall through */
38357 case 0x09: /* Pentium M (Banias) */
38358 return speedstep_get_frequency(SPEEDSTEP_CPU_PM);
38359@@ -175,7 +179,9 @@ static unsigned int cpufreq_p4_get_frequency(struct cpuinfo_x86 *c)
38360
38361 /* on P-4s, the TSC runs with constant frequency independent whether
38362 * throttling is active or not. */
38363- p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
38364+ pax_open_kernel();
38365+ *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
38366+ pax_close_kernel();
38367
38368 if (speedstep_detect_processor() == SPEEDSTEP_CPU_P4M) {
38369 printk(KERN_WARNING PFX "Warning: Pentium 4-M detected. "
38370diff --git a/drivers/cpufreq/sparc-us3-cpufreq.c b/drivers/cpufreq/sparc-us3-cpufreq.c
38371index ac76b48..2445bc6 100644
38372--- a/drivers/cpufreq/sparc-us3-cpufreq.c
38373+++ b/drivers/cpufreq/sparc-us3-cpufreq.c
38374@@ -18,14 +18,12 @@
38375 #include <asm/head.h>
38376 #include <asm/timer.h>
38377
38378-static struct cpufreq_driver *cpufreq_us3_driver;
38379-
38380 struct us3_freq_percpu_info {
38381 struct cpufreq_frequency_table table[4];
38382 };
38383
38384 /* Indexed by cpu number. */
38385-static struct us3_freq_percpu_info *us3_freq_table;
38386+static struct us3_freq_percpu_info us3_freq_table[NR_CPUS];
38387
38388 /* UltraSPARC-III has three dividers: 1, 2, and 32. These are controlled
38389 * in the Safari config register.
38390@@ -186,12 +184,25 @@ static int __init us3_freq_cpu_init(struct cpufreq_policy *policy)
38391
38392 static int us3_freq_cpu_exit(struct cpufreq_policy *policy)
38393 {
38394- if (cpufreq_us3_driver)
38395- us3_set_cpu_divider_index(policy, 0);
38396+ us3_set_cpu_divider_index(policy->cpu, 0);
38397
38398 return 0;
38399 }
38400
38401+static int __init us3_freq_init(void);
38402+static void __exit us3_freq_exit(void);
38403+
38404+static struct cpufreq_driver cpufreq_us3_driver = {
38405+ .init = us3_freq_cpu_init,
38406+ .verify = us3_freq_verify,
38407+ .target = us3_freq_target,
38408+ .get = us3_freq_get,
38409+ .exit = us3_freq_cpu_exit,
38410+ .owner = THIS_MODULE,
38411+ .name = "UltraSPARC-III",
38412+
38413+};
38414+
38415 static int __init us3_freq_init(void)
38416 {
38417 unsigned long manuf, impl, ver;
38418@@ -208,55 +219,15 @@ static int __init us3_freq_init(void)
38419 (impl == CHEETAH_IMPL ||
38420 impl == CHEETAH_PLUS_IMPL ||
38421 impl == JAGUAR_IMPL ||
38422- impl == PANTHER_IMPL)) {
38423- struct cpufreq_driver *driver;
38424-
38425- ret = -ENOMEM;
38426- driver = kzalloc(sizeof(*driver), GFP_KERNEL);
38427- if (!driver)
38428- goto err_out;
38429-
38430- us3_freq_table = kzalloc((NR_CPUS * sizeof(*us3_freq_table)),
38431- GFP_KERNEL);
38432- if (!us3_freq_table)
38433- goto err_out;
38434-
38435- driver->init = us3_freq_cpu_init;
38436- driver->verify = us3_freq_verify;
38437- driver->target = us3_freq_target;
38438- driver->get = us3_freq_get;
38439- driver->exit = us3_freq_cpu_exit;
38440- strcpy(driver->name, "UltraSPARC-III");
38441-
38442- cpufreq_us3_driver = driver;
38443- ret = cpufreq_register_driver(driver);
38444- if (ret)
38445- goto err_out;
38446-
38447- return 0;
38448-
38449-err_out:
38450- if (driver) {
38451- kfree(driver);
38452- cpufreq_us3_driver = NULL;
38453- }
38454- kfree(us3_freq_table);
38455- us3_freq_table = NULL;
38456- return ret;
38457- }
38458+ impl == PANTHER_IMPL))
38459+ return cpufreq_register_driver(&cpufreq_us3_driver);
38460
38461 return -ENODEV;
38462 }
38463
38464 static void __exit us3_freq_exit(void)
38465 {
38466- if (cpufreq_us3_driver) {
38467- cpufreq_unregister_driver(cpufreq_us3_driver);
38468- kfree(cpufreq_us3_driver);
38469- cpufreq_us3_driver = NULL;
38470- kfree(us3_freq_table);
38471- us3_freq_table = NULL;
38472- }
38473+ cpufreq_unregister_driver(&cpufreq_us3_driver);
38474 }
38475
38476 MODULE_AUTHOR("David S. Miller <davem@redhat.com>");
38477diff --git a/drivers/cpufreq/speedstep-centrino.c b/drivers/cpufreq/speedstep-centrino.c
38478index f897d51..15da295 100644
38479--- a/drivers/cpufreq/speedstep-centrino.c
38480+++ b/drivers/cpufreq/speedstep-centrino.c
38481@@ -353,8 +353,11 @@ static int centrino_cpu_init(struct cpufreq_policy *policy)
38482 !cpu_has(cpu, X86_FEATURE_EST))
38483 return -ENODEV;
38484
38485- if (cpu_has(cpu, X86_FEATURE_CONSTANT_TSC))
38486- centrino_driver.flags |= CPUFREQ_CONST_LOOPS;
38487+ if (cpu_has(cpu, X86_FEATURE_CONSTANT_TSC)) {
38488+ pax_open_kernel();
38489+ *(u8 *)&centrino_driver.flags |= CPUFREQ_CONST_LOOPS;
38490+ pax_close_kernel();
38491+ }
38492
38493 if (policy->cpu != 0)
38494 return -ENODEV;
38495diff --git a/drivers/cpuidle/cpuidle.c b/drivers/cpuidle/cpuidle.c
38496index 22c07fb..9dff5ac 100644
38497--- a/drivers/cpuidle/cpuidle.c
38498+++ b/drivers/cpuidle/cpuidle.c
38499@@ -252,7 +252,7 @@ static int poll_idle(struct cpuidle_device *dev,
38500
38501 static void poll_idle_init(struct cpuidle_driver *drv)
38502 {
38503- struct cpuidle_state *state = &drv->states[0];
38504+ cpuidle_state_no_const *state = &drv->states[0];
38505
38506 snprintf(state->name, CPUIDLE_NAME_LEN, "POLL");
38507 snprintf(state->desc, CPUIDLE_DESC_LEN, "CPUIDLE CORE POLL IDLE");
38508diff --git a/drivers/cpuidle/governor.c b/drivers/cpuidle/governor.c
38509index ea2f8e7..70ac501 100644
38510--- a/drivers/cpuidle/governor.c
38511+++ b/drivers/cpuidle/governor.c
38512@@ -87,7 +87,7 @@ int cpuidle_register_governor(struct cpuidle_governor *gov)
38513 mutex_lock(&cpuidle_lock);
38514 if (__cpuidle_find_governor(gov->name) == NULL) {
38515 ret = 0;
38516- list_add_tail(&gov->governor_list, &cpuidle_governors);
38517+ pax_list_add_tail((struct list_head *)&gov->governor_list, &cpuidle_governors);
38518 if (!cpuidle_curr_governor ||
38519 cpuidle_curr_governor->rating < gov->rating)
38520 cpuidle_switch_governor(gov);
38521@@ -135,7 +135,7 @@ void cpuidle_unregister_governor(struct cpuidle_governor *gov)
38522 new_gov = cpuidle_replace_governor(gov->rating);
38523 cpuidle_switch_governor(new_gov);
38524 }
38525- list_del(&gov->governor_list);
38526+ pax_list_del((struct list_head *)&gov->governor_list);
38527 mutex_unlock(&cpuidle_lock);
38528 }
38529
38530diff --git a/drivers/cpuidle/sysfs.c b/drivers/cpuidle/sysfs.c
38531index 8739cc0..dc859d0 100644
38532--- a/drivers/cpuidle/sysfs.c
38533+++ b/drivers/cpuidle/sysfs.c
38534@@ -134,7 +134,7 @@ static struct attribute *cpuidle_switch_attrs[] = {
38535 NULL
38536 };
38537
38538-static struct attribute_group cpuidle_attr_group = {
38539+static attribute_group_no_const cpuidle_attr_group = {
38540 .attrs = cpuidle_default_attrs,
38541 .name = "cpuidle",
38542 };
38543diff --git a/drivers/crypto/hifn_795x.c b/drivers/crypto/hifn_795x.c
38544index 12fea3e..1e28f47 100644
38545--- a/drivers/crypto/hifn_795x.c
38546+++ b/drivers/crypto/hifn_795x.c
38547@@ -51,7 +51,7 @@ module_param_string(hifn_pll_ref, hifn_pll_ref, sizeof(hifn_pll_ref), 0444);
38548 MODULE_PARM_DESC(hifn_pll_ref,
38549 "PLL reference clock (pci[freq] or ext[freq], default ext)");
38550
38551-static atomic_t hifn_dev_number;
38552+static atomic_unchecked_t hifn_dev_number;
38553
38554 #define ACRYPTO_OP_DECRYPT 0
38555 #define ACRYPTO_OP_ENCRYPT 1
38556@@ -2577,7 +2577,7 @@ static int hifn_probe(struct pci_dev *pdev, const struct pci_device_id *id)
38557 goto err_out_disable_pci_device;
38558
38559 snprintf(name, sizeof(name), "hifn%d",
38560- atomic_inc_return(&hifn_dev_number)-1);
38561+ atomic_inc_return_unchecked(&hifn_dev_number)-1);
38562
38563 err = pci_request_regions(pdev, name);
38564 if (err)
38565diff --git a/drivers/devfreq/devfreq.c b/drivers/devfreq/devfreq.c
38566index c99c00d..990a4b2 100644
38567--- a/drivers/devfreq/devfreq.c
38568+++ b/drivers/devfreq/devfreq.c
38569@@ -607,7 +607,7 @@ int devfreq_add_governor(struct devfreq_governor *governor)
38570 goto err_out;
38571 }
38572
38573- list_add(&governor->node, &devfreq_governor_list);
38574+ pax_list_add((struct list_head *)&governor->node, &devfreq_governor_list);
38575
38576 list_for_each_entry(devfreq, &devfreq_list, node) {
38577 int ret = 0;
38578@@ -695,7 +695,7 @@ int devfreq_remove_governor(struct devfreq_governor *governor)
38579 }
38580 }
38581
38582- list_del(&governor->node);
38583+ pax_list_del((struct list_head *)&governor->node);
38584 err_out:
38585 mutex_unlock(&devfreq_list_lock);
38586
38587diff --git a/drivers/dma/sh/shdmac.c b/drivers/dma/sh/shdmac.c
38588index 1069e88..dfcd642 100644
38589--- a/drivers/dma/sh/shdmac.c
38590+++ b/drivers/dma/sh/shdmac.c
38591@@ -511,7 +511,7 @@ static int sh_dmae_nmi_handler(struct notifier_block *self,
38592 return ret;
38593 }
38594
38595-static struct notifier_block sh_dmae_nmi_notifier __read_mostly = {
38596+static struct notifier_block sh_dmae_nmi_notifier = {
38597 .notifier_call = sh_dmae_nmi_handler,
38598
38599 /* Run before NMI debug handler and KGDB */
38600diff --git a/drivers/edac/edac_device.c b/drivers/edac/edac_device.c
38601index 211021d..201d47f 100644
38602--- a/drivers/edac/edac_device.c
38603+++ b/drivers/edac/edac_device.c
38604@@ -474,9 +474,9 @@ void edac_device_reset_delay_period(struct edac_device_ctl_info *edac_dev,
38605 */
38606 int edac_device_alloc_index(void)
38607 {
38608- static atomic_t device_indexes = ATOMIC_INIT(0);
38609+ static atomic_unchecked_t device_indexes = ATOMIC_INIT(0);
38610
38611- return atomic_inc_return(&device_indexes) - 1;
38612+ return atomic_inc_return_unchecked(&device_indexes) - 1;
38613 }
38614 EXPORT_SYMBOL_GPL(edac_device_alloc_index);
38615
38616diff --git a/drivers/edac/edac_mc_sysfs.c b/drivers/edac/edac_mc_sysfs.c
38617index 9f7e0e60..348c875 100644
38618--- a/drivers/edac/edac_mc_sysfs.c
38619+++ b/drivers/edac/edac_mc_sysfs.c
38620@@ -150,7 +150,7 @@ static const char * const edac_caps[] = {
38621 struct dev_ch_attribute {
38622 struct device_attribute attr;
38623 int channel;
38624-};
38625+} __do_const;
38626
38627 #define DEVICE_CHANNEL(_name, _mode, _show, _store, _var) \
38628 struct dev_ch_attribute dev_attr_legacy_##_name = \
38629@@ -1007,14 +1007,16 @@ int edac_create_sysfs_mci_device(struct mem_ctl_info *mci)
38630 }
38631
38632 if (mci->set_sdram_scrub_rate || mci->get_sdram_scrub_rate) {
38633+ pax_open_kernel();
38634 if (mci->get_sdram_scrub_rate) {
38635- dev_attr_sdram_scrub_rate.attr.mode |= S_IRUGO;
38636- dev_attr_sdram_scrub_rate.show = &mci_sdram_scrub_rate_show;
38637+ *(umode_t *)&dev_attr_sdram_scrub_rate.attr.mode |= S_IRUGO;
38638+ *(void **)&dev_attr_sdram_scrub_rate.show = &mci_sdram_scrub_rate_show;
38639 }
38640 if (mci->set_sdram_scrub_rate) {
38641- dev_attr_sdram_scrub_rate.attr.mode |= S_IWUSR;
38642- dev_attr_sdram_scrub_rate.store = &mci_sdram_scrub_rate_store;
38643+ *(umode_t *)&dev_attr_sdram_scrub_rate.attr.mode |= S_IWUSR;
38644+ *(void **)&dev_attr_sdram_scrub_rate.store = &mci_sdram_scrub_rate_store;
38645 }
38646+ pax_close_kernel();
38647 err = device_create_file(&mci->dev,
38648 &dev_attr_sdram_scrub_rate);
38649 if (err) {
38650diff --git a/drivers/edac/edac_pci.c b/drivers/edac/edac_pci.c
38651index dd370f9..0281629 100644
38652--- a/drivers/edac/edac_pci.c
38653+++ b/drivers/edac/edac_pci.c
38654@@ -29,7 +29,7 @@
38655
38656 static DEFINE_MUTEX(edac_pci_ctls_mutex);
38657 static LIST_HEAD(edac_pci_list);
38658-static atomic_t pci_indexes = ATOMIC_INIT(0);
38659+static atomic_unchecked_t pci_indexes = ATOMIC_INIT(0);
38660
38661 /*
38662 * edac_pci_alloc_ctl_info
38663@@ -315,7 +315,7 @@ EXPORT_SYMBOL_GPL(edac_pci_reset_delay_period);
38664 */
38665 int edac_pci_alloc_index(void)
38666 {
38667- return atomic_inc_return(&pci_indexes) - 1;
38668+ return atomic_inc_return_unchecked(&pci_indexes) - 1;
38669 }
38670 EXPORT_SYMBOL_GPL(edac_pci_alloc_index);
38671
38672diff --git a/drivers/edac/edac_pci_sysfs.c b/drivers/edac/edac_pci_sysfs.c
38673index e8658e4..22746d6 100644
38674--- a/drivers/edac/edac_pci_sysfs.c
38675+++ b/drivers/edac/edac_pci_sysfs.c
38676@@ -26,8 +26,8 @@ static int edac_pci_log_pe = 1; /* log PCI parity errors */
38677 static int edac_pci_log_npe = 1; /* log PCI non-parity error errors */
38678 static int edac_pci_poll_msec = 1000; /* one second workq period */
38679
38680-static atomic_t pci_parity_count = ATOMIC_INIT(0);
38681-static atomic_t pci_nonparity_count = ATOMIC_INIT(0);
38682+static atomic_unchecked_t pci_parity_count = ATOMIC_INIT(0);
38683+static atomic_unchecked_t pci_nonparity_count = ATOMIC_INIT(0);
38684
38685 static struct kobject *edac_pci_top_main_kobj;
38686 static atomic_t edac_pci_sysfs_refcount = ATOMIC_INIT(0);
38687@@ -235,7 +235,7 @@ struct edac_pci_dev_attribute {
38688 void *value;
38689 ssize_t(*show) (void *, char *);
38690 ssize_t(*store) (void *, const char *, size_t);
38691-};
38692+} __do_const;
38693
38694 /* Set of show/store abstract level functions for PCI Parity object */
38695 static ssize_t edac_pci_dev_show(struct kobject *kobj, struct attribute *attr,
38696@@ -579,7 +579,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
38697 edac_printk(KERN_CRIT, EDAC_PCI,
38698 "Signaled System Error on %s\n",
38699 pci_name(dev));
38700- atomic_inc(&pci_nonparity_count);
38701+ atomic_inc_unchecked(&pci_nonparity_count);
38702 }
38703
38704 if (status & (PCI_STATUS_PARITY)) {
38705@@ -587,7 +587,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
38706 "Master Data Parity Error on %s\n",
38707 pci_name(dev));
38708
38709- atomic_inc(&pci_parity_count);
38710+ atomic_inc_unchecked(&pci_parity_count);
38711 }
38712
38713 if (status & (PCI_STATUS_DETECTED_PARITY)) {
38714@@ -595,7 +595,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
38715 "Detected Parity Error on %s\n",
38716 pci_name(dev));
38717
38718- atomic_inc(&pci_parity_count);
38719+ atomic_inc_unchecked(&pci_parity_count);
38720 }
38721 }
38722
38723@@ -618,7 +618,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
38724 edac_printk(KERN_CRIT, EDAC_PCI, "Bridge "
38725 "Signaled System Error on %s\n",
38726 pci_name(dev));
38727- atomic_inc(&pci_nonparity_count);
38728+ atomic_inc_unchecked(&pci_nonparity_count);
38729 }
38730
38731 if (status & (PCI_STATUS_PARITY)) {
38732@@ -626,7 +626,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
38733 "Master Data Parity Error on "
38734 "%s\n", pci_name(dev));
38735
38736- atomic_inc(&pci_parity_count);
38737+ atomic_inc_unchecked(&pci_parity_count);
38738 }
38739
38740 if (status & (PCI_STATUS_DETECTED_PARITY)) {
38741@@ -634,7 +634,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
38742 "Detected Parity Error on %s\n",
38743 pci_name(dev));
38744
38745- atomic_inc(&pci_parity_count);
38746+ atomic_inc_unchecked(&pci_parity_count);
38747 }
38748 }
38749 }
38750@@ -672,7 +672,7 @@ void edac_pci_do_parity_check(void)
38751 if (!check_pci_errors)
38752 return;
38753
38754- before_count = atomic_read(&pci_parity_count);
38755+ before_count = atomic_read_unchecked(&pci_parity_count);
38756
38757 /* scan all PCI devices looking for a Parity Error on devices and
38758 * bridges.
38759@@ -684,7 +684,7 @@ void edac_pci_do_parity_check(void)
38760 /* Only if operator has selected panic on PCI Error */
38761 if (edac_pci_get_panic_on_pe()) {
38762 /* If the count is different 'after' from 'before' */
38763- if (before_count != atomic_read(&pci_parity_count))
38764+ if (before_count != atomic_read_unchecked(&pci_parity_count))
38765 panic("EDAC: PCI Parity Error");
38766 }
38767 }
38768diff --git a/drivers/edac/mce_amd.h b/drivers/edac/mce_amd.h
38769index 51b7e3a..aa8a3e8 100644
38770--- a/drivers/edac/mce_amd.h
38771+++ b/drivers/edac/mce_amd.h
38772@@ -77,7 +77,7 @@ struct amd_decoder_ops {
38773 bool (*mc0_mce)(u16, u8);
38774 bool (*mc1_mce)(u16, u8);
38775 bool (*mc2_mce)(u16, u8);
38776-};
38777+} __no_const;
38778
38779 void amd_report_gart_errors(bool);
38780 void amd_register_ecc_decoder(void (*f)(int, struct mce *));
38781diff --git a/drivers/firewire/core-card.c b/drivers/firewire/core-card.c
38782index 57ea7f4..af06b76 100644
38783--- a/drivers/firewire/core-card.c
38784+++ b/drivers/firewire/core-card.c
38785@@ -528,9 +528,9 @@ void fw_card_initialize(struct fw_card *card,
38786 const struct fw_card_driver *driver,
38787 struct device *device)
38788 {
38789- static atomic_t index = ATOMIC_INIT(-1);
38790+ static atomic_unchecked_t index = ATOMIC_INIT(-1);
38791
38792- card->index = atomic_inc_return(&index);
38793+ card->index = atomic_inc_return_unchecked(&index);
38794 card->driver = driver;
38795 card->device = device;
38796 card->current_tlabel = 0;
38797@@ -680,7 +680,7 @@ EXPORT_SYMBOL_GPL(fw_card_release);
38798
38799 void fw_core_remove_card(struct fw_card *card)
38800 {
38801- struct fw_card_driver dummy_driver = dummy_driver_template;
38802+ fw_card_driver_no_const dummy_driver = dummy_driver_template;
38803
38804 card->driver->update_phy_reg(card, 4,
38805 PHY_LINK_ACTIVE | PHY_CONTENDER, 0);
38806diff --git a/drivers/firewire/core-device.c b/drivers/firewire/core-device.c
38807index de4aa40..49ab1f2 100644
38808--- a/drivers/firewire/core-device.c
38809+++ b/drivers/firewire/core-device.c
38810@@ -253,7 +253,7 @@ EXPORT_SYMBOL(fw_device_enable_phys_dma);
38811 struct config_rom_attribute {
38812 struct device_attribute attr;
38813 u32 key;
38814-};
38815+} __do_const;
38816
38817 static ssize_t show_immediate(struct device *dev,
38818 struct device_attribute *dattr, char *buf)
38819diff --git a/drivers/firewire/core-transaction.c b/drivers/firewire/core-transaction.c
38820index e5af0e3..d318058 100644
38821--- a/drivers/firewire/core-transaction.c
38822+++ b/drivers/firewire/core-transaction.c
38823@@ -38,6 +38,7 @@
38824 #include <linux/timer.h>
38825 #include <linux/types.h>
38826 #include <linux/workqueue.h>
38827+#include <linux/sched.h>
38828
38829 #include <asm/byteorder.h>
38830
38831diff --git a/drivers/firewire/core.h b/drivers/firewire/core.h
38832index 515a42c..5ecf3ba 100644
38833--- a/drivers/firewire/core.h
38834+++ b/drivers/firewire/core.h
38835@@ -111,6 +111,7 @@ struct fw_card_driver {
38836
38837 int (*stop_iso)(struct fw_iso_context *ctx);
38838 };
38839+typedef struct fw_card_driver __no_const fw_card_driver_no_const;
38840
38841 void fw_card_initialize(struct fw_card *card,
38842 const struct fw_card_driver *driver, struct device *device);
38843diff --git a/drivers/firmware/dmi-id.c b/drivers/firmware/dmi-id.c
38844index 94a58a0..f5eba42 100644
38845--- a/drivers/firmware/dmi-id.c
38846+++ b/drivers/firmware/dmi-id.c
38847@@ -16,7 +16,7 @@
38848 struct dmi_device_attribute{
38849 struct device_attribute dev_attr;
38850 int field;
38851-};
38852+} __do_const;
38853 #define to_dmi_dev_attr(_dev_attr) \
38854 container_of(_dev_attr, struct dmi_device_attribute, dev_attr)
38855
38856diff --git a/drivers/firmware/dmi_scan.c b/drivers/firmware/dmi_scan.c
38857index fa0affb..aa448eb 100644
38858--- a/drivers/firmware/dmi_scan.c
38859+++ b/drivers/firmware/dmi_scan.c
38860@@ -791,7 +791,7 @@ int dmi_walk(void (*decode)(const struct dmi_header *, void *),
38861 if (buf == NULL)
38862 return -1;
38863
38864- dmi_table(buf, dmi_len, dmi_num, decode, private_data);
38865+ dmi_table((char __force_kernel *)buf, dmi_len, dmi_num, decode, private_data);
38866
38867 iounmap(buf);
38868 return 0;
38869diff --git a/drivers/firmware/efi/efi.c b/drivers/firmware/efi/efi.c
38870index 5145fa3..0d3babd 100644
38871--- a/drivers/firmware/efi/efi.c
38872+++ b/drivers/firmware/efi/efi.c
38873@@ -65,14 +65,16 @@ static struct attribute_group efi_subsys_attr_group = {
38874 };
38875
38876 static struct efivars generic_efivars;
38877-static struct efivar_operations generic_ops;
38878+static efivar_operations_no_const generic_ops __read_only;
38879
38880 static int generic_ops_register(void)
38881 {
38882- generic_ops.get_variable = efi.get_variable;
38883- generic_ops.set_variable = efi.set_variable;
38884- generic_ops.get_next_variable = efi.get_next_variable;
38885- generic_ops.query_variable_store = efi_query_variable_store;
38886+ pax_open_kernel();
38887+ *(void **)&generic_ops.get_variable = efi.get_variable;
38888+ *(void **)&generic_ops.set_variable = efi.set_variable;
38889+ *(void **)&generic_ops.get_next_variable = efi.get_next_variable;
38890+ *(void **)&generic_ops.query_variable_store = efi_query_variable_store;
38891+ pax_close_kernel();
38892
38893 return efivars_register(&generic_efivars, &generic_ops, efi_kobj);
38894 }
38895diff --git a/drivers/firmware/efi/efivars.c b/drivers/firmware/efi/efivars.c
38896index 8c5a61a..cf07bd0 100644
38897--- a/drivers/firmware/efi/efivars.c
38898+++ b/drivers/firmware/efi/efivars.c
38899@@ -456,7 +456,7 @@ efivar_create_sysfs_entry(struct efivar_entry *new_var)
38900 static int
38901 create_efivars_bin_attributes(void)
38902 {
38903- struct bin_attribute *attr;
38904+ bin_attribute_no_const *attr;
38905 int error;
38906
38907 /* new_var */
38908diff --git a/drivers/firmware/google/memconsole.c b/drivers/firmware/google/memconsole.c
38909index 2a90ba6..07f3733 100644
38910--- a/drivers/firmware/google/memconsole.c
38911+++ b/drivers/firmware/google/memconsole.c
38912@@ -147,7 +147,9 @@ static int __init memconsole_init(void)
38913 if (!found_memconsole())
38914 return -ENODEV;
38915
38916- memconsole_bin_attr.size = memconsole_length;
38917+ pax_open_kernel();
38918+ *(size_t *)&memconsole_bin_attr.size = memconsole_length;
38919+ pax_close_kernel();
38920
38921 ret = sysfs_create_bin_file(firmware_kobj, &memconsole_bin_attr);
38922
38923diff --git a/drivers/gpio/gpio-ich.c b/drivers/gpio/gpio-ich.c
38924index 814addb..0937d7f 100644
38925--- a/drivers/gpio/gpio-ich.c
38926+++ b/drivers/gpio/gpio-ich.c
38927@@ -71,7 +71,7 @@ struct ichx_desc {
38928 /* Some chipsets have quirks, let these use their own request/get */
38929 int (*request)(struct gpio_chip *chip, unsigned offset);
38930 int (*get)(struct gpio_chip *chip, unsigned offset);
38931-};
38932+} __do_const;
38933
38934 static struct {
38935 spinlock_t lock;
38936diff --git a/drivers/gpio/gpio-vr41xx.c b/drivers/gpio/gpio-vr41xx.c
38937index 9902732..64b62dd 100644
38938--- a/drivers/gpio/gpio-vr41xx.c
38939+++ b/drivers/gpio/gpio-vr41xx.c
38940@@ -204,7 +204,7 @@ static int giu_get_irq(unsigned int irq)
38941 printk(KERN_ERR "spurious GIU interrupt: %04x(%04x),%04x(%04x)\n",
38942 maskl, pendl, maskh, pendh);
38943
38944- atomic_inc(&irq_err_count);
38945+ atomic_inc_unchecked(&irq_err_count);
38946
38947 return -EINVAL;
38948 }
38949diff --git a/drivers/gpu/drm/drm_crtc_helper.c b/drivers/gpu/drm/drm_crtc_helper.c
38950index c722c3b..2ec6040 100644
38951--- a/drivers/gpu/drm/drm_crtc_helper.c
38952+++ b/drivers/gpu/drm/drm_crtc_helper.c
38953@@ -328,7 +328,7 @@ static bool drm_encoder_crtc_ok(struct drm_encoder *encoder,
38954 struct drm_crtc *tmp;
38955 int crtc_mask = 1;
38956
38957- WARN(!crtc, "checking null crtc?\n");
38958+ BUG_ON(!crtc);
38959
38960 dev = crtc->dev;
38961
38962diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c
38963index fe58d08..07bc38e 100644
38964--- a/drivers/gpu/drm/drm_drv.c
38965+++ b/drivers/gpu/drm/drm_drv.c
38966@@ -186,7 +186,7 @@ static void drm_legacy_dev_reinit(struct drm_device *dev)
38967 atomic_set(&dev->vma_count, 0);
38968
38969 for (i = 0; i < ARRAY_SIZE(dev->counts); i++)
38970- atomic_set(&dev->counts[i], 0);
38971+ atomic_set_unchecked(&dev->counts[i], 0);
38972
38973 dev->sigdata.lock = NULL;
38974
38975@@ -302,7 +302,7 @@ module_exit(drm_core_exit);
38976 /**
38977 * Copy and IOCTL return string to user space
38978 */
38979-static int drm_copy_field(char *buf, size_t *buf_len, const char *value)
38980+static int drm_copy_field(char __user *buf, size_t *buf_len, const char *value)
38981 {
38982 int len;
38983
38984@@ -372,7 +372,7 @@ long drm_ioctl(struct file *filp,
38985 struct drm_file *file_priv = filp->private_data;
38986 struct drm_device *dev;
38987 const struct drm_ioctl_desc *ioctl = NULL;
38988- drm_ioctl_t *func;
38989+ drm_ioctl_no_const_t func;
38990 unsigned int nr = DRM_IOCTL_NR(cmd);
38991 int retcode = -EINVAL;
38992 char stack_kdata[128];
38993@@ -385,7 +385,7 @@ long drm_ioctl(struct file *filp,
38994 return -ENODEV;
38995
38996 atomic_inc(&dev->ioctl_count);
38997- atomic_inc(&dev->counts[_DRM_STAT_IOCTLS]);
38998+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_IOCTLS]);
38999 ++file_priv->ioctl_count;
39000
39001 if ((nr >= DRM_CORE_IOCTL_COUNT) &&
39002diff --git a/drivers/gpu/drm/drm_fops.c b/drivers/gpu/drm/drm_fops.c
39003index 3f84277..c627c54 100644
39004--- a/drivers/gpu/drm/drm_fops.c
39005+++ b/drivers/gpu/drm/drm_fops.c
39006@@ -97,7 +97,7 @@ int drm_open(struct inode *inode, struct file *filp)
39007 if (drm_device_is_unplugged(dev))
39008 return -ENODEV;
39009
39010- if (!dev->open_count++)
39011+ if (local_inc_return(&dev->open_count) == 1)
39012 need_setup = 1;
39013 mutex_lock(&dev->struct_mutex);
39014 old_imapping = inode->i_mapping;
39015@@ -113,7 +113,7 @@ int drm_open(struct inode *inode, struct file *filp)
39016 retcode = drm_open_helper(inode, filp, dev);
39017 if (retcode)
39018 goto err_undo;
39019- atomic_inc(&dev->counts[_DRM_STAT_OPENS]);
39020+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_OPENS]);
39021 if (need_setup) {
39022 retcode = drm_setup(dev);
39023 if (retcode)
39024@@ -128,7 +128,7 @@ err_undo:
39025 iput(container_of(dev->dev_mapping, struct inode, i_data));
39026 dev->dev_mapping = old_mapping;
39027 mutex_unlock(&dev->struct_mutex);
39028- dev->open_count--;
39029+ local_dec(&dev->open_count);
39030 return retcode;
39031 }
39032 EXPORT_SYMBOL(drm_open);
39033@@ -405,7 +405,7 @@ int drm_release(struct inode *inode, struct file *filp)
39034
39035 mutex_lock(&drm_global_mutex);
39036
39037- DRM_DEBUG("open_count = %d\n", dev->open_count);
39038+ DRM_DEBUG("open_count = %ld\n", local_read(&dev->open_count));
39039
39040 if (dev->driver->preclose)
39041 dev->driver->preclose(dev, file_priv);
39042@@ -414,10 +414,10 @@ int drm_release(struct inode *inode, struct file *filp)
39043 * Begin inline drm_release
39044 */
39045
39046- DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %d\n",
39047+ DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %ld\n",
39048 task_pid_nr(current),
39049 (long)old_encode_dev(file_priv->minor->device),
39050- dev->open_count);
39051+ local_read(&dev->open_count));
39052
39053 /* Release any auth tokens that might point to this file_priv,
39054 (do that under the drm_global_mutex) */
39055@@ -516,8 +516,8 @@ int drm_release(struct inode *inode, struct file *filp)
39056 * End inline drm_release
39057 */
39058
39059- atomic_inc(&dev->counts[_DRM_STAT_CLOSES]);
39060- if (!--dev->open_count) {
39061+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_CLOSES]);
39062+ if (local_dec_and_test(&dev->open_count)) {
39063 if (atomic_read(&dev->ioctl_count)) {
39064 DRM_ERROR("Device busy: %d\n",
39065 atomic_read(&dev->ioctl_count));
39066diff --git a/drivers/gpu/drm/drm_global.c b/drivers/gpu/drm/drm_global.c
39067index f731116..629842c 100644
39068--- a/drivers/gpu/drm/drm_global.c
39069+++ b/drivers/gpu/drm/drm_global.c
39070@@ -36,7 +36,7 @@
39071 struct drm_global_item {
39072 struct mutex mutex;
39073 void *object;
39074- int refcount;
39075+ atomic_t refcount;
39076 };
39077
39078 static struct drm_global_item glob[DRM_GLOBAL_NUM];
39079@@ -49,7 +49,7 @@ void drm_global_init(void)
39080 struct drm_global_item *item = &glob[i];
39081 mutex_init(&item->mutex);
39082 item->object = NULL;
39083- item->refcount = 0;
39084+ atomic_set(&item->refcount, 0);
39085 }
39086 }
39087
39088@@ -59,7 +59,7 @@ void drm_global_release(void)
39089 for (i = 0; i < DRM_GLOBAL_NUM; ++i) {
39090 struct drm_global_item *item = &glob[i];
39091 BUG_ON(item->object != NULL);
39092- BUG_ON(item->refcount != 0);
39093+ BUG_ON(atomic_read(&item->refcount) != 0);
39094 }
39095 }
39096
39097@@ -70,7 +70,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
39098 void *object;
39099
39100 mutex_lock(&item->mutex);
39101- if (item->refcount == 0) {
39102+ if (atomic_read(&item->refcount) == 0) {
39103 item->object = kzalloc(ref->size, GFP_KERNEL);
39104 if (unlikely(item->object == NULL)) {
39105 ret = -ENOMEM;
39106@@ -83,7 +83,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
39107 goto out_err;
39108
39109 }
39110- ++item->refcount;
39111+ atomic_inc(&item->refcount);
39112 ref->object = item->object;
39113 object = item->object;
39114 mutex_unlock(&item->mutex);
39115@@ -100,9 +100,9 @@ void drm_global_item_unref(struct drm_global_reference *ref)
39116 struct drm_global_item *item = &glob[ref->global_type];
39117
39118 mutex_lock(&item->mutex);
39119- BUG_ON(item->refcount == 0);
39120+ BUG_ON(atomic_read(&item->refcount) == 0);
39121 BUG_ON(ref->object != item->object);
39122- if (--item->refcount == 0) {
39123+ if (atomic_dec_and_test(&item->refcount)) {
39124 ref->release(ref);
39125 item->object = NULL;
39126 }
39127diff --git a/drivers/gpu/drm/drm_info.c b/drivers/gpu/drm/drm_info.c
39128index 5329832..b503f49 100644
39129--- a/drivers/gpu/drm/drm_info.c
39130+++ b/drivers/gpu/drm/drm_info.c
39131@@ -75,10 +75,14 @@ int drm_vm_info(struct seq_file *m, void *data)
39132 struct drm_local_map *map;
39133 struct drm_map_list *r_list;
39134
39135- /* Hardcoded from _DRM_FRAME_BUFFER,
39136- _DRM_REGISTERS, _DRM_SHM, _DRM_AGP, and
39137- _DRM_SCATTER_GATHER and _DRM_CONSISTENT */
39138- const char *types[] = { "FB", "REG", "SHM", "AGP", "SG", "PCI" };
39139+ static const char * const types[] = {
39140+ [_DRM_FRAME_BUFFER] = "FB",
39141+ [_DRM_REGISTERS] = "REG",
39142+ [_DRM_SHM] = "SHM",
39143+ [_DRM_AGP] = "AGP",
39144+ [_DRM_SCATTER_GATHER] = "SG",
39145+ [_DRM_CONSISTENT] = "PCI",
39146+ [_DRM_GEM] = "GEM" };
39147 const char *type;
39148 int i;
39149
39150@@ -89,7 +93,7 @@ int drm_vm_info(struct seq_file *m, void *data)
39151 map = r_list->map;
39152 if (!map)
39153 continue;
39154- if (map->type < 0 || map->type > 5)
39155+ if (map->type >= ARRAY_SIZE(types))
39156 type = "??";
39157 else
39158 type = types[map->type];
39159@@ -257,7 +261,11 @@ int drm_vma_info(struct seq_file *m, void *data)
39160 vma->vm_flags & VM_MAYSHARE ? 's' : 'p',
39161 vma->vm_flags & VM_LOCKED ? 'l' : '-',
39162 vma->vm_flags & VM_IO ? 'i' : '-',
39163+#ifdef CONFIG_GRKERNSEC_HIDESYM
39164+ 0);
39165+#else
39166 vma->vm_pgoff);
39167+#endif
39168
39169 #if defined(__i386__)
39170 pgprot = pgprot_val(vma->vm_page_prot);
39171diff --git a/drivers/gpu/drm/drm_ioc32.c b/drivers/gpu/drm/drm_ioc32.c
39172index 2f4c434..dd12cd2 100644
39173--- a/drivers/gpu/drm/drm_ioc32.c
39174+++ b/drivers/gpu/drm/drm_ioc32.c
39175@@ -457,7 +457,7 @@ static int compat_drm_infobufs(struct file *file, unsigned int cmd,
39176 request = compat_alloc_user_space(nbytes);
39177 if (!access_ok(VERIFY_WRITE, request, nbytes))
39178 return -EFAULT;
39179- list = (struct drm_buf_desc *) (request + 1);
39180+ list = (struct drm_buf_desc __user *) (request + 1);
39181
39182 if (__put_user(count, &request->count)
39183 || __put_user(list, &request->list))
39184@@ -518,7 +518,7 @@ static int compat_drm_mapbufs(struct file *file, unsigned int cmd,
39185 request = compat_alloc_user_space(nbytes);
39186 if (!access_ok(VERIFY_WRITE, request, nbytes))
39187 return -EFAULT;
39188- list = (struct drm_buf_pub *) (request + 1);
39189+ list = (struct drm_buf_pub __user *) (request + 1);
39190
39191 if (__put_user(count, &request->count)
39192 || __put_user(list, &request->list))
39193@@ -1016,7 +1016,7 @@ static int compat_drm_wait_vblank(struct file *file, unsigned int cmd,
39194 return 0;
39195 }
39196
39197-drm_ioctl_compat_t *drm_compat_ioctls[] = {
39198+drm_ioctl_compat_t drm_compat_ioctls[] = {
39199 [DRM_IOCTL_NR(DRM_IOCTL_VERSION32)] = compat_drm_version,
39200 [DRM_IOCTL_NR(DRM_IOCTL_GET_UNIQUE32)] = compat_drm_getunique,
39201 [DRM_IOCTL_NR(DRM_IOCTL_GET_MAP32)] = compat_drm_getmap,
39202@@ -1062,7 +1062,6 @@ drm_ioctl_compat_t *drm_compat_ioctls[] = {
39203 long drm_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
39204 {
39205 unsigned int nr = DRM_IOCTL_NR(cmd);
39206- drm_ioctl_compat_t *fn;
39207 int ret;
39208
39209 /* Assume that ioctls without an explicit compat routine will just
39210@@ -1072,10 +1071,8 @@ long drm_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
39211 if (nr >= ARRAY_SIZE(drm_compat_ioctls))
39212 return drm_ioctl(filp, cmd, arg);
39213
39214- fn = drm_compat_ioctls[nr];
39215-
39216- if (fn != NULL)
39217- ret = (*fn) (filp, cmd, arg);
39218+ if (drm_compat_ioctls[nr] != NULL)
39219+ ret = (*drm_compat_ioctls[nr]) (filp, cmd, arg);
39220 else
39221 ret = drm_ioctl(filp, cmd, arg);
39222
39223diff --git a/drivers/gpu/drm/drm_lock.c b/drivers/gpu/drm/drm_lock.c
39224index d752c96..fe08455 100644
39225--- a/drivers/gpu/drm/drm_lock.c
39226+++ b/drivers/gpu/drm/drm_lock.c
39227@@ -86,7 +86,7 @@ int drm_lock(struct drm_device *dev, void *data, struct drm_file *file_priv)
39228 if (drm_lock_take(&master->lock, lock->context)) {
39229 master->lock.file_priv = file_priv;
39230 master->lock.lock_time = jiffies;
39231- atomic_inc(&dev->counts[_DRM_STAT_LOCKS]);
39232+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_LOCKS]);
39233 break; /* Got lock */
39234 }
39235
39236@@ -157,7 +157,7 @@ int drm_unlock(struct drm_device *dev, void *data, struct drm_file *file_priv)
39237 return -EINVAL;
39238 }
39239
39240- atomic_inc(&dev->counts[_DRM_STAT_UNLOCKS]);
39241+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_UNLOCKS]);
39242
39243 if (drm_lock_free(&master->lock, lock->context)) {
39244 /* FIXME: Should really bail out here. */
39245diff --git a/drivers/gpu/drm/drm_stub.c b/drivers/gpu/drm/drm_stub.c
39246index 39d8645..59e06fa 100644
39247--- a/drivers/gpu/drm/drm_stub.c
39248+++ b/drivers/gpu/drm/drm_stub.c
39249@@ -484,7 +484,7 @@ void drm_unplug_dev(struct drm_device *dev)
39250
39251 drm_device_set_unplugged(dev);
39252
39253- if (dev->open_count == 0) {
39254+ if (local_read(&dev->open_count) == 0) {
39255 drm_put_dev(dev);
39256 }
39257 mutex_unlock(&drm_global_mutex);
39258diff --git a/drivers/gpu/drm/drm_sysfs.c b/drivers/gpu/drm/drm_sysfs.c
39259index 2290b3b..22056a1 100644
39260--- a/drivers/gpu/drm/drm_sysfs.c
39261+++ b/drivers/gpu/drm/drm_sysfs.c
39262@@ -524,7 +524,7 @@ EXPORT_SYMBOL(drm_sysfs_hotplug_event);
39263 int drm_sysfs_device_add(struct drm_minor *minor)
39264 {
39265 int err;
39266- char *minor_str;
39267+ const char *minor_str;
39268
39269 minor->kdev.parent = minor->dev->dev;
39270
39271diff --git a/drivers/gpu/drm/i810/i810_dma.c b/drivers/gpu/drm/i810/i810_dma.c
39272index ab1892eb..d7009ca 100644
39273--- a/drivers/gpu/drm/i810/i810_dma.c
39274+++ b/drivers/gpu/drm/i810/i810_dma.c
39275@@ -944,8 +944,8 @@ static int i810_dma_vertex(struct drm_device *dev, void *data,
39276 dma->buflist[vertex->idx],
39277 vertex->discard, vertex->used);
39278
39279- atomic_add(vertex->used, &dev->counts[_DRM_STAT_SECONDARY]);
39280- atomic_inc(&dev->counts[_DRM_STAT_DMA]);
39281+ atomic_add_unchecked(vertex->used, &dev->counts[_DRM_STAT_SECONDARY]);
39282+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_DMA]);
39283 sarea_priv->last_enqueue = dev_priv->counter - 1;
39284 sarea_priv->last_dispatch = (int)hw_status[5];
39285
39286@@ -1105,8 +1105,8 @@ static int i810_dma_mc(struct drm_device *dev, void *data,
39287 i810_dma_dispatch_mc(dev, dma->buflist[mc->idx], mc->used,
39288 mc->last_render);
39289
39290- atomic_add(mc->used, &dev->counts[_DRM_STAT_SECONDARY]);
39291- atomic_inc(&dev->counts[_DRM_STAT_DMA]);
39292+ atomic_add_unchecked(mc->used, &dev->counts[_DRM_STAT_SECONDARY]);
39293+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_DMA]);
39294 sarea_priv->last_enqueue = dev_priv->counter - 1;
39295 sarea_priv->last_dispatch = (int)hw_status[5];
39296
39297diff --git a/drivers/gpu/drm/i810/i810_drv.h b/drivers/gpu/drm/i810/i810_drv.h
39298index d4d16ed..8fb0b51 100644
39299--- a/drivers/gpu/drm/i810/i810_drv.h
39300+++ b/drivers/gpu/drm/i810/i810_drv.h
39301@@ -108,8 +108,8 @@ typedef struct drm_i810_private {
39302 int page_flipping;
39303
39304 wait_queue_head_t irq_queue;
39305- atomic_t irq_received;
39306- atomic_t irq_emitted;
39307+ atomic_unchecked_t irq_received;
39308+ atomic_unchecked_t irq_emitted;
39309
39310 int front_offset;
39311 } drm_i810_private_t;
39312diff --git a/drivers/gpu/drm/i915/i915_debugfs.c b/drivers/gpu/drm/i915/i915_debugfs.c
39313index a6f4cb5..6b2beb2 100644
39314--- a/drivers/gpu/drm/i915/i915_debugfs.c
39315+++ b/drivers/gpu/drm/i915/i915_debugfs.c
39316@@ -624,7 +624,7 @@ static int i915_interrupt_info(struct seq_file *m, void *data)
39317 I915_READ(GTIMR));
39318 }
39319 seq_printf(m, "Interrupts received: %d\n",
39320- atomic_read(&dev_priv->irq_received));
39321+ atomic_read_unchecked(&dev_priv->irq_received));
39322 for_each_ring(ring, dev_priv, i) {
39323 if (IS_GEN6(dev) || IS_GEN7(dev)) {
39324 seq_printf(m,
39325diff --git a/drivers/gpu/drm/i915/i915_dma.c b/drivers/gpu/drm/i915/i915_dma.c
39326index 5a25f24..5af2004 100644
39327--- a/drivers/gpu/drm/i915/i915_dma.c
39328+++ b/drivers/gpu/drm/i915/i915_dma.c
39329@@ -1271,7 +1271,7 @@ static bool i915_switcheroo_can_switch(struct pci_dev *pdev)
39330 bool can_switch;
39331
39332 spin_lock(&dev->count_lock);
39333- can_switch = (dev->open_count == 0);
39334+ can_switch = (local_read(&dev->open_count) == 0);
39335 spin_unlock(&dev->count_lock);
39336 return can_switch;
39337 }
39338diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
39339index ab0f2c0..53c1bda 100644
39340--- a/drivers/gpu/drm/i915/i915_drv.h
39341+++ b/drivers/gpu/drm/i915/i915_drv.h
39342@@ -1181,7 +1181,7 @@ typedef struct drm_i915_private {
39343 drm_dma_handle_t *status_page_dmah;
39344 struct resource mch_res;
39345
39346- atomic_t irq_received;
39347+ atomic_unchecked_t irq_received;
39348
39349 /* protects the irq masks */
39350 spinlock_t irq_lock;
39351diff --git a/drivers/gpu/drm/i915/i915_gem_execbuffer.c b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
39352index bf34577..3fd2ffa 100644
39353--- a/drivers/gpu/drm/i915/i915_gem_execbuffer.c
39354+++ b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
39355@@ -768,9 +768,9 @@ i915_gem_check_execbuffer(struct drm_i915_gem_execbuffer2 *exec)
39356
39357 static int
39358 validate_exec_list(struct drm_i915_gem_exec_object2 *exec,
39359- int count)
39360+ unsigned int count)
39361 {
39362- int i;
39363+ unsigned int i;
39364 int relocs_total = 0;
39365 int relocs_max = INT_MAX / sizeof(struct drm_i915_gem_relocation_entry);
39366
39367diff --git a/drivers/gpu/drm/i915/i915_ioc32.c b/drivers/gpu/drm/i915/i915_ioc32.c
39368index 3c59584..500f2e9 100644
39369--- a/drivers/gpu/drm/i915/i915_ioc32.c
39370+++ b/drivers/gpu/drm/i915/i915_ioc32.c
39371@@ -181,7 +181,7 @@ static int compat_i915_alloc(struct file *file, unsigned int cmd,
39372 (unsigned long)request);
39373 }
39374
39375-static drm_ioctl_compat_t *i915_compat_ioctls[] = {
39376+static drm_ioctl_compat_t i915_compat_ioctls[] = {
39377 [DRM_I915_BATCHBUFFER] = compat_i915_batchbuffer,
39378 [DRM_I915_CMDBUFFER] = compat_i915_cmdbuffer,
39379 [DRM_I915_GETPARAM] = compat_i915_getparam,
39380@@ -202,18 +202,15 @@ static drm_ioctl_compat_t *i915_compat_ioctls[] = {
39381 long i915_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
39382 {
39383 unsigned int nr = DRM_IOCTL_NR(cmd);
39384- drm_ioctl_compat_t *fn = NULL;
39385 int ret;
39386
39387 if (nr < DRM_COMMAND_BASE)
39388 return drm_compat_ioctl(filp, cmd, arg);
39389
39390- if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(i915_compat_ioctls))
39391- fn = i915_compat_ioctls[nr - DRM_COMMAND_BASE];
39392-
39393- if (fn != NULL)
39394+ if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(i915_compat_ioctls)) {
39395+ drm_ioctl_compat_t fn = i915_compat_ioctls[nr - DRM_COMMAND_BASE];
39396 ret = (*fn) (filp, cmd, arg);
39397- else
39398+ } else
39399 ret = drm_ioctl(filp, cmd, arg);
39400
39401 return ret;
39402diff --git a/drivers/gpu/drm/i915/i915_irq.c b/drivers/gpu/drm/i915/i915_irq.c
39403index 4b91228..590c643 100644
39404--- a/drivers/gpu/drm/i915/i915_irq.c
39405+++ b/drivers/gpu/drm/i915/i915_irq.c
39406@@ -1085,7 +1085,7 @@ static irqreturn_t valleyview_irq_handler(int irq, void *arg)
39407 int pipe;
39408 u32 pipe_stats[I915_MAX_PIPES];
39409
39410- atomic_inc(&dev_priv->irq_received);
39411+ atomic_inc_unchecked(&dev_priv->irq_received);
39412
39413 while (true) {
39414 iir = I915_READ(VLV_IIR);
39415@@ -1390,7 +1390,7 @@ static irqreturn_t ironlake_irq_handler(int irq, void *arg)
39416 irqreturn_t ret = IRQ_NONE;
39417 bool err_int_reenable = false;
39418
39419- atomic_inc(&dev_priv->irq_received);
39420+ atomic_inc_unchecked(&dev_priv->irq_received);
39421
39422 /* We get interrupts on unclaimed registers, so check for this before we
39423 * do any I915_{READ,WRITE}. */
39424@@ -2146,7 +2146,7 @@ static void ironlake_irq_preinstall(struct drm_device *dev)
39425 {
39426 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
39427
39428- atomic_set(&dev_priv->irq_received, 0);
39429+ atomic_set_unchecked(&dev_priv->irq_received, 0);
39430
39431 I915_WRITE(HWSTAM, 0xeffe);
39432
39433@@ -2164,7 +2164,7 @@ static void valleyview_irq_preinstall(struct drm_device *dev)
39434 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
39435 int pipe;
39436
39437- atomic_set(&dev_priv->irq_received, 0);
39438+ atomic_set_unchecked(&dev_priv->irq_received, 0);
39439
39440 /* VLV magic */
39441 I915_WRITE(VLV_IMR, 0);
39442@@ -2452,7 +2452,7 @@ static void i8xx_irq_preinstall(struct drm_device * dev)
39443 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
39444 int pipe;
39445
39446- atomic_set(&dev_priv->irq_received, 0);
39447+ atomic_set_unchecked(&dev_priv->irq_received, 0);
39448
39449 for_each_pipe(pipe)
39450 I915_WRITE(PIPESTAT(pipe), 0);
39451@@ -2530,7 +2530,7 @@ static irqreturn_t i8xx_irq_handler(int irq, void *arg)
39452 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
39453 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
39454
39455- atomic_inc(&dev_priv->irq_received);
39456+ atomic_inc_unchecked(&dev_priv->irq_received);
39457
39458 iir = I915_READ16(IIR);
39459 if (iir == 0)
39460@@ -2604,7 +2604,7 @@ static void i915_irq_preinstall(struct drm_device * dev)
39461 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
39462 int pipe;
39463
39464- atomic_set(&dev_priv->irq_received, 0);
39465+ atomic_set_unchecked(&dev_priv->irq_received, 0);
39466
39467 if (I915_HAS_HOTPLUG(dev)) {
39468 I915_WRITE(PORT_HOTPLUG_EN, 0);
39469@@ -2703,7 +2703,7 @@ static irqreturn_t i915_irq_handler(int irq, void *arg)
39470 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
39471 int pipe, ret = IRQ_NONE;
39472
39473- atomic_inc(&dev_priv->irq_received);
39474+ atomic_inc_unchecked(&dev_priv->irq_received);
39475
39476 iir = I915_READ(IIR);
39477 do {
39478@@ -2827,7 +2827,7 @@ static void i965_irq_preinstall(struct drm_device * dev)
39479 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
39480 int pipe;
39481
39482- atomic_set(&dev_priv->irq_received, 0);
39483+ atomic_set_unchecked(&dev_priv->irq_received, 0);
39484
39485 I915_WRITE(PORT_HOTPLUG_EN, 0);
39486 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
39487@@ -2941,7 +2941,7 @@ static irqreturn_t i965_irq_handler(int irq, void *arg)
39488 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
39489 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
39490
39491- atomic_inc(&dev_priv->irq_received);
39492+ atomic_inc_unchecked(&dev_priv->irq_received);
39493
39494 iir = I915_READ(IIR);
39495
39496diff --git a/drivers/gpu/drm/i915/intel_display.c b/drivers/gpu/drm/i915/intel_display.c
39497index aad6f7b..dcc91447 100644
39498--- a/drivers/gpu/drm/i915/intel_display.c
39499+++ b/drivers/gpu/drm/i915/intel_display.c
39500@@ -10019,13 +10019,13 @@ struct intel_quirk {
39501 int subsystem_vendor;
39502 int subsystem_device;
39503 void (*hook)(struct drm_device *dev);
39504-};
39505+} __do_const;
39506
39507 /* For systems that don't have a meaningful PCI subdevice/subvendor ID */
39508 struct intel_dmi_quirk {
39509 void (*hook)(struct drm_device *dev);
39510 const struct dmi_system_id (*dmi_id_list)[];
39511-};
39512+} __do_const;
39513
39514 static int intel_dmi_reverse_brightness(const struct dmi_system_id *id)
39515 {
39516@@ -10033,18 +10033,20 @@ static int intel_dmi_reverse_brightness(const struct dmi_system_id *id)
39517 return 1;
39518 }
39519
39520-static const struct intel_dmi_quirk intel_dmi_quirks[] = {
39521+static const struct dmi_system_id intel_dmi_quirks_table[] = {
39522 {
39523- .dmi_id_list = &(const struct dmi_system_id[]) {
39524- {
39525- .callback = intel_dmi_reverse_brightness,
39526- .ident = "NCR Corporation",
39527- .matches = {DMI_MATCH(DMI_SYS_VENDOR, "NCR Corporation"),
39528- DMI_MATCH(DMI_PRODUCT_NAME, ""),
39529- },
39530- },
39531- { } /* terminating entry */
39532+ .callback = intel_dmi_reverse_brightness,
39533+ .ident = "NCR Corporation",
39534+ .matches = {DMI_MATCH(DMI_SYS_VENDOR, "NCR Corporation"),
39535+ DMI_MATCH(DMI_PRODUCT_NAME, ""),
39536 },
39537+ },
39538+ { } /* terminating entry */
39539+};
39540+
39541+static const struct intel_dmi_quirk intel_dmi_quirks[] = {
39542+ {
39543+ .dmi_id_list = &intel_dmi_quirks_table,
39544 .hook = quirk_invert_brightness,
39545 },
39546 };
39547diff --git a/drivers/gpu/drm/mga/mga_drv.h b/drivers/gpu/drm/mga/mga_drv.h
39548index ca4bc54..ee598a2 100644
39549--- a/drivers/gpu/drm/mga/mga_drv.h
39550+++ b/drivers/gpu/drm/mga/mga_drv.h
39551@@ -120,9 +120,9 @@ typedef struct drm_mga_private {
39552 u32 clear_cmd;
39553 u32 maccess;
39554
39555- atomic_t vbl_received; /**< Number of vblanks received. */
39556+ atomic_unchecked_t vbl_received; /**< Number of vblanks received. */
39557 wait_queue_head_t fence_queue;
39558- atomic_t last_fence_retired;
39559+ atomic_unchecked_t last_fence_retired;
39560 u32 next_fence_to_post;
39561
39562 unsigned int fb_cpp;
39563diff --git a/drivers/gpu/drm/mga/mga_ioc32.c b/drivers/gpu/drm/mga/mga_ioc32.c
39564index 709e90d..89a1c0d 100644
39565--- a/drivers/gpu/drm/mga/mga_ioc32.c
39566+++ b/drivers/gpu/drm/mga/mga_ioc32.c
39567@@ -189,7 +189,7 @@ static int compat_mga_dma_bootstrap(struct file *file, unsigned int cmd,
39568 return 0;
39569 }
39570
39571-drm_ioctl_compat_t *mga_compat_ioctls[] = {
39572+drm_ioctl_compat_t mga_compat_ioctls[] = {
39573 [DRM_MGA_INIT] = compat_mga_init,
39574 [DRM_MGA_GETPARAM] = compat_mga_getparam,
39575 [DRM_MGA_DMA_BOOTSTRAP] = compat_mga_dma_bootstrap,
39576@@ -207,18 +207,15 @@ drm_ioctl_compat_t *mga_compat_ioctls[] = {
39577 long mga_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
39578 {
39579 unsigned int nr = DRM_IOCTL_NR(cmd);
39580- drm_ioctl_compat_t *fn = NULL;
39581 int ret;
39582
39583 if (nr < DRM_COMMAND_BASE)
39584 return drm_compat_ioctl(filp, cmd, arg);
39585
39586- if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(mga_compat_ioctls))
39587- fn = mga_compat_ioctls[nr - DRM_COMMAND_BASE];
39588-
39589- if (fn != NULL)
39590+ if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(mga_compat_ioctls)) {
39591+ drm_ioctl_compat_t fn = mga_compat_ioctls[nr - DRM_COMMAND_BASE];
39592 ret = (*fn) (filp, cmd, arg);
39593- else
39594+ } else
39595 ret = drm_ioctl(filp, cmd, arg);
39596
39597 return ret;
39598diff --git a/drivers/gpu/drm/mga/mga_irq.c b/drivers/gpu/drm/mga/mga_irq.c
39599index 598c281..60d590e 100644
39600--- a/drivers/gpu/drm/mga/mga_irq.c
39601+++ b/drivers/gpu/drm/mga/mga_irq.c
39602@@ -43,7 +43,7 @@ u32 mga_get_vblank_counter(struct drm_device *dev, int crtc)
39603 if (crtc != 0)
39604 return 0;
39605
39606- return atomic_read(&dev_priv->vbl_received);
39607+ return atomic_read_unchecked(&dev_priv->vbl_received);
39608 }
39609
39610
39611@@ -59,7 +59,7 @@ irqreturn_t mga_driver_irq_handler(DRM_IRQ_ARGS)
39612 /* VBLANK interrupt */
39613 if (status & MGA_VLINEPEN) {
39614 MGA_WRITE(MGA_ICLEAR, MGA_VLINEICLR);
39615- atomic_inc(&dev_priv->vbl_received);
39616+ atomic_inc_unchecked(&dev_priv->vbl_received);
39617 drm_handle_vblank(dev, 0);
39618 handled = 1;
39619 }
39620@@ -78,7 +78,7 @@ irqreturn_t mga_driver_irq_handler(DRM_IRQ_ARGS)
39621 if ((prim_start & ~0x03) != (prim_end & ~0x03))
39622 MGA_WRITE(MGA_PRIMEND, prim_end);
39623
39624- atomic_inc(&dev_priv->last_fence_retired);
39625+ atomic_inc_unchecked(&dev_priv->last_fence_retired);
39626 DRM_WAKEUP(&dev_priv->fence_queue);
39627 handled = 1;
39628 }
39629@@ -129,7 +129,7 @@ int mga_driver_fence_wait(struct drm_device *dev, unsigned int *sequence)
39630 * using fences.
39631 */
39632 DRM_WAIT_ON(ret, dev_priv->fence_queue, 3 * DRM_HZ,
39633- (((cur_fence = atomic_read(&dev_priv->last_fence_retired))
39634+ (((cur_fence = atomic_read_unchecked(&dev_priv->last_fence_retired))
39635 - *sequence) <= (1 << 23)));
39636
39637 *sequence = cur_fence;
39638diff --git a/drivers/gpu/drm/nouveau/nouveau_bios.c b/drivers/gpu/drm/nouveau/nouveau_bios.c
39639index 3e72876..d1c15ad 100644
39640--- a/drivers/gpu/drm/nouveau/nouveau_bios.c
39641+++ b/drivers/gpu/drm/nouveau/nouveau_bios.c
39642@@ -965,7 +965,7 @@ static int parse_bit_tmds_tbl_entry(struct drm_device *dev, struct nvbios *bios,
39643 struct bit_table {
39644 const char id;
39645 int (* const parse_fn)(struct drm_device *, struct nvbios *, struct bit_entry *);
39646-};
39647+} __no_const;
39648
39649 #define BIT_TABLE(id, funcid) ((struct bit_table){ id, parse_bit_##funcid##_tbl_entry })
39650
39651diff --git a/drivers/gpu/drm/nouveau/nouveau_drm.h b/drivers/gpu/drm/nouveau/nouveau_drm.h
39652index 994fd6e..6e12565 100644
39653--- a/drivers/gpu/drm/nouveau/nouveau_drm.h
39654+++ b/drivers/gpu/drm/nouveau/nouveau_drm.h
39655@@ -94,7 +94,6 @@ struct nouveau_drm {
39656 struct drm_global_reference mem_global_ref;
39657 struct ttm_bo_global_ref bo_global_ref;
39658 struct ttm_bo_device bdev;
39659- atomic_t validate_sequence;
39660 int (*move)(struct nouveau_channel *,
39661 struct ttm_buffer_object *,
39662 struct ttm_mem_reg *, struct ttm_mem_reg *);
39663diff --git a/drivers/gpu/drm/nouveau/nouveau_ioc32.c b/drivers/gpu/drm/nouveau/nouveau_ioc32.c
39664index c1a7e5a..38b8539 100644
39665--- a/drivers/gpu/drm/nouveau/nouveau_ioc32.c
39666+++ b/drivers/gpu/drm/nouveau/nouveau_ioc32.c
39667@@ -50,7 +50,7 @@ long nouveau_compat_ioctl(struct file *filp, unsigned int cmd,
39668 unsigned long arg)
39669 {
39670 unsigned int nr = DRM_IOCTL_NR(cmd);
39671- drm_ioctl_compat_t *fn = NULL;
39672+ drm_ioctl_compat_t fn = NULL;
39673 int ret;
39674
39675 if (nr < DRM_COMMAND_BASE)
39676diff --git a/drivers/gpu/drm/nouveau/nouveau_ttm.c b/drivers/gpu/drm/nouveau/nouveau_ttm.c
39677index 19e3757..ad16478 100644
39678--- a/drivers/gpu/drm/nouveau/nouveau_ttm.c
39679+++ b/drivers/gpu/drm/nouveau/nouveau_ttm.c
39680@@ -130,11 +130,11 @@ nouveau_vram_manager_debug(struct ttm_mem_type_manager *man, const char *prefix)
39681 }
39682
39683 const struct ttm_mem_type_manager_func nouveau_vram_manager = {
39684- nouveau_vram_manager_init,
39685- nouveau_vram_manager_fini,
39686- nouveau_vram_manager_new,
39687- nouveau_vram_manager_del,
39688- nouveau_vram_manager_debug
39689+ .init = nouveau_vram_manager_init,
39690+ .takedown = nouveau_vram_manager_fini,
39691+ .get_node = nouveau_vram_manager_new,
39692+ .put_node = nouveau_vram_manager_del,
39693+ .debug = nouveau_vram_manager_debug
39694 };
39695
39696 static int
39697@@ -198,11 +198,11 @@ nouveau_gart_manager_debug(struct ttm_mem_type_manager *man, const char *prefix)
39698 }
39699
39700 const struct ttm_mem_type_manager_func nouveau_gart_manager = {
39701- nouveau_gart_manager_init,
39702- nouveau_gart_manager_fini,
39703- nouveau_gart_manager_new,
39704- nouveau_gart_manager_del,
39705- nouveau_gart_manager_debug
39706+ .init = nouveau_gart_manager_init,
39707+ .takedown = nouveau_gart_manager_fini,
39708+ .get_node = nouveau_gart_manager_new,
39709+ .put_node = nouveau_gart_manager_del,
39710+ .debug = nouveau_gart_manager_debug
39711 };
39712
39713 #include <core/subdev/vm/nv04.h>
39714@@ -270,11 +270,11 @@ nv04_gart_manager_debug(struct ttm_mem_type_manager *man, const char *prefix)
39715 }
39716
39717 const struct ttm_mem_type_manager_func nv04_gart_manager = {
39718- nv04_gart_manager_init,
39719- nv04_gart_manager_fini,
39720- nv04_gart_manager_new,
39721- nv04_gart_manager_del,
39722- nv04_gart_manager_debug
39723+ .init = nv04_gart_manager_init,
39724+ .takedown = nv04_gart_manager_fini,
39725+ .get_node = nv04_gart_manager_new,
39726+ .put_node = nv04_gart_manager_del,
39727+ .debug = nv04_gart_manager_debug
39728 };
39729
39730 int
39731diff --git a/drivers/gpu/drm/nouveau/nouveau_vga.c b/drivers/gpu/drm/nouveau/nouveau_vga.c
39732index 81638d7..2e45854 100644
39733--- a/drivers/gpu/drm/nouveau/nouveau_vga.c
39734+++ b/drivers/gpu/drm/nouveau/nouveau_vga.c
39735@@ -65,7 +65,7 @@ nouveau_switcheroo_can_switch(struct pci_dev *pdev)
39736 bool can_switch;
39737
39738 spin_lock(&dev->count_lock);
39739- can_switch = (dev->open_count == 0);
39740+ can_switch = (local_read(&dev->open_count) == 0);
39741 spin_unlock(&dev->count_lock);
39742 return can_switch;
39743 }
39744diff --git a/drivers/gpu/drm/qxl/qxl_cmd.c b/drivers/gpu/drm/qxl/qxl_cmd.c
39745index eb89653..613cf71 100644
39746--- a/drivers/gpu/drm/qxl/qxl_cmd.c
39747+++ b/drivers/gpu/drm/qxl/qxl_cmd.c
39748@@ -285,27 +285,27 @@ static int wait_for_io_cmd_user(struct qxl_device *qdev, uint8_t val, long port,
39749 int ret;
39750
39751 mutex_lock(&qdev->async_io_mutex);
39752- irq_num = atomic_read(&qdev->irq_received_io_cmd);
39753+ irq_num = atomic_read_unchecked(&qdev->irq_received_io_cmd);
39754 if (qdev->last_sent_io_cmd > irq_num) {
39755 if (intr)
39756 ret = wait_event_interruptible_timeout(qdev->io_cmd_event,
39757- atomic_read(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
39758+ atomic_read_unchecked(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
39759 else
39760 ret = wait_event_timeout(qdev->io_cmd_event,
39761- atomic_read(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
39762+ atomic_read_unchecked(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
39763 /* 0 is timeout, just bail the "hw" has gone away */
39764 if (ret <= 0)
39765 goto out;
39766- irq_num = atomic_read(&qdev->irq_received_io_cmd);
39767+ irq_num = atomic_read_unchecked(&qdev->irq_received_io_cmd);
39768 }
39769 outb(val, addr);
39770 qdev->last_sent_io_cmd = irq_num + 1;
39771 if (intr)
39772 ret = wait_event_interruptible_timeout(qdev->io_cmd_event,
39773- atomic_read(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
39774+ atomic_read_unchecked(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
39775 else
39776 ret = wait_event_timeout(qdev->io_cmd_event,
39777- atomic_read(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
39778+ atomic_read_unchecked(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
39779 out:
39780 if (ret > 0)
39781 ret = 0;
39782diff --git a/drivers/gpu/drm/qxl/qxl_debugfs.c b/drivers/gpu/drm/qxl/qxl_debugfs.c
39783index c3c2bbd..bc3c0fb 100644
39784--- a/drivers/gpu/drm/qxl/qxl_debugfs.c
39785+++ b/drivers/gpu/drm/qxl/qxl_debugfs.c
39786@@ -42,10 +42,10 @@ qxl_debugfs_irq_received(struct seq_file *m, void *data)
39787 struct drm_info_node *node = (struct drm_info_node *) m->private;
39788 struct qxl_device *qdev = node->minor->dev->dev_private;
39789
39790- seq_printf(m, "%d\n", atomic_read(&qdev->irq_received));
39791- seq_printf(m, "%d\n", atomic_read(&qdev->irq_received_display));
39792- seq_printf(m, "%d\n", atomic_read(&qdev->irq_received_cursor));
39793- seq_printf(m, "%d\n", atomic_read(&qdev->irq_received_io_cmd));
39794+ seq_printf(m, "%d\n", atomic_read_unchecked(&qdev->irq_received));
39795+ seq_printf(m, "%d\n", atomic_read_unchecked(&qdev->irq_received_display));
39796+ seq_printf(m, "%d\n", atomic_read_unchecked(&qdev->irq_received_cursor));
39797+ seq_printf(m, "%d\n", atomic_read_unchecked(&qdev->irq_received_io_cmd));
39798 seq_printf(m, "%d\n", qdev->irq_received_error);
39799 return 0;
39800 }
39801diff --git a/drivers/gpu/drm/qxl/qxl_drv.h b/drivers/gpu/drm/qxl/qxl_drv.h
39802index f7c9add..fb971d2 100644
39803--- a/drivers/gpu/drm/qxl/qxl_drv.h
39804+++ b/drivers/gpu/drm/qxl/qxl_drv.h
39805@@ -290,10 +290,10 @@ struct qxl_device {
39806 unsigned int last_sent_io_cmd;
39807
39808 /* interrupt handling */
39809- atomic_t irq_received;
39810- atomic_t irq_received_display;
39811- atomic_t irq_received_cursor;
39812- atomic_t irq_received_io_cmd;
39813+ atomic_unchecked_t irq_received;
39814+ atomic_unchecked_t irq_received_display;
39815+ atomic_unchecked_t irq_received_cursor;
39816+ atomic_unchecked_t irq_received_io_cmd;
39817 unsigned irq_received_error;
39818 wait_queue_head_t display_event;
39819 wait_queue_head_t cursor_event;
39820diff --git a/drivers/gpu/drm/qxl/qxl_irq.c b/drivers/gpu/drm/qxl/qxl_irq.c
39821index 21393dc..329f3a9 100644
39822--- a/drivers/gpu/drm/qxl/qxl_irq.c
39823+++ b/drivers/gpu/drm/qxl/qxl_irq.c
39824@@ -33,19 +33,19 @@ irqreturn_t qxl_irq_handler(DRM_IRQ_ARGS)
39825
39826 pending = xchg(&qdev->ram_header->int_pending, 0);
39827
39828- atomic_inc(&qdev->irq_received);
39829+ atomic_inc_unchecked(&qdev->irq_received);
39830
39831 if (pending & QXL_INTERRUPT_DISPLAY) {
39832- atomic_inc(&qdev->irq_received_display);
39833+ atomic_inc_unchecked(&qdev->irq_received_display);
39834 wake_up_all(&qdev->display_event);
39835 qxl_queue_garbage_collect(qdev, false);
39836 }
39837 if (pending & QXL_INTERRUPT_CURSOR) {
39838- atomic_inc(&qdev->irq_received_cursor);
39839+ atomic_inc_unchecked(&qdev->irq_received_cursor);
39840 wake_up_all(&qdev->cursor_event);
39841 }
39842 if (pending & QXL_INTERRUPT_IO_CMD) {
39843- atomic_inc(&qdev->irq_received_io_cmd);
39844+ atomic_inc_unchecked(&qdev->irq_received_io_cmd);
39845 wake_up_all(&qdev->io_cmd_event);
39846 }
39847 if (pending & QXL_INTERRUPT_ERROR) {
39848@@ -82,10 +82,10 @@ int qxl_irq_init(struct qxl_device *qdev)
39849 init_waitqueue_head(&qdev->io_cmd_event);
39850 INIT_WORK(&qdev->client_monitors_config_work,
39851 qxl_client_monitors_config_work_func);
39852- atomic_set(&qdev->irq_received, 0);
39853- atomic_set(&qdev->irq_received_display, 0);
39854- atomic_set(&qdev->irq_received_cursor, 0);
39855- atomic_set(&qdev->irq_received_io_cmd, 0);
39856+ atomic_set_unchecked(&qdev->irq_received, 0);
39857+ atomic_set_unchecked(&qdev->irq_received_display, 0);
39858+ atomic_set_unchecked(&qdev->irq_received_cursor, 0);
39859+ atomic_set_unchecked(&qdev->irq_received_io_cmd, 0);
39860 qdev->irq_received_error = 0;
39861 ret = drm_irq_install(qdev->ddev);
39862 qdev->ram_header->int_mask = QXL_INTERRUPT_MASK;
39863diff --git a/drivers/gpu/drm/qxl/qxl_ttm.c b/drivers/gpu/drm/qxl/qxl_ttm.c
39864index 037786d..2a95e33 100644
39865--- a/drivers/gpu/drm/qxl/qxl_ttm.c
39866+++ b/drivers/gpu/drm/qxl/qxl_ttm.c
39867@@ -103,7 +103,7 @@ static void qxl_ttm_global_fini(struct qxl_device *qdev)
39868 }
39869 }
39870
39871-static struct vm_operations_struct qxl_ttm_vm_ops;
39872+static vm_operations_struct_no_const qxl_ttm_vm_ops __read_only;
39873 static const struct vm_operations_struct *ttm_vm_ops;
39874
39875 static int qxl_ttm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
39876@@ -147,8 +147,10 @@ int qxl_mmap(struct file *filp, struct vm_area_struct *vma)
39877 return r;
39878 if (unlikely(ttm_vm_ops == NULL)) {
39879 ttm_vm_ops = vma->vm_ops;
39880+ pax_open_kernel();
39881 qxl_ttm_vm_ops = *ttm_vm_ops;
39882 qxl_ttm_vm_ops.fault = &qxl_ttm_fault;
39883+ pax_close_kernel();
39884 }
39885 vma->vm_ops = &qxl_ttm_vm_ops;
39886 return 0;
39887@@ -558,25 +560,23 @@ static int qxl_mm_dump_table(struct seq_file *m, void *data)
39888 static int qxl_ttm_debugfs_init(struct qxl_device *qdev)
39889 {
39890 #if defined(CONFIG_DEBUG_FS)
39891- static struct drm_info_list qxl_mem_types_list[QXL_DEBUGFS_MEM_TYPES];
39892- static char qxl_mem_types_names[QXL_DEBUGFS_MEM_TYPES][32];
39893- unsigned i;
39894+ static struct drm_info_list qxl_mem_types_list[QXL_DEBUGFS_MEM_TYPES] = {
39895+ {
39896+ .name = "qxl_mem_mm",
39897+ .show = &qxl_mm_dump_table,
39898+ },
39899+ {
39900+ .name = "qxl_surf_mm",
39901+ .show = &qxl_mm_dump_table,
39902+ }
39903+ };
39904
39905- for (i = 0; i < QXL_DEBUGFS_MEM_TYPES; i++) {
39906- if (i == 0)
39907- sprintf(qxl_mem_types_names[i], "qxl_mem_mm");
39908- else
39909- sprintf(qxl_mem_types_names[i], "qxl_surf_mm");
39910- qxl_mem_types_list[i].name = qxl_mem_types_names[i];
39911- qxl_mem_types_list[i].show = &qxl_mm_dump_table;
39912- qxl_mem_types_list[i].driver_features = 0;
39913- if (i == 0)
39914- qxl_mem_types_list[i].data = qdev->mman.bdev.man[TTM_PL_VRAM].priv;
39915- else
39916- qxl_mem_types_list[i].data = qdev->mman.bdev.man[TTM_PL_PRIV0].priv;
39917+ pax_open_kernel();
39918+ *(void **)&qxl_mem_types_list[0].data = qdev->mman.bdev.man[TTM_PL_VRAM].priv;
39919+ *(void **)&qxl_mem_types_list[1].data = qdev->mman.bdev.man[TTM_PL_PRIV0].priv;
39920+ pax_close_kernel();
39921
39922- }
39923- return qxl_debugfs_add_files(qdev, qxl_mem_types_list, i);
39924+ return qxl_debugfs_add_files(qdev, qxl_mem_types_list, QXL_DEBUGFS_MEM_TYPES);
39925 #else
39926 return 0;
39927 #endif
39928diff --git a/drivers/gpu/drm/r128/r128_cce.c b/drivers/gpu/drm/r128/r128_cce.c
39929index c451257..0ad2134 100644
39930--- a/drivers/gpu/drm/r128/r128_cce.c
39931+++ b/drivers/gpu/drm/r128/r128_cce.c
39932@@ -377,7 +377,7 @@ static int r128_do_init_cce(struct drm_device *dev, drm_r128_init_t *init)
39933
39934 /* GH: Simple idle check.
39935 */
39936- atomic_set(&dev_priv->idle_count, 0);
39937+ atomic_set_unchecked(&dev_priv->idle_count, 0);
39938
39939 /* We don't support anything other than bus-mastering ring mode,
39940 * but the ring can be in either AGP or PCI space for the ring
39941diff --git a/drivers/gpu/drm/r128/r128_drv.h b/drivers/gpu/drm/r128/r128_drv.h
39942index 56eb5e3..c4ec43d 100644
39943--- a/drivers/gpu/drm/r128/r128_drv.h
39944+++ b/drivers/gpu/drm/r128/r128_drv.h
39945@@ -90,14 +90,14 @@ typedef struct drm_r128_private {
39946 int is_pci;
39947 unsigned long cce_buffers_offset;
39948
39949- atomic_t idle_count;
39950+ atomic_unchecked_t idle_count;
39951
39952 int page_flipping;
39953 int current_page;
39954 u32 crtc_offset;
39955 u32 crtc_offset_cntl;
39956
39957- atomic_t vbl_received;
39958+ atomic_unchecked_t vbl_received;
39959
39960 u32 color_fmt;
39961 unsigned int front_offset;
39962diff --git a/drivers/gpu/drm/r128/r128_ioc32.c b/drivers/gpu/drm/r128/r128_ioc32.c
39963index a954c54..9cc595c 100644
39964--- a/drivers/gpu/drm/r128/r128_ioc32.c
39965+++ b/drivers/gpu/drm/r128/r128_ioc32.c
39966@@ -177,7 +177,7 @@ static int compat_r128_getparam(struct file *file, unsigned int cmd,
39967 return drm_ioctl(file, DRM_IOCTL_R128_GETPARAM, (unsigned long)getparam);
39968 }
39969
39970-drm_ioctl_compat_t *r128_compat_ioctls[] = {
39971+drm_ioctl_compat_t r128_compat_ioctls[] = {
39972 [DRM_R128_INIT] = compat_r128_init,
39973 [DRM_R128_DEPTH] = compat_r128_depth,
39974 [DRM_R128_STIPPLE] = compat_r128_stipple,
39975@@ -196,18 +196,15 @@ drm_ioctl_compat_t *r128_compat_ioctls[] = {
39976 long r128_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
39977 {
39978 unsigned int nr = DRM_IOCTL_NR(cmd);
39979- drm_ioctl_compat_t *fn = NULL;
39980 int ret;
39981
39982 if (nr < DRM_COMMAND_BASE)
39983 return drm_compat_ioctl(filp, cmd, arg);
39984
39985- if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(r128_compat_ioctls))
39986- fn = r128_compat_ioctls[nr - DRM_COMMAND_BASE];
39987-
39988- if (fn != NULL)
39989+ if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(r128_compat_ioctls)) {
39990+ drm_ioctl_compat_t fn = r128_compat_ioctls[nr - DRM_COMMAND_BASE];
39991 ret = (*fn) (filp, cmd, arg);
39992- else
39993+ } else
39994 ret = drm_ioctl(filp, cmd, arg);
39995
39996 return ret;
39997diff --git a/drivers/gpu/drm/r128/r128_irq.c b/drivers/gpu/drm/r128/r128_irq.c
39998index 2ea4f09..d391371 100644
39999--- a/drivers/gpu/drm/r128/r128_irq.c
40000+++ b/drivers/gpu/drm/r128/r128_irq.c
40001@@ -41,7 +41,7 @@ u32 r128_get_vblank_counter(struct drm_device *dev, int crtc)
40002 if (crtc != 0)
40003 return 0;
40004
40005- return atomic_read(&dev_priv->vbl_received);
40006+ return atomic_read_unchecked(&dev_priv->vbl_received);
40007 }
40008
40009 irqreturn_t r128_driver_irq_handler(DRM_IRQ_ARGS)
40010@@ -55,7 +55,7 @@ irqreturn_t r128_driver_irq_handler(DRM_IRQ_ARGS)
40011 /* VBLANK interrupt */
40012 if (status & R128_CRTC_VBLANK_INT) {
40013 R128_WRITE(R128_GEN_INT_STATUS, R128_CRTC_VBLANK_INT_AK);
40014- atomic_inc(&dev_priv->vbl_received);
40015+ atomic_inc_unchecked(&dev_priv->vbl_received);
40016 drm_handle_vblank(dev, 0);
40017 return IRQ_HANDLED;
40018 }
40019diff --git a/drivers/gpu/drm/r128/r128_state.c b/drivers/gpu/drm/r128/r128_state.c
40020index 01dd9ae..6352f04 100644
40021--- a/drivers/gpu/drm/r128/r128_state.c
40022+++ b/drivers/gpu/drm/r128/r128_state.c
40023@@ -320,10 +320,10 @@ static void r128_clear_box(drm_r128_private_t *dev_priv,
40024
40025 static void r128_cce_performance_boxes(drm_r128_private_t *dev_priv)
40026 {
40027- if (atomic_read(&dev_priv->idle_count) == 0)
40028+ if (atomic_read_unchecked(&dev_priv->idle_count) == 0)
40029 r128_clear_box(dev_priv, 64, 4, 8, 8, 0, 255, 0);
40030 else
40031- atomic_set(&dev_priv->idle_count, 0);
40032+ atomic_set_unchecked(&dev_priv->idle_count, 0);
40033 }
40034
40035 #endif
40036diff --git a/drivers/gpu/drm/radeon/mkregtable.c b/drivers/gpu/drm/radeon/mkregtable.c
40037index af85299..ed9ac8d 100644
40038--- a/drivers/gpu/drm/radeon/mkregtable.c
40039+++ b/drivers/gpu/drm/radeon/mkregtable.c
40040@@ -624,14 +624,14 @@ static int parser_auth(struct table *t, const char *filename)
40041 regex_t mask_rex;
40042 regmatch_t match[4];
40043 char buf[1024];
40044- size_t end;
40045+ long end;
40046 int len;
40047 int done = 0;
40048 int r;
40049 unsigned o;
40050 struct offset *offset;
40051 char last_reg_s[10];
40052- int last_reg;
40053+ unsigned long last_reg;
40054
40055 if (regcomp
40056 (&mask_rex, "(0x[0-9a-fA-F]*) *([_a-zA-Z0-9]*)", REG_EXTENDED)) {
40057diff --git a/drivers/gpu/drm/radeon/radeon_device.c b/drivers/gpu/drm/radeon/radeon_device.c
40058index 841d0e0..9eaa268 100644
40059--- a/drivers/gpu/drm/radeon/radeon_device.c
40060+++ b/drivers/gpu/drm/radeon/radeon_device.c
40061@@ -1117,7 +1117,7 @@ static bool radeon_switcheroo_can_switch(struct pci_dev *pdev)
40062 bool can_switch;
40063
40064 spin_lock(&dev->count_lock);
40065- can_switch = (dev->open_count == 0);
40066+ can_switch = (local_read(&dev->open_count) == 0);
40067 spin_unlock(&dev->count_lock);
40068 return can_switch;
40069 }
40070diff --git a/drivers/gpu/drm/radeon/radeon_drv.h b/drivers/gpu/drm/radeon/radeon_drv.h
40071index b369d42..8dd04eb 100644
40072--- a/drivers/gpu/drm/radeon/radeon_drv.h
40073+++ b/drivers/gpu/drm/radeon/radeon_drv.h
40074@@ -258,7 +258,7 @@ typedef struct drm_radeon_private {
40075
40076 /* SW interrupt */
40077 wait_queue_head_t swi_queue;
40078- atomic_t swi_emitted;
40079+ atomic_unchecked_t swi_emitted;
40080 int vblank_crtc;
40081 uint32_t irq_enable_reg;
40082 uint32_t r500_disp_irq_reg;
40083diff --git a/drivers/gpu/drm/radeon/radeon_ioc32.c b/drivers/gpu/drm/radeon/radeon_ioc32.c
40084index c180df8..5fd8186 100644
40085--- a/drivers/gpu/drm/radeon/radeon_ioc32.c
40086+++ b/drivers/gpu/drm/radeon/radeon_ioc32.c
40087@@ -358,7 +358,7 @@ static int compat_radeon_cp_setparam(struct file *file, unsigned int cmd,
40088 request = compat_alloc_user_space(sizeof(*request));
40089 if (!access_ok(VERIFY_WRITE, request, sizeof(*request))
40090 || __put_user(req32.param, &request->param)
40091- || __put_user((void __user *)(unsigned long)req32.value,
40092+ || __put_user((unsigned long)req32.value,
40093 &request->value))
40094 return -EFAULT;
40095
40096@@ -368,7 +368,7 @@ static int compat_radeon_cp_setparam(struct file *file, unsigned int cmd,
40097 #define compat_radeon_cp_setparam NULL
40098 #endif /* X86_64 || IA64 */
40099
40100-static drm_ioctl_compat_t *radeon_compat_ioctls[] = {
40101+static drm_ioctl_compat_t radeon_compat_ioctls[] = {
40102 [DRM_RADEON_CP_INIT] = compat_radeon_cp_init,
40103 [DRM_RADEON_CLEAR] = compat_radeon_cp_clear,
40104 [DRM_RADEON_STIPPLE] = compat_radeon_cp_stipple,
40105@@ -393,18 +393,15 @@ static drm_ioctl_compat_t *radeon_compat_ioctls[] = {
40106 long radeon_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
40107 {
40108 unsigned int nr = DRM_IOCTL_NR(cmd);
40109- drm_ioctl_compat_t *fn = NULL;
40110 int ret;
40111
40112 if (nr < DRM_COMMAND_BASE)
40113 return drm_compat_ioctl(filp, cmd, arg);
40114
40115- if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(radeon_compat_ioctls))
40116- fn = radeon_compat_ioctls[nr - DRM_COMMAND_BASE];
40117-
40118- if (fn != NULL)
40119+ if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(radeon_compat_ioctls)) {
40120+ drm_ioctl_compat_t fn = radeon_compat_ioctls[nr - DRM_COMMAND_BASE];
40121 ret = (*fn) (filp, cmd, arg);
40122- else
40123+ } else
40124 ret = drm_ioctl(filp, cmd, arg);
40125
40126 return ret;
40127diff --git a/drivers/gpu/drm/radeon/radeon_irq.c b/drivers/gpu/drm/radeon/radeon_irq.c
40128index 8d68e97..9dcfed8 100644
40129--- a/drivers/gpu/drm/radeon/radeon_irq.c
40130+++ b/drivers/gpu/drm/radeon/radeon_irq.c
40131@@ -226,8 +226,8 @@ static int radeon_emit_irq(struct drm_device * dev)
40132 unsigned int ret;
40133 RING_LOCALS;
40134
40135- atomic_inc(&dev_priv->swi_emitted);
40136- ret = atomic_read(&dev_priv->swi_emitted);
40137+ atomic_inc_unchecked(&dev_priv->swi_emitted);
40138+ ret = atomic_read_unchecked(&dev_priv->swi_emitted);
40139
40140 BEGIN_RING(4);
40141 OUT_RING_REG(RADEON_LAST_SWI_REG, ret);
40142@@ -353,7 +353,7 @@ int radeon_driver_irq_postinstall(struct drm_device *dev)
40143 drm_radeon_private_t *dev_priv =
40144 (drm_radeon_private_t *) dev->dev_private;
40145
40146- atomic_set(&dev_priv->swi_emitted, 0);
40147+ atomic_set_unchecked(&dev_priv->swi_emitted, 0);
40148 DRM_INIT_WAITQUEUE(&dev_priv->swi_queue);
40149
40150 dev->max_vblank_count = 0x001fffff;
40151diff --git a/drivers/gpu/drm/radeon/radeon_state.c b/drivers/gpu/drm/radeon/radeon_state.c
40152index 4d20910..6726b6d 100644
40153--- a/drivers/gpu/drm/radeon/radeon_state.c
40154+++ b/drivers/gpu/drm/radeon/radeon_state.c
40155@@ -2168,7 +2168,7 @@ static int radeon_cp_clear(struct drm_device *dev, void *data, struct drm_file *
40156 if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS)
40157 sarea_priv->nbox = RADEON_NR_SAREA_CLIPRECTS;
40158
40159- if (DRM_COPY_FROM_USER(&depth_boxes, clear->depth_boxes,
40160+ if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS || DRM_COPY_FROM_USER(&depth_boxes, clear->depth_boxes,
40161 sarea_priv->nbox * sizeof(depth_boxes[0])))
40162 return -EFAULT;
40163
40164@@ -3031,7 +3031,7 @@ static int radeon_cp_getparam(struct drm_device *dev, void *data, struct drm_fil
40165 {
40166 drm_radeon_private_t *dev_priv = dev->dev_private;
40167 drm_radeon_getparam_t *param = data;
40168- int value;
40169+ int value = 0;
40170
40171 DRM_DEBUG("pid=%d\n", DRM_CURRENTPID);
40172
40173diff --git a/drivers/gpu/drm/radeon/radeon_ttm.c b/drivers/gpu/drm/radeon/radeon_ttm.c
40174index 71245d6..94c556d 100644
40175--- a/drivers/gpu/drm/radeon/radeon_ttm.c
40176+++ b/drivers/gpu/drm/radeon/radeon_ttm.c
40177@@ -784,7 +784,7 @@ void radeon_ttm_set_active_vram_size(struct radeon_device *rdev, u64 size)
40178 man->size = size >> PAGE_SHIFT;
40179 }
40180
40181-static struct vm_operations_struct radeon_ttm_vm_ops;
40182+static vm_operations_struct_no_const radeon_ttm_vm_ops __read_only;
40183 static const struct vm_operations_struct *ttm_vm_ops = NULL;
40184
40185 static int radeon_ttm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
40186@@ -825,8 +825,10 @@ int radeon_mmap(struct file *filp, struct vm_area_struct *vma)
40187 }
40188 if (unlikely(ttm_vm_ops == NULL)) {
40189 ttm_vm_ops = vma->vm_ops;
40190+ pax_open_kernel();
40191 radeon_ttm_vm_ops = *ttm_vm_ops;
40192 radeon_ttm_vm_ops.fault = &radeon_ttm_fault;
40193+ pax_close_kernel();
40194 }
40195 vma->vm_ops = &radeon_ttm_vm_ops;
40196 return 0;
40197@@ -855,38 +857,33 @@ static int radeon_mm_dump_table(struct seq_file *m, void *data)
40198 static int radeon_ttm_debugfs_init(struct radeon_device *rdev)
40199 {
40200 #if defined(CONFIG_DEBUG_FS)
40201- static struct drm_info_list radeon_mem_types_list[RADEON_DEBUGFS_MEM_TYPES+2];
40202- static char radeon_mem_types_names[RADEON_DEBUGFS_MEM_TYPES+2][32];
40203- unsigned i;
40204+ static struct drm_info_list radeon_mem_types_list[RADEON_DEBUGFS_MEM_TYPES+2] = {
40205+ {
40206+ .name = "radeon_vram_mm",
40207+ .show = &radeon_mm_dump_table,
40208+ },
40209+ {
40210+ .name = "radeon_gtt_mm",
40211+ .show = &radeon_mm_dump_table,
40212+ },
40213+ {
40214+ .name = "ttm_page_pool",
40215+ .show = &ttm_page_alloc_debugfs,
40216+ },
40217+ {
40218+ .name = "ttm_dma_page_pool",
40219+ .show = &ttm_dma_page_alloc_debugfs,
40220+ },
40221+ };
40222+ unsigned i = RADEON_DEBUGFS_MEM_TYPES + 1;
40223
40224- for (i = 0; i < RADEON_DEBUGFS_MEM_TYPES; i++) {
40225- if (i == 0)
40226- sprintf(radeon_mem_types_names[i], "radeon_vram_mm");
40227- else
40228- sprintf(radeon_mem_types_names[i], "radeon_gtt_mm");
40229- radeon_mem_types_list[i].name = radeon_mem_types_names[i];
40230- radeon_mem_types_list[i].show = &radeon_mm_dump_table;
40231- radeon_mem_types_list[i].driver_features = 0;
40232- if (i == 0)
40233- radeon_mem_types_list[i].data = rdev->mman.bdev.man[TTM_PL_VRAM].priv;
40234- else
40235- radeon_mem_types_list[i].data = rdev->mman.bdev.man[TTM_PL_TT].priv;
40236-
40237- }
40238- /* Add ttm page pool to debugfs */
40239- sprintf(radeon_mem_types_names[i], "ttm_page_pool");
40240- radeon_mem_types_list[i].name = radeon_mem_types_names[i];
40241- radeon_mem_types_list[i].show = &ttm_page_alloc_debugfs;
40242- radeon_mem_types_list[i].driver_features = 0;
40243- radeon_mem_types_list[i++].data = NULL;
40244+ pax_open_kernel();
40245+ *(void **)&radeon_mem_types_list[0].data = rdev->mman.bdev.man[TTM_PL_VRAM].priv;
40246+ *(void **)&radeon_mem_types_list[1].data = rdev->mman.bdev.man[TTM_PL_TT].priv;
40247+ pax_close_kernel();
40248 #ifdef CONFIG_SWIOTLB
40249- if (swiotlb_nr_tbl()) {
40250- sprintf(radeon_mem_types_names[i], "ttm_dma_page_pool");
40251- radeon_mem_types_list[i].name = radeon_mem_types_names[i];
40252- radeon_mem_types_list[i].show = &ttm_dma_page_alloc_debugfs;
40253- radeon_mem_types_list[i].driver_features = 0;
40254- radeon_mem_types_list[i++].data = NULL;
40255- }
40256+ if (swiotlb_nr_tbl())
40257+ i++;
40258 #endif
40259 return radeon_debugfs_add_files(rdev, radeon_mem_types_list, i);
40260
40261diff --git a/drivers/gpu/drm/radeon/rs690.c b/drivers/gpu/drm/radeon/rs690.c
40262index 3c38f0a..13816e3 100644
40263--- a/drivers/gpu/drm/radeon/rs690.c
40264+++ b/drivers/gpu/drm/radeon/rs690.c
40265@@ -355,9 +355,11 @@ static void rs690_crtc_bandwidth_compute(struct radeon_device *rdev,
40266 if (max_bandwidth.full > rdev->pm.sideport_bandwidth.full &&
40267 rdev->pm.sideport_bandwidth.full)
40268 max_bandwidth = rdev->pm.sideport_bandwidth;
40269- read_delay_latency.full = dfixed_const(370 * 800 * 1000);
40270+ read_delay_latency.full = dfixed_const(800 * 1000);
40271 read_delay_latency.full = dfixed_div(read_delay_latency,
40272 rdev->pm.igp_sideport_mclk);
40273+ a.full = dfixed_const(370);
40274+ read_delay_latency.full = dfixed_mul(read_delay_latency, a);
40275 } else {
40276 if (max_bandwidth.full > rdev->pm.k8_bandwidth.full &&
40277 rdev->pm.k8_bandwidth.full)
40278diff --git a/drivers/gpu/drm/ttm/ttm_bo_manager.c b/drivers/gpu/drm/ttm/ttm_bo_manager.c
40279index c58eba33..83c2728 100644
40280--- a/drivers/gpu/drm/ttm/ttm_bo_manager.c
40281+++ b/drivers/gpu/drm/ttm/ttm_bo_manager.c
40282@@ -141,10 +141,10 @@ static void ttm_bo_man_debug(struct ttm_mem_type_manager *man,
40283 }
40284
40285 const struct ttm_mem_type_manager_func ttm_bo_manager_func = {
40286- ttm_bo_man_init,
40287- ttm_bo_man_takedown,
40288- ttm_bo_man_get_node,
40289- ttm_bo_man_put_node,
40290- ttm_bo_man_debug
40291+ .init = ttm_bo_man_init,
40292+ .takedown = ttm_bo_man_takedown,
40293+ .get_node = ttm_bo_man_get_node,
40294+ .put_node = ttm_bo_man_put_node,
40295+ .debug = ttm_bo_man_debug
40296 };
40297 EXPORT_SYMBOL(ttm_bo_manager_func);
40298diff --git a/drivers/gpu/drm/ttm/ttm_memory.c b/drivers/gpu/drm/ttm/ttm_memory.c
40299index dbc2def..0a9f710 100644
40300--- a/drivers/gpu/drm/ttm/ttm_memory.c
40301+++ b/drivers/gpu/drm/ttm/ttm_memory.c
40302@@ -264,7 +264,7 @@ static int ttm_mem_init_kernel_zone(struct ttm_mem_global *glob,
40303 zone->glob = glob;
40304 glob->zone_kernel = zone;
40305 ret = kobject_init_and_add(
40306- &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, zone->name);
40307+ &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, "%s", zone->name);
40308 if (unlikely(ret != 0)) {
40309 kobject_put(&zone->kobj);
40310 return ret;
40311@@ -347,7 +347,7 @@ static int ttm_mem_init_dma32_zone(struct ttm_mem_global *glob,
40312 zone->glob = glob;
40313 glob->zone_dma32 = zone;
40314 ret = kobject_init_and_add(
40315- &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, zone->name);
40316+ &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, "%s", zone->name);
40317 if (unlikely(ret != 0)) {
40318 kobject_put(&zone->kobj);
40319 return ret;
40320diff --git a/drivers/gpu/drm/ttm/ttm_page_alloc.c b/drivers/gpu/drm/ttm/ttm_page_alloc.c
40321index 863bef9..cba15cf 100644
40322--- a/drivers/gpu/drm/ttm/ttm_page_alloc.c
40323+++ b/drivers/gpu/drm/ttm/ttm_page_alloc.c
40324@@ -391,9 +391,9 @@ out:
40325 static unsigned long
40326 ttm_pool_shrink_scan(struct shrinker *shrink, struct shrink_control *sc)
40327 {
40328- static atomic_t start_pool = ATOMIC_INIT(0);
40329+ static atomic_unchecked_t start_pool = ATOMIC_INIT(0);
40330 unsigned i;
40331- unsigned pool_offset = atomic_add_return(1, &start_pool);
40332+ unsigned pool_offset = atomic_add_return_unchecked(1, &start_pool);
40333 struct ttm_page_pool *pool;
40334 int shrink_pages = sc->nr_to_scan;
40335 unsigned long freed = 0;
40336diff --git a/drivers/gpu/drm/udl/udl_fb.c b/drivers/gpu/drm/udl/udl_fb.c
40337index 97e9d61..bf23c461 100644
40338--- a/drivers/gpu/drm/udl/udl_fb.c
40339+++ b/drivers/gpu/drm/udl/udl_fb.c
40340@@ -367,7 +367,6 @@ static int udl_fb_release(struct fb_info *info, int user)
40341 fb_deferred_io_cleanup(info);
40342 kfree(info->fbdefio);
40343 info->fbdefio = NULL;
40344- info->fbops->fb_mmap = udl_fb_mmap;
40345 }
40346
40347 pr_warn("released /dev/fb%d user=%d count=%d\n",
40348diff --git a/drivers/gpu/drm/via/via_drv.h b/drivers/gpu/drm/via/via_drv.h
40349index a811ef2..ff99b05 100644
40350--- a/drivers/gpu/drm/via/via_drv.h
40351+++ b/drivers/gpu/drm/via/via_drv.h
40352@@ -51,7 +51,7 @@ typedef struct drm_via_ring_buffer {
40353 typedef uint32_t maskarray_t[5];
40354
40355 typedef struct drm_via_irq {
40356- atomic_t irq_received;
40357+ atomic_unchecked_t irq_received;
40358 uint32_t pending_mask;
40359 uint32_t enable_mask;
40360 wait_queue_head_t irq_queue;
40361@@ -75,7 +75,7 @@ typedef struct drm_via_private {
40362 struct timeval last_vblank;
40363 int last_vblank_valid;
40364 unsigned usec_per_vblank;
40365- atomic_t vbl_received;
40366+ atomic_unchecked_t vbl_received;
40367 drm_via_state_t hc_state;
40368 char pci_buf[VIA_PCI_BUF_SIZE];
40369 const uint32_t *fire_offsets[VIA_FIRE_BUF_SIZE];
40370diff --git a/drivers/gpu/drm/via/via_irq.c b/drivers/gpu/drm/via/via_irq.c
40371index ac98964..5dbf512 100644
40372--- a/drivers/gpu/drm/via/via_irq.c
40373+++ b/drivers/gpu/drm/via/via_irq.c
40374@@ -101,7 +101,7 @@ u32 via_get_vblank_counter(struct drm_device *dev, int crtc)
40375 if (crtc != 0)
40376 return 0;
40377
40378- return atomic_read(&dev_priv->vbl_received);
40379+ return atomic_read_unchecked(&dev_priv->vbl_received);
40380 }
40381
40382 irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
40383@@ -116,8 +116,8 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
40384
40385 status = VIA_READ(VIA_REG_INTERRUPT);
40386 if (status & VIA_IRQ_VBLANK_PENDING) {
40387- atomic_inc(&dev_priv->vbl_received);
40388- if (!(atomic_read(&dev_priv->vbl_received) & 0x0F)) {
40389+ atomic_inc_unchecked(&dev_priv->vbl_received);
40390+ if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0x0F)) {
40391 do_gettimeofday(&cur_vblank);
40392 if (dev_priv->last_vblank_valid) {
40393 dev_priv->usec_per_vblank =
40394@@ -127,7 +127,7 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
40395 dev_priv->last_vblank = cur_vblank;
40396 dev_priv->last_vblank_valid = 1;
40397 }
40398- if (!(atomic_read(&dev_priv->vbl_received) & 0xFF)) {
40399+ if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0xFF)) {
40400 DRM_DEBUG("US per vblank is: %u\n",
40401 dev_priv->usec_per_vblank);
40402 }
40403@@ -137,7 +137,7 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
40404
40405 for (i = 0; i < dev_priv->num_irqs; ++i) {
40406 if (status & cur_irq->pending_mask) {
40407- atomic_inc(&cur_irq->irq_received);
40408+ atomic_inc_unchecked(&cur_irq->irq_received);
40409 DRM_WAKEUP(&cur_irq->irq_queue);
40410 handled = 1;
40411 if (dev_priv->irq_map[drm_via_irq_dma0_td] == i)
40412@@ -242,11 +242,11 @@ via_driver_irq_wait(struct drm_device *dev, unsigned int irq, int force_sequence
40413 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
40414 ((VIA_READ(masks[irq][2]) & masks[irq][3]) ==
40415 masks[irq][4]));
40416- cur_irq_sequence = atomic_read(&cur_irq->irq_received);
40417+ cur_irq_sequence = atomic_read_unchecked(&cur_irq->irq_received);
40418 } else {
40419 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
40420 (((cur_irq_sequence =
40421- atomic_read(&cur_irq->irq_received)) -
40422+ atomic_read_unchecked(&cur_irq->irq_received)) -
40423 *sequence) <= (1 << 23)));
40424 }
40425 *sequence = cur_irq_sequence;
40426@@ -284,7 +284,7 @@ void via_driver_irq_preinstall(struct drm_device *dev)
40427 }
40428
40429 for (i = 0; i < dev_priv->num_irqs; ++i) {
40430- atomic_set(&cur_irq->irq_received, 0);
40431+ atomic_set_unchecked(&cur_irq->irq_received, 0);
40432 cur_irq->enable_mask = dev_priv->irq_masks[i][0];
40433 cur_irq->pending_mask = dev_priv->irq_masks[i][1];
40434 DRM_INIT_WAITQUEUE(&cur_irq->irq_queue);
40435@@ -366,7 +366,7 @@ int via_wait_irq(struct drm_device *dev, void *data, struct drm_file *file_priv)
40436 switch (irqwait->request.type & ~VIA_IRQ_FLAGS_MASK) {
40437 case VIA_IRQ_RELATIVE:
40438 irqwait->request.sequence +=
40439- atomic_read(&cur_irq->irq_received);
40440+ atomic_read_unchecked(&cur_irq->irq_received);
40441 irqwait->request.type &= ~_DRM_VBLANK_RELATIVE;
40442 case VIA_IRQ_ABSOLUTE:
40443 break;
40444diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
40445index 150ec64..f5165f2 100644
40446--- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
40447+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
40448@@ -290,7 +290,7 @@ struct vmw_private {
40449 * Fencing and IRQs.
40450 */
40451
40452- atomic_t marker_seq;
40453+ atomic_unchecked_t marker_seq;
40454 wait_queue_head_t fence_queue;
40455 wait_queue_head_t fifo_queue;
40456 int fence_queue_waiters; /* Protected by hw_mutex */
40457diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
40458index 3eb1486..0a47ee9 100644
40459--- a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
40460+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
40461@@ -137,7 +137,7 @@ int vmw_fifo_init(struct vmw_private *dev_priv, struct vmw_fifo_state *fifo)
40462 (unsigned int) min,
40463 (unsigned int) fifo->capabilities);
40464
40465- atomic_set(&dev_priv->marker_seq, dev_priv->last_read_seqno);
40466+ atomic_set_unchecked(&dev_priv->marker_seq, dev_priv->last_read_seqno);
40467 iowrite32(dev_priv->last_read_seqno, fifo_mem + SVGA_FIFO_FENCE);
40468 vmw_marker_queue_init(&fifo->marker_queue);
40469 return vmw_fifo_send_fence(dev_priv, &dummy);
40470@@ -355,7 +355,7 @@ void *vmw_fifo_reserve(struct vmw_private *dev_priv, uint32_t bytes)
40471 if (reserveable)
40472 iowrite32(bytes, fifo_mem +
40473 SVGA_FIFO_RESERVED);
40474- return fifo_mem + (next_cmd >> 2);
40475+ return (__le32 __force_kernel *)fifo_mem + (next_cmd >> 2);
40476 } else {
40477 need_bounce = true;
40478 }
40479@@ -475,7 +475,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
40480
40481 fm = vmw_fifo_reserve(dev_priv, bytes);
40482 if (unlikely(fm == NULL)) {
40483- *seqno = atomic_read(&dev_priv->marker_seq);
40484+ *seqno = atomic_read_unchecked(&dev_priv->marker_seq);
40485 ret = -ENOMEM;
40486 (void)vmw_fallback_wait(dev_priv, false, true, *seqno,
40487 false, 3*HZ);
40488@@ -483,7 +483,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
40489 }
40490
40491 do {
40492- *seqno = atomic_add_return(1, &dev_priv->marker_seq);
40493+ *seqno = atomic_add_return_unchecked(1, &dev_priv->marker_seq);
40494 } while (*seqno == 0);
40495
40496 if (!(fifo_state->capabilities & SVGA_FIFO_CAP_FENCE)) {
40497diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c b/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c
40498index c5c054a..46f0548 100644
40499--- a/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c
40500+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c
40501@@ -153,9 +153,9 @@ static void vmw_gmrid_man_debug(struct ttm_mem_type_manager *man,
40502 }
40503
40504 const struct ttm_mem_type_manager_func vmw_gmrid_manager_func = {
40505- vmw_gmrid_man_init,
40506- vmw_gmrid_man_takedown,
40507- vmw_gmrid_man_get_node,
40508- vmw_gmrid_man_put_node,
40509- vmw_gmrid_man_debug
40510+ .init = vmw_gmrid_man_init,
40511+ .takedown = vmw_gmrid_man_takedown,
40512+ .get_node = vmw_gmrid_man_get_node,
40513+ .put_node = vmw_gmrid_man_put_node,
40514+ .debug = vmw_gmrid_man_debug
40515 };
40516diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c b/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c
40517index c509d40..3b640c3 100644
40518--- a/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c
40519+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c
40520@@ -138,7 +138,7 @@ int vmw_present_ioctl(struct drm_device *dev, void *data,
40521 int ret;
40522
40523 num_clips = arg->num_clips;
40524- clips_ptr = (struct drm_vmw_rect *)(unsigned long)arg->clips_ptr;
40525+ clips_ptr = (struct drm_vmw_rect __user *)(unsigned long)arg->clips_ptr;
40526
40527 if (unlikely(num_clips == 0))
40528 return 0;
40529@@ -222,7 +222,7 @@ int vmw_present_readback_ioctl(struct drm_device *dev, void *data,
40530 int ret;
40531
40532 num_clips = arg->num_clips;
40533- clips_ptr = (struct drm_vmw_rect *)(unsigned long)arg->clips_ptr;
40534+ clips_ptr = (struct drm_vmw_rect __user *)(unsigned long)arg->clips_ptr;
40535
40536 if (unlikely(num_clips == 0))
40537 return 0;
40538diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
40539index 4640adb..e1384ed 100644
40540--- a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
40541+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
40542@@ -107,7 +107,7 @@ bool vmw_seqno_passed(struct vmw_private *dev_priv,
40543 * emitted. Then the fence is stale and signaled.
40544 */
40545
40546- ret = ((atomic_read(&dev_priv->marker_seq) - seqno)
40547+ ret = ((atomic_read_unchecked(&dev_priv->marker_seq) - seqno)
40548 > VMW_FENCE_WRAP);
40549
40550 return ret;
40551@@ -138,7 +138,7 @@ int vmw_fallback_wait(struct vmw_private *dev_priv,
40552
40553 if (fifo_idle)
40554 down_read(&fifo_state->rwsem);
40555- signal_seq = atomic_read(&dev_priv->marker_seq);
40556+ signal_seq = atomic_read_unchecked(&dev_priv->marker_seq);
40557 ret = 0;
40558
40559 for (;;) {
40560diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
40561index 8a8725c2..afed796 100644
40562--- a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
40563+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
40564@@ -151,7 +151,7 @@ int vmw_wait_lag(struct vmw_private *dev_priv,
40565 while (!vmw_lag_lt(queue, us)) {
40566 spin_lock(&queue->lock);
40567 if (list_empty(&queue->head))
40568- seqno = atomic_read(&dev_priv->marker_seq);
40569+ seqno = atomic_read_unchecked(&dev_priv->marker_seq);
40570 else {
40571 marker = list_first_entry(&queue->head,
40572 struct vmw_marker, head);
40573diff --git a/drivers/gpu/host1x/drm/dc.c b/drivers/gpu/host1x/drm/dc.c
40574index b1a05ad..1c9d899 100644
40575--- a/drivers/gpu/host1x/drm/dc.c
40576+++ b/drivers/gpu/host1x/drm/dc.c
40577@@ -1004,7 +1004,7 @@ static int tegra_dc_debugfs_init(struct tegra_dc *dc, struct drm_minor *minor)
40578 }
40579
40580 for (i = 0; i < ARRAY_SIZE(debugfs_files); i++)
40581- dc->debugfs_files[i].data = dc;
40582+ *(void **)&dc->debugfs_files[i].data = dc;
40583
40584 err = drm_debugfs_create_files(dc->debugfs_files,
40585 ARRAY_SIZE(debugfs_files),
40586diff --git a/drivers/gpu/vga/vga_switcheroo.c b/drivers/gpu/vga/vga_switcheroo.c
40587index ec0ae2d..dc0780b 100644
40588--- a/drivers/gpu/vga/vga_switcheroo.c
40589+++ b/drivers/gpu/vga/vga_switcheroo.c
40590@@ -643,7 +643,7 @@ static int vga_switcheroo_runtime_resume(struct device *dev)
40591
40592 /* this version is for the case where the power switch is separate
40593 to the device being powered down. */
40594-int vga_switcheroo_init_domain_pm_ops(struct device *dev, struct dev_pm_domain *domain)
40595+int vga_switcheroo_init_domain_pm_ops(struct device *dev, dev_pm_domain_no_const *domain)
40596 {
40597 /* copy over all the bus versions */
40598 if (dev->bus && dev->bus->pm) {
40599@@ -688,7 +688,7 @@ static int vga_switcheroo_runtime_resume_hdmi_audio(struct device *dev)
40600 return ret;
40601 }
40602
40603-int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, struct dev_pm_domain *domain)
40604+int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, dev_pm_domain_no_const *domain)
40605 {
40606 /* copy over all the bus versions */
40607 if (dev->bus && dev->bus->pm) {
40608diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
40609index aedfe50..1dc929b 100644
40610--- a/drivers/hid/hid-core.c
40611+++ b/drivers/hid/hid-core.c
40612@@ -2416,7 +2416,7 @@ EXPORT_SYMBOL_GPL(hid_ignore);
40613
40614 int hid_add_device(struct hid_device *hdev)
40615 {
40616- static atomic_t id = ATOMIC_INIT(0);
40617+ static atomic_unchecked_t id = ATOMIC_INIT(0);
40618 int ret;
40619
40620 if (WARN_ON(hdev->status & HID_STAT_ADDED))
40621@@ -2450,7 +2450,7 @@ int hid_add_device(struct hid_device *hdev)
40622 /* XXX hack, any other cleaner solution after the driver core
40623 * is converted to allow more than 20 bytes as the device name? */
40624 dev_set_name(&hdev->dev, "%04X:%04X:%04X.%04X", hdev->bus,
40625- hdev->vendor, hdev->product, atomic_inc_return(&id));
40626+ hdev->vendor, hdev->product, atomic_inc_return_unchecked(&id));
40627
40628 hid_debug_register(hdev, dev_name(&hdev->dev));
40629 ret = device_add(&hdev->dev);
40630diff --git a/drivers/hid/hid-wiimote-debug.c b/drivers/hid/hid-wiimote-debug.c
40631index c13fb5b..55a3802 100644
40632--- a/drivers/hid/hid-wiimote-debug.c
40633+++ b/drivers/hid/hid-wiimote-debug.c
40634@@ -66,7 +66,7 @@ static ssize_t wiidebug_eeprom_read(struct file *f, char __user *u, size_t s,
40635 else if (size == 0)
40636 return -EIO;
40637
40638- if (copy_to_user(u, buf, size))
40639+ if (size > sizeof(buf) || copy_to_user(u, buf, size))
40640 return -EFAULT;
40641
40642 *off += size;
40643diff --git a/drivers/hid/uhid.c b/drivers/hid/uhid.c
40644index cedc6da..2c3da2a 100644
40645--- a/drivers/hid/uhid.c
40646+++ b/drivers/hid/uhid.c
40647@@ -47,7 +47,7 @@ struct uhid_device {
40648 struct mutex report_lock;
40649 wait_queue_head_t report_wait;
40650 atomic_t report_done;
40651- atomic_t report_id;
40652+ atomic_unchecked_t report_id;
40653 struct uhid_event report_buf;
40654 };
40655
40656@@ -163,7 +163,7 @@ static int uhid_hid_get_raw(struct hid_device *hid, unsigned char rnum,
40657
40658 spin_lock_irqsave(&uhid->qlock, flags);
40659 ev->type = UHID_FEATURE;
40660- ev->u.feature.id = atomic_inc_return(&uhid->report_id);
40661+ ev->u.feature.id = atomic_inc_return_unchecked(&uhid->report_id);
40662 ev->u.feature.rnum = rnum;
40663 ev->u.feature.rtype = report_type;
40664
40665@@ -446,7 +446,7 @@ static int uhid_dev_feature_answer(struct uhid_device *uhid,
40666 spin_lock_irqsave(&uhid->qlock, flags);
40667
40668 /* id for old report; drop it silently */
40669- if (atomic_read(&uhid->report_id) != ev->u.feature_answer.id)
40670+ if (atomic_read_unchecked(&uhid->report_id) != ev->u.feature_answer.id)
40671 goto unlock;
40672 if (atomic_read(&uhid->report_done))
40673 goto unlock;
40674diff --git a/drivers/hv/channel.c b/drivers/hv/channel.c
40675index 6de6c98..18319e9 100644
40676--- a/drivers/hv/channel.c
40677+++ b/drivers/hv/channel.c
40678@@ -406,8 +406,8 @@ int vmbus_establish_gpadl(struct vmbus_channel *channel, void *kbuffer,
40679 int ret = 0;
40680 int t;
40681
40682- next_gpadl_handle = atomic_read(&vmbus_connection.next_gpadl_handle);
40683- atomic_inc(&vmbus_connection.next_gpadl_handle);
40684+ next_gpadl_handle = atomic_read_unchecked(&vmbus_connection.next_gpadl_handle);
40685+ atomic_inc_unchecked(&vmbus_connection.next_gpadl_handle);
40686
40687 ret = create_gpadl_header(kbuffer, size, &msginfo, &msgcount);
40688 if (ret)
40689diff --git a/drivers/hv/hv.c b/drivers/hv/hv.c
40690index 88f4096..e50452e 100644
40691--- a/drivers/hv/hv.c
40692+++ b/drivers/hv/hv.c
40693@@ -112,7 +112,7 @@ static u64 do_hypercall(u64 control, void *input, void *output)
40694 u64 output_address = (output) ? virt_to_phys(output) : 0;
40695 u32 output_address_hi = output_address >> 32;
40696 u32 output_address_lo = output_address & 0xFFFFFFFF;
40697- void *hypercall_page = hv_context.hypercall_page;
40698+ void *hypercall_page = ktva_ktla(hv_context.hypercall_page);
40699
40700 __asm__ __volatile__ ("call *%8" : "=d"(hv_status_hi),
40701 "=a"(hv_status_lo) : "d" (control_hi),
40702diff --git a/drivers/hv/hv_balloon.c b/drivers/hv/hv_balloon.c
40703index 7e17a54..a50a33d 100644
40704--- a/drivers/hv/hv_balloon.c
40705+++ b/drivers/hv/hv_balloon.c
40706@@ -464,7 +464,7 @@ MODULE_PARM_DESC(hot_add, "If set attempt memory hot_add");
40707
40708 module_param(pressure_report_delay, uint, (S_IRUGO | S_IWUSR));
40709 MODULE_PARM_DESC(pressure_report_delay, "Delay in secs in reporting pressure");
40710-static atomic_t trans_id = ATOMIC_INIT(0);
40711+static atomic_unchecked_t trans_id = ATOMIC_INIT(0);
40712
40713 static int dm_ring_size = (5 * PAGE_SIZE);
40714
40715@@ -886,7 +886,7 @@ static void hot_add_req(struct work_struct *dummy)
40716 pr_info("Memory hot add failed\n");
40717
40718 dm->state = DM_INITIALIZED;
40719- resp.hdr.trans_id = atomic_inc_return(&trans_id);
40720+ resp.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
40721 vmbus_sendpacket(dm->dev->channel, &resp,
40722 sizeof(struct dm_hot_add_response),
40723 (unsigned long)NULL,
40724@@ -960,7 +960,7 @@ static void post_status(struct hv_dynmem_device *dm)
40725 memset(&status, 0, sizeof(struct dm_status));
40726 status.hdr.type = DM_STATUS_REPORT;
40727 status.hdr.size = sizeof(struct dm_status);
40728- status.hdr.trans_id = atomic_inc_return(&trans_id);
40729+ status.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
40730
40731 /*
40732 * The host expects the guest to report free memory.
40733@@ -980,7 +980,7 @@ static void post_status(struct hv_dynmem_device *dm)
40734 * send the status. This can happen if we were interrupted
40735 * after we picked our transaction ID.
40736 */
40737- if (status.hdr.trans_id != atomic_read(&trans_id))
40738+ if (status.hdr.trans_id != atomic_read_unchecked(&trans_id))
40739 return;
40740
40741 vmbus_sendpacket(dm->dev->channel, &status,
40742@@ -1108,7 +1108,7 @@ static void balloon_up(struct work_struct *dummy)
40743 */
40744
40745 do {
40746- bl_resp->hdr.trans_id = atomic_inc_return(&trans_id);
40747+ bl_resp->hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
40748 ret = vmbus_sendpacket(dm_device.dev->channel,
40749 bl_resp,
40750 bl_resp->hdr.size,
40751@@ -1152,7 +1152,7 @@ static void balloon_down(struct hv_dynmem_device *dm,
40752
40753 memset(&resp, 0, sizeof(struct dm_unballoon_response));
40754 resp.hdr.type = DM_UNBALLOON_RESPONSE;
40755- resp.hdr.trans_id = atomic_inc_return(&trans_id);
40756+ resp.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
40757 resp.hdr.size = sizeof(struct dm_unballoon_response);
40758
40759 vmbus_sendpacket(dm_device.dev->channel, &resp,
40760@@ -1215,7 +1215,7 @@ static void version_resp(struct hv_dynmem_device *dm,
40761 memset(&version_req, 0, sizeof(struct dm_version_request));
40762 version_req.hdr.type = DM_VERSION_REQUEST;
40763 version_req.hdr.size = sizeof(struct dm_version_request);
40764- version_req.hdr.trans_id = atomic_inc_return(&trans_id);
40765+ version_req.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
40766 version_req.version.version = DYNMEM_PROTOCOL_VERSION_WIN7;
40767 version_req.is_last_attempt = 1;
40768
40769@@ -1385,7 +1385,7 @@ static int balloon_probe(struct hv_device *dev,
40770 memset(&version_req, 0, sizeof(struct dm_version_request));
40771 version_req.hdr.type = DM_VERSION_REQUEST;
40772 version_req.hdr.size = sizeof(struct dm_version_request);
40773- version_req.hdr.trans_id = atomic_inc_return(&trans_id);
40774+ version_req.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
40775 version_req.version.version = DYNMEM_PROTOCOL_VERSION_WIN8;
40776 version_req.is_last_attempt = 0;
40777
40778@@ -1416,7 +1416,7 @@ static int balloon_probe(struct hv_device *dev,
40779 memset(&cap_msg, 0, sizeof(struct dm_capabilities));
40780 cap_msg.hdr.type = DM_CAPABILITIES_REPORT;
40781 cap_msg.hdr.size = sizeof(struct dm_capabilities);
40782- cap_msg.hdr.trans_id = atomic_inc_return(&trans_id);
40783+ cap_msg.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
40784
40785 cap_msg.caps.cap_bits.balloon = 1;
40786 cap_msg.caps.cap_bits.hot_add = 1;
40787diff --git a/drivers/hv/hyperv_vmbus.h b/drivers/hv/hyperv_vmbus.h
40788index d84918f..7f38f9f 100644
40789--- a/drivers/hv/hyperv_vmbus.h
40790+++ b/drivers/hv/hyperv_vmbus.h
40791@@ -595,7 +595,7 @@ enum vmbus_connect_state {
40792 struct vmbus_connection {
40793 enum vmbus_connect_state conn_state;
40794
40795- atomic_t next_gpadl_handle;
40796+ atomic_unchecked_t next_gpadl_handle;
40797
40798 /*
40799 * Represents channel interrupts. Each bit position represents a
40800diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c
40801index f9fe46f..356b119 100644
40802--- a/drivers/hv/vmbus_drv.c
40803+++ b/drivers/hv/vmbus_drv.c
40804@@ -672,10 +672,10 @@ int vmbus_device_register(struct hv_device *child_device_obj)
40805 {
40806 int ret = 0;
40807
40808- static atomic_t device_num = ATOMIC_INIT(0);
40809+ static atomic_unchecked_t device_num = ATOMIC_INIT(0);
40810
40811 dev_set_name(&child_device_obj->device, "vmbus_0_%d",
40812- atomic_inc_return(&device_num));
40813+ atomic_inc_return_unchecked(&device_num));
40814
40815 child_device_obj->device.bus = &hv_bus;
40816 child_device_obj->device.parent = &hv_acpi_dev->dev;
40817diff --git a/drivers/hwmon/acpi_power_meter.c b/drivers/hwmon/acpi_power_meter.c
40818index a9e3d01..9dd246e 100644
40819--- a/drivers/hwmon/acpi_power_meter.c
40820+++ b/drivers/hwmon/acpi_power_meter.c
40821@@ -117,7 +117,7 @@ struct sensor_template {
40822 struct device_attribute *devattr,
40823 const char *buf, size_t count);
40824 int index;
40825-};
40826+} __do_const;
40827
40828 /* Averaging interval */
40829 static int update_avg_interval(struct acpi_power_meter_resource *resource)
40830@@ -629,7 +629,7 @@ static int register_attrs(struct acpi_power_meter_resource *resource,
40831 struct sensor_template *attrs)
40832 {
40833 struct device *dev = &resource->acpi_dev->dev;
40834- struct sensor_device_attribute *sensors =
40835+ sensor_device_attribute_no_const *sensors =
40836 &resource->sensors[resource->num_sensors];
40837 int res = 0;
40838
40839diff --git a/drivers/hwmon/applesmc.c b/drivers/hwmon/applesmc.c
40840index 3288f13..71cfb4e 100644
40841--- a/drivers/hwmon/applesmc.c
40842+++ b/drivers/hwmon/applesmc.c
40843@@ -1106,7 +1106,7 @@ static int applesmc_create_nodes(struct applesmc_node_group *groups, int num)
40844 {
40845 struct applesmc_node_group *grp;
40846 struct applesmc_dev_attr *node;
40847- struct attribute *attr;
40848+ attribute_no_const *attr;
40849 int ret, i;
40850
40851 for (grp = groups; grp->format; grp++) {
40852diff --git a/drivers/hwmon/asus_atk0110.c b/drivers/hwmon/asus_atk0110.c
40853index b25c643..a13460d 100644
40854--- a/drivers/hwmon/asus_atk0110.c
40855+++ b/drivers/hwmon/asus_atk0110.c
40856@@ -152,10 +152,10 @@ MODULE_DEVICE_TABLE(acpi, atk_ids);
40857 struct atk_sensor_data {
40858 struct list_head list;
40859 struct atk_data *data;
40860- struct device_attribute label_attr;
40861- struct device_attribute input_attr;
40862- struct device_attribute limit1_attr;
40863- struct device_attribute limit2_attr;
40864+ device_attribute_no_const label_attr;
40865+ device_attribute_no_const input_attr;
40866+ device_attribute_no_const limit1_attr;
40867+ device_attribute_no_const limit2_attr;
40868 char label_attr_name[ATTR_NAME_SIZE];
40869 char input_attr_name[ATTR_NAME_SIZE];
40870 char limit1_attr_name[ATTR_NAME_SIZE];
40871@@ -275,7 +275,7 @@ static ssize_t atk_name_show(struct device *dev,
40872 static struct device_attribute atk_name_attr =
40873 __ATTR(name, 0444, atk_name_show, NULL);
40874
40875-static void atk_init_attribute(struct device_attribute *attr, char *name,
40876+static void atk_init_attribute(device_attribute_no_const *attr, char *name,
40877 sysfs_show_func show)
40878 {
40879 sysfs_attr_init(&attr->attr);
40880diff --git a/drivers/hwmon/coretemp.c b/drivers/hwmon/coretemp.c
40881index 78be661..4dd032f 100644
40882--- a/drivers/hwmon/coretemp.c
40883+++ b/drivers/hwmon/coretemp.c
40884@@ -797,7 +797,7 @@ static int coretemp_cpu_callback(struct notifier_block *nfb,
40885 return NOTIFY_OK;
40886 }
40887
40888-static struct notifier_block coretemp_cpu_notifier __refdata = {
40889+static struct notifier_block coretemp_cpu_notifier = {
40890 .notifier_call = coretemp_cpu_callback,
40891 };
40892
40893diff --git a/drivers/hwmon/ibmaem.c b/drivers/hwmon/ibmaem.c
40894index 632f1dc..57e6a58 100644
40895--- a/drivers/hwmon/ibmaem.c
40896+++ b/drivers/hwmon/ibmaem.c
40897@@ -926,7 +926,7 @@ static int aem_register_sensors(struct aem_data *data,
40898 struct aem_rw_sensor_template *rw)
40899 {
40900 struct device *dev = &data->pdev->dev;
40901- struct sensor_device_attribute *sensors = data->sensors;
40902+ sensor_device_attribute_no_const *sensors = data->sensors;
40903 int err;
40904
40905 /* Set up read-only sensors */
40906diff --git a/drivers/hwmon/iio_hwmon.c b/drivers/hwmon/iio_hwmon.c
40907index 708081b..fe2d4ab 100644
40908--- a/drivers/hwmon/iio_hwmon.c
40909+++ b/drivers/hwmon/iio_hwmon.c
40910@@ -73,7 +73,7 @@ static int iio_hwmon_probe(struct platform_device *pdev)
40911 {
40912 struct device *dev = &pdev->dev;
40913 struct iio_hwmon_state *st;
40914- struct sensor_device_attribute *a;
40915+ sensor_device_attribute_no_const *a;
40916 int ret, i;
40917 int in_i = 1, temp_i = 1, curr_i = 1;
40918 enum iio_chan_type type;
40919diff --git a/drivers/hwmon/nct6775.c b/drivers/hwmon/nct6775.c
40920index 6eb03ce..bea7e3e 100644
40921--- a/drivers/hwmon/nct6775.c
40922+++ b/drivers/hwmon/nct6775.c
40923@@ -936,10 +936,10 @@ static struct attribute_group *
40924 nct6775_create_attr_group(struct device *dev, struct sensor_template_group *tg,
40925 int repeat)
40926 {
40927- struct attribute_group *group;
40928+ attribute_group_no_const *group;
40929 struct sensor_device_attr_u *su;
40930- struct sensor_device_attribute *a;
40931- struct sensor_device_attribute_2 *a2;
40932+ sensor_device_attribute_no_const *a;
40933+ sensor_device_attribute_2_no_const *a2;
40934 struct attribute **attrs;
40935 struct sensor_device_template **t;
40936 int err, i, j, count;
40937diff --git a/drivers/hwmon/pmbus/pmbus_core.c b/drivers/hwmon/pmbus/pmbus_core.c
40938index 9319fcf..189ff45 100644
40939--- a/drivers/hwmon/pmbus/pmbus_core.c
40940+++ b/drivers/hwmon/pmbus/pmbus_core.c
40941@@ -781,7 +781,7 @@ static int pmbus_add_attribute(struct pmbus_data *data, struct attribute *attr)
40942 return 0;
40943 }
40944
40945-static void pmbus_dev_attr_init(struct device_attribute *dev_attr,
40946+static void pmbus_dev_attr_init(device_attribute_no_const *dev_attr,
40947 const char *name,
40948 umode_t mode,
40949 ssize_t (*show)(struct device *dev,
40950@@ -798,7 +798,7 @@ static void pmbus_dev_attr_init(struct device_attribute *dev_attr,
40951 dev_attr->store = store;
40952 }
40953
40954-static void pmbus_attr_init(struct sensor_device_attribute *a,
40955+static void pmbus_attr_init(sensor_device_attribute_no_const *a,
40956 const char *name,
40957 umode_t mode,
40958 ssize_t (*show)(struct device *dev,
40959@@ -820,7 +820,7 @@ static int pmbus_add_boolean(struct pmbus_data *data,
40960 u16 reg, u8 mask)
40961 {
40962 struct pmbus_boolean *boolean;
40963- struct sensor_device_attribute *a;
40964+ sensor_device_attribute_no_const *a;
40965
40966 boolean = devm_kzalloc(data->dev, sizeof(*boolean), GFP_KERNEL);
40967 if (!boolean)
40968@@ -845,7 +845,7 @@ static struct pmbus_sensor *pmbus_add_sensor(struct pmbus_data *data,
40969 bool update, bool readonly)
40970 {
40971 struct pmbus_sensor *sensor;
40972- struct device_attribute *a;
40973+ device_attribute_no_const *a;
40974
40975 sensor = devm_kzalloc(data->dev, sizeof(*sensor), GFP_KERNEL);
40976 if (!sensor)
40977@@ -876,7 +876,7 @@ static int pmbus_add_label(struct pmbus_data *data,
40978 const char *lstring, int index)
40979 {
40980 struct pmbus_label *label;
40981- struct device_attribute *a;
40982+ device_attribute_no_const *a;
40983
40984 label = devm_kzalloc(data->dev, sizeof(*label), GFP_KERNEL);
40985 if (!label)
40986diff --git a/drivers/hwmon/sht15.c b/drivers/hwmon/sht15.c
40987index 97cd45a..ac54d8b 100644
40988--- a/drivers/hwmon/sht15.c
40989+++ b/drivers/hwmon/sht15.c
40990@@ -169,7 +169,7 @@ struct sht15_data {
40991 int supply_uv;
40992 bool supply_uv_valid;
40993 struct work_struct update_supply_work;
40994- atomic_t interrupt_handled;
40995+ atomic_unchecked_t interrupt_handled;
40996 };
40997
40998 /**
40999@@ -542,13 +542,13 @@ static int sht15_measurement(struct sht15_data *data,
41000 ret = gpio_direction_input(data->pdata->gpio_data);
41001 if (ret)
41002 return ret;
41003- atomic_set(&data->interrupt_handled, 0);
41004+ atomic_set_unchecked(&data->interrupt_handled, 0);
41005
41006 enable_irq(gpio_to_irq(data->pdata->gpio_data));
41007 if (gpio_get_value(data->pdata->gpio_data) == 0) {
41008 disable_irq_nosync(gpio_to_irq(data->pdata->gpio_data));
41009 /* Only relevant if the interrupt hasn't occurred. */
41010- if (!atomic_read(&data->interrupt_handled))
41011+ if (!atomic_read_unchecked(&data->interrupt_handled))
41012 schedule_work(&data->read_work);
41013 }
41014 ret = wait_event_timeout(data->wait_queue,
41015@@ -820,7 +820,7 @@ static irqreturn_t sht15_interrupt_fired(int irq, void *d)
41016
41017 /* First disable the interrupt */
41018 disable_irq_nosync(irq);
41019- atomic_inc(&data->interrupt_handled);
41020+ atomic_inc_unchecked(&data->interrupt_handled);
41021 /* Then schedule a reading work struct */
41022 if (data->state != SHT15_READING_NOTHING)
41023 schedule_work(&data->read_work);
41024@@ -842,11 +842,11 @@ static void sht15_bh_read_data(struct work_struct *work_s)
41025 * If not, then start the interrupt again - care here as could
41026 * have gone low in meantime so verify it hasn't!
41027 */
41028- atomic_set(&data->interrupt_handled, 0);
41029+ atomic_set_unchecked(&data->interrupt_handled, 0);
41030 enable_irq(gpio_to_irq(data->pdata->gpio_data));
41031 /* If still not occurred or another handler was scheduled */
41032 if (gpio_get_value(data->pdata->gpio_data)
41033- || atomic_read(&data->interrupt_handled))
41034+ || atomic_read_unchecked(&data->interrupt_handled))
41035 return;
41036 }
41037
41038diff --git a/drivers/hwmon/via-cputemp.c b/drivers/hwmon/via-cputemp.c
41039index 38944e9..ae9e5ed 100644
41040--- a/drivers/hwmon/via-cputemp.c
41041+++ b/drivers/hwmon/via-cputemp.c
41042@@ -296,7 +296,7 @@ static int via_cputemp_cpu_callback(struct notifier_block *nfb,
41043 return NOTIFY_OK;
41044 }
41045
41046-static struct notifier_block via_cputemp_cpu_notifier __refdata = {
41047+static struct notifier_block via_cputemp_cpu_notifier = {
41048 .notifier_call = via_cputemp_cpu_callback,
41049 };
41050
41051diff --git a/drivers/i2c/busses/i2c-amd756-s4882.c b/drivers/i2c/busses/i2c-amd756-s4882.c
41052index 07f01ac..d79ad3d 100644
41053--- a/drivers/i2c/busses/i2c-amd756-s4882.c
41054+++ b/drivers/i2c/busses/i2c-amd756-s4882.c
41055@@ -43,7 +43,7 @@
41056 extern struct i2c_adapter amd756_smbus;
41057
41058 static struct i2c_adapter *s4882_adapter;
41059-static struct i2c_algorithm *s4882_algo;
41060+static i2c_algorithm_no_const *s4882_algo;
41061
41062 /* Wrapper access functions for multiplexed SMBus */
41063 static DEFINE_MUTEX(amd756_lock);
41064diff --git a/drivers/i2c/busses/i2c-diolan-u2c.c b/drivers/i2c/busses/i2c-diolan-u2c.c
41065index dae3ddf..26e21d1 100644
41066--- a/drivers/i2c/busses/i2c-diolan-u2c.c
41067+++ b/drivers/i2c/busses/i2c-diolan-u2c.c
41068@@ -99,7 +99,7 @@ MODULE_PARM_DESC(frequency, "I2C clock frequency in hertz");
41069 /* usb layer */
41070
41071 /* Send command to device, and get response. */
41072-static int diolan_usb_transfer(struct i2c_diolan_u2c *dev)
41073+static int __intentional_overflow(-1) diolan_usb_transfer(struct i2c_diolan_u2c *dev)
41074 {
41075 int ret = 0;
41076 int actual;
41077diff --git a/drivers/i2c/busses/i2c-nforce2-s4985.c b/drivers/i2c/busses/i2c-nforce2-s4985.c
41078index 2ca268d..c6acbdf 100644
41079--- a/drivers/i2c/busses/i2c-nforce2-s4985.c
41080+++ b/drivers/i2c/busses/i2c-nforce2-s4985.c
41081@@ -41,7 +41,7 @@
41082 extern struct i2c_adapter *nforce2_smbus;
41083
41084 static struct i2c_adapter *s4985_adapter;
41085-static struct i2c_algorithm *s4985_algo;
41086+static i2c_algorithm_no_const *s4985_algo;
41087
41088 /* Wrapper access functions for multiplexed SMBus */
41089 static DEFINE_MUTEX(nforce2_lock);
41090diff --git a/drivers/i2c/i2c-dev.c b/drivers/i2c/i2c-dev.c
41091index c3ccdea..5b3dc1a 100644
41092--- a/drivers/i2c/i2c-dev.c
41093+++ b/drivers/i2c/i2c-dev.c
41094@@ -271,7 +271,7 @@ static noinline int i2cdev_ioctl_rdrw(struct i2c_client *client,
41095 break;
41096 }
41097
41098- data_ptrs[i] = (u8 __user *)rdwr_pa[i].buf;
41099+ data_ptrs[i] = (u8 __force_user *)rdwr_pa[i].buf;
41100 rdwr_pa[i].buf = memdup_user(data_ptrs[i], rdwr_pa[i].len);
41101 if (IS_ERR(rdwr_pa[i].buf)) {
41102 res = PTR_ERR(rdwr_pa[i].buf);
41103diff --git a/drivers/ide/ide-cd.c b/drivers/ide/ide-cd.c
41104index 0b510ba..4fbb5085 100644
41105--- a/drivers/ide/ide-cd.c
41106+++ b/drivers/ide/ide-cd.c
41107@@ -768,7 +768,7 @@ static void cdrom_do_block_pc(ide_drive_t *drive, struct request *rq)
41108 alignment = queue_dma_alignment(q) | q->dma_pad_mask;
41109 if ((unsigned long)buf & alignment
41110 || blk_rq_bytes(rq) & q->dma_pad_mask
41111- || object_is_on_stack(buf))
41112+ || object_starts_on_stack(buf))
41113 drive->dma = 0;
41114 }
41115 }
41116diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-core.c
41117index f95c697..0a1b05c 100644
41118--- a/drivers/iio/industrialio-core.c
41119+++ b/drivers/iio/industrialio-core.c
41120@@ -506,7 +506,7 @@ static ssize_t iio_write_channel_info(struct device *dev,
41121 }
41122
41123 static
41124-int __iio_device_attr_init(struct device_attribute *dev_attr,
41125+int __iio_device_attr_init(device_attribute_no_const *dev_attr,
41126 const char *postfix,
41127 struct iio_chan_spec const *chan,
41128 ssize_t (*readfunc)(struct device *dev,
41129diff --git a/drivers/infiniband/core/cm.c b/drivers/infiniband/core/cm.c
41130index 784b97c..c9ceadf 100644
41131--- a/drivers/infiniband/core/cm.c
41132+++ b/drivers/infiniband/core/cm.c
41133@@ -114,7 +114,7 @@ static char const counter_group_names[CM_COUNTER_GROUPS]
41134
41135 struct cm_counter_group {
41136 struct kobject obj;
41137- atomic_long_t counter[CM_ATTR_COUNT];
41138+ atomic_long_unchecked_t counter[CM_ATTR_COUNT];
41139 };
41140
41141 struct cm_counter_attribute {
41142@@ -1395,7 +1395,7 @@ static void cm_dup_req_handler(struct cm_work *work,
41143 struct ib_mad_send_buf *msg = NULL;
41144 int ret;
41145
41146- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
41147+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
41148 counter[CM_REQ_COUNTER]);
41149
41150 /* Quick state check to discard duplicate REQs. */
41151@@ -1779,7 +1779,7 @@ static void cm_dup_rep_handler(struct cm_work *work)
41152 if (!cm_id_priv)
41153 return;
41154
41155- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
41156+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
41157 counter[CM_REP_COUNTER]);
41158 ret = cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg);
41159 if (ret)
41160@@ -1946,7 +1946,7 @@ static int cm_rtu_handler(struct cm_work *work)
41161 if (cm_id_priv->id.state != IB_CM_REP_SENT &&
41162 cm_id_priv->id.state != IB_CM_MRA_REP_RCVD) {
41163 spin_unlock_irq(&cm_id_priv->lock);
41164- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
41165+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
41166 counter[CM_RTU_COUNTER]);
41167 goto out;
41168 }
41169@@ -2129,7 +2129,7 @@ static int cm_dreq_handler(struct cm_work *work)
41170 cm_id_priv = cm_acquire_id(dreq_msg->remote_comm_id,
41171 dreq_msg->local_comm_id);
41172 if (!cm_id_priv) {
41173- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
41174+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
41175 counter[CM_DREQ_COUNTER]);
41176 cm_issue_drep(work->port, work->mad_recv_wc);
41177 return -EINVAL;
41178@@ -2154,7 +2154,7 @@ static int cm_dreq_handler(struct cm_work *work)
41179 case IB_CM_MRA_REP_RCVD:
41180 break;
41181 case IB_CM_TIMEWAIT:
41182- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
41183+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
41184 counter[CM_DREQ_COUNTER]);
41185 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
41186 goto unlock;
41187@@ -2168,7 +2168,7 @@ static int cm_dreq_handler(struct cm_work *work)
41188 cm_free_msg(msg);
41189 goto deref;
41190 case IB_CM_DREQ_RCVD:
41191- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
41192+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
41193 counter[CM_DREQ_COUNTER]);
41194 goto unlock;
41195 default:
41196@@ -2535,7 +2535,7 @@ static int cm_mra_handler(struct cm_work *work)
41197 ib_modify_mad(cm_id_priv->av.port->mad_agent,
41198 cm_id_priv->msg, timeout)) {
41199 if (cm_id_priv->id.lap_state == IB_CM_MRA_LAP_RCVD)
41200- atomic_long_inc(&work->port->
41201+ atomic_long_inc_unchecked(&work->port->
41202 counter_group[CM_RECV_DUPLICATES].
41203 counter[CM_MRA_COUNTER]);
41204 goto out;
41205@@ -2544,7 +2544,7 @@ static int cm_mra_handler(struct cm_work *work)
41206 break;
41207 case IB_CM_MRA_REQ_RCVD:
41208 case IB_CM_MRA_REP_RCVD:
41209- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
41210+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
41211 counter[CM_MRA_COUNTER]);
41212 /* fall through */
41213 default:
41214@@ -2706,7 +2706,7 @@ static int cm_lap_handler(struct cm_work *work)
41215 case IB_CM_LAP_IDLE:
41216 break;
41217 case IB_CM_MRA_LAP_SENT:
41218- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
41219+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
41220 counter[CM_LAP_COUNTER]);
41221 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
41222 goto unlock;
41223@@ -2722,7 +2722,7 @@ static int cm_lap_handler(struct cm_work *work)
41224 cm_free_msg(msg);
41225 goto deref;
41226 case IB_CM_LAP_RCVD:
41227- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
41228+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
41229 counter[CM_LAP_COUNTER]);
41230 goto unlock;
41231 default:
41232@@ -3006,7 +3006,7 @@ static int cm_sidr_req_handler(struct cm_work *work)
41233 cur_cm_id_priv = cm_insert_remote_sidr(cm_id_priv);
41234 if (cur_cm_id_priv) {
41235 spin_unlock_irq(&cm.lock);
41236- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
41237+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
41238 counter[CM_SIDR_REQ_COUNTER]);
41239 goto out; /* Duplicate message. */
41240 }
41241@@ -3218,10 +3218,10 @@ static void cm_send_handler(struct ib_mad_agent *mad_agent,
41242 if (!msg->context[0] && (attr_index != CM_REJ_COUNTER))
41243 msg->retries = 1;
41244
41245- atomic_long_add(1 + msg->retries,
41246+ atomic_long_add_unchecked(1 + msg->retries,
41247 &port->counter_group[CM_XMIT].counter[attr_index]);
41248 if (msg->retries)
41249- atomic_long_add(msg->retries,
41250+ atomic_long_add_unchecked(msg->retries,
41251 &port->counter_group[CM_XMIT_RETRIES].
41252 counter[attr_index]);
41253
41254@@ -3431,7 +3431,7 @@ static void cm_recv_handler(struct ib_mad_agent *mad_agent,
41255 }
41256
41257 attr_id = be16_to_cpu(mad_recv_wc->recv_buf.mad->mad_hdr.attr_id);
41258- atomic_long_inc(&port->counter_group[CM_RECV].
41259+ atomic_long_inc_unchecked(&port->counter_group[CM_RECV].
41260 counter[attr_id - CM_ATTR_ID_OFFSET]);
41261
41262 work = kmalloc(sizeof *work + sizeof(struct ib_sa_path_rec) * paths,
41263@@ -3636,7 +3636,7 @@ static ssize_t cm_show_counter(struct kobject *obj, struct attribute *attr,
41264 cm_attr = container_of(attr, struct cm_counter_attribute, attr);
41265
41266 return sprintf(buf, "%ld\n",
41267- atomic_long_read(&group->counter[cm_attr->index]));
41268+ atomic_long_read_unchecked(&group->counter[cm_attr->index]));
41269 }
41270
41271 static const struct sysfs_ops cm_counter_ops = {
41272diff --git a/drivers/infiniband/core/fmr_pool.c b/drivers/infiniband/core/fmr_pool.c
41273index 9f5ad7c..588cd84 100644
41274--- a/drivers/infiniband/core/fmr_pool.c
41275+++ b/drivers/infiniband/core/fmr_pool.c
41276@@ -98,8 +98,8 @@ struct ib_fmr_pool {
41277
41278 struct task_struct *thread;
41279
41280- atomic_t req_ser;
41281- atomic_t flush_ser;
41282+ atomic_unchecked_t req_ser;
41283+ atomic_unchecked_t flush_ser;
41284
41285 wait_queue_head_t force_wait;
41286 };
41287@@ -179,10 +179,10 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
41288 struct ib_fmr_pool *pool = pool_ptr;
41289
41290 do {
41291- if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) < 0) {
41292+ if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) < 0) {
41293 ib_fmr_batch_release(pool);
41294
41295- atomic_inc(&pool->flush_ser);
41296+ atomic_inc_unchecked(&pool->flush_ser);
41297 wake_up_interruptible(&pool->force_wait);
41298
41299 if (pool->flush_function)
41300@@ -190,7 +190,7 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
41301 }
41302
41303 set_current_state(TASK_INTERRUPTIBLE);
41304- if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) >= 0 &&
41305+ if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) >= 0 &&
41306 !kthread_should_stop())
41307 schedule();
41308 __set_current_state(TASK_RUNNING);
41309@@ -282,8 +282,8 @@ struct ib_fmr_pool *ib_create_fmr_pool(struct ib_pd *pd,
41310 pool->dirty_watermark = params->dirty_watermark;
41311 pool->dirty_len = 0;
41312 spin_lock_init(&pool->pool_lock);
41313- atomic_set(&pool->req_ser, 0);
41314- atomic_set(&pool->flush_ser, 0);
41315+ atomic_set_unchecked(&pool->req_ser, 0);
41316+ atomic_set_unchecked(&pool->flush_ser, 0);
41317 init_waitqueue_head(&pool->force_wait);
41318
41319 pool->thread = kthread_run(ib_fmr_cleanup_thread,
41320@@ -411,11 +411,11 @@ int ib_flush_fmr_pool(struct ib_fmr_pool *pool)
41321 }
41322 spin_unlock_irq(&pool->pool_lock);
41323
41324- serial = atomic_inc_return(&pool->req_ser);
41325+ serial = atomic_inc_return_unchecked(&pool->req_ser);
41326 wake_up_process(pool->thread);
41327
41328 if (wait_event_interruptible(pool->force_wait,
41329- atomic_read(&pool->flush_ser) - serial >= 0))
41330+ atomic_read_unchecked(&pool->flush_ser) - serial >= 0))
41331 return -EINTR;
41332
41333 return 0;
41334@@ -525,7 +525,7 @@ int ib_fmr_pool_unmap(struct ib_pool_fmr *fmr)
41335 } else {
41336 list_add_tail(&fmr->list, &pool->dirty_list);
41337 if (++pool->dirty_len >= pool->dirty_watermark) {
41338- atomic_inc(&pool->req_ser);
41339+ atomic_inc_unchecked(&pool->req_ser);
41340 wake_up_process(pool->thread);
41341 }
41342 }
41343diff --git a/drivers/infiniband/hw/cxgb4/mem.c b/drivers/infiniband/hw/cxgb4/mem.c
41344index 4cb8eb2..146bf60 100644
41345--- a/drivers/infiniband/hw/cxgb4/mem.c
41346+++ b/drivers/infiniband/hw/cxgb4/mem.c
41347@@ -249,7 +249,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
41348 int err;
41349 struct fw_ri_tpte tpt;
41350 u32 stag_idx;
41351- static atomic_t key;
41352+ static atomic_unchecked_t key;
41353
41354 if (c4iw_fatal_error(rdev))
41355 return -EIO;
41356@@ -266,7 +266,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
41357 if (rdev->stats.stag.cur > rdev->stats.stag.max)
41358 rdev->stats.stag.max = rdev->stats.stag.cur;
41359 mutex_unlock(&rdev->stats.lock);
41360- *stag = (stag_idx << 8) | (atomic_inc_return(&key) & 0xff);
41361+ *stag = (stag_idx << 8) | (atomic_inc_return_unchecked(&key) & 0xff);
41362 }
41363 PDBG("%s stag_state 0x%0x type 0x%0x pdid 0x%0x, stag_idx 0x%x\n",
41364 __func__, stag_state, type, pdid, stag_idx);
41365diff --git a/drivers/infiniband/hw/ipath/ipath_dma.c b/drivers/infiniband/hw/ipath/ipath_dma.c
41366index 644c2c7..ecf0879 100644
41367--- a/drivers/infiniband/hw/ipath/ipath_dma.c
41368+++ b/drivers/infiniband/hw/ipath/ipath_dma.c
41369@@ -176,17 +176,17 @@ static void ipath_dma_free_coherent(struct ib_device *dev, size_t size,
41370 }
41371
41372 struct ib_dma_mapping_ops ipath_dma_mapping_ops = {
41373- ipath_mapping_error,
41374- ipath_dma_map_single,
41375- ipath_dma_unmap_single,
41376- ipath_dma_map_page,
41377- ipath_dma_unmap_page,
41378- ipath_map_sg,
41379- ipath_unmap_sg,
41380- ipath_sg_dma_address,
41381- ipath_sg_dma_len,
41382- ipath_sync_single_for_cpu,
41383- ipath_sync_single_for_device,
41384- ipath_dma_alloc_coherent,
41385- ipath_dma_free_coherent
41386+ .mapping_error = ipath_mapping_error,
41387+ .map_single = ipath_dma_map_single,
41388+ .unmap_single = ipath_dma_unmap_single,
41389+ .map_page = ipath_dma_map_page,
41390+ .unmap_page = ipath_dma_unmap_page,
41391+ .map_sg = ipath_map_sg,
41392+ .unmap_sg = ipath_unmap_sg,
41393+ .dma_address = ipath_sg_dma_address,
41394+ .dma_len = ipath_sg_dma_len,
41395+ .sync_single_for_cpu = ipath_sync_single_for_cpu,
41396+ .sync_single_for_device = ipath_sync_single_for_device,
41397+ .alloc_coherent = ipath_dma_alloc_coherent,
41398+ .free_coherent = ipath_dma_free_coherent
41399 };
41400diff --git a/drivers/infiniband/hw/ipath/ipath_rc.c b/drivers/infiniband/hw/ipath/ipath_rc.c
41401index 79b3dbc..96e5fcc 100644
41402--- a/drivers/infiniband/hw/ipath/ipath_rc.c
41403+++ b/drivers/infiniband/hw/ipath/ipath_rc.c
41404@@ -1868,7 +1868,7 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
41405 struct ib_atomic_eth *ateth;
41406 struct ipath_ack_entry *e;
41407 u64 vaddr;
41408- atomic64_t *maddr;
41409+ atomic64_unchecked_t *maddr;
41410 u64 sdata;
41411 u32 rkey;
41412 u8 next;
41413@@ -1903,11 +1903,11 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
41414 IB_ACCESS_REMOTE_ATOMIC)))
41415 goto nack_acc_unlck;
41416 /* Perform atomic OP and save result. */
41417- maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
41418+ maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
41419 sdata = be64_to_cpu(ateth->swap_data);
41420 e = &qp->s_ack_queue[qp->r_head_ack_queue];
41421 e->atomic_data = (opcode == OP(FETCH_ADD)) ?
41422- (u64) atomic64_add_return(sdata, maddr) - sdata :
41423+ (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
41424 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
41425 be64_to_cpu(ateth->compare_data),
41426 sdata);
41427diff --git a/drivers/infiniband/hw/ipath/ipath_ruc.c b/drivers/infiniband/hw/ipath/ipath_ruc.c
41428index 1f95bba..9530f87 100644
41429--- a/drivers/infiniband/hw/ipath/ipath_ruc.c
41430+++ b/drivers/infiniband/hw/ipath/ipath_ruc.c
41431@@ -266,7 +266,7 @@ static void ipath_ruc_loopback(struct ipath_qp *sqp)
41432 unsigned long flags;
41433 struct ib_wc wc;
41434 u64 sdata;
41435- atomic64_t *maddr;
41436+ atomic64_unchecked_t *maddr;
41437 enum ib_wc_status send_status;
41438
41439 /*
41440@@ -382,11 +382,11 @@ again:
41441 IB_ACCESS_REMOTE_ATOMIC)))
41442 goto acc_err;
41443 /* Perform atomic OP and save result. */
41444- maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
41445+ maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
41446 sdata = wqe->wr.wr.atomic.compare_add;
41447 *(u64 *) sqp->s_sge.sge.vaddr =
41448 (wqe->wr.opcode == IB_WR_ATOMIC_FETCH_AND_ADD) ?
41449- (u64) atomic64_add_return(sdata, maddr) - sdata :
41450+ (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
41451 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
41452 sdata, wqe->wr.wr.atomic.swap);
41453 goto send_comp;
41454diff --git a/drivers/infiniband/hw/mlx4/mad.c b/drivers/infiniband/hw/mlx4/mad.c
41455index f2a3f48..673ec79 100644
41456--- a/drivers/infiniband/hw/mlx4/mad.c
41457+++ b/drivers/infiniband/hw/mlx4/mad.c
41458@@ -98,7 +98,7 @@ __be64 mlx4_ib_gen_node_guid(void)
41459
41460 __be64 mlx4_ib_get_new_demux_tid(struct mlx4_ib_demux_ctx *ctx)
41461 {
41462- return cpu_to_be64(atomic_inc_return(&ctx->tid)) |
41463+ return cpu_to_be64(atomic_inc_return_unchecked(&ctx->tid)) |
41464 cpu_to_be64(0xff00000000000000LL);
41465 }
41466
41467diff --git a/drivers/infiniband/hw/mlx4/mcg.c b/drivers/infiniband/hw/mlx4/mcg.c
41468index 25b2cdf..099ff97 100644
41469--- a/drivers/infiniband/hw/mlx4/mcg.c
41470+++ b/drivers/infiniband/hw/mlx4/mcg.c
41471@@ -1040,7 +1040,7 @@ int mlx4_ib_mcg_port_init(struct mlx4_ib_demux_ctx *ctx)
41472 {
41473 char name[20];
41474
41475- atomic_set(&ctx->tid, 0);
41476+ atomic_set_unchecked(&ctx->tid, 0);
41477 sprintf(name, "mlx4_ib_mcg%d", ctx->port);
41478 ctx->mcg_wq = create_singlethread_workqueue(name);
41479 if (!ctx->mcg_wq)
41480diff --git a/drivers/infiniband/hw/mlx4/mlx4_ib.h b/drivers/infiniband/hw/mlx4/mlx4_ib.h
41481index 036b663..c9a8c73 100644
41482--- a/drivers/infiniband/hw/mlx4/mlx4_ib.h
41483+++ b/drivers/infiniband/hw/mlx4/mlx4_ib.h
41484@@ -404,7 +404,7 @@ struct mlx4_ib_demux_ctx {
41485 struct list_head mcg_mgid0_list;
41486 struct workqueue_struct *mcg_wq;
41487 struct mlx4_ib_demux_pv_ctx **tun;
41488- atomic_t tid;
41489+ atomic_unchecked_t tid;
41490 int flushing; /* flushing the work queue */
41491 };
41492
41493diff --git a/drivers/infiniband/hw/mthca/mthca_cmd.c b/drivers/infiniband/hw/mthca/mthca_cmd.c
41494index 9d3e5c1..6f166df 100644
41495--- a/drivers/infiniband/hw/mthca/mthca_cmd.c
41496+++ b/drivers/infiniband/hw/mthca/mthca_cmd.c
41497@@ -772,7 +772,7 @@ static void mthca_setup_cmd_doorbells(struct mthca_dev *dev, u64 base)
41498 mthca_dbg(dev, "Mapped doorbell page for posting FW commands\n");
41499 }
41500
41501-int mthca_QUERY_FW(struct mthca_dev *dev)
41502+int __intentional_overflow(-1) mthca_QUERY_FW(struct mthca_dev *dev)
41503 {
41504 struct mthca_mailbox *mailbox;
41505 u32 *outbox;
41506@@ -1612,7 +1612,7 @@ int mthca_HW2SW_MPT(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
41507 CMD_TIME_CLASS_B);
41508 }
41509
41510-int mthca_WRITE_MTT(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
41511+int __intentional_overflow(-1) mthca_WRITE_MTT(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
41512 int num_mtt)
41513 {
41514 return mthca_cmd(dev, mailbox->dma, num_mtt, 0, CMD_WRITE_MTT,
41515@@ -1634,7 +1634,7 @@ int mthca_MAP_EQ(struct mthca_dev *dev, u64 event_mask, int unmap,
41516 0, CMD_MAP_EQ, CMD_TIME_CLASS_B);
41517 }
41518
41519-int mthca_SW2HW_EQ(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
41520+int __intentional_overflow(-1) mthca_SW2HW_EQ(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
41521 int eq_num)
41522 {
41523 return mthca_cmd(dev, mailbox->dma, eq_num, 0, CMD_SW2HW_EQ,
41524@@ -1857,7 +1857,7 @@ int mthca_CONF_SPECIAL_QP(struct mthca_dev *dev, int type, u32 qpn)
41525 CMD_TIME_CLASS_B);
41526 }
41527
41528-int mthca_MAD_IFC(struct mthca_dev *dev, int ignore_mkey, int ignore_bkey,
41529+int __intentional_overflow(-1) mthca_MAD_IFC(struct mthca_dev *dev, int ignore_mkey, int ignore_bkey,
41530 int port, struct ib_wc *in_wc, struct ib_grh *in_grh,
41531 void *in_mad, void *response_mad)
41532 {
41533diff --git a/drivers/infiniband/hw/mthca/mthca_main.c b/drivers/infiniband/hw/mthca/mthca_main.c
41534index 87897b9..7e79542 100644
41535--- a/drivers/infiniband/hw/mthca/mthca_main.c
41536+++ b/drivers/infiniband/hw/mthca/mthca_main.c
41537@@ -692,7 +692,7 @@ err_close:
41538 return err;
41539 }
41540
41541-static int mthca_setup_hca(struct mthca_dev *dev)
41542+static int __intentional_overflow(-1) mthca_setup_hca(struct mthca_dev *dev)
41543 {
41544 int err;
41545
41546diff --git a/drivers/infiniband/hw/mthca/mthca_mr.c b/drivers/infiniband/hw/mthca/mthca_mr.c
41547index ed9a989..6aa5dc2 100644
41548--- a/drivers/infiniband/hw/mthca/mthca_mr.c
41549+++ b/drivers/infiniband/hw/mthca/mthca_mr.c
41550@@ -81,7 +81,7 @@ struct mthca_mpt_entry {
41551 * through the bitmaps)
41552 */
41553
41554-static u32 mthca_buddy_alloc(struct mthca_buddy *buddy, int order)
41555+static u32 __intentional_overflow(-1) mthca_buddy_alloc(struct mthca_buddy *buddy, int order)
41556 {
41557 int o;
41558 int m;
41559@@ -426,7 +426,7 @@ static inline u32 adjust_key(struct mthca_dev *dev, u32 key)
41560 return key;
41561 }
41562
41563-int mthca_mr_alloc(struct mthca_dev *dev, u32 pd, int buffer_size_shift,
41564+int __intentional_overflow(-1) mthca_mr_alloc(struct mthca_dev *dev, u32 pd, int buffer_size_shift,
41565 u64 iova, u64 total_size, u32 access, struct mthca_mr *mr)
41566 {
41567 struct mthca_mailbox *mailbox;
41568@@ -516,7 +516,7 @@ int mthca_mr_alloc_notrans(struct mthca_dev *dev, u32 pd,
41569 return mthca_mr_alloc(dev, pd, 12, 0, ~0ULL, access, mr);
41570 }
41571
41572-int mthca_mr_alloc_phys(struct mthca_dev *dev, u32 pd,
41573+int __intentional_overflow(-1) mthca_mr_alloc_phys(struct mthca_dev *dev, u32 pd,
41574 u64 *buffer_list, int buffer_size_shift,
41575 int list_len, u64 iova, u64 total_size,
41576 u32 access, struct mthca_mr *mr)
41577diff --git a/drivers/infiniband/hw/mthca/mthca_provider.c b/drivers/infiniband/hw/mthca/mthca_provider.c
41578index 5b71d43..35a9e14 100644
41579--- a/drivers/infiniband/hw/mthca/mthca_provider.c
41580+++ b/drivers/infiniband/hw/mthca/mthca_provider.c
41581@@ -763,7 +763,7 @@ unlock:
41582 return 0;
41583 }
41584
41585-static int mthca_resize_cq(struct ib_cq *ibcq, int entries, struct ib_udata *udata)
41586+static int __intentional_overflow(-1) mthca_resize_cq(struct ib_cq *ibcq, int entries, struct ib_udata *udata)
41587 {
41588 struct mthca_dev *dev = to_mdev(ibcq->device);
41589 struct mthca_cq *cq = to_mcq(ibcq);
41590diff --git a/drivers/infiniband/hw/nes/nes.c b/drivers/infiniband/hw/nes/nes.c
41591index 4291410..d2ab1fb 100644
41592--- a/drivers/infiniband/hw/nes/nes.c
41593+++ b/drivers/infiniband/hw/nes/nes.c
41594@@ -98,7 +98,7 @@ MODULE_PARM_DESC(limit_maxrdreqsz, "Limit max read request size to 256 Bytes");
41595 LIST_HEAD(nes_adapter_list);
41596 static LIST_HEAD(nes_dev_list);
41597
41598-atomic_t qps_destroyed;
41599+atomic_unchecked_t qps_destroyed;
41600
41601 static unsigned int ee_flsh_adapter;
41602 static unsigned int sysfs_nonidx_addr;
41603@@ -269,7 +269,7 @@ static void nes_cqp_rem_ref_callback(struct nes_device *nesdev, struct nes_cqp_r
41604 struct nes_qp *nesqp = cqp_request->cqp_callback_pointer;
41605 struct nes_adapter *nesadapter = nesdev->nesadapter;
41606
41607- atomic_inc(&qps_destroyed);
41608+ atomic_inc_unchecked(&qps_destroyed);
41609
41610 /* Free the control structures */
41611
41612diff --git a/drivers/infiniband/hw/nes/nes.h b/drivers/infiniband/hw/nes/nes.h
41613index 33cc589..3bd6538 100644
41614--- a/drivers/infiniband/hw/nes/nes.h
41615+++ b/drivers/infiniband/hw/nes/nes.h
41616@@ -177,17 +177,17 @@ extern unsigned int nes_debug_level;
41617 extern unsigned int wqm_quanta;
41618 extern struct list_head nes_adapter_list;
41619
41620-extern atomic_t cm_connects;
41621-extern atomic_t cm_accepts;
41622-extern atomic_t cm_disconnects;
41623-extern atomic_t cm_closes;
41624-extern atomic_t cm_connecteds;
41625-extern atomic_t cm_connect_reqs;
41626-extern atomic_t cm_rejects;
41627-extern atomic_t mod_qp_timouts;
41628-extern atomic_t qps_created;
41629-extern atomic_t qps_destroyed;
41630-extern atomic_t sw_qps_destroyed;
41631+extern atomic_unchecked_t cm_connects;
41632+extern atomic_unchecked_t cm_accepts;
41633+extern atomic_unchecked_t cm_disconnects;
41634+extern atomic_unchecked_t cm_closes;
41635+extern atomic_unchecked_t cm_connecteds;
41636+extern atomic_unchecked_t cm_connect_reqs;
41637+extern atomic_unchecked_t cm_rejects;
41638+extern atomic_unchecked_t mod_qp_timouts;
41639+extern atomic_unchecked_t qps_created;
41640+extern atomic_unchecked_t qps_destroyed;
41641+extern atomic_unchecked_t sw_qps_destroyed;
41642 extern u32 mh_detected;
41643 extern u32 mh_pauses_sent;
41644 extern u32 cm_packets_sent;
41645@@ -196,16 +196,16 @@ extern u32 cm_packets_created;
41646 extern u32 cm_packets_received;
41647 extern u32 cm_packets_dropped;
41648 extern u32 cm_packets_retrans;
41649-extern atomic_t cm_listens_created;
41650-extern atomic_t cm_listens_destroyed;
41651+extern atomic_unchecked_t cm_listens_created;
41652+extern atomic_unchecked_t cm_listens_destroyed;
41653 extern u32 cm_backlog_drops;
41654-extern atomic_t cm_loopbacks;
41655-extern atomic_t cm_nodes_created;
41656-extern atomic_t cm_nodes_destroyed;
41657-extern atomic_t cm_accel_dropped_pkts;
41658-extern atomic_t cm_resets_recvd;
41659-extern atomic_t pau_qps_created;
41660-extern atomic_t pau_qps_destroyed;
41661+extern atomic_unchecked_t cm_loopbacks;
41662+extern atomic_unchecked_t cm_nodes_created;
41663+extern atomic_unchecked_t cm_nodes_destroyed;
41664+extern atomic_unchecked_t cm_accel_dropped_pkts;
41665+extern atomic_unchecked_t cm_resets_recvd;
41666+extern atomic_unchecked_t pau_qps_created;
41667+extern atomic_unchecked_t pau_qps_destroyed;
41668
41669 extern u32 int_mod_timer_init;
41670 extern u32 int_mod_cq_depth_256;
41671diff --git a/drivers/infiniband/hw/nes/nes_cm.c b/drivers/infiniband/hw/nes/nes_cm.c
41672index 6b29249..461d143 100644
41673--- a/drivers/infiniband/hw/nes/nes_cm.c
41674+++ b/drivers/infiniband/hw/nes/nes_cm.c
41675@@ -68,14 +68,14 @@ u32 cm_packets_dropped;
41676 u32 cm_packets_retrans;
41677 u32 cm_packets_created;
41678 u32 cm_packets_received;
41679-atomic_t cm_listens_created;
41680-atomic_t cm_listens_destroyed;
41681+atomic_unchecked_t cm_listens_created;
41682+atomic_unchecked_t cm_listens_destroyed;
41683 u32 cm_backlog_drops;
41684-atomic_t cm_loopbacks;
41685-atomic_t cm_nodes_created;
41686-atomic_t cm_nodes_destroyed;
41687-atomic_t cm_accel_dropped_pkts;
41688-atomic_t cm_resets_recvd;
41689+atomic_unchecked_t cm_loopbacks;
41690+atomic_unchecked_t cm_nodes_created;
41691+atomic_unchecked_t cm_nodes_destroyed;
41692+atomic_unchecked_t cm_accel_dropped_pkts;
41693+atomic_unchecked_t cm_resets_recvd;
41694
41695 static inline int mini_cm_accelerated(struct nes_cm_core *, struct nes_cm_node *);
41696 static struct nes_cm_listener *mini_cm_listen(struct nes_cm_core *, struct nes_vnic *, struct nes_cm_info *);
41697@@ -133,28 +133,28 @@ static void print_core(struct nes_cm_core *core);
41698 /* instance of function pointers for client API */
41699 /* set address of this instance to cm_core->cm_ops at cm_core alloc */
41700 static struct nes_cm_ops nes_cm_api = {
41701- mini_cm_accelerated,
41702- mini_cm_listen,
41703- mini_cm_del_listen,
41704- mini_cm_connect,
41705- mini_cm_close,
41706- mini_cm_accept,
41707- mini_cm_reject,
41708- mini_cm_recv_pkt,
41709- mini_cm_dealloc_core,
41710- mini_cm_get,
41711- mini_cm_set
41712+ .accelerated = mini_cm_accelerated,
41713+ .listen = mini_cm_listen,
41714+ .stop_listener = mini_cm_del_listen,
41715+ .connect = mini_cm_connect,
41716+ .close = mini_cm_close,
41717+ .accept = mini_cm_accept,
41718+ .reject = mini_cm_reject,
41719+ .recv_pkt = mini_cm_recv_pkt,
41720+ .destroy_cm_core = mini_cm_dealloc_core,
41721+ .get = mini_cm_get,
41722+ .set = mini_cm_set
41723 };
41724
41725 static struct nes_cm_core *g_cm_core;
41726
41727-atomic_t cm_connects;
41728-atomic_t cm_accepts;
41729-atomic_t cm_disconnects;
41730-atomic_t cm_closes;
41731-atomic_t cm_connecteds;
41732-atomic_t cm_connect_reqs;
41733-atomic_t cm_rejects;
41734+atomic_unchecked_t cm_connects;
41735+atomic_unchecked_t cm_accepts;
41736+atomic_unchecked_t cm_disconnects;
41737+atomic_unchecked_t cm_closes;
41738+atomic_unchecked_t cm_connecteds;
41739+atomic_unchecked_t cm_connect_reqs;
41740+atomic_unchecked_t cm_rejects;
41741
41742 int nes_add_ref_cm_node(struct nes_cm_node *cm_node)
41743 {
41744@@ -1272,7 +1272,7 @@ static int mini_cm_dec_refcnt_listen(struct nes_cm_core *cm_core,
41745 kfree(listener);
41746 listener = NULL;
41747 ret = 0;
41748- atomic_inc(&cm_listens_destroyed);
41749+ atomic_inc_unchecked(&cm_listens_destroyed);
41750 } else {
41751 spin_unlock_irqrestore(&cm_core->listen_list_lock, flags);
41752 }
41753@@ -1466,7 +1466,7 @@ static struct nes_cm_node *make_cm_node(struct nes_cm_core *cm_core,
41754 cm_node->rem_mac);
41755
41756 add_hte_node(cm_core, cm_node);
41757- atomic_inc(&cm_nodes_created);
41758+ atomic_inc_unchecked(&cm_nodes_created);
41759
41760 return cm_node;
41761 }
41762@@ -1524,7 +1524,7 @@ static int rem_ref_cm_node(struct nes_cm_core *cm_core,
41763 }
41764
41765 atomic_dec(&cm_core->node_cnt);
41766- atomic_inc(&cm_nodes_destroyed);
41767+ atomic_inc_unchecked(&cm_nodes_destroyed);
41768 nesqp = cm_node->nesqp;
41769 if (nesqp) {
41770 nesqp->cm_node = NULL;
41771@@ -1588,7 +1588,7 @@ static int process_options(struct nes_cm_node *cm_node, u8 *optionsloc,
41772
41773 static void drop_packet(struct sk_buff *skb)
41774 {
41775- atomic_inc(&cm_accel_dropped_pkts);
41776+ atomic_inc_unchecked(&cm_accel_dropped_pkts);
41777 dev_kfree_skb_any(skb);
41778 }
41779
41780@@ -1651,7 +1651,7 @@ static void handle_rst_pkt(struct nes_cm_node *cm_node, struct sk_buff *skb,
41781 {
41782
41783 int reset = 0; /* whether to send reset in case of err.. */
41784- atomic_inc(&cm_resets_recvd);
41785+ atomic_inc_unchecked(&cm_resets_recvd);
41786 nes_debug(NES_DBG_CM, "Received Reset, cm_node = %p, state = %u."
41787 " refcnt=%d\n", cm_node, cm_node->state,
41788 atomic_read(&cm_node->ref_count));
41789@@ -2292,7 +2292,7 @@ static struct nes_cm_node *mini_cm_connect(struct nes_cm_core *cm_core,
41790 rem_ref_cm_node(cm_node->cm_core, cm_node);
41791 return NULL;
41792 }
41793- atomic_inc(&cm_loopbacks);
41794+ atomic_inc_unchecked(&cm_loopbacks);
41795 loopbackremotenode->loopbackpartner = cm_node;
41796 loopbackremotenode->tcp_cntxt.rcv_wscale =
41797 NES_CM_DEFAULT_RCV_WND_SCALE;
41798@@ -2567,7 +2567,7 @@ static int mini_cm_recv_pkt(struct nes_cm_core *cm_core,
41799 nes_queue_mgt_skbs(skb, nesvnic, cm_node->nesqp);
41800 else {
41801 rem_ref_cm_node(cm_core, cm_node);
41802- atomic_inc(&cm_accel_dropped_pkts);
41803+ atomic_inc_unchecked(&cm_accel_dropped_pkts);
41804 dev_kfree_skb_any(skb);
41805 }
41806 break;
41807@@ -2875,7 +2875,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
41808
41809 if ((cm_id) && (cm_id->event_handler)) {
41810 if (issue_disconn) {
41811- atomic_inc(&cm_disconnects);
41812+ atomic_inc_unchecked(&cm_disconnects);
41813 cm_event.event = IW_CM_EVENT_DISCONNECT;
41814 cm_event.status = disconn_status;
41815 cm_event.local_addr = cm_id->local_addr;
41816@@ -2897,7 +2897,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
41817 }
41818
41819 if (issue_close) {
41820- atomic_inc(&cm_closes);
41821+ atomic_inc_unchecked(&cm_closes);
41822 nes_disconnect(nesqp, 1);
41823
41824 cm_id->provider_data = nesqp;
41825@@ -3035,7 +3035,7 @@ int nes_accept(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
41826
41827 nes_debug(NES_DBG_CM, "QP%u, cm_node=%p, jiffies = %lu listener = %p\n",
41828 nesqp->hwqp.qp_id, cm_node, jiffies, cm_node->listener);
41829- atomic_inc(&cm_accepts);
41830+ atomic_inc_unchecked(&cm_accepts);
41831
41832 nes_debug(NES_DBG_CM, "netdev refcnt = %u.\n",
41833 netdev_refcnt_read(nesvnic->netdev));
41834@@ -3224,7 +3224,7 @@ int nes_reject(struct iw_cm_id *cm_id, const void *pdata, u8 pdata_len)
41835 struct nes_cm_core *cm_core;
41836 u8 *start_buff;
41837
41838- atomic_inc(&cm_rejects);
41839+ atomic_inc_unchecked(&cm_rejects);
41840 cm_node = (struct nes_cm_node *)cm_id->provider_data;
41841 loopback = cm_node->loopbackpartner;
41842 cm_core = cm_node->cm_core;
41843@@ -3286,7 +3286,7 @@ int nes_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
41844 ntohs(raddr->sin_port), ntohl(laddr->sin_addr.s_addr),
41845 ntohs(laddr->sin_port));
41846
41847- atomic_inc(&cm_connects);
41848+ atomic_inc_unchecked(&cm_connects);
41849 nesqp->active_conn = 1;
41850
41851 /* cache the cm_id in the qp */
41852@@ -3398,7 +3398,7 @@ int nes_create_listen(struct iw_cm_id *cm_id, int backlog)
41853 g_cm_core->api->stop_listener(g_cm_core, (void *)cm_node);
41854 return err;
41855 }
41856- atomic_inc(&cm_listens_created);
41857+ atomic_inc_unchecked(&cm_listens_created);
41858 }
41859
41860 cm_id->add_ref(cm_id);
41861@@ -3505,7 +3505,7 @@ static void cm_event_connected(struct nes_cm_event *event)
41862
41863 if (nesqp->destroyed)
41864 return;
41865- atomic_inc(&cm_connecteds);
41866+ atomic_inc_unchecked(&cm_connecteds);
41867 nes_debug(NES_DBG_CM, "QP%u attempting to connect to 0x%08X:0x%04X on"
41868 " local port 0x%04X. jiffies = %lu.\n",
41869 nesqp->hwqp.qp_id, ntohl(raddr->sin_addr.s_addr),
41870@@ -3686,7 +3686,7 @@ static void cm_event_reset(struct nes_cm_event *event)
41871
41872 cm_id->add_ref(cm_id);
41873 ret = cm_id->event_handler(cm_id, &cm_event);
41874- atomic_inc(&cm_closes);
41875+ atomic_inc_unchecked(&cm_closes);
41876 cm_event.event = IW_CM_EVENT_CLOSE;
41877 cm_event.status = 0;
41878 cm_event.provider_data = cm_id->provider_data;
41879@@ -3726,7 +3726,7 @@ static void cm_event_mpa_req(struct nes_cm_event *event)
41880 return;
41881 cm_id = cm_node->cm_id;
41882
41883- atomic_inc(&cm_connect_reqs);
41884+ atomic_inc_unchecked(&cm_connect_reqs);
41885 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
41886 cm_node, cm_id, jiffies);
41887
41888@@ -3770,7 +3770,7 @@ static void cm_event_mpa_reject(struct nes_cm_event *event)
41889 return;
41890 cm_id = cm_node->cm_id;
41891
41892- atomic_inc(&cm_connect_reqs);
41893+ atomic_inc_unchecked(&cm_connect_reqs);
41894 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
41895 cm_node, cm_id, jiffies);
41896
41897diff --git a/drivers/infiniband/hw/nes/nes_mgt.c b/drivers/infiniband/hw/nes/nes_mgt.c
41898index 4166452..fc952c3 100644
41899--- a/drivers/infiniband/hw/nes/nes_mgt.c
41900+++ b/drivers/infiniband/hw/nes/nes_mgt.c
41901@@ -40,8 +40,8 @@
41902 #include "nes.h"
41903 #include "nes_mgt.h"
41904
41905-atomic_t pau_qps_created;
41906-atomic_t pau_qps_destroyed;
41907+atomic_unchecked_t pau_qps_created;
41908+atomic_unchecked_t pau_qps_destroyed;
41909
41910 static void nes_replenish_mgt_rq(struct nes_vnic_mgt *mgtvnic)
41911 {
41912@@ -621,7 +621,7 @@ void nes_destroy_pau_qp(struct nes_device *nesdev, struct nes_qp *nesqp)
41913 {
41914 struct sk_buff *skb;
41915 unsigned long flags;
41916- atomic_inc(&pau_qps_destroyed);
41917+ atomic_inc_unchecked(&pau_qps_destroyed);
41918
41919 /* Free packets that have not yet been forwarded */
41920 /* Lock is acquired by skb_dequeue when removing the skb */
41921@@ -810,7 +810,7 @@ static void nes_mgt_ce_handler(struct nes_device *nesdev, struct nes_hw_nic_cq *
41922 cq->cq_vbase[head].cqe_words[NES_NIC_CQE_HASH_RCVNXT]);
41923 skb_queue_head_init(&nesqp->pau_list);
41924 spin_lock_init(&nesqp->pau_lock);
41925- atomic_inc(&pau_qps_created);
41926+ atomic_inc_unchecked(&pau_qps_created);
41927 nes_change_quad_hash(nesdev, mgtvnic->nesvnic, nesqp);
41928 }
41929
41930diff --git a/drivers/infiniband/hw/nes/nes_nic.c b/drivers/infiniband/hw/nes/nes_nic.c
41931index 49eb511..a774366 100644
41932--- a/drivers/infiniband/hw/nes/nes_nic.c
41933+++ b/drivers/infiniband/hw/nes/nes_nic.c
41934@@ -1273,39 +1273,39 @@ static void nes_netdev_get_ethtool_stats(struct net_device *netdev,
41935 target_stat_values[++index] = mh_detected;
41936 target_stat_values[++index] = mh_pauses_sent;
41937 target_stat_values[++index] = nesvnic->endnode_ipv4_tcp_retransmits;
41938- target_stat_values[++index] = atomic_read(&cm_connects);
41939- target_stat_values[++index] = atomic_read(&cm_accepts);
41940- target_stat_values[++index] = atomic_read(&cm_disconnects);
41941- target_stat_values[++index] = atomic_read(&cm_connecteds);
41942- target_stat_values[++index] = atomic_read(&cm_connect_reqs);
41943- target_stat_values[++index] = atomic_read(&cm_rejects);
41944- target_stat_values[++index] = atomic_read(&mod_qp_timouts);
41945- target_stat_values[++index] = atomic_read(&qps_created);
41946- target_stat_values[++index] = atomic_read(&sw_qps_destroyed);
41947- target_stat_values[++index] = atomic_read(&qps_destroyed);
41948- target_stat_values[++index] = atomic_read(&cm_closes);
41949+ target_stat_values[++index] = atomic_read_unchecked(&cm_connects);
41950+ target_stat_values[++index] = atomic_read_unchecked(&cm_accepts);
41951+ target_stat_values[++index] = atomic_read_unchecked(&cm_disconnects);
41952+ target_stat_values[++index] = atomic_read_unchecked(&cm_connecteds);
41953+ target_stat_values[++index] = atomic_read_unchecked(&cm_connect_reqs);
41954+ target_stat_values[++index] = atomic_read_unchecked(&cm_rejects);
41955+ target_stat_values[++index] = atomic_read_unchecked(&mod_qp_timouts);
41956+ target_stat_values[++index] = atomic_read_unchecked(&qps_created);
41957+ target_stat_values[++index] = atomic_read_unchecked(&sw_qps_destroyed);
41958+ target_stat_values[++index] = atomic_read_unchecked(&qps_destroyed);
41959+ target_stat_values[++index] = atomic_read_unchecked(&cm_closes);
41960 target_stat_values[++index] = cm_packets_sent;
41961 target_stat_values[++index] = cm_packets_bounced;
41962 target_stat_values[++index] = cm_packets_created;
41963 target_stat_values[++index] = cm_packets_received;
41964 target_stat_values[++index] = cm_packets_dropped;
41965 target_stat_values[++index] = cm_packets_retrans;
41966- target_stat_values[++index] = atomic_read(&cm_listens_created);
41967- target_stat_values[++index] = atomic_read(&cm_listens_destroyed);
41968+ target_stat_values[++index] = atomic_read_unchecked(&cm_listens_created);
41969+ target_stat_values[++index] = atomic_read_unchecked(&cm_listens_destroyed);
41970 target_stat_values[++index] = cm_backlog_drops;
41971- target_stat_values[++index] = atomic_read(&cm_loopbacks);
41972- target_stat_values[++index] = atomic_read(&cm_nodes_created);
41973- target_stat_values[++index] = atomic_read(&cm_nodes_destroyed);
41974- target_stat_values[++index] = atomic_read(&cm_accel_dropped_pkts);
41975- target_stat_values[++index] = atomic_read(&cm_resets_recvd);
41976+ target_stat_values[++index] = atomic_read_unchecked(&cm_loopbacks);
41977+ target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_created);
41978+ target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_destroyed);
41979+ target_stat_values[++index] = atomic_read_unchecked(&cm_accel_dropped_pkts);
41980+ target_stat_values[++index] = atomic_read_unchecked(&cm_resets_recvd);
41981 target_stat_values[++index] = nesadapter->free_4kpbl;
41982 target_stat_values[++index] = nesadapter->free_256pbl;
41983 target_stat_values[++index] = int_mod_timer_init;
41984 target_stat_values[++index] = nesvnic->lro_mgr.stats.aggregated;
41985 target_stat_values[++index] = nesvnic->lro_mgr.stats.flushed;
41986 target_stat_values[++index] = nesvnic->lro_mgr.stats.no_desc;
41987- target_stat_values[++index] = atomic_read(&pau_qps_created);
41988- target_stat_values[++index] = atomic_read(&pau_qps_destroyed);
41989+ target_stat_values[++index] = atomic_read_unchecked(&pau_qps_created);
41990+ target_stat_values[++index] = atomic_read_unchecked(&pau_qps_destroyed);
41991 }
41992
41993 /**
41994diff --git a/drivers/infiniband/hw/nes/nes_verbs.c b/drivers/infiniband/hw/nes/nes_verbs.c
41995index 5b53ca5..443da3c 100644
41996--- a/drivers/infiniband/hw/nes/nes_verbs.c
41997+++ b/drivers/infiniband/hw/nes/nes_verbs.c
41998@@ -46,9 +46,9 @@
41999
42000 #include <rdma/ib_umem.h>
42001
42002-atomic_t mod_qp_timouts;
42003-atomic_t qps_created;
42004-atomic_t sw_qps_destroyed;
42005+atomic_unchecked_t mod_qp_timouts;
42006+atomic_unchecked_t qps_created;
42007+atomic_unchecked_t sw_qps_destroyed;
42008
42009 static void nes_unregister_ofa_device(struct nes_ib_device *nesibdev);
42010
42011@@ -1134,7 +1134,7 @@ static struct ib_qp *nes_create_qp(struct ib_pd *ibpd,
42012 if (init_attr->create_flags)
42013 return ERR_PTR(-EINVAL);
42014
42015- atomic_inc(&qps_created);
42016+ atomic_inc_unchecked(&qps_created);
42017 switch (init_attr->qp_type) {
42018 case IB_QPT_RC:
42019 if (nes_drv_opt & NES_DRV_OPT_NO_INLINE_DATA) {
42020@@ -1466,7 +1466,7 @@ static int nes_destroy_qp(struct ib_qp *ibqp)
42021 struct iw_cm_event cm_event;
42022 int ret = 0;
42023
42024- atomic_inc(&sw_qps_destroyed);
42025+ atomic_inc_unchecked(&sw_qps_destroyed);
42026 nesqp->destroyed = 1;
42027
42028 /* Blow away the connection if it exists. */
42029diff --git a/drivers/infiniband/hw/qib/qib.h b/drivers/infiniband/hw/qib/qib.h
42030index 1946101..09766d2 100644
42031--- a/drivers/infiniband/hw/qib/qib.h
42032+++ b/drivers/infiniband/hw/qib/qib.h
42033@@ -52,6 +52,7 @@
42034 #include <linux/kref.h>
42035 #include <linux/sched.h>
42036 #include <linux/kthread.h>
42037+#include <linux/slab.h>
42038
42039 #include "qib_common.h"
42040 #include "qib_verbs.h"
42041diff --git a/drivers/input/gameport/gameport.c b/drivers/input/gameport/gameport.c
42042index 922a7fe..bb035db 100644
42043--- a/drivers/input/gameport/gameport.c
42044+++ b/drivers/input/gameport/gameport.c
42045@@ -487,14 +487,14 @@ EXPORT_SYMBOL(gameport_set_phys);
42046 */
42047 static void gameport_init_port(struct gameport *gameport)
42048 {
42049- static atomic_t gameport_no = ATOMIC_INIT(0);
42050+ static atomic_unchecked_t gameport_no = ATOMIC_INIT(0);
42051
42052 __module_get(THIS_MODULE);
42053
42054 mutex_init(&gameport->drv_mutex);
42055 device_initialize(&gameport->dev);
42056 dev_set_name(&gameport->dev, "gameport%lu",
42057- (unsigned long)atomic_inc_return(&gameport_no) - 1);
42058+ (unsigned long)atomic_inc_return_unchecked(&gameport_no) - 1);
42059 gameport->dev.bus = &gameport_bus;
42060 gameport->dev.release = gameport_release_port;
42061 if (gameport->parent)
42062diff --git a/drivers/input/input.c b/drivers/input/input.c
42063index 74f4798..d9f7168 100644
42064--- a/drivers/input/input.c
42065+++ b/drivers/input/input.c
42066@@ -1734,7 +1734,7 @@ EXPORT_SYMBOL_GPL(input_class);
42067 */
42068 struct input_dev *input_allocate_device(void)
42069 {
42070- static atomic_t input_no = ATOMIC_INIT(0);
42071+ static atomic_unchecked_t input_no = ATOMIC_INIT(0);
42072 struct input_dev *dev;
42073
42074 dev = kzalloc(sizeof(struct input_dev), GFP_KERNEL);
42075@@ -1749,7 +1749,7 @@ struct input_dev *input_allocate_device(void)
42076 INIT_LIST_HEAD(&dev->node);
42077
42078 dev_set_name(&dev->dev, "input%ld",
42079- (unsigned long) atomic_inc_return(&input_no) - 1);
42080+ (unsigned long) atomic_inc_return_unchecked(&input_no) - 1);
42081
42082 __module_get(THIS_MODULE);
42083 }
42084diff --git a/drivers/input/joystick/sidewinder.c b/drivers/input/joystick/sidewinder.c
42085index 04c69af..5f92d00 100644
42086--- a/drivers/input/joystick/sidewinder.c
42087+++ b/drivers/input/joystick/sidewinder.c
42088@@ -30,6 +30,7 @@
42089 #include <linux/kernel.h>
42090 #include <linux/module.h>
42091 #include <linux/slab.h>
42092+#include <linux/sched.h>
42093 #include <linux/init.h>
42094 #include <linux/input.h>
42095 #include <linux/gameport.h>
42096diff --git a/drivers/input/joystick/xpad.c b/drivers/input/joystick/xpad.c
42097index 75e3b10..fb390fd 100644
42098--- a/drivers/input/joystick/xpad.c
42099+++ b/drivers/input/joystick/xpad.c
42100@@ -736,7 +736,7 @@ static void xpad_led_set(struct led_classdev *led_cdev,
42101
42102 static int xpad_led_probe(struct usb_xpad *xpad)
42103 {
42104- static atomic_t led_seq = ATOMIC_INIT(0);
42105+ static atomic_unchecked_t led_seq = ATOMIC_INIT(0);
42106 long led_no;
42107 struct xpad_led *led;
42108 struct led_classdev *led_cdev;
42109@@ -749,7 +749,7 @@ static int xpad_led_probe(struct usb_xpad *xpad)
42110 if (!led)
42111 return -ENOMEM;
42112
42113- led_no = (long)atomic_inc_return(&led_seq) - 1;
42114+ led_no = (long)atomic_inc_return_unchecked(&led_seq) - 1;
42115
42116 snprintf(led->name, sizeof(led->name), "xpad%ld", led_no);
42117 led->xpad = xpad;
42118diff --git a/drivers/input/misc/ims-pcu.c b/drivers/input/misc/ims-pcu.c
42119index e204f26..8459f15 100644
42120--- a/drivers/input/misc/ims-pcu.c
42121+++ b/drivers/input/misc/ims-pcu.c
42122@@ -1621,7 +1621,7 @@ static int ims_pcu_identify_type(struct ims_pcu *pcu, u8 *device_id)
42123
42124 static int ims_pcu_init_application_mode(struct ims_pcu *pcu)
42125 {
42126- static atomic_t device_no = ATOMIC_INIT(0);
42127+ static atomic_unchecked_t device_no = ATOMIC_INIT(0);
42128
42129 const struct ims_pcu_device_info *info;
42130 u8 device_id;
42131@@ -1653,7 +1653,7 @@ static int ims_pcu_init_application_mode(struct ims_pcu *pcu)
42132 }
42133
42134 /* Device appears to be operable, complete initialization */
42135- pcu->device_no = atomic_inc_return(&device_no) - 1;
42136+ pcu->device_no = atomic_inc_return_unchecked(&device_no) - 1;
42137
42138 error = ims_pcu_setup_backlight(pcu);
42139 if (error)
42140diff --git a/drivers/input/mouse/psmouse.h b/drivers/input/mouse/psmouse.h
42141index 2f0b39d..7370f13 100644
42142--- a/drivers/input/mouse/psmouse.h
42143+++ b/drivers/input/mouse/psmouse.h
42144@@ -116,7 +116,7 @@ struct psmouse_attribute {
42145 ssize_t (*set)(struct psmouse *psmouse, void *data,
42146 const char *buf, size_t count);
42147 bool protect;
42148-};
42149+} __do_const;
42150 #define to_psmouse_attr(a) container_of((a), struct psmouse_attribute, dattr)
42151
42152 ssize_t psmouse_attr_show_helper(struct device *dev, struct device_attribute *attr,
42153diff --git a/drivers/input/mousedev.c b/drivers/input/mousedev.c
42154index 4c842c3..590b0bf 100644
42155--- a/drivers/input/mousedev.c
42156+++ b/drivers/input/mousedev.c
42157@@ -738,7 +738,7 @@ static ssize_t mousedev_read(struct file *file, char __user *buffer,
42158
42159 spin_unlock_irq(&client->packet_lock);
42160
42161- if (copy_to_user(buffer, data, count))
42162+ if (count > sizeof(data) || copy_to_user(buffer, data, count))
42163 return -EFAULT;
42164
42165 return count;
42166diff --git a/drivers/input/serio/serio.c b/drivers/input/serio/serio.c
42167index 2b56855..5a55837 100644
42168--- a/drivers/input/serio/serio.c
42169+++ b/drivers/input/serio/serio.c
42170@@ -496,7 +496,7 @@ static void serio_release_port(struct device *dev)
42171 */
42172 static void serio_init_port(struct serio *serio)
42173 {
42174- static atomic_t serio_no = ATOMIC_INIT(0);
42175+ static atomic_unchecked_t serio_no = ATOMIC_INIT(0);
42176
42177 __module_get(THIS_MODULE);
42178
42179@@ -507,7 +507,7 @@ static void serio_init_port(struct serio *serio)
42180 mutex_init(&serio->drv_mutex);
42181 device_initialize(&serio->dev);
42182 dev_set_name(&serio->dev, "serio%ld",
42183- (long)atomic_inc_return(&serio_no) - 1);
42184+ (long)atomic_inc_return_unchecked(&serio_no) - 1);
42185 serio->dev.bus = &serio_bus;
42186 serio->dev.release = serio_release_port;
42187 serio->dev.groups = serio_device_attr_groups;
42188diff --git a/drivers/input/serio/serio_raw.c b/drivers/input/serio/serio_raw.c
42189index 59df2e7..8f1cafb 100644
42190--- a/drivers/input/serio/serio_raw.c
42191+++ b/drivers/input/serio/serio_raw.c
42192@@ -293,7 +293,7 @@ static irqreturn_t serio_raw_interrupt(struct serio *serio, unsigned char data,
42193
42194 static int serio_raw_connect(struct serio *serio, struct serio_driver *drv)
42195 {
42196- static atomic_t serio_raw_no = ATOMIC_INIT(0);
42197+ static atomic_unchecked_t serio_raw_no = ATOMIC_INIT(0);
42198 struct serio_raw *serio_raw;
42199 int err;
42200
42201@@ -304,7 +304,7 @@ static int serio_raw_connect(struct serio *serio, struct serio_driver *drv)
42202 }
42203
42204 snprintf(serio_raw->name, sizeof(serio_raw->name),
42205- "serio_raw%ld", (long)atomic_inc_return(&serio_raw_no) - 1);
42206+ "serio_raw%ld", (long)atomic_inc_return_unchecked(&serio_raw_no) - 1);
42207 kref_init(&serio_raw->kref);
42208 INIT_LIST_HEAD(&serio_raw->client_list);
42209 init_waitqueue_head(&serio_raw->wait);
42210diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c
42211index fbe9ca7..dbee61d 100644
42212--- a/drivers/iommu/iommu.c
42213+++ b/drivers/iommu/iommu.c
42214@@ -583,7 +583,7 @@ static struct notifier_block iommu_bus_nb = {
42215 static void iommu_bus_init(struct bus_type *bus, struct iommu_ops *ops)
42216 {
42217 bus_register_notifier(bus, &iommu_bus_nb);
42218- bus_for_each_dev(bus, NULL, ops, add_iommu_group);
42219+ bus_for_each_dev(bus, NULL, (void *)ops, add_iommu_group);
42220 }
42221
42222 /**
42223diff --git a/drivers/iommu/irq_remapping.c b/drivers/iommu/irq_remapping.c
42224index 39f81ae..2660096 100644
42225--- a/drivers/iommu/irq_remapping.c
42226+++ b/drivers/iommu/irq_remapping.c
42227@@ -356,7 +356,7 @@ int setup_hpet_msi_remapped(unsigned int irq, unsigned int id)
42228 void panic_if_irq_remap(const char *msg)
42229 {
42230 if (irq_remapping_enabled)
42231- panic(msg);
42232+ panic("%s", msg);
42233 }
42234
42235 static void ir_ack_apic_edge(struct irq_data *data)
42236@@ -377,10 +377,12 @@ static void ir_print_prefix(struct irq_data *data, struct seq_file *p)
42237
42238 void irq_remap_modify_chip_defaults(struct irq_chip *chip)
42239 {
42240- chip->irq_print_chip = ir_print_prefix;
42241- chip->irq_ack = ir_ack_apic_edge;
42242- chip->irq_eoi = ir_ack_apic_level;
42243- chip->irq_set_affinity = x86_io_apic_ops.set_affinity;
42244+ pax_open_kernel();
42245+ *(void **)&chip->irq_print_chip = ir_print_prefix;
42246+ *(void **)&chip->irq_ack = ir_ack_apic_edge;
42247+ *(void **)&chip->irq_eoi = ir_ack_apic_level;
42248+ *(void **)&chip->irq_set_affinity = x86_io_apic_ops.set_affinity;
42249+ pax_close_kernel();
42250 }
42251
42252 bool setup_remapped_irq(int irq, struct irq_cfg *cfg, struct irq_chip *chip)
42253diff --git a/drivers/irqchip/irq-gic.c b/drivers/irqchip/irq-gic.c
42254index d0e9480..d2b6340 100644
42255--- a/drivers/irqchip/irq-gic.c
42256+++ b/drivers/irqchip/irq-gic.c
42257@@ -84,7 +84,7 @@ static u8 gic_cpu_map[NR_GIC_CPU_IF] __read_mostly;
42258 * Supported arch specific GIC irq extension.
42259 * Default make them NULL.
42260 */
42261-struct irq_chip gic_arch_extn = {
42262+irq_chip_no_const gic_arch_extn = {
42263 .irq_eoi = NULL,
42264 .irq_mask = NULL,
42265 .irq_unmask = NULL,
42266@@ -333,7 +333,7 @@ static void gic_handle_cascade_irq(unsigned int irq, struct irq_desc *desc)
42267 chained_irq_exit(chip, desc);
42268 }
42269
42270-static struct irq_chip gic_chip = {
42271+static irq_chip_no_const gic_chip __read_only = {
42272 .name = "GIC",
42273 .irq_mask = gic_mask_irq,
42274 .irq_unmask = gic_unmask_irq,
42275diff --git a/drivers/isdn/capi/capi.c b/drivers/isdn/capi/capi.c
42276index ac6f72b..81150f2 100644
42277--- a/drivers/isdn/capi/capi.c
42278+++ b/drivers/isdn/capi/capi.c
42279@@ -81,8 +81,8 @@ struct capiminor {
42280
42281 struct capi20_appl *ap;
42282 u32 ncci;
42283- atomic_t datahandle;
42284- atomic_t msgid;
42285+ atomic_unchecked_t datahandle;
42286+ atomic_unchecked_t msgid;
42287
42288 struct tty_port port;
42289 int ttyinstop;
42290@@ -391,7 +391,7 @@ gen_data_b3_resp_for(struct capiminor *mp, struct sk_buff *skb)
42291 capimsg_setu16(s, 2, mp->ap->applid);
42292 capimsg_setu8 (s, 4, CAPI_DATA_B3);
42293 capimsg_setu8 (s, 5, CAPI_RESP);
42294- capimsg_setu16(s, 6, atomic_inc_return(&mp->msgid));
42295+ capimsg_setu16(s, 6, atomic_inc_return_unchecked(&mp->msgid));
42296 capimsg_setu32(s, 8, mp->ncci);
42297 capimsg_setu16(s, 12, datahandle);
42298 }
42299@@ -512,14 +512,14 @@ static void handle_minor_send(struct capiminor *mp)
42300 mp->outbytes -= len;
42301 spin_unlock_bh(&mp->outlock);
42302
42303- datahandle = atomic_inc_return(&mp->datahandle);
42304+ datahandle = atomic_inc_return_unchecked(&mp->datahandle);
42305 skb_push(skb, CAPI_DATA_B3_REQ_LEN);
42306 memset(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
42307 capimsg_setu16(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
42308 capimsg_setu16(skb->data, 2, mp->ap->applid);
42309 capimsg_setu8 (skb->data, 4, CAPI_DATA_B3);
42310 capimsg_setu8 (skb->data, 5, CAPI_REQ);
42311- capimsg_setu16(skb->data, 6, atomic_inc_return(&mp->msgid));
42312+ capimsg_setu16(skb->data, 6, atomic_inc_return_unchecked(&mp->msgid));
42313 capimsg_setu32(skb->data, 8, mp->ncci); /* NCCI */
42314 capimsg_setu32(skb->data, 12, (u32)(long)skb->data);/* Data32 */
42315 capimsg_setu16(skb->data, 16, len); /* Data length */
42316diff --git a/drivers/isdn/gigaset/bas-gigaset.c b/drivers/isdn/gigaset/bas-gigaset.c
42317index c44950d..10ac276 100644
42318--- a/drivers/isdn/gigaset/bas-gigaset.c
42319+++ b/drivers/isdn/gigaset/bas-gigaset.c
42320@@ -2564,22 +2564,22 @@ static int gigaset_post_reset(struct usb_interface *intf)
42321
42322
42323 static const struct gigaset_ops gigops = {
42324- gigaset_write_cmd,
42325- gigaset_write_room,
42326- gigaset_chars_in_buffer,
42327- gigaset_brkchars,
42328- gigaset_init_bchannel,
42329- gigaset_close_bchannel,
42330- gigaset_initbcshw,
42331- gigaset_freebcshw,
42332- gigaset_reinitbcshw,
42333- gigaset_initcshw,
42334- gigaset_freecshw,
42335- gigaset_set_modem_ctrl,
42336- gigaset_baud_rate,
42337- gigaset_set_line_ctrl,
42338- gigaset_isoc_send_skb,
42339- gigaset_isoc_input,
42340+ .write_cmd = gigaset_write_cmd,
42341+ .write_room = gigaset_write_room,
42342+ .chars_in_buffer = gigaset_chars_in_buffer,
42343+ .brkchars = gigaset_brkchars,
42344+ .init_bchannel = gigaset_init_bchannel,
42345+ .close_bchannel = gigaset_close_bchannel,
42346+ .initbcshw = gigaset_initbcshw,
42347+ .freebcshw = gigaset_freebcshw,
42348+ .reinitbcshw = gigaset_reinitbcshw,
42349+ .initcshw = gigaset_initcshw,
42350+ .freecshw = gigaset_freecshw,
42351+ .set_modem_ctrl = gigaset_set_modem_ctrl,
42352+ .baud_rate = gigaset_baud_rate,
42353+ .set_line_ctrl = gigaset_set_line_ctrl,
42354+ .send_skb = gigaset_isoc_send_skb,
42355+ .handle_input = gigaset_isoc_input,
42356 };
42357
42358 /* bas_gigaset_init
42359diff --git a/drivers/isdn/gigaset/interface.c b/drivers/isdn/gigaset/interface.c
42360index 600c79b..3752bab 100644
42361--- a/drivers/isdn/gigaset/interface.c
42362+++ b/drivers/isdn/gigaset/interface.c
42363@@ -130,9 +130,9 @@ static int if_open(struct tty_struct *tty, struct file *filp)
42364 }
42365 tty->driver_data = cs;
42366
42367- ++cs->port.count;
42368+ atomic_inc(&cs->port.count);
42369
42370- if (cs->port.count == 1) {
42371+ if (atomic_read(&cs->port.count) == 1) {
42372 tty_port_tty_set(&cs->port, tty);
42373 cs->port.low_latency = 1;
42374 }
42375@@ -156,9 +156,9 @@ static void if_close(struct tty_struct *tty, struct file *filp)
42376
42377 if (!cs->connected)
42378 gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */
42379- else if (!cs->port.count)
42380+ else if (!atomic_read(&cs->port.count))
42381 dev_warn(cs->dev, "%s: device not opened\n", __func__);
42382- else if (!--cs->port.count)
42383+ else if (!atomic_dec_return(&cs->port.count))
42384 tty_port_tty_set(&cs->port, NULL);
42385
42386 mutex_unlock(&cs->mutex);
42387diff --git a/drivers/isdn/gigaset/ser-gigaset.c b/drivers/isdn/gigaset/ser-gigaset.c
42388index 8c91fd5..14f13ce 100644
42389--- a/drivers/isdn/gigaset/ser-gigaset.c
42390+++ b/drivers/isdn/gigaset/ser-gigaset.c
42391@@ -453,22 +453,22 @@ static int gigaset_set_line_ctrl(struct cardstate *cs, unsigned cflag)
42392 }
42393
42394 static const struct gigaset_ops ops = {
42395- gigaset_write_cmd,
42396- gigaset_write_room,
42397- gigaset_chars_in_buffer,
42398- gigaset_brkchars,
42399- gigaset_init_bchannel,
42400- gigaset_close_bchannel,
42401- gigaset_initbcshw,
42402- gigaset_freebcshw,
42403- gigaset_reinitbcshw,
42404- gigaset_initcshw,
42405- gigaset_freecshw,
42406- gigaset_set_modem_ctrl,
42407- gigaset_baud_rate,
42408- gigaset_set_line_ctrl,
42409- gigaset_m10x_send_skb, /* asyncdata.c */
42410- gigaset_m10x_input, /* asyncdata.c */
42411+ .write_cmd = gigaset_write_cmd,
42412+ .write_room = gigaset_write_room,
42413+ .chars_in_buffer = gigaset_chars_in_buffer,
42414+ .brkchars = gigaset_brkchars,
42415+ .init_bchannel = gigaset_init_bchannel,
42416+ .close_bchannel = gigaset_close_bchannel,
42417+ .initbcshw = gigaset_initbcshw,
42418+ .freebcshw = gigaset_freebcshw,
42419+ .reinitbcshw = gigaset_reinitbcshw,
42420+ .initcshw = gigaset_initcshw,
42421+ .freecshw = gigaset_freecshw,
42422+ .set_modem_ctrl = gigaset_set_modem_ctrl,
42423+ .baud_rate = gigaset_baud_rate,
42424+ .set_line_ctrl = gigaset_set_line_ctrl,
42425+ .send_skb = gigaset_m10x_send_skb, /* asyncdata.c */
42426+ .handle_input = gigaset_m10x_input, /* asyncdata.c */
42427 };
42428
42429
42430diff --git a/drivers/isdn/gigaset/usb-gigaset.c b/drivers/isdn/gigaset/usb-gigaset.c
42431index d0a41cb..b953e50 100644
42432--- a/drivers/isdn/gigaset/usb-gigaset.c
42433+++ b/drivers/isdn/gigaset/usb-gigaset.c
42434@@ -547,7 +547,7 @@ static int gigaset_brkchars(struct cardstate *cs, const unsigned char buf[6])
42435 gigaset_dbg_buffer(DEBUG_USBREQ, "brkchars", 6, buf);
42436 memcpy(cs->hw.usb->bchars, buf, 6);
42437 return usb_control_msg(udev, usb_sndctrlpipe(udev, 0), 0x19, 0x41,
42438- 0, 0, &buf, 6, 2000);
42439+ 0, 0, buf, 6, 2000);
42440 }
42441
42442 static void gigaset_freebcshw(struct bc_state *bcs)
42443@@ -869,22 +869,22 @@ static int gigaset_pre_reset(struct usb_interface *intf)
42444 }
42445
42446 static const struct gigaset_ops ops = {
42447- gigaset_write_cmd,
42448- gigaset_write_room,
42449- gigaset_chars_in_buffer,
42450- gigaset_brkchars,
42451- gigaset_init_bchannel,
42452- gigaset_close_bchannel,
42453- gigaset_initbcshw,
42454- gigaset_freebcshw,
42455- gigaset_reinitbcshw,
42456- gigaset_initcshw,
42457- gigaset_freecshw,
42458- gigaset_set_modem_ctrl,
42459- gigaset_baud_rate,
42460- gigaset_set_line_ctrl,
42461- gigaset_m10x_send_skb,
42462- gigaset_m10x_input,
42463+ .write_cmd = gigaset_write_cmd,
42464+ .write_room = gigaset_write_room,
42465+ .chars_in_buffer = gigaset_chars_in_buffer,
42466+ .brkchars = gigaset_brkchars,
42467+ .init_bchannel = gigaset_init_bchannel,
42468+ .close_bchannel = gigaset_close_bchannel,
42469+ .initbcshw = gigaset_initbcshw,
42470+ .freebcshw = gigaset_freebcshw,
42471+ .reinitbcshw = gigaset_reinitbcshw,
42472+ .initcshw = gigaset_initcshw,
42473+ .freecshw = gigaset_freecshw,
42474+ .set_modem_ctrl = gigaset_set_modem_ctrl,
42475+ .baud_rate = gigaset_baud_rate,
42476+ .set_line_ctrl = gigaset_set_line_ctrl,
42477+ .send_skb = gigaset_m10x_send_skb,
42478+ .handle_input = gigaset_m10x_input,
42479 };
42480
42481 /*
42482diff --git a/drivers/isdn/hardware/avm/b1.c b/drivers/isdn/hardware/avm/b1.c
42483index 4d9b195..455075c 100644
42484--- a/drivers/isdn/hardware/avm/b1.c
42485+++ b/drivers/isdn/hardware/avm/b1.c
42486@@ -176,7 +176,7 @@ int b1_load_t4file(avmcard *card, capiloaddatapart *t4file)
42487 }
42488 if (left) {
42489 if (t4file->user) {
42490- if (copy_from_user(buf, dp, left))
42491+ if (left > sizeof buf || copy_from_user(buf, dp, left))
42492 return -EFAULT;
42493 } else {
42494 memcpy(buf, dp, left);
42495@@ -224,7 +224,7 @@ int b1_load_config(avmcard *card, capiloaddatapart *config)
42496 }
42497 if (left) {
42498 if (config->user) {
42499- if (copy_from_user(buf, dp, left))
42500+ if (left > sizeof buf || copy_from_user(buf, dp, left))
42501 return -EFAULT;
42502 } else {
42503 memcpy(buf, dp, left);
42504diff --git a/drivers/isdn/i4l/isdn_common.c b/drivers/isdn/i4l/isdn_common.c
42505index 9bb12ba..d4262f7 100644
42506--- a/drivers/isdn/i4l/isdn_common.c
42507+++ b/drivers/isdn/i4l/isdn_common.c
42508@@ -1651,6 +1651,8 @@ isdn_ioctl(struct file *file, uint cmd, ulong arg)
42509 } else
42510 return -EINVAL;
42511 case IIOCDBGVAR:
42512+ if (!capable(CAP_SYS_RAWIO))
42513+ return -EPERM;
42514 if (arg) {
42515 if (copy_to_user(argp, &dev, sizeof(ulong)))
42516 return -EFAULT;
42517diff --git a/drivers/isdn/i4l/isdn_concap.c b/drivers/isdn/i4l/isdn_concap.c
42518index 91d5730..336523e 100644
42519--- a/drivers/isdn/i4l/isdn_concap.c
42520+++ b/drivers/isdn/i4l/isdn_concap.c
42521@@ -80,9 +80,9 @@ static int isdn_concap_dl_disconn_req(struct concap_proto *concap)
42522 }
42523
42524 struct concap_device_ops isdn_concap_reliable_dl_dops = {
42525- &isdn_concap_dl_data_req,
42526- &isdn_concap_dl_connect_req,
42527- &isdn_concap_dl_disconn_req
42528+ .data_req = &isdn_concap_dl_data_req,
42529+ .connect_req = &isdn_concap_dl_connect_req,
42530+ .disconn_req = &isdn_concap_dl_disconn_req
42531 };
42532
42533 /* The following should better go into a dedicated source file such that
42534diff --git a/drivers/isdn/i4l/isdn_tty.c b/drivers/isdn/i4l/isdn_tty.c
42535index 3c5f249..5fac4d0 100644
42536--- a/drivers/isdn/i4l/isdn_tty.c
42537+++ b/drivers/isdn/i4l/isdn_tty.c
42538@@ -1508,9 +1508,9 @@ isdn_tty_open(struct tty_struct *tty, struct file *filp)
42539
42540 #ifdef ISDN_DEBUG_MODEM_OPEN
42541 printk(KERN_DEBUG "isdn_tty_open %s, count = %d\n", tty->name,
42542- port->count);
42543+ atomic_read(&port->count));
42544 #endif
42545- port->count++;
42546+ atomic_inc(&port->count);
42547 port->tty = tty;
42548 /*
42549 * Start up serial port
42550@@ -1554,7 +1554,7 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
42551 #endif
42552 return;
42553 }
42554- if ((tty->count == 1) && (port->count != 1)) {
42555+ if ((tty->count == 1) && (atomic_read(&port->count) != 1)) {
42556 /*
42557 * Uh, oh. tty->count is 1, which means that the tty
42558 * structure will be freed. Info->count should always
42559@@ -1563,15 +1563,15 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
42560 * serial port won't be shutdown.
42561 */
42562 printk(KERN_ERR "isdn_tty_close: bad port count; tty->count is 1, "
42563- "info->count is %d\n", port->count);
42564- port->count = 1;
42565+ "info->count is %d\n", atomic_read(&port->count));
42566+ atomic_set(&port->count, 1);
42567 }
42568- if (--port->count < 0) {
42569+ if (atomic_dec_return(&port->count) < 0) {
42570 printk(KERN_ERR "isdn_tty_close: bad port count for ttyi%d: %d\n",
42571- info->line, port->count);
42572- port->count = 0;
42573+ info->line, atomic_read(&port->count));
42574+ atomic_set(&port->count, 0);
42575 }
42576- if (port->count) {
42577+ if (atomic_read(&port->count)) {
42578 #ifdef ISDN_DEBUG_MODEM_OPEN
42579 printk(KERN_DEBUG "isdn_tty_close after info->count != 0\n");
42580 #endif
42581@@ -1625,7 +1625,7 @@ isdn_tty_hangup(struct tty_struct *tty)
42582 if (isdn_tty_paranoia_check(info, tty->name, "isdn_tty_hangup"))
42583 return;
42584 isdn_tty_shutdown(info);
42585- port->count = 0;
42586+ atomic_set(&port->count, 0);
42587 port->flags &= ~ASYNC_NORMAL_ACTIVE;
42588 port->tty = NULL;
42589 wake_up_interruptible(&port->open_wait);
42590@@ -1970,7 +1970,7 @@ isdn_tty_find_icall(int di, int ch, setup_parm *setup)
42591 for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
42592 modem_info *info = &dev->mdm.info[i];
42593
42594- if (info->port.count == 0)
42595+ if (atomic_read(&info->port.count) == 0)
42596 continue;
42597 if ((info->emu.mdmreg[REG_SI1] & si2bit[si1]) && /* SI1 is matching */
42598 (info->emu.mdmreg[REG_SI2] == si2)) { /* SI2 is matching */
42599diff --git a/drivers/isdn/i4l/isdn_x25iface.c b/drivers/isdn/i4l/isdn_x25iface.c
42600index e2d4e58..40cd045 100644
42601--- a/drivers/isdn/i4l/isdn_x25iface.c
42602+++ b/drivers/isdn/i4l/isdn_x25iface.c
42603@@ -53,14 +53,14 @@ static int isdn_x25iface_disconn_ind(struct concap_proto *);
42604
42605
42606 static struct concap_proto_ops ix25_pops = {
42607- &isdn_x25iface_proto_new,
42608- &isdn_x25iface_proto_del,
42609- &isdn_x25iface_proto_restart,
42610- &isdn_x25iface_proto_close,
42611- &isdn_x25iface_xmit,
42612- &isdn_x25iface_receive,
42613- &isdn_x25iface_connect_ind,
42614- &isdn_x25iface_disconn_ind
42615+ .proto_new = &isdn_x25iface_proto_new,
42616+ .proto_del = &isdn_x25iface_proto_del,
42617+ .restart = &isdn_x25iface_proto_restart,
42618+ .close = &isdn_x25iface_proto_close,
42619+ .encap_and_xmit = &isdn_x25iface_xmit,
42620+ .data_ind = &isdn_x25iface_receive,
42621+ .connect_ind = &isdn_x25iface_connect_ind,
42622+ .disconn_ind = &isdn_x25iface_disconn_ind
42623 };
42624
42625 /* error message helper function */
42626diff --git a/drivers/isdn/icn/icn.c b/drivers/isdn/icn/icn.c
42627index e74df7c..03a03ba 100644
42628--- a/drivers/isdn/icn/icn.c
42629+++ b/drivers/isdn/icn/icn.c
42630@@ -1045,7 +1045,7 @@ icn_writecmd(const u_char *buf, int len, int user, icn_card *card)
42631 if (count > len)
42632 count = len;
42633 if (user) {
42634- if (copy_from_user(msg, buf, count))
42635+ if (count > sizeof msg || copy_from_user(msg, buf, count))
42636 return -EFAULT;
42637 } else
42638 memcpy(msg, buf, count);
42639diff --git a/drivers/isdn/mISDN/dsp_cmx.c b/drivers/isdn/mISDN/dsp_cmx.c
42640index a4f05c5..1433bc5 100644
42641--- a/drivers/isdn/mISDN/dsp_cmx.c
42642+++ b/drivers/isdn/mISDN/dsp_cmx.c
42643@@ -1628,7 +1628,7 @@ unsigned long dsp_spl_jiffies; /* calculate the next time to fire */
42644 static u16 dsp_count; /* last sample count */
42645 static int dsp_count_valid; /* if we have last sample count */
42646
42647-void
42648+void __intentional_overflow(-1)
42649 dsp_cmx_send(void *arg)
42650 {
42651 struct dsp_conf *conf;
42652diff --git a/drivers/leds/leds-clevo-mail.c b/drivers/leds/leds-clevo-mail.c
42653index d93e245..e7ece6b 100644
42654--- a/drivers/leds/leds-clevo-mail.c
42655+++ b/drivers/leds/leds-clevo-mail.c
42656@@ -40,7 +40,7 @@ static int __init clevo_mail_led_dmi_callback(const struct dmi_system_id *id)
42657 * detected as working, but in reality it is not) as low as
42658 * possible.
42659 */
42660-static struct dmi_system_id clevo_mail_led_dmi_table[] __initdata = {
42661+static struct dmi_system_id clevo_mail_led_dmi_table[] __initconst = {
42662 {
42663 .callback = clevo_mail_led_dmi_callback,
42664 .ident = "Clevo D410J",
42665diff --git a/drivers/leds/leds-ss4200.c b/drivers/leds/leds-ss4200.c
42666index 5b8f938..b73d657 100644
42667--- a/drivers/leds/leds-ss4200.c
42668+++ b/drivers/leds/leds-ss4200.c
42669@@ -91,7 +91,7 @@ MODULE_PARM_DESC(nodetect, "Skip DMI-based hardware detection");
42670 * detected as working, but in reality it is not) as low as
42671 * possible.
42672 */
42673-static struct dmi_system_id nas_led_whitelist[] __initdata = {
42674+static struct dmi_system_id nas_led_whitelist[] __initconst = {
42675 {
42676 .callback = ss4200_led_dmi_callback,
42677 .ident = "Intel SS4200-E",
42678diff --git a/drivers/lguest/core.c b/drivers/lguest/core.c
42679index 0bf1e4e..b4bf44e 100644
42680--- a/drivers/lguest/core.c
42681+++ b/drivers/lguest/core.c
42682@@ -97,9 +97,17 @@ static __init int map_switcher(void)
42683 * The end address needs +1 because __get_vm_area allocates an
42684 * extra guard page, so we need space for that.
42685 */
42686+
42687+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
42688+ switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
42689+ VM_ALLOC | VM_KERNEXEC, switcher_addr, switcher_addr
42690+ + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
42691+#else
42692 switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
42693 VM_ALLOC, switcher_addr, switcher_addr
42694 + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
42695+#endif
42696+
42697 if (!switcher_vma) {
42698 err = -ENOMEM;
42699 printk("lguest: could not map switcher pages high\n");
42700@@ -124,7 +132,7 @@ static __init int map_switcher(void)
42701 * Now the Switcher is mapped at the right address, we can't fail!
42702 * Copy in the compiled-in Switcher code (from x86/switcher_32.S).
42703 */
42704- memcpy(switcher_vma->addr, start_switcher_text,
42705+ memcpy(switcher_vma->addr, ktla_ktva(start_switcher_text),
42706 end_switcher_text - start_switcher_text);
42707
42708 printk(KERN_INFO "lguest: mapped switcher at %p\n",
42709diff --git a/drivers/lguest/page_tables.c b/drivers/lguest/page_tables.c
42710index bfb39bb..08a603b 100644
42711--- a/drivers/lguest/page_tables.c
42712+++ b/drivers/lguest/page_tables.c
42713@@ -559,7 +559,7 @@ void pin_page(struct lg_cpu *cpu, unsigned long vaddr)
42714 /*:*/
42715
42716 #ifdef CONFIG_X86_PAE
42717-static void release_pmd(pmd_t *spmd)
42718+static void __intentional_overflow(-1) release_pmd(pmd_t *spmd)
42719 {
42720 /* If the entry's not present, there's nothing to release. */
42721 if (pmd_flags(*spmd) & _PAGE_PRESENT) {
42722diff --git a/drivers/lguest/x86/core.c b/drivers/lguest/x86/core.c
42723index 5169239..47cb4db 100644
42724--- a/drivers/lguest/x86/core.c
42725+++ b/drivers/lguest/x86/core.c
42726@@ -59,7 +59,7 @@ static struct {
42727 /* Offset from where switcher.S was compiled to where we've copied it */
42728 static unsigned long switcher_offset(void)
42729 {
42730- return switcher_addr - (unsigned long)start_switcher_text;
42731+ return switcher_addr - (unsigned long)ktla_ktva(start_switcher_text);
42732 }
42733
42734 /* This cpu's struct lguest_pages (after the Switcher text page) */
42735@@ -99,7 +99,13 @@ static void copy_in_guest_info(struct lg_cpu *cpu, struct lguest_pages *pages)
42736 * These copies are pretty cheap, so we do them unconditionally: */
42737 /* Save the current Host top-level page directory.
42738 */
42739+
42740+#ifdef CONFIG_PAX_PER_CPU_PGD
42741+ pages->state.host_cr3 = read_cr3();
42742+#else
42743 pages->state.host_cr3 = __pa(current->mm->pgd);
42744+#endif
42745+
42746 /*
42747 * Set up the Guest's page tables to see this CPU's pages (and no
42748 * other CPU's pages).
42749@@ -475,7 +481,7 @@ void __init lguest_arch_host_init(void)
42750 * compiled-in switcher code and the high-mapped copy we just made.
42751 */
42752 for (i = 0; i < IDT_ENTRIES; i++)
42753- default_idt_entries[i] += switcher_offset();
42754+ default_idt_entries[i] = ktla_ktva(default_idt_entries[i]) + switcher_offset();
42755
42756 /*
42757 * Set up the Switcher's per-cpu areas.
42758@@ -558,7 +564,7 @@ void __init lguest_arch_host_init(void)
42759 * it will be undisturbed when we switch. To change %cs and jump we
42760 * need this structure to feed to Intel's "lcall" instruction.
42761 */
42762- lguest_entry.offset = (long)switch_to_guest + switcher_offset();
42763+ lguest_entry.offset = (long)ktla_ktva(switch_to_guest) + switcher_offset();
42764 lguest_entry.segment = LGUEST_CS;
42765
42766 /*
42767diff --git a/drivers/lguest/x86/switcher_32.S b/drivers/lguest/x86/switcher_32.S
42768index 40634b0..4f5855e 100644
42769--- a/drivers/lguest/x86/switcher_32.S
42770+++ b/drivers/lguest/x86/switcher_32.S
42771@@ -87,6 +87,7 @@
42772 #include <asm/page.h>
42773 #include <asm/segment.h>
42774 #include <asm/lguest.h>
42775+#include <asm/processor-flags.h>
42776
42777 // We mark the start of the code to copy
42778 // It's placed in .text tho it's never run here
42779@@ -149,6 +150,13 @@ ENTRY(switch_to_guest)
42780 // Changes type when we load it: damn Intel!
42781 // For after we switch over our page tables
42782 // That entry will be read-only: we'd crash.
42783+
42784+#ifdef CONFIG_PAX_KERNEXEC
42785+ mov %cr0, %edx
42786+ xor $X86_CR0_WP, %edx
42787+ mov %edx, %cr0
42788+#endif
42789+
42790 movl $(GDT_ENTRY_TSS*8), %edx
42791 ltr %dx
42792
42793@@ -157,9 +165,15 @@ ENTRY(switch_to_guest)
42794 // Let's clear it again for our return.
42795 // The GDT descriptor of the Host
42796 // Points to the table after two "size" bytes
42797- movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %edx
42798+ movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %eax
42799 // Clear "used" from type field (byte 5, bit 2)
42800- andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%edx)
42801+ andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%eax)
42802+
42803+#ifdef CONFIG_PAX_KERNEXEC
42804+ mov %cr0, %eax
42805+ xor $X86_CR0_WP, %eax
42806+ mov %eax, %cr0
42807+#endif
42808
42809 // Once our page table's switched, the Guest is live!
42810 // The Host fades as we run this final step.
42811@@ -295,13 +309,12 @@ deliver_to_host:
42812 // I consulted gcc, and it gave
42813 // These instructions, which I gladly credit:
42814 leal (%edx,%ebx,8), %eax
42815- movzwl (%eax),%edx
42816- movl 4(%eax), %eax
42817- xorw %ax, %ax
42818- orl %eax, %edx
42819+ movl 4(%eax), %edx
42820+ movw (%eax), %dx
42821 // Now the address of the handler's in %edx
42822 // We call it now: its "iret" drops us home.
42823- jmp *%edx
42824+ ljmp $__KERNEL_CS, $1f
42825+1: jmp *%edx
42826
42827 // Every interrupt can come to us here
42828 // But we must truly tell each apart.
42829diff --git a/drivers/md/bcache/closure.h b/drivers/md/bcache/closure.h
42830index 0003992..854bbce 100644
42831--- a/drivers/md/bcache/closure.h
42832+++ b/drivers/md/bcache/closure.h
42833@@ -622,7 +622,7 @@ static inline void closure_wake_up(struct closure_waitlist *list)
42834 static inline void set_closure_fn(struct closure *cl, closure_fn *fn,
42835 struct workqueue_struct *wq)
42836 {
42837- BUG_ON(object_is_on_stack(cl));
42838+ BUG_ON(object_starts_on_stack(cl));
42839 closure_set_ip(cl);
42840 cl->fn = fn;
42841 cl->wq = wq;
42842diff --git a/drivers/md/bcache/super.c b/drivers/md/bcache/super.c
42843index 547c4c5..5be1de4 100644
42844--- a/drivers/md/bcache/super.c
42845+++ b/drivers/md/bcache/super.c
42846@@ -1644,7 +1644,7 @@ err_unlock_gc:
42847 err:
42848 closure_sync(&op.cl);
42849 /* XXX: test this, it's broken */
42850- bch_cache_set_error(c, err);
42851+ bch_cache_set_error(c, "%s", err);
42852 }
42853
42854 static bool can_attach_cache(struct cache *ca, struct cache_set *c)
42855diff --git a/drivers/md/bitmap.c b/drivers/md/bitmap.c
42856index a7fd821..9dcf6c3 100644
42857--- a/drivers/md/bitmap.c
42858+++ b/drivers/md/bitmap.c
42859@@ -1779,7 +1779,7 @@ void bitmap_status(struct seq_file *seq, struct bitmap *bitmap)
42860 chunk_kb ? "KB" : "B");
42861 if (bitmap->storage.file) {
42862 seq_printf(seq, ", file: ");
42863- seq_path(seq, &bitmap->storage.file->f_path, " \t\n");
42864+ seq_path(seq, &bitmap->storage.file->f_path, " \t\n\\");
42865 }
42866
42867 seq_printf(seq, "\n");
42868diff --git a/drivers/md/dm-ioctl.c b/drivers/md/dm-ioctl.c
42869index afe0814..8cf3794 100644
42870--- a/drivers/md/dm-ioctl.c
42871+++ b/drivers/md/dm-ioctl.c
42872@@ -1745,7 +1745,7 @@ static int validate_params(uint cmd, struct dm_ioctl *param)
42873 cmd == DM_LIST_VERSIONS_CMD)
42874 return 0;
42875
42876- if ((cmd == DM_DEV_CREATE_CMD)) {
42877+ if (cmd == DM_DEV_CREATE_CMD) {
42878 if (!*param->name) {
42879 DMWARN("name not supplied when creating device");
42880 return -EINVAL;
42881diff --git a/drivers/md/dm-raid1.c b/drivers/md/dm-raid1.c
42882index 9584443..9fc9ac9 100644
42883--- a/drivers/md/dm-raid1.c
42884+++ b/drivers/md/dm-raid1.c
42885@@ -40,7 +40,7 @@ enum dm_raid1_error {
42886
42887 struct mirror {
42888 struct mirror_set *ms;
42889- atomic_t error_count;
42890+ atomic_unchecked_t error_count;
42891 unsigned long error_type;
42892 struct dm_dev *dev;
42893 sector_t offset;
42894@@ -186,7 +186,7 @@ static struct mirror *get_valid_mirror(struct mirror_set *ms)
42895 struct mirror *m;
42896
42897 for (m = ms->mirror; m < ms->mirror + ms->nr_mirrors; m++)
42898- if (!atomic_read(&m->error_count))
42899+ if (!atomic_read_unchecked(&m->error_count))
42900 return m;
42901
42902 return NULL;
42903@@ -218,7 +218,7 @@ static void fail_mirror(struct mirror *m, enum dm_raid1_error error_type)
42904 * simple way to tell if a device has encountered
42905 * errors.
42906 */
42907- atomic_inc(&m->error_count);
42908+ atomic_inc_unchecked(&m->error_count);
42909
42910 if (test_and_set_bit(error_type, &m->error_type))
42911 return;
42912@@ -409,7 +409,7 @@ static struct mirror *choose_mirror(struct mirror_set *ms, sector_t sector)
42913 struct mirror *m = get_default_mirror(ms);
42914
42915 do {
42916- if (likely(!atomic_read(&m->error_count)))
42917+ if (likely(!atomic_read_unchecked(&m->error_count)))
42918 return m;
42919
42920 if (m-- == ms->mirror)
42921@@ -423,7 +423,7 @@ static int default_ok(struct mirror *m)
42922 {
42923 struct mirror *default_mirror = get_default_mirror(m->ms);
42924
42925- return !atomic_read(&default_mirror->error_count);
42926+ return !atomic_read_unchecked(&default_mirror->error_count);
42927 }
42928
42929 static int mirror_available(struct mirror_set *ms, struct bio *bio)
42930@@ -560,7 +560,7 @@ static void do_reads(struct mirror_set *ms, struct bio_list *reads)
42931 */
42932 if (likely(region_in_sync(ms, region, 1)))
42933 m = choose_mirror(ms, bio->bi_sector);
42934- else if (m && atomic_read(&m->error_count))
42935+ else if (m && atomic_read_unchecked(&m->error_count))
42936 m = NULL;
42937
42938 if (likely(m))
42939@@ -927,7 +927,7 @@ static int get_mirror(struct mirror_set *ms, struct dm_target *ti,
42940 }
42941
42942 ms->mirror[mirror].ms = ms;
42943- atomic_set(&(ms->mirror[mirror].error_count), 0);
42944+ atomic_set_unchecked(&(ms->mirror[mirror].error_count), 0);
42945 ms->mirror[mirror].error_type = 0;
42946 ms->mirror[mirror].offset = offset;
42947
42948@@ -1339,7 +1339,7 @@ static void mirror_resume(struct dm_target *ti)
42949 */
42950 static char device_status_char(struct mirror *m)
42951 {
42952- if (!atomic_read(&(m->error_count)))
42953+ if (!atomic_read_unchecked(&(m->error_count)))
42954 return 'A';
42955
42956 return (test_bit(DM_RAID1_FLUSH_ERROR, &(m->error_type))) ? 'F' :
42957diff --git a/drivers/md/dm-stats.c b/drivers/md/dm-stats.c
42958index 28a9012..9c0f6a5 100644
42959--- a/drivers/md/dm-stats.c
42960+++ b/drivers/md/dm-stats.c
42961@@ -382,7 +382,7 @@ do_sync_free:
42962 synchronize_rcu_expedited();
42963 dm_stat_free(&s->rcu_head);
42964 } else {
42965- ACCESS_ONCE(dm_stat_need_rcu_barrier) = 1;
42966+ ACCESS_ONCE_RW(dm_stat_need_rcu_barrier) = 1;
42967 call_rcu(&s->rcu_head, dm_stat_free);
42968 }
42969 return 0;
42970@@ -554,8 +554,8 @@ void dm_stats_account_io(struct dm_stats *stats, unsigned long bi_rw,
42971 ((bi_rw & (REQ_WRITE | REQ_DISCARD)) ==
42972 (ACCESS_ONCE(last->last_rw) & (REQ_WRITE | REQ_DISCARD)))
42973 ));
42974- ACCESS_ONCE(last->last_sector) = end_sector;
42975- ACCESS_ONCE(last->last_rw) = bi_rw;
42976+ ACCESS_ONCE_RW(last->last_sector) = end_sector;
42977+ ACCESS_ONCE_RW(last->last_rw) = bi_rw;
42978 }
42979
42980 rcu_read_lock();
42981diff --git a/drivers/md/dm-stripe.c b/drivers/md/dm-stripe.c
42982index 73c1712..7347292 100644
42983--- a/drivers/md/dm-stripe.c
42984+++ b/drivers/md/dm-stripe.c
42985@@ -21,7 +21,7 @@ struct stripe {
42986 struct dm_dev *dev;
42987 sector_t physical_start;
42988
42989- atomic_t error_count;
42990+ atomic_unchecked_t error_count;
42991 };
42992
42993 struct stripe_c {
42994@@ -186,7 +186,7 @@ static int stripe_ctr(struct dm_target *ti, unsigned int argc, char **argv)
42995 kfree(sc);
42996 return r;
42997 }
42998- atomic_set(&(sc->stripe[i].error_count), 0);
42999+ atomic_set_unchecked(&(sc->stripe[i].error_count), 0);
43000 }
43001
43002 ti->private = sc;
43003@@ -327,7 +327,7 @@ static void stripe_status(struct dm_target *ti, status_type_t type,
43004 DMEMIT("%d ", sc->stripes);
43005 for (i = 0; i < sc->stripes; i++) {
43006 DMEMIT("%s ", sc->stripe[i].dev->name);
43007- buffer[i] = atomic_read(&(sc->stripe[i].error_count)) ?
43008+ buffer[i] = atomic_read_unchecked(&(sc->stripe[i].error_count)) ?
43009 'D' : 'A';
43010 }
43011 buffer[i] = '\0';
43012@@ -372,8 +372,8 @@ static int stripe_end_io(struct dm_target *ti, struct bio *bio, int error)
43013 */
43014 for (i = 0; i < sc->stripes; i++)
43015 if (!strcmp(sc->stripe[i].dev->name, major_minor)) {
43016- atomic_inc(&(sc->stripe[i].error_count));
43017- if (atomic_read(&(sc->stripe[i].error_count)) <
43018+ atomic_inc_unchecked(&(sc->stripe[i].error_count));
43019+ if (atomic_read_unchecked(&(sc->stripe[i].error_count)) <
43020 DM_IO_ERROR_THRESHOLD)
43021 schedule_work(&sc->trigger_event);
43022 }
43023diff --git a/drivers/md/dm-table.c b/drivers/md/dm-table.c
43024index 20a8cc0..5447b11 100644
43025--- a/drivers/md/dm-table.c
43026+++ b/drivers/md/dm-table.c
43027@@ -291,7 +291,7 @@ static struct dm_dev_internal *find_device(struct list_head *l, dev_t dev)
43028 static int open_dev(struct dm_dev_internal *d, dev_t dev,
43029 struct mapped_device *md)
43030 {
43031- static char *_claim_ptr = "I belong to device-mapper";
43032+ static char _claim_ptr[] = "I belong to device-mapper";
43033 struct block_device *bdev;
43034
43035 int r;
43036@@ -359,7 +359,7 @@ static int device_area_is_invalid(struct dm_target *ti, struct dm_dev *dev,
43037 if (!dev_size)
43038 return 0;
43039
43040- if ((start >= dev_size) || (start + len > dev_size)) {
43041+ if ((start >= dev_size) || (len > dev_size - start)) {
43042 DMWARN("%s: %s too small for target: "
43043 "start=%llu, len=%llu, dev_size=%llu",
43044 dm_device_name(ti->table->md), bdevname(bdev, b),
43045diff --git a/drivers/md/dm-thin-metadata.c b/drivers/md/dm-thin-metadata.c
43046index 8a30ad5..72792d3 100644
43047--- a/drivers/md/dm-thin-metadata.c
43048+++ b/drivers/md/dm-thin-metadata.c
43049@@ -397,7 +397,7 @@ static void __setup_btree_details(struct dm_pool_metadata *pmd)
43050 {
43051 pmd->info.tm = pmd->tm;
43052 pmd->info.levels = 2;
43053- pmd->info.value_type.context = pmd->data_sm;
43054+ pmd->info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
43055 pmd->info.value_type.size = sizeof(__le64);
43056 pmd->info.value_type.inc = data_block_inc;
43057 pmd->info.value_type.dec = data_block_dec;
43058@@ -416,7 +416,7 @@ static void __setup_btree_details(struct dm_pool_metadata *pmd)
43059
43060 pmd->bl_info.tm = pmd->tm;
43061 pmd->bl_info.levels = 1;
43062- pmd->bl_info.value_type.context = pmd->data_sm;
43063+ pmd->bl_info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
43064 pmd->bl_info.value_type.size = sizeof(__le64);
43065 pmd->bl_info.value_type.inc = data_block_inc;
43066 pmd->bl_info.value_type.dec = data_block_dec;
43067diff --git a/drivers/md/dm.c b/drivers/md/dm.c
43068index b3e26c7..1efca94 100644
43069--- a/drivers/md/dm.c
43070+++ b/drivers/md/dm.c
43071@@ -179,9 +179,9 @@ struct mapped_device {
43072 /*
43073 * Event handling.
43074 */
43075- atomic_t event_nr;
43076+ atomic_unchecked_t event_nr;
43077 wait_queue_head_t eventq;
43078- atomic_t uevent_seq;
43079+ atomic_unchecked_t uevent_seq;
43080 struct list_head uevent_list;
43081 spinlock_t uevent_lock; /* Protect access to uevent_list */
43082
43083@@ -1985,8 +1985,8 @@ static struct mapped_device *alloc_dev(int minor)
43084 spin_lock_init(&md->deferred_lock);
43085 atomic_set(&md->holders, 1);
43086 atomic_set(&md->open_count, 0);
43087- atomic_set(&md->event_nr, 0);
43088- atomic_set(&md->uevent_seq, 0);
43089+ atomic_set_unchecked(&md->event_nr, 0);
43090+ atomic_set_unchecked(&md->uevent_seq, 0);
43091 INIT_LIST_HEAD(&md->uevent_list);
43092 spin_lock_init(&md->uevent_lock);
43093
43094@@ -2139,7 +2139,7 @@ static void event_callback(void *context)
43095
43096 dm_send_uevents(&uevents, &disk_to_dev(md->disk)->kobj);
43097
43098- atomic_inc(&md->event_nr);
43099+ atomic_inc_unchecked(&md->event_nr);
43100 wake_up(&md->eventq);
43101 }
43102
43103@@ -2832,18 +2832,18 @@ int dm_kobject_uevent(struct mapped_device *md, enum kobject_action action,
43104
43105 uint32_t dm_next_uevent_seq(struct mapped_device *md)
43106 {
43107- return atomic_add_return(1, &md->uevent_seq);
43108+ return atomic_add_return_unchecked(1, &md->uevent_seq);
43109 }
43110
43111 uint32_t dm_get_event_nr(struct mapped_device *md)
43112 {
43113- return atomic_read(&md->event_nr);
43114+ return atomic_read_unchecked(&md->event_nr);
43115 }
43116
43117 int dm_wait_event(struct mapped_device *md, int event_nr)
43118 {
43119 return wait_event_interruptible(md->eventq,
43120- (event_nr != atomic_read(&md->event_nr)));
43121+ (event_nr != atomic_read_unchecked(&md->event_nr)));
43122 }
43123
43124 void dm_uevent_add(struct mapped_device *md, struct list_head *elist)
43125diff --git a/drivers/md/md.c b/drivers/md/md.c
43126index ba46d97..f8f5019 100644
43127--- a/drivers/md/md.c
43128+++ b/drivers/md/md.c
43129@@ -234,10 +234,10 @@ EXPORT_SYMBOL_GPL(md_trim_bio);
43130 * start build, activate spare
43131 */
43132 static DECLARE_WAIT_QUEUE_HEAD(md_event_waiters);
43133-static atomic_t md_event_count;
43134+static atomic_unchecked_t md_event_count;
43135 void md_new_event(struct mddev *mddev)
43136 {
43137- atomic_inc(&md_event_count);
43138+ atomic_inc_unchecked(&md_event_count);
43139 wake_up(&md_event_waiters);
43140 }
43141 EXPORT_SYMBOL_GPL(md_new_event);
43142@@ -247,7 +247,7 @@ EXPORT_SYMBOL_GPL(md_new_event);
43143 */
43144 static void md_new_event_inintr(struct mddev *mddev)
43145 {
43146- atomic_inc(&md_event_count);
43147+ atomic_inc_unchecked(&md_event_count);
43148 wake_up(&md_event_waiters);
43149 }
43150
43151@@ -1502,7 +1502,7 @@ static int super_1_load(struct md_rdev *rdev, struct md_rdev *refdev, int minor_
43152 if ((le32_to_cpu(sb->feature_map) & MD_FEATURE_RESHAPE_ACTIVE) &&
43153 (le32_to_cpu(sb->feature_map) & MD_FEATURE_NEW_OFFSET))
43154 rdev->new_data_offset += (s32)le32_to_cpu(sb->new_offset);
43155- atomic_set(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
43156+ atomic_set_unchecked(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
43157
43158 rdev->sb_size = le32_to_cpu(sb->max_dev) * 2 + 256;
43159 bmask = queue_logical_block_size(rdev->bdev->bd_disk->queue)-1;
43160@@ -1746,7 +1746,7 @@ static void super_1_sync(struct mddev *mddev, struct md_rdev *rdev)
43161 else
43162 sb->resync_offset = cpu_to_le64(0);
43163
43164- sb->cnt_corrected_read = cpu_to_le32(atomic_read(&rdev->corrected_errors));
43165+ sb->cnt_corrected_read = cpu_to_le32(atomic_read_unchecked(&rdev->corrected_errors));
43166
43167 sb->raid_disks = cpu_to_le32(mddev->raid_disks);
43168 sb->size = cpu_to_le64(mddev->dev_sectors);
43169@@ -2751,7 +2751,7 @@ __ATTR(state, S_IRUGO|S_IWUSR, state_show, state_store);
43170 static ssize_t
43171 errors_show(struct md_rdev *rdev, char *page)
43172 {
43173- return sprintf(page, "%d\n", atomic_read(&rdev->corrected_errors));
43174+ return sprintf(page, "%d\n", atomic_read_unchecked(&rdev->corrected_errors));
43175 }
43176
43177 static ssize_t
43178@@ -2760,7 +2760,7 @@ errors_store(struct md_rdev *rdev, const char *buf, size_t len)
43179 char *e;
43180 unsigned long n = simple_strtoul(buf, &e, 10);
43181 if (*buf && (*e == 0 || *e == '\n')) {
43182- atomic_set(&rdev->corrected_errors, n);
43183+ atomic_set_unchecked(&rdev->corrected_errors, n);
43184 return len;
43185 }
43186 return -EINVAL;
43187@@ -3208,8 +3208,8 @@ int md_rdev_init(struct md_rdev *rdev)
43188 rdev->sb_loaded = 0;
43189 rdev->bb_page = NULL;
43190 atomic_set(&rdev->nr_pending, 0);
43191- atomic_set(&rdev->read_errors, 0);
43192- atomic_set(&rdev->corrected_errors, 0);
43193+ atomic_set_unchecked(&rdev->read_errors, 0);
43194+ atomic_set_unchecked(&rdev->corrected_errors, 0);
43195
43196 INIT_LIST_HEAD(&rdev->same_set);
43197 init_waitqueue_head(&rdev->blocked_wait);
43198@@ -7043,7 +7043,7 @@ static int md_seq_show(struct seq_file *seq, void *v)
43199
43200 spin_unlock(&pers_lock);
43201 seq_printf(seq, "\n");
43202- seq->poll_event = atomic_read(&md_event_count);
43203+ seq->poll_event = atomic_read_unchecked(&md_event_count);
43204 return 0;
43205 }
43206 if (v == (void*)2) {
43207@@ -7146,7 +7146,7 @@ static int md_seq_open(struct inode *inode, struct file *file)
43208 return error;
43209
43210 seq = file->private_data;
43211- seq->poll_event = atomic_read(&md_event_count);
43212+ seq->poll_event = atomic_read_unchecked(&md_event_count);
43213 return error;
43214 }
43215
43216@@ -7160,7 +7160,7 @@ static unsigned int mdstat_poll(struct file *filp, poll_table *wait)
43217 /* always allow read */
43218 mask = POLLIN | POLLRDNORM;
43219
43220- if (seq->poll_event != atomic_read(&md_event_count))
43221+ if (seq->poll_event != atomic_read_unchecked(&md_event_count))
43222 mask |= POLLERR | POLLPRI;
43223 return mask;
43224 }
43225@@ -7204,7 +7204,7 @@ static int is_mddev_idle(struct mddev *mddev, int init)
43226 struct gendisk *disk = rdev->bdev->bd_contains->bd_disk;
43227 curr_events = (int)part_stat_read(&disk->part0, sectors[0]) +
43228 (int)part_stat_read(&disk->part0, sectors[1]) -
43229- atomic_read(&disk->sync_io);
43230+ atomic_read_unchecked(&disk->sync_io);
43231 /* sync IO will cause sync_io to increase before the disk_stats
43232 * as sync_io is counted when a request starts, and
43233 * disk_stats is counted when it completes.
43234diff --git a/drivers/md/md.h b/drivers/md/md.h
43235index 608050c..6e77db5d 100644
43236--- a/drivers/md/md.h
43237+++ b/drivers/md/md.h
43238@@ -94,13 +94,13 @@ struct md_rdev {
43239 * only maintained for arrays that
43240 * support hot removal
43241 */
43242- atomic_t read_errors; /* number of consecutive read errors that
43243+ atomic_unchecked_t read_errors; /* number of consecutive read errors that
43244 * we have tried to ignore.
43245 */
43246 struct timespec last_read_error; /* monotonic time since our
43247 * last read error
43248 */
43249- atomic_t corrected_errors; /* number of corrected read errors,
43250+ atomic_unchecked_t corrected_errors; /* number of corrected read errors,
43251 * for reporting to userspace and storing
43252 * in superblock.
43253 */
43254@@ -446,7 +446,7 @@ static inline void rdev_dec_pending(struct md_rdev *rdev, struct mddev *mddev)
43255
43256 static inline void md_sync_acct(struct block_device *bdev, unsigned long nr_sectors)
43257 {
43258- atomic_add(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
43259+ atomic_add_unchecked(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
43260 }
43261
43262 struct md_personality
43263diff --git a/drivers/md/persistent-data/dm-space-map.h b/drivers/md/persistent-data/dm-space-map.h
43264index 3e6d115..ffecdeb 100644
43265--- a/drivers/md/persistent-data/dm-space-map.h
43266+++ b/drivers/md/persistent-data/dm-space-map.h
43267@@ -71,6 +71,7 @@ struct dm_space_map {
43268 dm_sm_threshold_fn fn,
43269 void *context);
43270 };
43271+typedef struct dm_space_map __no_const dm_space_map_no_const;
43272
43273 /*----------------------------------------------------------------*/
43274
43275diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
43276index aacf6bf..67d63f2 100644
43277--- a/drivers/md/raid1.c
43278+++ b/drivers/md/raid1.c
43279@@ -1824,7 +1824,7 @@ static int fix_sync_read_error(struct r1bio *r1_bio)
43280 if (r1_sync_page_io(rdev, sect, s,
43281 bio->bi_io_vec[idx].bv_page,
43282 READ) != 0)
43283- atomic_add(s, &rdev->corrected_errors);
43284+ atomic_add_unchecked(s, &rdev->corrected_errors);
43285 }
43286 sectors -= s;
43287 sect += s;
43288@@ -2051,7 +2051,7 @@ static void fix_read_error(struct r1conf *conf, int read_disk,
43289 test_bit(In_sync, &rdev->flags)) {
43290 if (r1_sync_page_io(rdev, sect, s,
43291 conf->tmppage, READ)) {
43292- atomic_add(s, &rdev->corrected_errors);
43293+ atomic_add_unchecked(s, &rdev->corrected_errors);
43294 printk(KERN_INFO
43295 "md/raid1:%s: read error corrected "
43296 "(%d sectors at %llu on %s)\n",
43297diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
43298index 73dc8a3..859d581f6 100644
43299--- a/drivers/md/raid10.c
43300+++ b/drivers/md/raid10.c
43301@@ -1319,7 +1319,7 @@ read_again:
43302 /* Could not read all from this device, so we will
43303 * need another r10_bio.
43304 */
43305- sectors_handled = (r10_bio->sectors + max_sectors
43306+ sectors_handled = (r10_bio->sector + max_sectors
43307 - bio->bi_sector);
43308 r10_bio->sectors = max_sectors;
43309 spin_lock_irq(&conf->device_lock);
43310@@ -1327,7 +1327,7 @@ read_again:
43311 bio->bi_phys_segments = 2;
43312 else
43313 bio->bi_phys_segments++;
43314- spin_unlock(&conf->device_lock);
43315+ spin_unlock_irq(&conf->device_lock);
43316 /* Cannot call generic_make_request directly
43317 * as that will be queued in __generic_make_request
43318 * and subsequent mempool_alloc might block
43319@@ -1963,7 +1963,7 @@ static void end_sync_read(struct bio *bio, int error)
43320 /* The write handler will notice the lack of
43321 * R10BIO_Uptodate and record any errors etc
43322 */
43323- atomic_add(r10_bio->sectors,
43324+ atomic_add_unchecked(r10_bio->sectors,
43325 &conf->mirrors[d].rdev->corrected_errors);
43326
43327 /* for reconstruct, we always reschedule after a read.
43328@@ -2321,7 +2321,7 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
43329 {
43330 struct timespec cur_time_mon;
43331 unsigned long hours_since_last;
43332- unsigned int read_errors = atomic_read(&rdev->read_errors);
43333+ unsigned int read_errors = atomic_read_unchecked(&rdev->read_errors);
43334
43335 ktime_get_ts(&cur_time_mon);
43336
43337@@ -2343,9 +2343,9 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
43338 * overflowing the shift of read_errors by hours_since_last.
43339 */
43340 if (hours_since_last >= 8 * sizeof(read_errors))
43341- atomic_set(&rdev->read_errors, 0);
43342+ atomic_set_unchecked(&rdev->read_errors, 0);
43343 else
43344- atomic_set(&rdev->read_errors, read_errors >> hours_since_last);
43345+ atomic_set_unchecked(&rdev->read_errors, read_errors >> hours_since_last);
43346 }
43347
43348 static int r10_sync_page_io(struct md_rdev *rdev, sector_t sector,
43349@@ -2399,8 +2399,8 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
43350 return;
43351
43352 check_decay_read_errors(mddev, rdev);
43353- atomic_inc(&rdev->read_errors);
43354- if (atomic_read(&rdev->read_errors) > max_read_errors) {
43355+ atomic_inc_unchecked(&rdev->read_errors);
43356+ if (atomic_read_unchecked(&rdev->read_errors) > max_read_errors) {
43357 char b[BDEVNAME_SIZE];
43358 bdevname(rdev->bdev, b);
43359
43360@@ -2408,7 +2408,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
43361 "md/raid10:%s: %s: Raid device exceeded "
43362 "read_error threshold [cur %d:max %d]\n",
43363 mdname(mddev), b,
43364- atomic_read(&rdev->read_errors), max_read_errors);
43365+ atomic_read_unchecked(&rdev->read_errors), max_read_errors);
43366 printk(KERN_NOTICE
43367 "md/raid10:%s: %s: Failing raid device\n",
43368 mdname(mddev), b);
43369@@ -2563,7 +2563,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
43370 sect +
43371 choose_data_offset(r10_bio, rdev)),
43372 bdevname(rdev->bdev, b));
43373- atomic_add(s, &rdev->corrected_errors);
43374+ atomic_add_unchecked(s, &rdev->corrected_errors);
43375 }
43376
43377 rdev_dec_pending(rdev, mddev);
43378@@ -3220,10 +3220,6 @@ static sector_t sync_request(struct mddev *mddev, sector_t sector_nr,
43379 if (j == conf->copies) {
43380 /* Cannot recover, so abort the recovery or
43381 * record a bad block */
43382- put_buf(r10_bio);
43383- if (rb2)
43384- atomic_dec(&rb2->remaining);
43385- r10_bio = rb2;
43386 if (any_working) {
43387 /* problem is that there are bad blocks
43388 * on other device(s)
43389@@ -3255,6 +3251,10 @@ static sector_t sync_request(struct mddev *mddev, sector_t sector_nr,
43390 mirror->recovery_disabled
43391 = mddev->recovery_disabled;
43392 }
43393+ put_buf(r10_bio);
43394+ if (rb2)
43395+ atomic_dec(&rb2->remaining);
43396+ r10_bio = rb2;
43397 break;
43398 }
43399 }
43400diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
43401index 8a0665d..b322118 100644
43402--- a/drivers/md/raid5.c
43403+++ b/drivers/md/raid5.c
43404@@ -1887,21 +1887,21 @@ static void raid5_end_read_request(struct bio * bi, int error)
43405 mdname(conf->mddev), STRIPE_SECTORS,
43406 (unsigned long long)s,
43407 bdevname(rdev->bdev, b));
43408- atomic_add(STRIPE_SECTORS, &rdev->corrected_errors);
43409+ atomic_add_unchecked(STRIPE_SECTORS, &rdev->corrected_errors);
43410 clear_bit(R5_ReadError, &sh->dev[i].flags);
43411 clear_bit(R5_ReWrite, &sh->dev[i].flags);
43412 } else if (test_bit(R5_ReadNoMerge, &sh->dev[i].flags))
43413 clear_bit(R5_ReadNoMerge, &sh->dev[i].flags);
43414
43415- if (atomic_read(&rdev->read_errors))
43416- atomic_set(&rdev->read_errors, 0);
43417+ if (atomic_read_unchecked(&rdev->read_errors))
43418+ atomic_set_unchecked(&rdev->read_errors, 0);
43419 } else {
43420 const char *bdn = bdevname(rdev->bdev, b);
43421 int retry = 0;
43422 int set_bad = 0;
43423
43424 clear_bit(R5_UPTODATE, &sh->dev[i].flags);
43425- atomic_inc(&rdev->read_errors);
43426+ atomic_inc_unchecked(&rdev->read_errors);
43427 if (test_bit(R5_ReadRepl, &sh->dev[i].flags))
43428 printk_ratelimited(
43429 KERN_WARNING
43430@@ -1929,7 +1929,7 @@ static void raid5_end_read_request(struct bio * bi, int error)
43431 mdname(conf->mddev),
43432 (unsigned long long)s,
43433 bdn);
43434- } else if (atomic_read(&rdev->read_errors)
43435+ } else if (atomic_read_unchecked(&rdev->read_errors)
43436 > conf->max_nr_stripes)
43437 printk(KERN_WARNING
43438 "md/raid:%s: Too many read errors, failing device %s.\n",
43439@@ -3502,7 +3502,7 @@ static void analyse_stripe(struct stripe_head *sh, struct stripe_head_state *s)
43440 */
43441 set_bit(R5_Insync, &dev->flags);
43442
43443- if (rdev && test_bit(R5_WriteError, &dev->flags)) {
43444+ if (test_bit(R5_WriteError, &dev->flags)) {
43445 /* This flag does not apply to '.replacement'
43446 * only to .rdev, so make sure to check that*/
43447 struct md_rdev *rdev2 = rcu_dereference(
43448@@ -3515,7 +3515,7 @@ static void analyse_stripe(struct stripe_head *sh, struct stripe_head_state *s)
43449 } else
43450 clear_bit(R5_WriteError, &dev->flags);
43451 }
43452- if (rdev && test_bit(R5_MadeGood, &dev->flags)) {
43453+ if (test_bit(R5_MadeGood, &dev->flags)) {
43454 /* This flag does not apply to '.replacement'
43455 * only to .rdev, so make sure to check that*/
43456 struct md_rdev *rdev2 = rcu_dereference(
43457diff --git a/drivers/media/dvb-core/dvbdev.c b/drivers/media/dvb-core/dvbdev.c
43458index 401ef64..836e563 100644
43459--- a/drivers/media/dvb-core/dvbdev.c
43460+++ b/drivers/media/dvb-core/dvbdev.c
43461@@ -192,7 +192,7 @@ int dvb_register_device(struct dvb_adapter *adap, struct dvb_device **pdvbdev,
43462 const struct dvb_device *template, void *priv, int type)
43463 {
43464 struct dvb_device *dvbdev;
43465- struct file_operations *dvbdevfops;
43466+ file_operations_no_const *dvbdevfops;
43467 struct device *clsdev;
43468 int minor;
43469 int id;
43470diff --git a/drivers/media/dvb-frontends/dib3000.h b/drivers/media/dvb-frontends/dib3000.h
43471index 9b6c3bb..baeb5c7 100644
43472--- a/drivers/media/dvb-frontends/dib3000.h
43473+++ b/drivers/media/dvb-frontends/dib3000.h
43474@@ -39,7 +39,7 @@ struct dib_fe_xfer_ops
43475 int (*fifo_ctrl)(struct dvb_frontend *fe, int onoff);
43476 int (*pid_ctrl)(struct dvb_frontend *fe, int index, int pid, int onoff);
43477 int (*tuner_pass_ctrl)(struct dvb_frontend *fe, int onoff, u8 pll_ctrl);
43478-};
43479+} __no_const;
43480
43481 #if IS_ENABLED(CONFIG_DVB_DIB3000MB)
43482 extern struct dvb_frontend* dib3000mb_attach(const struct dib3000_config* config,
43483diff --git a/drivers/media/pci/cx88/cx88-video.c b/drivers/media/pci/cx88/cx88-video.c
43484index ecf21d9..b992428d 100644
43485--- a/drivers/media/pci/cx88/cx88-video.c
43486+++ b/drivers/media/pci/cx88/cx88-video.c
43487@@ -50,9 +50,9 @@ MODULE_VERSION(CX88_VERSION);
43488
43489 /* ------------------------------------------------------------------ */
43490
43491-static unsigned int video_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
43492-static unsigned int vbi_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
43493-static unsigned int radio_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
43494+static int video_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
43495+static int vbi_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
43496+static int radio_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
43497
43498 module_param_array(video_nr, int, NULL, 0444);
43499 module_param_array(vbi_nr, int, NULL, 0444);
43500diff --git a/drivers/media/pci/ivtv/ivtv-driver.c b/drivers/media/pci/ivtv/ivtv-driver.c
43501index c08ae3e..eb59af1 100644
43502--- a/drivers/media/pci/ivtv/ivtv-driver.c
43503+++ b/drivers/media/pci/ivtv/ivtv-driver.c
43504@@ -83,7 +83,7 @@ static struct pci_device_id ivtv_pci_tbl[] = {
43505 MODULE_DEVICE_TABLE(pci,ivtv_pci_tbl);
43506
43507 /* ivtv instance counter */
43508-static atomic_t ivtv_instance = ATOMIC_INIT(0);
43509+static atomic_unchecked_t ivtv_instance = ATOMIC_INIT(0);
43510
43511 /* Parameter declarations */
43512 static int cardtype[IVTV_MAX_CARDS];
43513diff --git a/drivers/media/platform/omap/omap_vout.c b/drivers/media/platform/omap/omap_vout.c
43514index dfd0a21..6bbb465 100644
43515--- a/drivers/media/platform/omap/omap_vout.c
43516+++ b/drivers/media/platform/omap/omap_vout.c
43517@@ -63,7 +63,6 @@ enum omap_vout_channels {
43518 OMAP_VIDEO2,
43519 };
43520
43521-static struct videobuf_queue_ops video_vbq_ops;
43522 /* Variables configurable through module params*/
43523 static u32 video1_numbuffers = 3;
43524 static u32 video2_numbuffers = 3;
43525@@ -1014,6 +1013,12 @@ static int omap_vout_open(struct file *file)
43526 {
43527 struct videobuf_queue *q;
43528 struct omap_vout_device *vout = NULL;
43529+ static struct videobuf_queue_ops video_vbq_ops = {
43530+ .buf_setup = omap_vout_buffer_setup,
43531+ .buf_prepare = omap_vout_buffer_prepare,
43532+ .buf_release = omap_vout_buffer_release,
43533+ .buf_queue = omap_vout_buffer_queue,
43534+ };
43535
43536 vout = video_drvdata(file);
43537 v4l2_dbg(1, debug, &vout->vid_dev->v4l2_dev, "Entering %s\n", __func__);
43538@@ -1031,10 +1036,6 @@ static int omap_vout_open(struct file *file)
43539 vout->type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
43540
43541 q = &vout->vbq;
43542- video_vbq_ops.buf_setup = omap_vout_buffer_setup;
43543- video_vbq_ops.buf_prepare = omap_vout_buffer_prepare;
43544- video_vbq_ops.buf_release = omap_vout_buffer_release;
43545- video_vbq_ops.buf_queue = omap_vout_buffer_queue;
43546 spin_lock_init(&vout->vbq_lock);
43547
43548 videobuf_queue_dma_contig_init(q, &video_vbq_ops, q->dev,
43549diff --git a/drivers/media/platform/s5p-tv/mixer.h b/drivers/media/platform/s5p-tv/mixer.h
43550index 04e6490..2df65bf 100644
43551--- a/drivers/media/platform/s5p-tv/mixer.h
43552+++ b/drivers/media/platform/s5p-tv/mixer.h
43553@@ -156,7 +156,7 @@ struct mxr_layer {
43554 /** layer index (unique identifier) */
43555 int idx;
43556 /** callbacks for layer methods */
43557- struct mxr_layer_ops ops;
43558+ struct mxr_layer_ops *ops;
43559 /** format array */
43560 const struct mxr_format **fmt_array;
43561 /** size of format array */
43562diff --git a/drivers/media/platform/s5p-tv/mixer_grp_layer.c b/drivers/media/platform/s5p-tv/mixer_grp_layer.c
43563index b93a21f..2535195 100644
43564--- a/drivers/media/platform/s5p-tv/mixer_grp_layer.c
43565+++ b/drivers/media/platform/s5p-tv/mixer_grp_layer.c
43566@@ -235,7 +235,7 @@ struct mxr_layer *mxr_graph_layer_create(struct mxr_device *mdev, int idx)
43567 {
43568 struct mxr_layer *layer;
43569 int ret;
43570- struct mxr_layer_ops ops = {
43571+ static struct mxr_layer_ops ops = {
43572 .release = mxr_graph_layer_release,
43573 .buffer_set = mxr_graph_buffer_set,
43574 .stream_set = mxr_graph_stream_set,
43575diff --git a/drivers/media/platform/s5p-tv/mixer_reg.c b/drivers/media/platform/s5p-tv/mixer_reg.c
43576index b713403..53cb5ad 100644
43577--- a/drivers/media/platform/s5p-tv/mixer_reg.c
43578+++ b/drivers/media/platform/s5p-tv/mixer_reg.c
43579@@ -276,7 +276,7 @@ static void mxr_irq_layer_handle(struct mxr_layer *layer)
43580 layer->update_buf = next;
43581 }
43582
43583- layer->ops.buffer_set(layer, layer->update_buf);
43584+ layer->ops->buffer_set(layer, layer->update_buf);
43585
43586 if (done && done != layer->shadow_buf)
43587 vb2_buffer_done(&done->vb, VB2_BUF_STATE_DONE);
43588diff --git a/drivers/media/platform/s5p-tv/mixer_video.c b/drivers/media/platform/s5p-tv/mixer_video.c
43589index 641b1f0..49cff30 100644
43590--- a/drivers/media/platform/s5p-tv/mixer_video.c
43591+++ b/drivers/media/platform/s5p-tv/mixer_video.c
43592@@ -210,7 +210,7 @@ static void mxr_layer_default_geo(struct mxr_layer *layer)
43593 layer->geo.src.height = layer->geo.src.full_height;
43594
43595 mxr_geometry_dump(mdev, &layer->geo);
43596- layer->ops.fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
43597+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
43598 mxr_geometry_dump(mdev, &layer->geo);
43599 }
43600
43601@@ -228,7 +228,7 @@ static void mxr_layer_update_output(struct mxr_layer *layer)
43602 layer->geo.dst.full_width = mbus_fmt.width;
43603 layer->geo.dst.full_height = mbus_fmt.height;
43604 layer->geo.dst.field = mbus_fmt.field;
43605- layer->ops.fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
43606+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
43607
43608 mxr_geometry_dump(mdev, &layer->geo);
43609 }
43610@@ -334,7 +334,7 @@ static int mxr_s_fmt(struct file *file, void *priv,
43611 /* set source size to highest accepted value */
43612 geo->src.full_width = max(geo->dst.full_width, pix->width);
43613 geo->src.full_height = max(geo->dst.full_height, pix->height);
43614- layer->ops.fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
43615+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
43616 mxr_geometry_dump(mdev, &layer->geo);
43617 /* set cropping to total visible screen */
43618 geo->src.width = pix->width;
43619@@ -342,12 +342,12 @@ static int mxr_s_fmt(struct file *file, void *priv,
43620 geo->src.x_offset = 0;
43621 geo->src.y_offset = 0;
43622 /* assure consistency of geometry */
43623- layer->ops.fix_geometry(layer, MXR_GEOMETRY_CROP, MXR_NO_OFFSET);
43624+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_CROP, MXR_NO_OFFSET);
43625 mxr_geometry_dump(mdev, &layer->geo);
43626 /* set full size to lowest possible value */
43627 geo->src.full_width = 0;
43628 geo->src.full_height = 0;
43629- layer->ops.fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
43630+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
43631 mxr_geometry_dump(mdev, &layer->geo);
43632
43633 /* returning results */
43634@@ -474,7 +474,7 @@ static int mxr_s_selection(struct file *file, void *fh,
43635 target->width = s->r.width;
43636 target->height = s->r.height;
43637
43638- layer->ops.fix_geometry(layer, stage, s->flags);
43639+ layer->ops->fix_geometry(layer, stage, s->flags);
43640
43641 /* retrieve update selection rectangle */
43642 res.left = target->x_offset;
43643@@ -955,13 +955,13 @@ static int start_streaming(struct vb2_queue *vq, unsigned int count)
43644 mxr_output_get(mdev);
43645
43646 mxr_layer_update_output(layer);
43647- layer->ops.format_set(layer);
43648+ layer->ops->format_set(layer);
43649 /* enabling layer in hardware */
43650 spin_lock_irqsave(&layer->enq_slock, flags);
43651 layer->state = MXR_LAYER_STREAMING;
43652 spin_unlock_irqrestore(&layer->enq_slock, flags);
43653
43654- layer->ops.stream_set(layer, MXR_ENABLE);
43655+ layer->ops->stream_set(layer, MXR_ENABLE);
43656 mxr_streamer_get(mdev);
43657
43658 return 0;
43659@@ -1031,7 +1031,7 @@ static int stop_streaming(struct vb2_queue *vq)
43660 spin_unlock_irqrestore(&layer->enq_slock, flags);
43661
43662 /* disabling layer in hardware */
43663- layer->ops.stream_set(layer, MXR_DISABLE);
43664+ layer->ops->stream_set(layer, MXR_DISABLE);
43665 /* remove one streamer */
43666 mxr_streamer_put(mdev);
43667 /* allow changes in output configuration */
43668@@ -1070,8 +1070,8 @@ void mxr_base_layer_unregister(struct mxr_layer *layer)
43669
43670 void mxr_layer_release(struct mxr_layer *layer)
43671 {
43672- if (layer->ops.release)
43673- layer->ops.release(layer);
43674+ if (layer->ops->release)
43675+ layer->ops->release(layer);
43676 }
43677
43678 void mxr_base_layer_release(struct mxr_layer *layer)
43679@@ -1097,7 +1097,7 @@ struct mxr_layer *mxr_base_layer_create(struct mxr_device *mdev,
43680
43681 layer->mdev = mdev;
43682 layer->idx = idx;
43683- layer->ops = *ops;
43684+ layer->ops = ops;
43685
43686 spin_lock_init(&layer->enq_slock);
43687 INIT_LIST_HEAD(&layer->enq_list);
43688diff --git a/drivers/media/platform/s5p-tv/mixer_vp_layer.c b/drivers/media/platform/s5p-tv/mixer_vp_layer.c
43689index 3d13a63..da31bf1 100644
43690--- a/drivers/media/platform/s5p-tv/mixer_vp_layer.c
43691+++ b/drivers/media/platform/s5p-tv/mixer_vp_layer.c
43692@@ -206,7 +206,7 @@ struct mxr_layer *mxr_vp_layer_create(struct mxr_device *mdev, int idx)
43693 {
43694 struct mxr_layer *layer;
43695 int ret;
43696- struct mxr_layer_ops ops = {
43697+ static struct mxr_layer_ops ops = {
43698 .release = mxr_vp_layer_release,
43699 .buffer_set = mxr_vp_buffer_set,
43700 .stream_set = mxr_vp_stream_set,
43701diff --git a/drivers/media/platform/vivi.c b/drivers/media/platform/vivi.c
43702index 1d3f119..75f40bb 100644
43703--- a/drivers/media/platform/vivi.c
43704+++ b/drivers/media/platform/vivi.c
43705@@ -58,8 +58,8 @@ MODULE_AUTHOR("Mauro Carvalho Chehab, Ted Walther and John Sokol");
43706 MODULE_LICENSE("Dual BSD/GPL");
43707 MODULE_VERSION(VIVI_VERSION);
43708
43709-static unsigned video_nr = -1;
43710-module_param(video_nr, uint, 0644);
43711+static int video_nr = -1;
43712+module_param(video_nr, int, 0644);
43713 MODULE_PARM_DESC(video_nr, "videoX start number, -1 is autodetect");
43714
43715 static unsigned n_devs = 1;
43716diff --git a/drivers/media/radio/radio-cadet.c b/drivers/media/radio/radio-cadet.c
43717index 545c04c..a14bded 100644
43718--- a/drivers/media/radio/radio-cadet.c
43719+++ b/drivers/media/radio/radio-cadet.c
43720@@ -324,6 +324,8 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
43721 unsigned char readbuf[RDS_BUFFER];
43722 int i = 0;
43723
43724+ if (count > RDS_BUFFER)
43725+ return -EFAULT;
43726 mutex_lock(&dev->lock);
43727 if (dev->rdsstat == 0)
43728 cadet_start_rds(dev);
43729@@ -339,7 +341,7 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
43730 while (i < count && dev->rdsin != dev->rdsout)
43731 readbuf[i++] = dev->rdsbuf[dev->rdsout++];
43732
43733- if (i && copy_to_user(data, readbuf, i))
43734+ if (i > sizeof(readbuf) || copy_to_user(data, readbuf, i))
43735 i = -EFAULT;
43736 unlock:
43737 mutex_unlock(&dev->lock);
43738diff --git a/drivers/media/radio/radio-maxiradio.c b/drivers/media/radio/radio-maxiradio.c
43739index 5236035..c622c74 100644
43740--- a/drivers/media/radio/radio-maxiradio.c
43741+++ b/drivers/media/radio/radio-maxiradio.c
43742@@ -61,7 +61,7 @@ MODULE_PARM_DESC(radio_nr, "Radio device number");
43743 /* TEA5757 pin mappings */
43744 static const int clk = 1, data = 2, wren = 4, mo_st = 8, power = 16;
43745
43746-static atomic_t maxiradio_instance = ATOMIC_INIT(0);
43747+static atomic_unchecked_t maxiradio_instance = ATOMIC_INIT(0);
43748
43749 #define PCI_VENDOR_ID_GUILLEMOT 0x5046
43750 #define PCI_DEVICE_ID_GUILLEMOT_MAXIRADIO 0x1001
43751diff --git a/drivers/media/radio/radio-shark.c b/drivers/media/radio/radio-shark.c
43752index b914772..7ddbf9b 100644
43753--- a/drivers/media/radio/radio-shark.c
43754+++ b/drivers/media/radio/radio-shark.c
43755@@ -79,7 +79,7 @@ struct shark_device {
43756 u32 last_val;
43757 };
43758
43759-static atomic_t shark_instance = ATOMIC_INIT(0);
43760+static atomic_unchecked_t shark_instance = ATOMIC_INIT(0);
43761
43762 static void shark_write_val(struct snd_tea575x *tea, u32 val)
43763 {
43764diff --git a/drivers/media/radio/radio-shark2.c b/drivers/media/radio/radio-shark2.c
43765index 9fb6697..f167415 100644
43766--- a/drivers/media/radio/radio-shark2.c
43767+++ b/drivers/media/radio/radio-shark2.c
43768@@ -74,7 +74,7 @@ struct shark_device {
43769 u8 *transfer_buffer;
43770 };
43771
43772-static atomic_t shark_instance = ATOMIC_INIT(0);
43773+static atomic_unchecked_t shark_instance = ATOMIC_INIT(0);
43774
43775 static int shark_write_reg(struct radio_tea5777 *tea, u64 reg)
43776 {
43777diff --git a/drivers/media/radio/radio-si476x.c b/drivers/media/radio/radio-si476x.c
43778index 9c9084c..a9e8dfb 100644
43779--- a/drivers/media/radio/radio-si476x.c
43780+++ b/drivers/media/radio/radio-si476x.c
43781@@ -1445,7 +1445,7 @@ static int si476x_radio_probe(struct platform_device *pdev)
43782 struct si476x_radio *radio;
43783 struct v4l2_ctrl *ctrl;
43784
43785- static atomic_t instance = ATOMIC_INIT(0);
43786+ static atomic_unchecked_t instance = ATOMIC_INIT(0);
43787
43788 radio = devm_kzalloc(&pdev->dev, sizeof(*radio), GFP_KERNEL);
43789 if (!radio)
43790diff --git a/drivers/media/rc/rc-main.c b/drivers/media/rc/rc-main.c
43791index 46da365..3ba4206 100644
43792--- a/drivers/media/rc/rc-main.c
43793+++ b/drivers/media/rc/rc-main.c
43794@@ -1065,7 +1065,7 @@ EXPORT_SYMBOL_GPL(rc_free_device);
43795 int rc_register_device(struct rc_dev *dev)
43796 {
43797 static bool raw_init = false; /* raw decoders loaded? */
43798- static atomic_t devno = ATOMIC_INIT(0);
43799+ static atomic_unchecked_t devno = ATOMIC_INIT(0);
43800 struct rc_map *rc_map;
43801 const char *path;
43802 int rc;
43803@@ -1096,7 +1096,7 @@ int rc_register_device(struct rc_dev *dev)
43804 */
43805 mutex_lock(&dev->lock);
43806
43807- dev->devno = (unsigned long)(atomic_inc_return(&devno) - 1);
43808+ dev->devno = (unsigned long)(atomic_inc_return_unchecked(&devno) - 1);
43809 dev_set_name(&dev->dev, "rc%ld", dev->devno);
43810 dev_set_drvdata(&dev->dev, dev);
43811 rc = device_add(&dev->dev);
43812diff --git a/drivers/media/usb/dvb-usb/cxusb.c b/drivers/media/usb/dvb-usb/cxusb.c
43813index 20e345d..da56fe4 100644
43814--- a/drivers/media/usb/dvb-usb/cxusb.c
43815+++ b/drivers/media/usb/dvb-usb/cxusb.c
43816@@ -1101,7 +1101,7 @@ static struct dib0070_config dib7070p_dib0070_config = {
43817
43818 struct dib0700_adapter_state {
43819 int (*set_param_save) (struct dvb_frontend *);
43820-};
43821+} __no_const;
43822
43823 static int dib7070_set_param_override(struct dvb_frontend *fe)
43824 {
43825diff --git a/drivers/media/usb/dvb-usb/dw2102.c b/drivers/media/usb/dvb-usb/dw2102.c
43826index 71b22f5..a63b33f 100644
43827--- a/drivers/media/usb/dvb-usb/dw2102.c
43828+++ b/drivers/media/usb/dvb-usb/dw2102.c
43829@@ -121,7 +121,7 @@ struct su3000_state {
43830
43831 struct s6x0_state {
43832 int (*old_set_voltage)(struct dvb_frontend *f, fe_sec_voltage_t v);
43833-};
43834+} __no_const;
43835
43836 /* debug */
43837 static int dvb_usb_dw2102_debug;
43838diff --git a/drivers/media/v4l2-core/v4l2-compat-ioctl32.c b/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
43839index 8f7a6a4..59502dd 100644
43840--- a/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
43841+++ b/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
43842@@ -326,7 +326,7 @@ struct v4l2_buffer32 {
43843 __u32 reserved;
43844 };
43845
43846-static int get_v4l2_plane32(struct v4l2_plane *up, struct v4l2_plane32 *up32,
43847+static int get_v4l2_plane32(struct v4l2_plane __user *up, struct v4l2_plane32 __user *up32,
43848 enum v4l2_memory memory)
43849 {
43850 void __user *up_pln;
43851@@ -355,7 +355,7 @@ static int get_v4l2_plane32(struct v4l2_plane *up, struct v4l2_plane32 *up32,
43852 return 0;
43853 }
43854
43855-static int put_v4l2_plane32(struct v4l2_plane *up, struct v4l2_plane32 *up32,
43856+static int put_v4l2_plane32(struct v4l2_plane __user *up, struct v4l2_plane32 __user *up32,
43857 enum v4l2_memory memory)
43858 {
43859 if (copy_in_user(up32, up, 2 * sizeof(__u32)) ||
43860@@ -772,7 +772,7 @@ static int put_v4l2_subdev_edid32(struct v4l2_subdev_edid *kp, struct v4l2_subde
43861 put_user(kp->start_block, &up->start_block) ||
43862 put_user(kp->blocks, &up->blocks) ||
43863 put_user(tmp, &up->edid) ||
43864- copy_to_user(kp->reserved, up->reserved, sizeof(kp->reserved)))
43865+ copy_to_user(up->reserved, kp->reserved, sizeof(kp->reserved)))
43866 return -EFAULT;
43867 return 0;
43868 }
43869diff --git a/drivers/media/v4l2-core/v4l2-device.c b/drivers/media/v4l2-core/v4l2-device.c
43870index 02d1b63..5fd6b16 100644
43871--- a/drivers/media/v4l2-core/v4l2-device.c
43872+++ b/drivers/media/v4l2-core/v4l2-device.c
43873@@ -75,9 +75,9 @@ int v4l2_device_put(struct v4l2_device *v4l2_dev)
43874 EXPORT_SYMBOL_GPL(v4l2_device_put);
43875
43876 int v4l2_device_set_name(struct v4l2_device *v4l2_dev, const char *basename,
43877- atomic_t *instance)
43878+ atomic_unchecked_t *instance)
43879 {
43880- int num = atomic_inc_return(instance) - 1;
43881+ int num = atomic_inc_return_unchecked(instance) - 1;
43882 int len = strlen(basename);
43883
43884 if (basename[len - 1] >= '0' && basename[len - 1] <= '9')
43885diff --git a/drivers/media/v4l2-core/v4l2-ioctl.c b/drivers/media/v4l2-core/v4l2-ioctl.c
43886index 68e6b5e..d8b923e 100644
43887--- a/drivers/media/v4l2-core/v4l2-ioctl.c
43888+++ b/drivers/media/v4l2-core/v4l2-ioctl.c
43889@@ -1939,7 +1939,8 @@ struct v4l2_ioctl_info {
43890 struct file *file, void *fh, void *p);
43891 } u;
43892 void (*debug)(const void *arg, bool write_only);
43893-};
43894+} __do_const;
43895+typedef struct v4l2_ioctl_info __no_const v4l2_ioctl_info_no_const;
43896
43897 /* This control needs a priority check */
43898 #define INFO_FL_PRIO (1 << 0)
43899@@ -2120,7 +2121,7 @@ static long __video_do_ioctl(struct file *file,
43900 struct video_device *vfd = video_devdata(file);
43901 const struct v4l2_ioctl_ops *ops = vfd->ioctl_ops;
43902 bool write_only = false;
43903- struct v4l2_ioctl_info default_info;
43904+ v4l2_ioctl_info_no_const default_info;
43905 const struct v4l2_ioctl_info *info;
43906 void *fh = file->private_data;
43907 struct v4l2_fh *vfh = NULL;
43908@@ -2194,7 +2195,7 @@ done:
43909 }
43910
43911 static int check_array_args(unsigned int cmd, void *parg, size_t *array_size,
43912- void * __user *user_ptr, void ***kernel_ptr)
43913+ void __user **user_ptr, void ***kernel_ptr)
43914 {
43915 int ret = 0;
43916
43917@@ -2210,7 +2211,7 @@ static int check_array_args(unsigned int cmd, void *parg, size_t *array_size,
43918 ret = -EINVAL;
43919 break;
43920 }
43921- *user_ptr = (void __user *)buf->m.planes;
43922+ *user_ptr = (void __force_user *)buf->m.planes;
43923 *kernel_ptr = (void *)&buf->m.planes;
43924 *array_size = sizeof(struct v4l2_plane) * buf->length;
43925 ret = 1;
43926@@ -2245,7 +2246,7 @@ static int check_array_args(unsigned int cmd, void *parg, size_t *array_size,
43927 ret = -EINVAL;
43928 break;
43929 }
43930- *user_ptr = (void __user *)ctrls->controls;
43931+ *user_ptr = (void __force_user *)ctrls->controls;
43932 *kernel_ptr = (void *)&ctrls->controls;
43933 *array_size = sizeof(struct v4l2_ext_control)
43934 * ctrls->count;
43935diff --git a/drivers/message/fusion/mptbase.c b/drivers/message/fusion/mptbase.c
43936index 767ff4d..c69d259 100644
43937--- a/drivers/message/fusion/mptbase.c
43938+++ b/drivers/message/fusion/mptbase.c
43939@@ -6755,8 +6755,13 @@ static int mpt_iocinfo_proc_show(struct seq_file *m, void *v)
43940 seq_printf(m, " MaxChainDepth = 0x%02x frames\n", ioc->facts.MaxChainDepth);
43941 seq_printf(m, " MinBlockSize = 0x%02x bytes\n", 4*ioc->facts.BlockSize);
43942
43943+#ifdef CONFIG_GRKERNSEC_HIDESYM
43944+ seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n", NULL, NULL);
43945+#else
43946 seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n",
43947 (void *)ioc->req_frames, (void *)(ulong)ioc->req_frames_dma);
43948+#endif
43949+
43950 /*
43951 * Rounding UP to nearest 4-kB boundary here...
43952 */
43953@@ -6769,7 +6774,11 @@ static int mpt_iocinfo_proc_show(struct seq_file *m, void *v)
43954 ioc->facts.GlobalCredits);
43955
43956 seq_printf(m, " Frames @ 0x%p (Dma @ 0x%p)\n",
43957+#ifdef CONFIG_GRKERNSEC_HIDESYM
43958+ NULL, NULL);
43959+#else
43960 (void *)ioc->alloc, (void *)(ulong)ioc->alloc_dma);
43961+#endif
43962 sz = (ioc->reply_sz * ioc->reply_depth) + 128;
43963 seq_printf(m, " {CurRepSz=%d} x {CurRepDepth=%d} = %d bytes ^= 0x%x\n",
43964 ioc->reply_sz, ioc->reply_depth, ioc->reply_sz*ioc->reply_depth, sz);
43965diff --git a/drivers/message/fusion/mptsas.c b/drivers/message/fusion/mptsas.c
43966index dd239bd..689c4f7 100644
43967--- a/drivers/message/fusion/mptsas.c
43968+++ b/drivers/message/fusion/mptsas.c
43969@@ -446,6 +446,23 @@ mptsas_is_end_device(struct mptsas_devinfo * attached)
43970 return 0;
43971 }
43972
43973+static inline void
43974+mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
43975+{
43976+ if (phy_info->port_details) {
43977+ phy_info->port_details->rphy = rphy;
43978+ dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
43979+ ioc->name, rphy));
43980+ }
43981+
43982+ if (rphy) {
43983+ dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
43984+ &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
43985+ dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
43986+ ioc->name, rphy, rphy->dev.release));
43987+ }
43988+}
43989+
43990 /* no mutex */
43991 static void
43992 mptsas_port_delete(MPT_ADAPTER *ioc, struct mptsas_portinfo_details * port_details)
43993@@ -484,23 +501,6 @@ mptsas_get_rphy(struct mptsas_phyinfo *phy_info)
43994 return NULL;
43995 }
43996
43997-static inline void
43998-mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
43999-{
44000- if (phy_info->port_details) {
44001- phy_info->port_details->rphy = rphy;
44002- dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
44003- ioc->name, rphy));
44004- }
44005-
44006- if (rphy) {
44007- dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
44008- &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
44009- dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
44010- ioc->name, rphy, rphy->dev.release));
44011- }
44012-}
44013-
44014 static inline struct sas_port *
44015 mptsas_get_port(struct mptsas_phyinfo *phy_info)
44016 {
44017diff --git a/drivers/message/fusion/mptscsih.c b/drivers/message/fusion/mptscsih.c
44018index 727819c..ad74694 100644
44019--- a/drivers/message/fusion/mptscsih.c
44020+++ b/drivers/message/fusion/mptscsih.c
44021@@ -1271,15 +1271,16 @@ mptscsih_info(struct Scsi_Host *SChost)
44022
44023 h = shost_priv(SChost);
44024
44025- if (h) {
44026- if (h->info_kbuf == NULL)
44027- if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
44028- return h->info_kbuf;
44029- h->info_kbuf[0] = '\0';
44030+ if (!h)
44031+ return NULL;
44032
44033- mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
44034- h->info_kbuf[size-1] = '\0';
44035- }
44036+ if (h->info_kbuf == NULL)
44037+ if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
44038+ return h->info_kbuf;
44039+ h->info_kbuf[0] = '\0';
44040+
44041+ mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
44042+ h->info_kbuf[size-1] = '\0';
44043
44044 return h->info_kbuf;
44045 }
44046diff --git a/drivers/message/i2o/i2o_proc.c b/drivers/message/i2o/i2o_proc.c
44047index b7d87cd..3fb36da 100644
44048--- a/drivers/message/i2o/i2o_proc.c
44049+++ b/drivers/message/i2o/i2o_proc.c
44050@@ -255,12 +255,6 @@ static char *scsi_devices[] = {
44051 "Array Controller Device"
44052 };
44053
44054-static char *chtostr(char *tmp, u8 *chars, int n)
44055-{
44056- tmp[0] = 0;
44057- return strncat(tmp, (char *)chars, n);
44058-}
44059-
44060 static int i2o_report_query_status(struct seq_file *seq, int block_status,
44061 char *group)
44062 {
44063@@ -707,9 +701,9 @@ static int i2o_seq_show_status(struct seq_file *seq, void *v)
44064 static int i2o_seq_show_hw(struct seq_file *seq, void *v)
44065 {
44066 struct i2o_controller *c = (struct i2o_controller *)seq->private;
44067- static u32 work32[5];
44068- static u8 *work8 = (u8 *) work32;
44069- static u16 *work16 = (u16 *) work32;
44070+ u32 work32[5];
44071+ u8 *work8 = (u8 *) work32;
44072+ u16 *work16 = (u16 *) work32;
44073 int token;
44074 u32 hwcap;
44075
44076@@ -790,7 +784,6 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
44077 } *result;
44078
44079 i2o_exec_execute_ddm_table ddm_table;
44080- char tmp[28 + 1];
44081
44082 result = kmalloc(sizeof(*result), GFP_KERNEL);
44083 if (!result)
44084@@ -825,8 +818,7 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
44085
44086 seq_printf(seq, "%-#7x", ddm_table.i2o_vendor_id);
44087 seq_printf(seq, "%-#8x", ddm_table.module_id);
44088- seq_printf(seq, "%-29s",
44089- chtostr(tmp, ddm_table.module_name_version, 28));
44090+ seq_printf(seq, "%-.28s", ddm_table.module_name_version);
44091 seq_printf(seq, "%9d ", ddm_table.data_size);
44092 seq_printf(seq, "%8d", ddm_table.code_size);
44093
44094@@ -893,7 +885,6 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
44095
44096 i2o_driver_result_table *result;
44097 i2o_driver_store_table *dst;
44098- char tmp[28 + 1];
44099
44100 result = kmalloc(sizeof(i2o_driver_result_table), GFP_KERNEL);
44101 if (result == NULL)
44102@@ -928,9 +919,8 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
44103
44104 seq_printf(seq, "%-#7x", dst->i2o_vendor_id);
44105 seq_printf(seq, "%-#8x", dst->module_id);
44106- seq_printf(seq, "%-29s",
44107- chtostr(tmp, dst->module_name_version, 28));
44108- seq_printf(seq, "%-9s", chtostr(tmp, dst->date, 8));
44109+ seq_printf(seq, "%-.28s", dst->module_name_version);
44110+ seq_printf(seq, "%-.8s", dst->date);
44111 seq_printf(seq, "%8d ", dst->module_size);
44112 seq_printf(seq, "%8d ", dst->mpb_size);
44113 seq_printf(seq, "0x%04x", dst->module_flags);
44114@@ -1246,11 +1236,10 @@ static int i2o_seq_show_authorized_users(struct seq_file *seq, void *v)
44115 static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
44116 {
44117 struct i2o_device *d = (struct i2o_device *)seq->private;
44118- static u32 work32[128]; // allow for "stuff" + up to 256 byte (max) serial number
44119+ u32 work32[128]; // allow for "stuff" + up to 256 byte (max) serial number
44120 // == (allow) 512d bytes (max)
44121- static u16 *work16 = (u16 *) work32;
44122+ u16 *work16 = (u16 *) work32;
44123 int token;
44124- char tmp[16 + 1];
44125
44126 token = i2o_parm_field_get(d, 0xF100, -1, &work32, sizeof(work32));
44127
44128@@ -1262,14 +1251,10 @@ static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
44129 seq_printf(seq, "Device Class : %s\n", i2o_get_class_name(work16[0]));
44130 seq_printf(seq, "Owner TID : %0#5x\n", work16[2]);
44131 seq_printf(seq, "Parent TID : %0#5x\n", work16[3]);
44132- seq_printf(seq, "Vendor info : %s\n",
44133- chtostr(tmp, (u8 *) (work32 + 2), 16));
44134- seq_printf(seq, "Product info : %s\n",
44135- chtostr(tmp, (u8 *) (work32 + 6), 16));
44136- seq_printf(seq, "Description : %s\n",
44137- chtostr(tmp, (u8 *) (work32 + 10), 16));
44138- seq_printf(seq, "Product rev. : %s\n",
44139- chtostr(tmp, (u8 *) (work32 + 14), 8));
44140+ seq_printf(seq, "Vendor info : %.16s\n", (u8 *) (work32 + 2));
44141+ seq_printf(seq, "Product info : %.16s\n", (u8 *) (work32 + 6));
44142+ seq_printf(seq, "Description : %.16s\n", (u8 *) (work32 + 10));
44143+ seq_printf(seq, "Product rev. : %.8s\n", (u8 *) (work32 + 14));
44144
44145 seq_printf(seq, "Serial number : ");
44146 print_serial_number(seq, (u8 *) (work32 + 16),
44147@@ -1306,8 +1291,6 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
44148 u8 pad[256]; // allow up to 256 byte (max) serial number
44149 } result;
44150
44151- char tmp[24 + 1];
44152-
44153 token = i2o_parm_field_get(d, 0xF101, -1, &result, sizeof(result));
44154
44155 if (token < 0) {
44156@@ -1316,10 +1299,8 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
44157 }
44158
44159 seq_printf(seq, "Registering DDM TID : 0x%03x\n", result.ddm_tid);
44160- seq_printf(seq, "Module name : %s\n",
44161- chtostr(tmp, result.module_name, 24));
44162- seq_printf(seq, "Module revision : %s\n",
44163- chtostr(tmp, result.module_rev, 8));
44164+ seq_printf(seq, "Module name : %.24s\n", result.module_name);
44165+ seq_printf(seq, "Module revision : %.8s\n", result.module_rev);
44166
44167 seq_printf(seq, "Serial number : ");
44168 print_serial_number(seq, result.serial_number, sizeof(result) - 36);
44169@@ -1343,8 +1324,6 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
44170 u8 instance_number[4];
44171 } result;
44172
44173- char tmp[64 + 1];
44174-
44175 token = i2o_parm_field_get(d, 0xF102, -1, &result, sizeof(result));
44176
44177 if (token < 0) {
44178@@ -1352,14 +1331,10 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
44179 return 0;
44180 }
44181
44182- seq_printf(seq, "Device name : %s\n",
44183- chtostr(tmp, result.device_name, 64));
44184- seq_printf(seq, "Service name : %s\n",
44185- chtostr(tmp, result.service_name, 64));
44186- seq_printf(seq, "Physical name : %s\n",
44187- chtostr(tmp, result.physical_location, 64));
44188- seq_printf(seq, "Instance number : %s\n",
44189- chtostr(tmp, result.instance_number, 4));
44190+ seq_printf(seq, "Device name : %.64s\n", result.device_name);
44191+ seq_printf(seq, "Service name : %.64s\n", result.service_name);
44192+ seq_printf(seq, "Physical name : %.64s\n", result.physical_location);
44193+ seq_printf(seq, "Instance number : %.4s\n", result.instance_number);
44194
44195 return 0;
44196 }
44197@@ -1368,9 +1343,9 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
44198 static int i2o_seq_show_sgl_limits(struct seq_file *seq, void *v)
44199 {
44200 struct i2o_device *d = (struct i2o_device *)seq->private;
44201- static u32 work32[12];
44202- static u16 *work16 = (u16 *) work32;
44203- static u8 *work8 = (u8 *) work32;
44204+ u32 work32[12];
44205+ u16 *work16 = (u16 *) work32;
44206+ u8 *work8 = (u8 *) work32;
44207 int token;
44208
44209 token = i2o_parm_field_get(d, 0xF103, -1, &work32, sizeof(work32));
44210diff --git a/drivers/message/i2o/iop.c b/drivers/message/i2o/iop.c
44211index a8c08f3..155fe3d 100644
44212--- a/drivers/message/i2o/iop.c
44213+++ b/drivers/message/i2o/iop.c
44214@@ -111,10 +111,10 @@ u32 i2o_cntxt_list_add(struct i2o_controller * c, void *ptr)
44215
44216 spin_lock_irqsave(&c->context_list_lock, flags);
44217
44218- if (unlikely(atomic_inc_and_test(&c->context_list_counter)))
44219- atomic_inc(&c->context_list_counter);
44220+ if (unlikely(atomic_inc_and_test_unchecked(&c->context_list_counter)))
44221+ atomic_inc_unchecked(&c->context_list_counter);
44222
44223- entry->context = atomic_read(&c->context_list_counter);
44224+ entry->context = atomic_read_unchecked(&c->context_list_counter);
44225
44226 list_add(&entry->list, &c->context_list);
44227
44228@@ -1077,7 +1077,7 @@ struct i2o_controller *i2o_iop_alloc(void)
44229
44230 #if BITS_PER_LONG == 64
44231 spin_lock_init(&c->context_list_lock);
44232- atomic_set(&c->context_list_counter, 0);
44233+ atomic_set_unchecked(&c->context_list_counter, 0);
44234 INIT_LIST_HEAD(&c->context_list);
44235 #endif
44236
44237diff --git a/drivers/mfd/janz-cmodio.c b/drivers/mfd/janz-cmodio.c
44238index fcbb2e9..2635e11 100644
44239--- a/drivers/mfd/janz-cmodio.c
44240+++ b/drivers/mfd/janz-cmodio.c
44241@@ -13,6 +13,7 @@
44242
44243 #include <linux/kernel.h>
44244 #include <linux/module.h>
44245+#include <linux/slab.h>
44246 #include <linux/init.h>
44247 #include <linux/pci.h>
44248 #include <linux/interrupt.h>
44249diff --git a/drivers/mfd/max8925-i2c.c b/drivers/mfd/max8925-i2c.c
44250index de7fb80..7c1b931 100644
44251--- a/drivers/mfd/max8925-i2c.c
44252+++ b/drivers/mfd/max8925-i2c.c
44253@@ -152,7 +152,7 @@ static int max8925_probe(struct i2c_client *client,
44254 const struct i2c_device_id *id)
44255 {
44256 struct max8925_platform_data *pdata = dev_get_platdata(&client->dev);
44257- static struct max8925_chip *chip;
44258+ struct max8925_chip *chip;
44259 struct device_node *node = client->dev.of_node;
44260
44261 if (node && !pdata) {
44262diff --git a/drivers/mfd/tps65910.c b/drivers/mfd/tps65910.c
44263index d792772..cd73ba3 100644
44264--- a/drivers/mfd/tps65910.c
44265+++ b/drivers/mfd/tps65910.c
44266@@ -229,7 +229,7 @@ static int tps65910_irq_init(struct tps65910 *tps65910, int irq,
44267 struct tps65910_platform_data *pdata)
44268 {
44269 int ret = 0;
44270- static struct regmap_irq_chip *tps6591x_irqs_chip;
44271+ struct regmap_irq_chip *tps6591x_irqs_chip;
44272
44273 if (!irq) {
44274 dev_warn(tps65910->dev, "No interrupt support, no core IRQ\n");
44275diff --git a/drivers/mfd/twl4030-irq.c b/drivers/mfd/twl4030-irq.c
44276index 9aa6d1e..1631bfc 100644
44277--- a/drivers/mfd/twl4030-irq.c
44278+++ b/drivers/mfd/twl4030-irq.c
44279@@ -35,6 +35,7 @@
44280 #include <linux/of.h>
44281 #include <linux/irqdomain.h>
44282 #include <linux/i2c/twl.h>
44283+#include <asm/pgtable.h>
44284
44285 #include "twl-core.h"
44286
44287@@ -726,10 +727,12 @@ int twl4030_init_irq(struct device *dev, int irq_num)
44288 * Install an irq handler for each of the SIH modules;
44289 * clone dummy irq_chip since PIH can't *do* anything
44290 */
44291- twl4030_irq_chip = dummy_irq_chip;
44292- twl4030_irq_chip.name = "twl4030";
44293+ pax_open_kernel();
44294+ memcpy((void *)&twl4030_irq_chip, &dummy_irq_chip, sizeof twl4030_irq_chip);
44295+ *(const char **)&twl4030_irq_chip.name = "twl4030";
44296
44297- twl4030_sih_irq_chip.irq_ack = dummy_irq_chip.irq_ack;
44298+ *(void **)&twl4030_sih_irq_chip.irq_ack = dummy_irq_chip.irq_ack;
44299+ pax_close_kernel();
44300
44301 for (i = irq_base; i < irq_end; i++) {
44302 irq_set_chip_and_handler(i, &twl4030_irq_chip,
44303diff --git a/drivers/misc/c2port/core.c b/drivers/misc/c2port/core.c
44304index 464419b..64bae8d 100644
44305--- a/drivers/misc/c2port/core.c
44306+++ b/drivers/misc/c2port/core.c
44307@@ -922,7 +922,9 @@ struct c2port_device *c2port_device_register(char *name,
44308 goto error_idr_alloc;
44309 c2dev->id = ret;
44310
44311- bin_attr_flash_data.size = ops->blocks_num * ops->block_size;
44312+ pax_open_kernel();
44313+ *(size_t *)&bin_attr_flash_data.size = ops->blocks_num * ops->block_size;
44314+ pax_close_kernel();
44315
44316 c2dev->dev = device_create(c2port_class, NULL, 0, c2dev,
44317 "c2port%d", c2dev->id);
44318diff --git a/drivers/misc/kgdbts.c b/drivers/misc/kgdbts.c
44319index 36f5d52..32311c3 100644
44320--- a/drivers/misc/kgdbts.c
44321+++ b/drivers/misc/kgdbts.c
44322@@ -834,7 +834,7 @@ static void run_plant_and_detach_test(int is_early)
44323 char before[BREAK_INSTR_SIZE];
44324 char after[BREAK_INSTR_SIZE];
44325
44326- probe_kernel_read(before, (char *)kgdbts_break_test,
44327+ probe_kernel_read(before, ktla_ktva((char *)kgdbts_break_test),
44328 BREAK_INSTR_SIZE);
44329 init_simple_test();
44330 ts.tst = plant_and_detach_test;
44331@@ -842,7 +842,7 @@ static void run_plant_and_detach_test(int is_early)
44332 /* Activate test with initial breakpoint */
44333 if (!is_early)
44334 kgdb_breakpoint();
44335- probe_kernel_read(after, (char *)kgdbts_break_test,
44336+ probe_kernel_read(after, ktla_ktva((char *)kgdbts_break_test),
44337 BREAK_INSTR_SIZE);
44338 if (memcmp(before, after, BREAK_INSTR_SIZE)) {
44339 printk(KERN_CRIT "kgdbts: ERROR kgdb corrupted memory\n");
44340diff --git a/drivers/misc/lis3lv02d/lis3lv02d.c b/drivers/misc/lis3lv02d/lis3lv02d.c
44341index 036effe..b3a6336 100644
44342--- a/drivers/misc/lis3lv02d/lis3lv02d.c
44343+++ b/drivers/misc/lis3lv02d/lis3lv02d.c
44344@@ -498,7 +498,7 @@ static irqreturn_t lis302dl_interrupt(int irq, void *data)
44345 * the lid is closed. This leads to interrupts as soon as a little move
44346 * is done.
44347 */
44348- atomic_inc(&lis3->count);
44349+ atomic_inc_unchecked(&lis3->count);
44350
44351 wake_up_interruptible(&lis3->misc_wait);
44352 kill_fasync(&lis3->async_queue, SIGIO, POLL_IN);
44353@@ -584,7 +584,7 @@ static int lis3lv02d_misc_open(struct inode *inode, struct file *file)
44354 if (lis3->pm_dev)
44355 pm_runtime_get_sync(lis3->pm_dev);
44356
44357- atomic_set(&lis3->count, 0);
44358+ atomic_set_unchecked(&lis3->count, 0);
44359 return 0;
44360 }
44361
44362@@ -616,7 +616,7 @@ static ssize_t lis3lv02d_misc_read(struct file *file, char __user *buf,
44363 add_wait_queue(&lis3->misc_wait, &wait);
44364 while (true) {
44365 set_current_state(TASK_INTERRUPTIBLE);
44366- data = atomic_xchg(&lis3->count, 0);
44367+ data = atomic_xchg_unchecked(&lis3->count, 0);
44368 if (data)
44369 break;
44370
44371@@ -657,7 +657,7 @@ static unsigned int lis3lv02d_misc_poll(struct file *file, poll_table *wait)
44372 struct lis3lv02d, miscdev);
44373
44374 poll_wait(file, &lis3->misc_wait, wait);
44375- if (atomic_read(&lis3->count))
44376+ if (atomic_read_unchecked(&lis3->count))
44377 return POLLIN | POLLRDNORM;
44378 return 0;
44379 }
44380diff --git a/drivers/misc/lis3lv02d/lis3lv02d.h b/drivers/misc/lis3lv02d/lis3lv02d.h
44381index c439c82..1f20f57 100644
44382--- a/drivers/misc/lis3lv02d/lis3lv02d.h
44383+++ b/drivers/misc/lis3lv02d/lis3lv02d.h
44384@@ -297,7 +297,7 @@ struct lis3lv02d {
44385 struct input_polled_dev *idev; /* input device */
44386 struct platform_device *pdev; /* platform device */
44387 struct regulator_bulk_data regulators[2];
44388- atomic_t count; /* interrupt count after last read */
44389+ atomic_unchecked_t count; /* interrupt count after last read */
44390 union axis_conversion ac; /* hw -> logical axis */
44391 int mapped_btns[3];
44392
44393diff --git a/drivers/misc/sgi-gru/gruhandles.c b/drivers/misc/sgi-gru/gruhandles.c
44394index 2f30bad..c4c13d0 100644
44395--- a/drivers/misc/sgi-gru/gruhandles.c
44396+++ b/drivers/misc/sgi-gru/gruhandles.c
44397@@ -44,8 +44,8 @@ static void update_mcs_stats(enum mcs_op op, unsigned long clks)
44398 unsigned long nsec;
44399
44400 nsec = CLKS2NSEC(clks);
44401- atomic_long_inc(&mcs_op_statistics[op].count);
44402- atomic_long_add(nsec, &mcs_op_statistics[op].total);
44403+ atomic_long_inc_unchecked(&mcs_op_statistics[op].count);
44404+ atomic_long_add_unchecked(nsec, &mcs_op_statistics[op].total);
44405 if (mcs_op_statistics[op].max < nsec)
44406 mcs_op_statistics[op].max = nsec;
44407 }
44408diff --git a/drivers/misc/sgi-gru/gruprocfs.c b/drivers/misc/sgi-gru/gruprocfs.c
44409index 4f76359..cdfcb2e 100644
44410--- a/drivers/misc/sgi-gru/gruprocfs.c
44411+++ b/drivers/misc/sgi-gru/gruprocfs.c
44412@@ -32,9 +32,9 @@
44413
44414 #define printstat(s, f) printstat_val(s, &gru_stats.f, #f)
44415
44416-static void printstat_val(struct seq_file *s, atomic_long_t *v, char *id)
44417+static void printstat_val(struct seq_file *s, atomic_long_unchecked_t *v, char *id)
44418 {
44419- unsigned long val = atomic_long_read(v);
44420+ unsigned long val = atomic_long_read_unchecked(v);
44421
44422 seq_printf(s, "%16lu %s\n", val, id);
44423 }
44424@@ -134,8 +134,8 @@ static int mcs_statistics_show(struct seq_file *s, void *p)
44425
44426 seq_printf(s, "%-20s%12s%12s%12s\n", "#id", "count", "aver-clks", "max-clks");
44427 for (op = 0; op < mcsop_last; op++) {
44428- count = atomic_long_read(&mcs_op_statistics[op].count);
44429- total = atomic_long_read(&mcs_op_statistics[op].total);
44430+ count = atomic_long_read_unchecked(&mcs_op_statistics[op].count);
44431+ total = atomic_long_read_unchecked(&mcs_op_statistics[op].total);
44432 max = mcs_op_statistics[op].max;
44433 seq_printf(s, "%-20s%12ld%12ld%12ld\n", id[op], count,
44434 count ? total / count : 0, max);
44435diff --git a/drivers/misc/sgi-gru/grutables.h b/drivers/misc/sgi-gru/grutables.h
44436index 5c3ce24..4915ccb 100644
44437--- a/drivers/misc/sgi-gru/grutables.h
44438+++ b/drivers/misc/sgi-gru/grutables.h
44439@@ -167,82 +167,82 @@ extern unsigned int gru_max_gids;
44440 * GRU statistics.
44441 */
44442 struct gru_stats_s {
44443- atomic_long_t vdata_alloc;
44444- atomic_long_t vdata_free;
44445- atomic_long_t gts_alloc;
44446- atomic_long_t gts_free;
44447- atomic_long_t gms_alloc;
44448- atomic_long_t gms_free;
44449- atomic_long_t gts_double_allocate;
44450- atomic_long_t assign_context;
44451- atomic_long_t assign_context_failed;
44452- atomic_long_t free_context;
44453- atomic_long_t load_user_context;
44454- atomic_long_t load_kernel_context;
44455- atomic_long_t lock_kernel_context;
44456- atomic_long_t unlock_kernel_context;
44457- atomic_long_t steal_user_context;
44458- atomic_long_t steal_kernel_context;
44459- atomic_long_t steal_context_failed;
44460- atomic_long_t nopfn;
44461- atomic_long_t asid_new;
44462- atomic_long_t asid_next;
44463- atomic_long_t asid_wrap;
44464- atomic_long_t asid_reuse;
44465- atomic_long_t intr;
44466- atomic_long_t intr_cbr;
44467- atomic_long_t intr_tfh;
44468- atomic_long_t intr_spurious;
44469- atomic_long_t intr_mm_lock_failed;
44470- atomic_long_t call_os;
44471- atomic_long_t call_os_wait_queue;
44472- atomic_long_t user_flush_tlb;
44473- atomic_long_t user_unload_context;
44474- atomic_long_t user_exception;
44475- atomic_long_t set_context_option;
44476- atomic_long_t check_context_retarget_intr;
44477- atomic_long_t check_context_unload;
44478- atomic_long_t tlb_dropin;
44479- atomic_long_t tlb_preload_page;
44480- atomic_long_t tlb_dropin_fail_no_asid;
44481- atomic_long_t tlb_dropin_fail_upm;
44482- atomic_long_t tlb_dropin_fail_invalid;
44483- atomic_long_t tlb_dropin_fail_range_active;
44484- atomic_long_t tlb_dropin_fail_idle;
44485- atomic_long_t tlb_dropin_fail_fmm;
44486- atomic_long_t tlb_dropin_fail_no_exception;
44487- atomic_long_t tfh_stale_on_fault;
44488- atomic_long_t mmu_invalidate_range;
44489- atomic_long_t mmu_invalidate_page;
44490- atomic_long_t flush_tlb;
44491- atomic_long_t flush_tlb_gru;
44492- atomic_long_t flush_tlb_gru_tgh;
44493- atomic_long_t flush_tlb_gru_zero_asid;
44494+ atomic_long_unchecked_t vdata_alloc;
44495+ atomic_long_unchecked_t vdata_free;
44496+ atomic_long_unchecked_t gts_alloc;
44497+ atomic_long_unchecked_t gts_free;
44498+ atomic_long_unchecked_t gms_alloc;
44499+ atomic_long_unchecked_t gms_free;
44500+ atomic_long_unchecked_t gts_double_allocate;
44501+ atomic_long_unchecked_t assign_context;
44502+ atomic_long_unchecked_t assign_context_failed;
44503+ atomic_long_unchecked_t free_context;
44504+ atomic_long_unchecked_t load_user_context;
44505+ atomic_long_unchecked_t load_kernel_context;
44506+ atomic_long_unchecked_t lock_kernel_context;
44507+ atomic_long_unchecked_t unlock_kernel_context;
44508+ atomic_long_unchecked_t steal_user_context;
44509+ atomic_long_unchecked_t steal_kernel_context;
44510+ atomic_long_unchecked_t steal_context_failed;
44511+ atomic_long_unchecked_t nopfn;
44512+ atomic_long_unchecked_t asid_new;
44513+ atomic_long_unchecked_t asid_next;
44514+ atomic_long_unchecked_t asid_wrap;
44515+ atomic_long_unchecked_t asid_reuse;
44516+ atomic_long_unchecked_t intr;
44517+ atomic_long_unchecked_t intr_cbr;
44518+ atomic_long_unchecked_t intr_tfh;
44519+ atomic_long_unchecked_t intr_spurious;
44520+ atomic_long_unchecked_t intr_mm_lock_failed;
44521+ atomic_long_unchecked_t call_os;
44522+ atomic_long_unchecked_t call_os_wait_queue;
44523+ atomic_long_unchecked_t user_flush_tlb;
44524+ atomic_long_unchecked_t user_unload_context;
44525+ atomic_long_unchecked_t user_exception;
44526+ atomic_long_unchecked_t set_context_option;
44527+ atomic_long_unchecked_t check_context_retarget_intr;
44528+ atomic_long_unchecked_t check_context_unload;
44529+ atomic_long_unchecked_t tlb_dropin;
44530+ atomic_long_unchecked_t tlb_preload_page;
44531+ atomic_long_unchecked_t tlb_dropin_fail_no_asid;
44532+ atomic_long_unchecked_t tlb_dropin_fail_upm;
44533+ atomic_long_unchecked_t tlb_dropin_fail_invalid;
44534+ atomic_long_unchecked_t tlb_dropin_fail_range_active;
44535+ atomic_long_unchecked_t tlb_dropin_fail_idle;
44536+ atomic_long_unchecked_t tlb_dropin_fail_fmm;
44537+ atomic_long_unchecked_t tlb_dropin_fail_no_exception;
44538+ atomic_long_unchecked_t tfh_stale_on_fault;
44539+ atomic_long_unchecked_t mmu_invalidate_range;
44540+ atomic_long_unchecked_t mmu_invalidate_page;
44541+ atomic_long_unchecked_t flush_tlb;
44542+ atomic_long_unchecked_t flush_tlb_gru;
44543+ atomic_long_unchecked_t flush_tlb_gru_tgh;
44544+ atomic_long_unchecked_t flush_tlb_gru_zero_asid;
44545
44546- atomic_long_t copy_gpa;
44547- atomic_long_t read_gpa;
44548+ atomic_long_unchecked_t copy_gpa;
44549+ atomic_long_unchecked_t read_gpa;
44550
44551- atomic_long_t mesq_receive;
44552- atomic_long_t mesq_receive_none;
44553- atomic_long_t mesq_send;
44554- atomic_long_t mesq_send_failed;
44555- atomic_long_t mesq_noop;
44556- atomic_long_t mesq_send_unexpected_error;
44557- atomic_long_t mesq_send_lb_overflow;
44558- atomic_long_t mesq_send_qlimit_reached;
44559- atomic_long_t mesq_send_amo_nacked;
44560- atomic_long_t mesq_send_put_nacked;
44561- atomic_long_t mesq_page_overflow;
44562- atomic_long_t mesq_qf_locked;
44563- atomic_long_t mesq_qf_noop_not_full;
44564- atomic_long_t mesq_qf_switch_head_failed;
44565- atomic_long_t mesq_qf_unexpected_error;
44566- atomic_long_t mesq_noop_unexpected_error;
44567- atomic_long_t mesq_noop_lb_overflow;
44568- atomic_long_t mesq_noop_qlimit_reached;
44569- atomic_long_t mesq_noop_amo_nacked;
44570- atomic_long_t mesq_noop_put_nacked;
44571- atomic_long_t mesq_noop_page_overflow;
44572+ atomic_long_unchecked_t mesq_receive;
44573+ atomic_long_unchecked_t mesq_receive_none;
44574+ atomic_long_unchecked_t mesq_send;
44575+ atomic_long_unchecked_t mesq_send_failed;
44576+ atomic_long_unchecked_t mesq_noop;
44577+ atomic_long_unchecked_t mesq_send_unexpected_error;
44578+ atomic_long_unchecked_t mesq_send_lb_overflow;
44579+ atomic_long_unchecked_t mesq_send_qlimit_reached;
44580+ atomic_long_unchecked_t mesq_send_amo_nacked;
44581+ atomic_long_unchecked_t mesq_send_put_nacked;
44582+ atomic_long_unchecked_t mesq_page_overflow;
44583+ atomic_long_unchecked_t mesq_qf_locked;
44584+ atomic_long_unchecked_t mesq_qf_noop_not_full;
44585+ atomic_long_unchecked_t mesq_qf_switch_head_failed;
44586+ atomic_long_unchecked_t mesq_qf_unexpected_error;
44587+ atomic_long_unchecked_t mesq_noop_unexpected_error;
44588+ atomic_long_unchecked_t mesq_noop_lb_overflow;
44589+ atomic_long_unchecked_t mesq_noop_qlimit_reached;
44590+ atomic_long_unchecked_t mesq_noop_amo_nacked;
44591+ atomic_long_unchecked_t mesq_noop_put_nacked;
44592+ atomic_long_unchecked_t mesq_noop_page_overflow;
44593
44594 };
44595
44596@@ -251,8 +251,8 @@ enum mcs_op {cchop_allocate, cchop_start, cchop_interrupt, cchop_interrupt_sync,
44597 tghop_invalidate, mcsop_last};
44598
44599 struct mcs_op_statistic {
44600- atomic_long_t count;
44601- atomic_long_t total;
44602+ atomic_long_unchecked_t count;
44603+ atomic_long_unchecked_t total;
44604 unsigned long max;
44605 };
44606
44607@@ -275,7 +275,7 @@ extern struct mcs_op_statistic mcs_op_statistics[mcsop_last];
44608
44609 #define STAT(id) do { \
44610 if (gru_options & OPT_STATS) \
44611- atomic_long_inc(&gru_stats.id); \
44612+ atomic_long_inc_unchecked(&gru_stats.id); \
44613 } while (0)
44614
44615 #ifdef CONFIG_SGI_GRU_DEBUG
44616diff --git a/drivers/misc/sgi-xp/xp.h b/drivers/misc/sgi-xp/xp.h
44617index c862cd4..0d176fe 100644
44618--- a/drivers/misc/sgi-xp/xp.h
44619+++ b/drivers/misc/sgi-xp/xp.h
44620@@ -288,7 +288,7 @@ struct xpc_interface {
44621 xpc_notify_func, void *);
44622 void (*received) (short, int, void *);
44623 enum xp_retval (*partid_to_nasids) (short, void *);
44624-};
44625+} __no_const;
44626
44627 extern struct xpc_interface xpc_interface;
44628
44629diff --git a/drivers/misc/sgi-xp/xp_main.c b/drivers/misc/sgi-xp/xp_main.c
44630index 01be66d..e3a0c7e 100644
44631--- a/drivers/misc/sgi-xp/xp_main.c
44632+++ b/drivers/misc/sgi-xp/xp_main.c
44633@@ -78,13 +78,13 @@ xpc_notloaded(void)
44634 }
44635
44636 struct xpc_interface xpc_interface = {
44637- (void (*)(int))xpc_notloaded,
44638- (void (*)(int))xpc_notloaded,
44639- (enum xp_retval(*)(short, int, u32, void *, u16))xpc_notloaded,
44640- (enum xp_retval(*)(short, int, u32, void *, u16, xpc_notify_func,
44641+ .connect = (void (*)(int))xpc_notloaded,
44642+ .disconnect = (void (*)(int))xpc_notloaded,
44643+ .send = (enum xp_retval(*)(short, int, u32, void *, u16))xpc_notloaded,
44644+ .send_notify = (enum xp_retval(*)(short, int, u32, void *, u16, xpc_notify_func,
44645 void *))xpc_notloaded,
44646- (void (*)(short, int, void *))xpc_notloaded,
44647- (enum xp_retval(*)(short, void *))xpc_notloaded
44648+ .received = (void (*)(short, int, void *))xpc_notloaded,
44649+ .partid_to_nasids = (enum xp_retval(*)(short, void *))xpc_notloaded
44650 };
44651 EXPORT_SYMBOL_GPL(xpc_interface);
44652
44653diff --git a/drivers/misc/sgi-xp/xpc.h b/drivers/misc/sgi-xp/xpc.h
44654index b94d5f7..7f494c5 100644
44655--- a/drivers/misc/sgi-xp/xpc.h
44656+++ b/drivers/misc/sgi-xp/xpc.h
44657@@ -835,6 +835,7 @@ struct xpc_arch_operations {
44658 void (*received_payload) (struct xpc_channel *, void *);
44659 void (*notify_senders_of_disconnect) (struct xpc_channel *);
44660 };
44661+typedef struct xpc_arch_operations __no_const xpc_arch_operations_no_const;
44662
44663 /* struct xpc_partition act_state values (for XPC HB) */
44664
44665@@ -876,7 +877,7 @@ extern struct xpc_registration xpc_registrations[];
44666 /* found in xpc_main.c */
44667 extern struct device *xpc_part;
44668 extern struct device *xpc_chan;
44669-extern struct xpc_arch_operations xpc_arch_ops;
44670+extern xpc_arch_operations_no_const xpc_arch_ops;
44671 extern int xpc_disengage_timelimit;
44672 extern int xpc_disengage_timedout;
44673 extern int xpc_activate_IRQ_rcvd;
44674diff --git a/drivers/misc/sgi-xp/xpc_main.c b/drivers/misc/sgi-xp/xpc_main.c
44675index 82dc574..8539ab2 100644
44676--- a/drivers/misc/sgi-xp/xpc_main.c
44677+++ b/drivers/misc/sgi-xp/xpc_main.c
44678@@ -166,7 +166,7 @@ static struct notifier_block xpc_die_notifier = {
44679 .notifier_call = xpc_system_die,
44680 };
44681
44682-struct xpc_arch_operations xpc_arch_ops;
44683+xpc_arch_operations_no_const xpc_arch_ops;
44684
44685 /*
44686 * Timer function to enforce the timelimit on the partition disengage.
44687@@ -1210,7 +1210,7 @@ xpc_system_die(struct notifier_block *nb, unsigned long event, void *_die_args)
44688
44689 if (((die_args->trapnr == X86_TRAP_MF) ||
44690 (die_args->trapnr == X86_TRAP_XF)) &&
44691- !user_mode_vm(die_args->regs))
44692+ !user_mode(die_args->regs))
44693 xpc_die_deactivate();
44694
44695 break;
44696diff --git a/drivers/mmc/core/mmc_ops.c b/drivers/mmc/core/mmc_ops.c
44697index ef18348..1b53cf0 100644
44698--- a/drivers/mmc/core/mmc_ops.c
44699+++ b/drivers/mmc/core/mmc_ops.c
44700@@ -213,7 +213,7 @@ mmc_send_cxd_data(struct mmc_card *card, struct mmc_host *host,
44701 void *data_buf;
44702 int is_on_stack;
44703
44704- is_on_stack = object_is_on_stack(buf);
44705+ is_on_stack = object_starts_on_stack(buf);
44706 if (is_on_stack) {
44707 /*
44708 * dma onto stack is unsafe/nonportable, but callers to this
44709diff --git a/drivers/mmc/host/dw_mmc.h b/drivers/mmc/host/dw_mmc.h
44710index 81b2994..dce857e 100644
44711--- a/drivers/mmc/host/dw_mmc.h
44712+++ b/drivers/mmc/host/dw_mmc.h
44713@@ -203,5 +203,5 @@ struct dw_mci_drv_data {
44714 void (*prepare_command)(struct dw_mci *host, u32 *cmdr);
44715 void (*set_ios)(struct dw_mci *host, struct mmc_ios *ios);
44716 int (*parse_dt)(struct dw_mci *host);
44717-};
44718+} __do_const;
44719 #endif /* _DW_MMC_H_ */
44720diff --git a/drivers/mmc/host/mmci.c b/drivers/mmc/host/mmci.c
44721index c3785ed..1984c44 100644
44722--- a/drivers/mmc/host/mmci.c
44723+++ b/drivers/mmc/host/mmci.c
44724@@ -1482,7 +1482,9 @@ static int mmci_probe(struct amba_device *dev,
44725 }
44726
44727 if (variant->busy_detect) {
44728- mmci_ops.card_busy = mmci_card_busy;
44729+ pax_open_kernel();
44730+ *(void **)&mmci_ops.card_busy = mmci_card_busy;
44731+ pax_close_kernel();
44732 mmci_write_datactrlreg(host, MCI_ST_DPSM_BUSYMODE);
44733 }
44734
44735diff --git a/drivers/mmc/host/sdhci-s3c.c b/drivers/mmc/host/sdhci-s3c.c
44736index 6debda9..2ba7427 100644
44737--- a/drivers/mmc/host/sdhci-s3c.c
44738+++ b/drivers/mmc/host/sdhci-s3c.c
44739@@ -668,9 +668,11 @@ static int sdhci_s3c_probe(struct platform_device *pdev)
44740 * we can use overriding functions instead of default.
44741 */
44742 if (host->quirks & SDHCI_QUIRK_NONSTANDARD_CLOCK) {
44743- sdhci_s3c_ops.set_clock = sdhci_cmu_set_clock;
44744- sdhci_s3c_ops.get_min_clock = sdhci_cmu_get_min_clock;
44745- sdhci_s3c_ops.get_max_clock = sdhci_cmu_get_max_clock;
44746+ pax_open_kernel();
44747+ *(void **)&sdhci_s3c_ops.set_clock = sdhci_cmu_set_clock;
44748+ *(void **)&sdhci_s3c_ops.get_min_clock = sdhci_cmu_get_min_clock;
44749+ *(void **)&sdhci_s3c_ops.get_max_clock = sdhci_cmu_get_max_clock;
44750+ pax_close_kernel();
44751 }
44752
44753 /* It supports additional host capabilities if needed */
44754diff --git a/drivers/mtd/chips/cfi_cmdset_0020.c b/drivers/mtd/chips/cfi_cmdset_0020.c
44755index 096993f..f02c23b 100644
44756--- a/drivers/mtd/chips/cfi_cmdset_0020.c
44757+++ b/drivers/mtd/chips/cfi_cmdset_0020.c
44758@@ -669,7 +669,7 @@ cfi_staa_writev(struct mtd_info *mtd, const struct kvec *vecs,
44759 size_t totlen = 0, thislen;
44760 int ret = 0;
44761 size_t buflen = 0;
44762- static char *buffer;
44763+ char *buffer;
44764
44765 if (!ECCBUF_SIZE) {
44766 /* We should fall back to a general writev implementation.
44767diff --git a/drivers/mtd/nand/denali.c b/drivers/mtd/nand/denali.c
44768index 2ed2bb3..2d0b82e 100644
44769--- a/drivers/mtd/nand/denali.c
44770+++ b/drivers/mtd/nand/denali.c
44771@@ -24,6 +24,7 @@
44772 #include <linux/slab.h>
44773 #include <linux/mtd/mtd.h>
44774 #include <linux/module.h>
44775+#include <linux/slab.h>
44776
44777 #include "denali.h"
44778
44779diff --git a/drivers/mtd/nftlmount.c b/drivers/mtd/nftlmount.c
44780index 51b9d6a..52af9a7 100644
44781--- a/drivers/mtd/nftlmount.c
44782+++ b/drivers/mtd/nftlmount.c
44783@@ -24,6 +24,7 @@
44784 #include <asm/errno.h>
44785 #include <linux/delay.h>
44786 #include <linux/slab.h>
44787+#include <linux/sched.h>
44788 #include <linux/mtd/mtd.h>
44789 #include <linux/mtd/nand.h>
44790 #include <linux/mtd/nftl.h>
44791diff --git a/drivers/mtd/sm_ftl.c b/drivers/mtd/sm_ftl.c
44792index 4b8e895..6b3c498 100644
44793--- a/drivers/mtd/sm_ftl.c
44794+++ b/drivers/mtd/sm_ftl.c
44795@@ -56,7 +56,7 @@ static ssize_t sm_attr_show(struct device *dev, struct device_attribute *attr,
44796 #define SM_CIS_VENDOR_OFFSET 0x59
44797 static struct attribute_group *sm_create_sysfs_attributes(struct sm_ftl *ftl)
44798 {
44799- struct attribute_group *attr_group;
44800+ attribute_group_no_const *attr_group;
44801 struct attribute **attributes;
44802 struct sm_sysfs_attribute *vendor_attribute;
44803
44804diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_main.c
44805index dd8057d..22aaf36 100644
44806--- a/drivers/net/bonding/bond_main.c
44807+++ b/drivers/net/bonding/bond_main.c
44808@@ -4511,7 +4511,7 @@ static unsigned int bond_get_num_tx_queues(void)
44809 return tx_queues;
44810 }
44811
44812-static struct rtnl_link_ops bond_link_ops __read_mostly = {
44813+static struct rtnl_link_ops bond_link_ops = {
44814 .kind = "bond",
44815 .priv_size = sizeof(struct bonding),
44816 .setup = bond_setup,
44817@@ -4636,8 +4636,8 @@ static void __exit bonding_exit(void)
44818
44819 bond_destroy_debugfs();
44820
44821- rtnl_link_unregister(&bond_link_ops);
44822 unregister_pernet_subsys(&bond_net_ops);
44823+ rtnl_link_unregister(&bond_link_ops);
44824
44825 #ifdef CONFIG_NET_POLL_CONTROLLER
44826 /*
44827diff --git a/drivers/net/ethernet/8390/ax88796.c b/drivers/net/ethernet/8390/ax88796.c
44828index f92f001..0b2f9bf 100644
44829--- a/drivers/net/ethernet/8390/ax88796.c
44830+++ b/drivers/net/ethernet/8390/ax88796.c
44831@@ -872,9 +872,11 @@ static int ax_probe(struct platform_device *pdev)
44832 if (ax->plat->reg_offsets)
44833 ei_local->reg_offset = ax->plat->reg_offsets;
44834 else {
44835+ resource_size_t _mem_size = mem_size;
44836+ do_div(_mem_size, 0x18);
44837 ei_local->reg_offset = ax->reg_offsets;
44838 for (ret = 0; ret < 0x18; ret++)
44839- ax->reg_offsets[ret] = (mem_size / 0x18) * ret;
44840+ ax->reg_offsets[ret] = _mem_size * ret;
44841 }
44842
44843 if (!request_mem_region(mem->start, mem_size, pdev->name)) {
44844diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
44845index da8fcaa..f4b5d3b 100644
44846--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
44847+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
44848@@ -1138,7 +1138,7 @@ static inline u8 bnx2x_get_path_func_num(struct bnx2x *bp)
44849 static inline void bnx2x_init_bp_objs(struct bnx2x *bp)
44850 {
44851 /* RX_MODE controlling object */
44852- bnx2x_init_rx_mode_obj(bp, &bp->rx_mode_obj);
44853+ bnx2x_init_rx_mode_obj(bp);
44854
44855 /* multicast configuration controlling object */
44856 bnx2x_init_mcast_obj(bp, &bp->mcast_obj, bp->fp->cl_id, bp->fp->cid,
44857diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
44858index 9fbeee5..5e3e37a 100644
44859--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
44860+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
44861@@ -2590,15 +2590,14 @@ int bnx2x_config_rx_mode(struct bnx2x *bp,
44862 return rc;
44863 }
44864
44865-void bnx2x_init_rx_mode_obj(struct bnx2x *bp,
44866- struct bnx2x_rx_mode_obj *o)
44867+void bnx2x_init_rx_mode_obj(struct bnx2x *bp)
44868 {
44869 if (CHIP_IS_E1x(bp)) {
44870- o->wait_comp = bnx2x_empty_rx_mode_wait;
44871- o->config_rx_mode = bnx2x_set_rx_mode_e1x;
44872+ bp->rx_mode_obj.wait_comp = bnx2x_empty_rx_mode_wait;
44873+ bp->rx_mode_obj.config_rx_mode = bnx2x_set_rx_mode_e1x;
44874 } else {
44875- o->wait_comp = bnx2x_wait_rx_mode_comp_e2;
44876- o->config_rx_mode = bnx2x_set_rx_mode_e2;
44877+ bp->rx_mode_obj.wait_comp = bnx2x_wait_rx_mode_comp_e2;
44878+ bp->rx_mode_obj.config_rx_mode = bnx2x_set_rx_mode_e2;
44879 }
44880 }
44881
44882diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
44883index 658f4e3..15074a6 100644
44884--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
44885+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
44886@@ -1325,8 +1325,7 @@ int bnx2x_vlan_mac_move(struct bnx2x *bp,
44887
44888 /********************* RX MODE ****************/
44889
44890-void bnx2x_init_rx_mode_obj(struct bnx2x *bp,
44891- struct bnx2x_rx_mode_obj *o);
44892+void bnx2x_init_rx_mode_obj(struct bnx2x *bp);
44893
44894 /**
44895 * bnx2x_config_rx_mode - Send and RX_MODE ramrod according to the provided parameters.
44896diff --git a/drivers/net/ethernet/broadcom/tg3.h b/drivers/net/ethernet/broadcom/tg3.h
44897index 7025780..e55a71c 100644
44898--- a/drivers/net/ethernet/broadcom/tg3.h
44899+++ b/drivers/net/ethernet/broadcom/tg3.h
44900@@ -147,6 +147,7 @@
44901 #define CHIPREV_ID_5750_A0 0x4000
44902 #define CHIPREV_ID_5750_A1 0x4001
44903 #define CHIPREV_ID_5750_A3 0x4003
44904+#define CHIPREV_ID_5750_C1 0x4201
44905 #define CHIPREV_ID_5750_C2 0x4202
44906 #define CHIPREV_ID_5752_A0_HW 0x5000
44907 #define CHIPREV_ID_5752_A0 0x6000
44908diff --git a/drivers/net/ethernet/brocade/bna/bna_enet.c b/drivers/net/ethernet/brocade/bna/bna_enet.c
44909index 3ca77fa..fcc015f 100644
44910--- a/drivers/net/ethernet/brocade/bna/bna_enet.c
44911+++ b/drivers/net/ethernet/brocade/bna/bna_enet.c
44912@@ -1690,10 +1690,10 @@ bna_cb_ioceth_reset(void *arg)
44913 }
44914
44915 static struct bfa_ioc_cbfn bna_ioceth_cbfn = {
44916- bna_cb_ioceth_enable,
44917- bna_cb_ioceth_disable,
44918- bna_cb_ioceth_hbfail,
44919- bna_cb_ioceth_reset
44920+ .enable_cbfn = bna_cb_ioceth_enable,
44921+ .disable_cbfn = bna_cb_ioceth_disable,
44922+ .hbfail_cbfn = bna_cb_ioceth_hbfail,
44923+ .reset_cbfn = bna_cb_ioceth_reset
44924 };
44925
44926 static void bna_attr_init(struct bna_ioceth *ioceth)
44927diff --git a/drivers/net/ethernet/chelsio/cxgb3/l2t.h b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
44928index 8cffcdf..aadf043 100644
44929--- a/drivers/net/ethernet/chelsio/cxgb3/l2t.h
44930+++ b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
44931@@ -87,7 +87,7 @@ typedef void (*arp_failure_handler_func)(struct t3cdev * dev,
44932 */
44933 struct l2t_skb_cb {
44934 arp_failure_handler_func arp_failure_handler;
44935-};
44936+} __no_const;
44937
44938 #define L2T_SKB_CB(skb) ((struct l2t_skb_cb *)(skb)->cb)
44939
44940diff --git a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c
44941index c73cabd..cd278b1 100644
44942--- a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c
44943+++ b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c
44944@@ -2186,7 +2186,7 @@ static void get_regs(struct net_device *dev, struct ethtool_regs *regs,
44945
44946 int i;
44947 struct adapter *ap = netdev2adap(dev);
44948- static const unsigned int *reg_ranges;
44949+ const unsigned int *reg_ranges;
44950 int arr_size = 0, buf_size = 0;
44951
44952 if (is_t4(ap->chip)) {
44953diff --git a/drivers/net/ethernet/dec/tulip/de4x5.c b/drivers/net/ethernet/dec/tulip/de4x5.c
44954index 263b92c..f05134b 100644
44955--- a/drivers/net/ethernet/dec/tulip/de4x5.c
44956+++ b/drivers/net/ethernet/dec/tulip/de4x5.c
44957@@ -5388,7 +5388,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
44958 for (i=0; i<ETH_ALEN; i++) {
44959 tmp.addr[i] = dev->dev_addr[i];
44960 }
44961- if (copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
44962+ if (ioc->len > sizeof tmp.addr || copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
44963 break;
44964
44965 case DE4X5_SET_HWADDR: /* Set the hardware address */
44966@@ -5428,7 +5428,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
44967 spin_lock_irqsave(&lp->lock, flags);
44968 memcpy(&statbuf, &lp->pktStats, ioc->len);
44969 spin_unlock_irqrestore(&lp->lock, flags);
44970- if (copy_to_user(ioc->data, &statbuf, ioc->len))
44971+ if (ioc->len > sizeof statbuf || copy_to_user(ioc->data, &statbuf, ioc->len))
44972 return -EFAULT;
44973 break;
44974 }
44975diff --git a/drivers/net/ethernet/emulex/benet/be_main.c b/drivers/net/ethernet/emulex/benet/be_main.c
44976index 2c38cc4..0323f6e 100644
44977--- a/drivers/net/ethernet/emulex/benet/be_main.c
44978+++ b/drivers/net/ethernet/emulex/benet/be_main.c
44979@@ -470,7 +470,7 @@ static void accumulate_16bit_val(u32 *acc, u16 val)
44980
44981 if (wrapped)
44982 newacc += 65536;
44983- ACCESS_ONCE(*acc) = newacc;
44984+ ACCESS_ONCE_RW(*acc) = newacc;
44985 }
44986
44987 static void populate_erx_stats(struct be_adapter *adapter,
44988diff --git a/drivers/net/ethernet/faraday/ftgmac100.c b/drivers/net/ethernet/faraday/ftgmac100.c
44989index 212f44b..fb69959 100644
44990--- a/drivers/net/ethernet/faraday/ftgmac100.c
44991+++ b/drivers/net/ethernet/faraday/ftgmac100.c
44992@@ -31,6 +31,8 @@
44993 #include <linux/netdevice.h>
44994 #include <linux/phy.h>
44995 #include <linux/platform_device.h>
44996+#include <linux/interrupt.h>
44997+#include <linux/irqreturn.h>
44998 #include <net/ip.h>
44999
45000 #include "ftgmac100.h"
45001diff --git a/drivers/net/ethernet/faraday/ftmac100.c b/drivers/net/ethernet/faraday/ftmac100.c
45002index 8be5b40..081bc1b 100644
45003--- a/drivers/net/ethernet/faraday/ftmac100.c
45004+++ b/drivers/net/ethernet/faraday/ftmac100.c
45005@@ -31,6 +31,8 @@
45006 #include <linux/module.h>
45007 #include <linux/netdevice.h>
45008 #include <linux/platform_device.h>
45009+#include <linux/interrupt.h>
45010+#include <linux/irqreturn.h>
45011
45012 #include "ftmac100.h"
45013
45014diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
45015index 5184e2a..acb28c3 100644
45016--- a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
45017+++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
45018@@ -776,7 +776,7 @@ void ixgbe_ptp_start_cyclecounter(struct ixgbe_adapter *adapter)
45019 }
45020
45021 /* update the base incval used to calculate frequency adjustment */
45022- ACCESS_ONCE(adapter->base_incval) = incval;
45023+ ACCESS_ONCE_RW(adapter->base_incval) = incval;
45024 smp_mb();
45025
45026 /* need lock to prevent incorrect read while modifying cyclecounter */
45027diff --git a/drivers/net/ethernet/neterion/vxge/vxge-config.c b/drivers/net/ethernet/neterion/vxge/vxge-config.c
45028index fbe5363..266b4e3 100644
45029--- a/drivers/net/ethernet/neterion/vxge/vxge-config.c
45030+++ b/drivers/net/ethernet/neterion/vxge/vxge-config.c
45031@@ -3461,7 +3461,10 @@ __vxge_hw_fifo_create(struct __vxge_hw_vpath_handle *vp,
45032 struct __vxge_hw_fifo *fifo;
45033 struct vxge_hw_fifo_config *config;
45034 u32 txdl_size, txdl_per_memblock;
45035- struct vxge_hw_mempool_cbs fifo_mp_callback;
45036+ static struct vxge_hw_mempool_cbs fifo_mp_callback = {
45037+ .item_func_alloc = __vxge_hw_fifo_mempool_item_alloc,
45038+ };
45039+
45040 struct __vxge_hw_virtualpath *vpath;
45041
45042 if ((vp == NULL) || (attr == NULL)) {
45043@@ -3544,8 +3547,6 @@ __vxge_hw_fifo_create(struct __vxge_hw_vpath_handle *vp,
45044 goto exit;
45045 }
45046
45047- fifo_mp_callback.item_func_alloc = __vxge_hw_fifo_mempool_item_alloc;
45048-
45049 fifo->mempool =
45050 __vxge_hw_mempool_create(vpath->hldev,
45051 fifo->config->memblock_size,
45052diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c
45053index f09e787..f3916a8 100644
45054--- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c
45055+++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c
45056@@ -2055,7 +2055,9 @@ int qlcnic_83xx_configure_opmode(struct qlcnic_adapter *adapter)
45057
45058 } else if (ret == QLC_83XX_DEFAULT_OPMODE) {
45059 ahw->nic_mode = QLC_83XX_DEFAULT_MODE;
45060- adapter->nic_ops->init_driver = qlcnic_83xx_init_default_driver;
45061+ pax_open_kernel();
45062+ *(void **)&adapter->nic_ops->init_driver = qlcnic_83xx_init_default_driver;
45063+ pax_close_kernel();
45064 ahw->idc.state_entry = qlcnic_83xx_idc_ready_state_entry;
45065 } else {
45066 return -EIO;
45067diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c
45068index 0248a4c..9648d96 100644
45069--- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c
45070+++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c
45071@@ -191,17 +191,23 @@ int qlcnic_83xx_config_vnic_opmode(struct qlcnic_adapter *adapter)
45072 case QLCNIC_NON_PRIV_FUNC:
45073 ahw->op_mode = QLCNIC_NON_PRIV_FUNC;
45074 ahw->idc.state_entry = qlcnic_83xx_idc_ready_state_entry;
45075- nic_ops->init_driver = qlcnic_83xx_init_non_privileged_vnic;
45076+ pax_open_kernel();
45077+ *(void **)&nic_ops->init_driver = qlcnic_83xx_init_non_privileged_vnic;
45078+ pax_close_kernel();
45079 break;
45080 case QLCNIC_PRIV_FUNC:
45081 ahw->op_mode = QLCNIC_PRIV_FUNC;
45082 ahw->idc.state_entry = qlcnic_83xx_idc_vnic_pf_entry;
45083- nic_ops->init_driver = qlcnic_83xx_init_privileged_vnic;
45084+ pax_open_kernel();
45085+ *(void **)&nic_ops->init_driver = qlcnic_83xx_init_privileged_vnic;
45086+ pax_close_kernel();
45087 break;
45088 case QLCNIC_MGMT_FUNC:
45089 ahw->op_mode = QLCNIC_MGMT_FUNC;
45090 ahw->idc.state_entry = qlcnic_83xx_idc_ready_state_entry;
45091- nic_ops->init_driver = qlcnic_83xx_init_mgmt_vnic;
45092+ pax_open_kernel();
45093+ *(void **)&nic_ops->init_driver = qlcnic_83xx_init_mgmt_vnic;
45094+ pax_close_kernel();
45095 break;
45096 default:
45097 dev_err(&adapter->pdev->dev, "Invalid Virtual NIC opmode\n");
45098diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_minidump.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_minidump.c
45099index 1551360..ed6510f 100644
45100--- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_minidump.c
45101+++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_minidump.c
45102@@ -1108,7 +1108,7 @@ int qlcnic_dump_fw(struct qlcnic_adapter *adapter)
45103 struct qlcnic_dump_entry *entry;
45104 struct qlcnic_fw_dump *fw_dump = &adapter->ahw->fw_dump;
45105 struct qlcnic_dump_template_hdr *tmpl_hdr = fw_dump->tmpl_hdr;
45106- static const struct qlcnic_dump_operations *fw_dump_ops;
45107+ const struct qlcnic_dump_operations *fw_dump_ops;
45108 struct device *dev = &adapter->pdev->dev;
45109 struct qlcnic_hardware_context *ahw;
45110 void *temp_buffer;
45111diff --git a/drivers/net/ethernet/realtek/r8169.c b/drivers/net/ethernet/realtek/r8169.c
45112index fb3f8dc..9d2ff38 100644
45113--- a/drivers/net/ethernet/realtek/r8169.c
45114+++ b/drivers/net/ethernet/realtek/r8169.c
45115@@ -759,22 +759,22 @@ struct rtl8169_private {
45116 struct mdio_ops {
45117 void (*write)(struct rtl8169_private *, int, int);
45118 int (*read)(struct rtl8169_private *, int);
45119- } mdio_ops;
45120+ } __no_const mdio_ops;
45121
45122 struct pll_power_ops {
45123 void (*down)(struct rtl8169_private *);
45124 void (*up)(struct rtl8169_private *);
45125- } pll_power_ops;
45126+ } __no_const pll_power_ops;
45127
45128 struct jumbo_ops {
45129 void (*enable)(struct rtl8169_private *);
45130 void (*disable)(struct rtl8169_private *);
45131- } jumbo_ops;
45132+ } __no_const jumbo_ops;
45133
45134 struct csi_ops {
45135 void (*write)(struct rtl8169_private *, int, int);
45136 u32 (*read)(struct rtl8169_private *, int);
45137- } csi_ops;
45138+ } __no_const csi_ops;
45139
45140 int (*set_speed)(struct net_device *, u8 aneg, u16 sp, u8 dpx, u32 adv);
45141 int (*get_settings)(struct net_device *, struct ethtool_cmd *);
45142diff --git a/drivers/net/ethernet/sfc/ptp.c b/drivers/net/ethernet/sfc/ptp.c
45143index 3dd39dc..85efa46 100644
45144--- a/drivers/net/ethernet/sfc/ptp.c
45145+++ b/drivers/net/ethernet/sfc/ptp.c
45146@@ -541,7 +541,7 @@ static int efx_ptp_synchronize(struct efx_nic *efx, unsigned int num_readings)
45147 ptp->start.dma_addr);
45148
45149 /* Clear flag that signals MC ready */
45150- ACCESS_ONCE(*start) = 0;
45151+ ACCESS_ONCE_RW(*start) = 0;
45152 rc = efx_mcdi_rpc_start(efx, MC_CMD_PTP, synch_buf,
45153 MC_CMD_PTP_IN_SYNCHRONIZE_LEN);
45154 EFX_BUG_ON_PARANOID(rc);
45155diff --git a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
45156index 50617c5..b13724c 100644
45157--- a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
45158+++ b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
45159@@ -140,8 +140,8 @@ void dwmac_mmc_ctrl(void __iomem *ioaddr, unsigned int mode)
45160
45161 writel(value, ioaddr + MMC_CNTRL);
45162
45163- pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
45164- MMC_CNTRL, value);
45165+// pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
45166+// MMC_CNTRL, value);
45167 }
45168
45169 /* To mask all all interrupts.*/
45170diff --git a/drivers/net/hyperv/hyperv_net.h b/drivers/net/hyperv/hyperv_net.h
45171index e6fe0d8..2b7d752 100644
45172--- a/drivers/net/hyperv/hyperv_net.h
45173+++ b/drivers/net/hyperv/hyperv_net.h
45174@@ -101,7 +101,7 @@ struct rndis_device {
45175
45176 enum rndis_device_state state;
45177 bool link_state;
45178- atomic_t new_req_id;
45179+ atomic_unchecked_t new_req_id;
45180
45181 spinlock_t request_lock;
45182 struct list_head req_list;
45183diff --git a/drivers/net/hyperv/rndis_filter.c b/drivers/net/hyperv/rndis_filter.c
45184index 0775f0a..d4fb316 100644
45185--- a/drivers/net/hyperv/rndis_filter.c
45186+++ b/drivers/net/hyperv/rndis_filter.c
45187@@ -104,7 +104,7 @@ static struct rndis_request *get_rndis_request(struct rndis_device *dev,
45188 * template
45189 */
45190 set = &rndis_msg->msg.set_req;
45191- set->req_id = atomic_inc_return(&dev->new_req_id);
45192+ set->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
45193
45194 /* Add to the request list */
45195 spin_lock_irqsave(&dev->request_lock, flags);
45196@@ -752,7 +752,7 @@ static void rndis_filter_halt_device(struct rndis_device *dev)
45197
45198 /* Setup the rndis set */
45199 halt = &request->request_msg.msg.halt_req;
45200- halt->req_id = atomic_inc_return(&dev->new_req_id);
45201+ halt->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
45202
45203 /* Ignore return since this msg is optional. */
45204 rndis_filter_send_request(dev, request);
45205diff --git a/drivers/net/ieee802154/fakehard.c b/drivers/net/ieee802154/fakehard.c
45206index bf0d55e..82bcfbd1 100644
45207--- a/drivers/net/ieee802154/fakehard.c
45208+++ b/drivers/net/ieee802154/fakehard.c
45209@@ -364,7 +364,7 @@ static int ieee802154fake_probe(struct platform_device *pdev)
45210 phy->transmit_power = 0xbf;
45211
45212 dev->netdev_ops = &fake_ops;
45213- dev->ml_priv = &fake_mlme;
45214+ dev->ml_priv = (void *)&fake_mlme;
45215
45216 priv = netdev_priv(dev);
45217 priv->phy = phy;
45218diff --git a/drivers/net/macvlan.c b/drivers/net/macvlan.c
45219index 9bf46bd..bfdaa84 100644
45220--- a/drivers/net/macvlan.c
45221+++ b/drivers/net/macvlan.c
45222@@ -939,13 +939,15 @@ static const struct nla_policy macvlan_policy[IFLA_MACVLAN_MAX + 1] = {
45223 int macvlan_link_register(struct rtnl_link_ops *ops)
45224 {
45225 /* common fields */
45226- ops->priv_size = sizeof(struct macvlan_dev);
45227- ops->validate = macvlan_validate;
45228- ops->maxtype = IFLA_MACVLAN_MAX;
45229- ops->policy = macvlan_policy;
45230- ops->changelink = macvlan_changelink;
45231- ops->get_size = macvlan_get_size;
45232- ops->fill_info = macvlan_fill_info;
45233+ pax_open_kernel();
45234+ *(size_t *)&ops->priv_size = sizeof(struct macvlan_dev);
45235+ *(void **)&ops->validate = macvlan_validate;
45236+ *(int *)&ops->maxtype = IFLA_MACVLAN_MAX;
45237+ *(const void **)&ops->policy = macvlan_policy;
45238+ *(void **)&ops->changelink = macvlan_changelink;
45239+ *(void **)&ops->get_size = macvlan_get_size;
45240+ *(void **)&ops->fill_info = macvlan_fill_info;
45241+ pax_close_kernel();
45242
45243 return rtnl_link_register(ops);
45244 };
45245@@ -1001,7 +1003,7 @@ static int macvlan_device_event(struct notifier_block *unused,
45246 return NOTIFY_DONE;
45247 }
45248
45249-static struct notifier_block macvlan_notifier_block __read_mostly = {
45250+static struct notifier_block macvlan_notifier_block = {
45251 .notifier_call = macvlan_device_event,
45252 };
45253
45254diff --git a/drivers/net/macvtap.c b/drivers/net/macvtap.c
45255index 5895e4d..0343d45 100644
45256--- a/drivers/net/macvtap.c
45257+++ b/drivers/net/macvtap.c
45258@@ -1182,7 +1182,7 @@ static int macvtap_device_event(struct notifier_block *unused,
45259 return NOTIFY_DONE;
45260 }
45261
45262-static struct notifier_block macvtap_notifier_block __read_mostly = {
45263+static struct notifier_block macvtap_notifier_block = {
45264 .notifier_call = macvtap_device_event,
45265 };
45266
45267diff --git a/drivers/net/phy/mdio-bitbang.c b/drivers/net/phy/mdio-bitbang.c
45268index daec9b0..6428fcb 100644
45269--- a/drivers/net/phy/mdio-bitbang.c
45270+++ b/drivers/net/phy/mdio-bitbang.c
45271@@ -234,6 +234,7 @@ void free_mdio_bitbang(struct mii_bus *bus)
45272 struct mdiobb_ctrl *ctrl = bus->priv;
45273
45274 module_put(ctrl->ops->owner);
45275+ mdiobus_unregister(bus);
45276 mdiobus_free(bus);
45277 }
45278 EXPORT_SYMBOL(free_mdio_bitbang);
45279diff --git a/drivers/net/ppp/ppp_generic.c b/drivers/net/ppp/ppp_generic.c
45280index 72ff14b..11d442d 100644
45281--- a/drivers/net/ppp/ppp_generic.c
45282+++ b/drivers/net/ppp/ppp_generic.c
45283@@ -999,7 +999,6 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
45284 void __user *addr = (void __user *) ifr->ifr_ifru.ifru_data;
45285 struct ppp_stats stats;
45286 struct ppp_comp_stats cstats;
45287- char *vers;
45288
45289 switch (cmd) {
45290 case SIOCGPPPSTATS:
45291@@ -1021,8 +1020,7 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
45292 break;
45293
45294 case SIOCGPPPVER:
45295- vers = PPP_VERSION;
45296- if (copy_to_user(addr, vers, strlen(vers) + 1))
45297+ if (copy_to_user(addr, PPP_VERSION, sizeof(PPP_VERSION)))
45298 break;
45299 err = 0;
45300 break;
45301diff --git a/drivers/net/slip/slhc.c b/drivers/net/slip/slhc.c
45302index 1252d9c..80e660b 100644
45303--- a/drivers/net/slip/slhc.c
45304+++ b/drivers/net/slip/slhc.c
45305@@ -488,7 +488,7 @@ slhc_uncompress(struct slcompress *comp, unsigned char *icp, int isize)
45306 register struct tcphdr *thp;
45307 register struct iphdr *ip;
45308 register struct cstate *cs;
45309- int len, hdrlen;
45310+ long len, hdrlen;
45311 unsigned char *cp = icp;
45312
45313 /* We've got a compressed packet; read the change byte */
45314diff --git a/drivers/net/team/team.c b/drivers/net/team/team.c
45315index 6327df2..e6e1ebe 100644
45316--- a/drivers/net/team/team.c
45317+++ b/drivers/net/team/team.c
45318@@ -2873,7 +2873,7 @@ static int team_device_event(struct notifier_block *unused,
45319 return NOTIFY_DONE;
45320 }
45321
45322-static struct notifier_block team_notifier_block __read_mostly = {
45323+static struct notifier_block team_notifier_block = {
45324 .notifier_call = team_device_event,
45325 };
45326
45327diff --git a/drivers/net/tun.c b/drivers/net/tun.c
45328index 7c8343a..80d1e69 100644
45329--- a/drivers/net/tun.c
45330+++ b/drivers/net/tun.c
45331@@ -1838,7 +1838,7 @@ unlock:
45332 }
45333
45334 static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
45335- unsigned long arg, int ifreq_len)
45336+ unsigned long arg, size_t ifreq_len)
45337 {
45338 struct tun_file *tfile = file->private_data;
45339 struct tun_struct *tun;
45340@@ -1851,6 +1851,9 @@ static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
45341 unsigned int ifindex;
45342 int ret;
45343
45344+ if (ifreq_len > sizeof ifr)
45345+ return -EFAULT;
45346+
45347 if (cmd == TUNSETIFF || cmd == TUNSETQUEUE || _IOC_TYPE(cmd) == 0x89) {
45348 if (copy_from_user(&ifr, argp, ifreq_len))
45349 return -EFAULT;
45350diff --git a/drivers/net/usb/hso.c b/drivers/net/usb/hso.c
45351index 86292e6..8d34433 100644
45352--- a/drivers/net/usb/hso.c
45353+++ b/drivers/net/usb/hso.c
45354@@ -71,7 +71,7 @@
45355 #include <asm/byteorder.h>
45356 #include <linux/serial_core.h>
45357 #include <linux/serial.h>
45358-
45359+#include <asm/local.h>
45360
45361 #define MOD_AUTHOR "Option Wireless"
45362 #define MOD_DESCRIPTION "USB High Speed Option driver"
45363@@ -1180,7 +1180,7 @@ static void put_rxbuf_data_and_resubmit_ctrl_urb(struct hso_serial *serial)
45364 struct urb *urb;
45365
45366 urb = serial->rx_urb[0];
45367- if (serial->port.count > 0) {
45368+ if (atomic_read(&serial->port.count) > 0) {
45369 count = put_rxbuf_data(urb, serial);
45370 if (count == -1)
45371 return;
45372@@ -1216,7 +1216,7 @@ static void hso_std_serial_read_bulk_callback(struct urb *urb)
45373 DUMP1(urb->transfer_buffer, urb->actual_length);
45374
45375 /* Anyone listening? */
45376- if (serial->port.count == 0)
45377+ if (atomic_read(&serial->port.count) == 0)
45378 return;
45379
45380 if (status == 0) {
45381@@ -1298,8 +1298,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
45382 tty_port_tty_set(&serial->port, tty);
45383
45384 /* check for port already opened, if not set the termios */
45385- serial->port.count++;
45386- if (serial->port.count == 1) {
45387+ if (atomic_inc_return(&serial->port.count) == 1) {
45388 serial->rx_state = RX_IDLE;
45389 /* Force default termio settings */
45390 _hso_serial_set_termios(tty, NULL);
45391@@ -1311,7 +1310,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
45392 result = hso_start_serial_device(serial->parent, GFP_KERNEL);
45393 if (result) {
45394 hso_stop_serial_device(serial->parent);
45395- serial->port.count--;
45396+ atomic_dec(&serial->port.count);
45397 kref_put(&serial->parent->ref, hso_serial_ref_free);
45398 }
45399 } else {
45400@@ -1348,10 +1347,10 @@ static void hso_serial_close(struct tty_struct *tty, struct file *filp)
45401
45402 /* reset the rts and dtr */
45403 /* do the actual close */
45404- serial->port.count--;
45405+ atomic_dec(&serial->port.count);
45406
45407- if (serial->port.count <= 0) {
45408- serial->port.count = 0;
45409+ if (atomic_read(&serial->port.count) <= 0) {
45410+ atomic_set(&serial->port.count, 0);
45411 tty_port_tty_set(&serial->port, NULL);
45412 if (!usb_gone)
45413 hso_stop_serial_device(serial->parent);
45414@@ -1427,7 +1426,7 @@ static void hso_serial_set_termios(struct tty_struct *tty, struct ktermios *old)
45415
45416 /* the actual setup */
45417 spin_lock_irqsave(&serial->serial_lock, flags);
45418- if (serial->port.count)
45419+ if (atomic_read(&serial->port.count))
45420 _hso_serial_set_termios(tty, old);
45421 else
45422 tty->termios = *old;
45423@@ -1886,7 +1885,7 @@ static void intr_callback(struct urb *urb)
45424 D1("Pending read interrupt on port %d\n", i);
45425 spin_lock(&serial->serial_lock);
45426 if (serial->rx_state == RX_IDLE &&
45427- serial->port.count > 0) {
45428+ atomic_read(&serial->port.count) > 0) {
45429 /* Setup and send a ctrl req read on
45430 * port i */
45431 if (!serial->rx_urb_filled[0]) {
45432@@ -3062,7 +3061,7 @@ static int hso_resume(struct usb_interface *iface)
45433 /* Start all serial ports */
45434 for (i = 0; i < HSO_SERIAL_TTY_MINORS; i++) {
45435 if (serial_table[i] && (serial_table[i]->interface == iface)) {
45436- if (dev2ser(serial_table[i])->port.count) {
45437+ if (atomic_read(&dev2ser(serial_table[i])->port.count)) {
45438 result =
45439 hso_start_serial_device(serial_table[i], GFP_NOIO);
45440 hso_kick_transmit(dev2ser(serial_table[i]));
45441diff --git a/drivers/net/usb/sierra_net.c b/drivers/net/usb/sierra_net.c
45442index a79e9d3..78cd4fa 100644
45443--- a/drivers/net/usb/sierra_net.c
45444+++ b/drivers/net/usb/sierra_net.c
45445@@ -52,7 +52,7 @@ static const char driver_name[] = "sierra_net";
45446 /* atomic counter partially included in MAC address to make sure 2 devices
45447 * do not end up with the same MAC - concept breaks in case of > 255 ifaces
45448 */
45449-static atomic_t iface_counter = ATOMIC_INIT(0);
45450+static atomic_unchecked_t iface_counter = ATOMIC_INIT(0);
45451
45452 /*
45453 * SYNC Timer Delay definition used to set the expiry time
45454@@ -698,7 +698,7 @@ static int sierra_net_bind(struct usbnet *dev, struct usb_interface *intf)
45455 dev->net->netdev_ops = &sierra_net_device_ops;
45456
45457 /* change MAC addr to include, ifacenum, and to be unique */
45458- dev->net->dev_addr[ETH_ALEN-2] = atomic_inc_return(&iface_counter);
45459+ dev->net->dev_addr[ETH_ALEN-2] = atomic_inc_return_unchecked(&iface_counter);
45460 dev->net->dev_addr[ETH_ALEN-1] = ifacenum;
45461
45462 /* we will have to manufacture ethernet headers, prepare template */
45463diff --git a/drivers/net/vxlan.c b/drivers/net/vxlan.c
45464index 1462368..578941c 100644
45465--- a/drivers/net/vxlan.c
45466+++ b/drivers/net/vxlan.c
45467@@ -2615,7 +2615,7 @@ nla_put_failure:
45468 return -EMSGSIZE;
45469 }
45470
45471-static struct rtnl_link_ops vxlan_link_ops __read_mostly = {
45472+static struct rtnl_link_ops vxlan_link_ops = {
45473 .kind = "vxlan",
45474 .maxtype = IFLA_VXLAN_MAX,
45475 .policy = vxlan_policy,
45476diff --git a/drivers/net/wan/lmc/lmc_media.c b/drivers/net/wan/lmc/lmc_media.c
45477index 5920c99..ff2e4a5 100644
45478--- a/drivers/net/wan/lmc/lmc_media.c
45479+++ b/drivers/net/wan/lmc/lmc_media.c
45480@@ -95,62 +95,63 @@ static inline void write_av9110_bit (lmc_softc_t *, int);
45481 static void write_av9110(lmc_softc_t *, u32, u32, u32, u32, u32);
45482
45483 lmc_media_t lmc_ds3_media = {
45484- lmc_ds3_init, /* special media init stuff */
45485- lmc_ds3_default, /* reset to default state */
45486- lmc_ds3_set_status, /* reset status to state provided */
45487- lmc_dummy_set_1, /* set clock source */
45488- lmc_dummy_set2_1, /* set line speed */
45489- lmc_ds3_set_100ft, /* set cable length */
45490- lmc_ds3_set_scram, /* set scrambler */
45491- lmc_ds3_get_link_status, /* get link status */
45492- lmc_dummy_set_1, /* set link status */
45493- lmc_ds3_set_crc_length, /* set CRC length */
45494- lmc_dummy_set_1, /* set T1 or E1 circuit type */
45495- lmc_ds3_watchdog
45496+ .init = lmc_ds3_init, /* special media init stuff */
45497+ .defaults = lmc_ds3_default, /* reset to default state */
45498+ .set_status = lmc_ds3_set_status, /* reset status to state provided */
45499+ .set_clock_source = lmc_dummy_set_1, /* set clock source */
45500+ .set_speed = lmc_dummy_set2_1, /* set line speed */
45501+ .set_cable_length = lmc_ds3_set_100ft, /* set cable length */
45502+ .set_scrambler = lmc_ds3_set_scram, /* set scrambler */
45503+ .get_link_status = lmc_ds3_get_link_status, /* get link status */
45504+ .set_link_status = lmc_dummy_set_1, /* set link status */
45505+ .set_crc_length = lmc_ds3_set_crc_length, /* set CRC length */
45506+ .set_circuit_type = lmc_dummy_set_1, /* set T1 or E1 circuit type */
45507+ .watchdog = lmc_ds3_watchdog
45508 };
45509
45510 lmc_media_t lmc_hssi_media = {
45511- lmc_hssi_init, /* special media init stuff */
45512- lmc_hssi_default, /* reset to default state */
45513- lmc_hssi_set_status, /* reset status to state provided */
45514- lmc_hssi_set_clock, /* set clock source */
45515- lmc_dummy_set2_1, /* set line speed */
45516- lmc_dummy_set_1, /* set cable length */
45517- lmc_dummy_set_1, /* set scrambler */
45518- lmc_hssi_get_link_status, /* get link status */
45519- lmc_hssi_set_link_status, /* set link status */
45520- lmc_hssi_set_crc_length, /* set CRC length */
45521- lmc_dummy_set_1, /* set T1 or E1 circuit type */
45522- lmc_hssi_watchdog
45523+ .init = lmc_hssi_init, /* special media init stuff */
45524+ .defaults = lmc_hssi_default, /* reset to default state */
45525+ .set_status = lmc_hssi_set_status, /* reset status to state provided */
45526+ .set_clock_source = lmc_hssi_set_clock, /* set clock source */
45527+ .set_speed = lmc_dummy_set2_1, /* set line speed */
45528+ .set_cable_length = lmc_dummy_set_1, /* set cable length */
45529+ .set_scrambler = lmc_dummy_set_1, /* set scrambler */
45530+ .get_link_status = lmc_hssi_get_link_status, /* get link status */
45531+ .set_link_status = lmc_hssi_set_link_status, /* set link status */
45532+ .set_crc_length = lmc_hssi_set_crc_length, /* set CRC length */
45533+ .set_circuit_type = lmc_dummy_set_1, /* set T1 or E1 circuit type */
45534+ .watchdog = lmc_hssi_watchdog
45535 };
45536
45537-lmc_media_t lmc_ssi_media = { lmc_ssi_init, /* special media init stuff */
45538- lmc_ssi_default, /* reset to default state */
45539- lmc_ssi_set_status, /* reset status to state provided */
45540- lmc_ssi_set_clock, /* set clock source */
45541- lmc_ssi_set_speed, /* set line speed */
45542- lmc_dummy_set_1, /* set cable length */
45543- lmc_dummy_set_1, /* set scrambler */
45544- lmc_ssi_get_link_status, /* get link status */
45545- lmc_ssi_set_link_status, /* set link status */
45546- lmc_ssi_set_crc_length, /* set CRC length */
45547- lmc_dummy_set_1, /* set T1 or E1 circuit type */
45548- lmc_ssi_watchdog
45549+lmc_media_t lmc_ssi_media = {
45550+ .init = lmc_ssi_init, /* special media init stuff */
45551+ .defaults = lmc_ssi_default, /* reset to default state */
45552+ .set_status = lmc_ssi_set_status, /* reset status to state provided */
45553+ .set_clock_source = lmc_ssi_set_clock, /* set clock source */
45554+ .set_speed = lmc_ssi_set_speed, /* set line speed */
45555+ .set_cable_length = lmc_dummy_set_1, /* set cable length */
45556+ .set_scrambler = lmc_dummy_set_1, /* set scrambler */
45557+ .get_link_status = lmc_ssi_get_link_status, /* get link status */
45558+ .set_link_status = lmc_ssi_set_link_status, /* set link status */
45559+ .set_crc_length = lmc_ssi_set_crc_length, /* set CRC length */
45560+ .set_circuit_type = lmc_dummy_set_1, /* set T1 or E1 circuit type */
45561+ .watchdog = lmc_ssi_watchdog
45562 };
45563
45564 lmc_media_t lmc_t1_media = {
45565- lmc_t1_init, /* special media init stuff */
45566- lmc_t1_default, /* reset to default state */
45567- lmc_t1_set_status, /* reset status to state provided */
45568- lmc_t1_set_clock, /* set clock source */
45569- lmc_dummy_set2_1, /* set line speed */
45570- lmc_dummy_set_1, /* set cable length */
45571- lmc_dummy_set_1, /* set scrambler */
45572- lmc_t1_get_link_status, /* get link status */
45573- lmc_dummy_set_1, /* set link status */
45574- lmc_t1_set_crc_length, /* set CRC length */
45575- lmc_t1_set_circuit_type, /* set T1 or E1 circuit type */
45576- lmc_t1_watchdog
45577+ .init = lmc_t1_init, /* special media init stuff */
45578+ .defaults = lmc_t1_default, /* reset to default state */
45579+ .set_status = lmc_t1_set_status, /* reset status to state provided */
45580+ .set_clock_source = lmc_t1_set_clock, /* set clock source */
45581+ .set_speed = lmc_dummy_set2_1, /* set line speed */
45582+ .set_cable_length = lmc_dummy_set_1, /* set cable length */
45583+ .set_scrambler = lmc_dummy_set_1, /* set scrambler */
45584+ .get_link_status = lmc_t1_get_link_status, /* get link status */
45585+ .set_link_status = lmc_dummy_set_1, /* set link status */
45586+ .set_crc_length = lmc_t1_set_crc_length, /* set CRC length */
45587+ .set_circuit_type = lmc_t1_set_circuit_type, /* set T1 or E1 circuit type */
45588+ .watchdog = lmc_t1_watchdog
45589 };
45590
45591 static void
45592diff --git a/drivers/net/wan/z85230.c b/drivers/net/wan/z85230.c
45593index feacc3b..5bac0de 100644
45594--- a/drivers/net/wan/z85230.c
45595+++ b/drivers/net/wan/z85230.c
45596@@ -485,9 +485,9 @@ static void z8530_status(struct z8530_channel *chan)
45597
45598 struct z8530_irqhandler z8530_sync =
45599 {
45600- z8530_rx,
45601- z8530_tx,
45602- z8530_status
45603+ .rx = z8530_rx,
45604+ .tx = z8530_tx,
45605+ .status = z8530_status
45606 };
45607
45608 EXPORT_SYMBOL(z8530_sync);
45609@@ -605,15 +605,15 @@ static void z8530_dma_status(struct z8530_channel *chan)
45610 }
45611
45612 static struct z8530_irqhandler z8530_dma_sync = {
45613- z8530_dma_rx,
45614- z8530_dma_tx,
45615- z8530_dma_status
45616+ .rx = z8530_dma_rx,
45617+ .tx = z8530_dma_tx,
45618+ .status = z8530_dma_status
45619 };
45620
45621 static struct z8530_irqhandler z8530_txdma_sync = {
45622- z8530_rx,
45623- z8530_dma_tx,
45624- z8530_dma_status
45625+ .rx = z8530_rx,
45626+ .tx = z8530_dma_tx,
45627+ .status = z8530_dma_status
45628 };
45629
45630 /**
45631@@ -680,9 +680,9 @@ static void z8530_status_clear(struct z8530_channel *chan)
45632
45633 struct z8530_irqhandler z8530_nop=
45634 {
45635- z8530_rx_clear,
45636- z8530_tx_clear,
45637- z8530_status_clear
45638+ .rx = z8530_rx_clear,
45639+ .tx = z8530_tx_clear,
45640+ .status = z8530_status_clear
45641 };
45642
45643
45644diff --git a/drivers/net/wimax/i2400m/rx.c b/drivers/net/wimax/i2400m/rx.c
45645index 0b60295..b8bfa5b 100644
45646--- a/drivers/net/wimax/i2400m/rx.c
45647+++ b/drivers/net/wimax/i2400m/rx.c
45648@@ -1359,7 +1359,7 @@ int i2400m_rx_setup(struct i2400m *i2400m)
45649 if (i2400m->rx_roq == NULL)
45650 goto error_roq_alloc;
45651
45652- rd = kcalloc(I2400M_RO_CIN + 1, sizeof(*i2400m->rx_roq[0].log),
45653+ rd = kcalloc(sizeof(*i2400m->rx_roq[0].log), I2400M_RO_CIN + 1,
45654 GFP_KERNEL);
45655 if (rd == NULL) {
45656 result = -ENOMEM;
45657diff --git a/drivers/net/wireless/airo.c b/drivers/net/wireless/airo.c
45658index 7fe1964..7016de0 100644
45659--- a/drivers/net/wireless/airo.c
45660+++ b/drivers/net/wireless/airo.c
45661@@ -7844,7 +7844,7 @@ static int writerids(struct net_device *dev, aironet_ioctl *comp) {
45662 struct airo_info *ai = dev->ml_priv;
45663 int ridcode;
45664 int enabled;
45665- static int (* writer)(struct airo_info *, u16 rid, const void *, int, int);
45666+ int (* writer)(struct airo_info *, u16 rid, const void *, int, int);
45667 unsigned char *iobuf;
45668
45669 /* Only super-user can write RIDs */
45670diff --git a/drivers/net/wireless/at76c50x-usb.c b/drivers/net/wireless/at76c50x-usb.c
45671index 34c8a33..3261fdc 100644
45672--- a/drivers/net/wireless/at76c50x-usb.c
45673+++ b/drivers/net/wireless/at76c50x-usb.c
45674@@ -353,7 +353,7 @@ static int at76_dfu_get_state(struct usb_device *udev, u8 *state)
45675 }
45676
45677 /* Convert timeout from the DFU status to jiffies */
45678-static inline unsigned long at76_get_timeout(struct dfu_status *s)
45679+static inline unsigned long __intentional_overflow(-1) at76_get_timeout(struct dfu_status *s)
45680 {
45681 return msecs_to_jiffies((s->poll_timeout[2] << 16)
45682 | (s->poll_timeout[1] << 8)
45683diff --git a/drivers/net/wireless/ath/ath10k/htc.c b/drivers/net/wireless/ath/ath10k/htc.c
45684index ef3329e..c28ff5d 100644
45685--- a/drivers/net/wireless/ath/ath10k/htc.c
45686+++ b/drivers/net/wireless/ath/ath10k/htc.c
45687@@ -963,7 +963,10 @@ void ath10k_htc_stop(struct ath10k_htc *htc)
45688 /* registered target arrival callback from the HIF layer */
45689 int ath10k_htc_init(struct ath10k *ar)
45690 {
45691- struct ath10k_hif_cb htc_callbacks;
45692+ static struct ath10k_hif_cb htc_callbacks = {
45693+ .rx_completion = ath10k_htc_rx_completion_handler,
45694+ .tx_completion = ath10k_htc_tx_completion_handler,
45695+ };
45696 struct ath10k_htc_ep *ep = NULL;
45697 struct ath10k_htc *htc = &ar->htc;
45698
45699@@ -973,8 +976,6 @@ int ath10k_htc_init(struct ath10k *ar)
45700 ath10k_htc_reset_endpoint_states(htc);
45701
45702 /* setup HIF layer callbacks */
45703- htc_callbacks.rx_completion = ath10k_htc_rx_completion_handler;
45704- htc_callbacks.tx_completion = ath10k_htc_tx_completion_handler;
45705 htc->ar = ar;
45706
45707 /* Get HIF default pipe for HTC message exchange */
45708diff --git a/drivers/net/wireless/ath/ath10k/htc.h b/drivers/net/wireless/ath/ath10k/htc.h
45709index e1dd8c7..9f91b3f 100644
45710--- a/drivers/net/wireless/ath/ath10k/htc.h
45711+++ b/drivers/net/wireless/ath/ath10k/htc.h
45712@@ -271,12 +271,12 @@ enum ath10k_htc_ep_id {
45713
45714 struct ath10k_htc_ops {
45715 void (*target_send_suspend_complete)(struct ath10k *ar);
45716-};
45717+} __no_const;
45718
45719 struct ath10k_htc_ep_ops {
45720 void (*ep_tx_complete)(struct ath10k *, struct sk_buff *);
45721 void (*ep_rx_complete)(struct ath10k *, struct sk_buff *);
45722-};
45723+} __no_const;
45724
45725 /* service connection information */
45726 struct ath10k_htc_svc_conn_req {
45727diff --git a/drivers/net/wireless/ath/ath9k/ar9002_mac.c b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
45728index a366d6b..b6f28f8 100644
45729--- a/drivers/net/wireless/ath/ath9k/ar9002_mac.c
45730+++ b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
45731@@ -218,8 +218,8 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
45732 ads->ds_txstatus6 = ads->ds_txstatus7 = 0;
45733 ads->ds_txstatus8 = ads->ds_txstatus9 = 0;
45734
45735- ACCESS_ONCE(ads->ds_link) = i->link;
45736- ACCESS_ONCE(ads->ds_data) = i->buf_addr[0];
45737+ ACCESS_ONCE_RW(ads->ds_link) = i->link;
45738+ ACCESS_ONCE_RW(ads->ds_data) = i->buf_addr[0];
45739
45740 ctl1 = i->buf_len[0] | (i->is_last ? 0 : AR_TxMore);
45741 ctl6 = SM(i->keytype, AR_EncrType);
45742@@ -233,26 +233,26 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
45743
45744 if ((i->is_first || i->is_last) &&
45745 i->aggr != AGGR_BUF_MIDDLE && i->aggr != AGGR_BUF_LAST) {
45746- ACCESS_ONCE(ads->ds_ctl2) = set11nTries(i->rates, 0)
45747+ ACCESS_ONCE_RW(ads->ds_ctl2) = set11nTries(i->rates, 0)
45748 | set11nTries(i->rates, 1)
45749 | set11nTries(i->rates, 2)
45750 | set11nTries(i->rates, 3)
45751 | (i->dur_update ? AR_DurUpdateEna : 0)
45752 | SM(0, AR_BurstDur);
45753
45754- ACCESS_ONCE(ads->ds_ctl3) = set11nRate(i->rates, 0)
45755+ ACCESS_ONCE_RW(ads->ds_ctl3) = set11nRate(i->rates, 0)
45756 | set11nRate(i->rates, 1)
45757 | set11nRate(i->rates, 2)
45758 | set11nRate(i->rates, 3);
45759 } else {
45760- ACCESS_ONCE(ads->ds_ctl2) = 0;
45761- ACCESS_ONCE(ads->ds_ctl3) = 0;
45762+ ACCESS_ONCE_RW(ads->ds_ctl2) = 0;
45763+ ACCESS_ONCE_RW(ads->ds_ctl3) = 0;
45764 }
45765
45766 if (!i->is_first) {
45767- ACCESS_ONCE(ads->ds_ctl0) = 0;
45768- ACCESS_ONCE(ads->ds_ctl1) = ctl1;
45769- ACCESS_ONCE(ads->ds_ctl6) = ctl6;
45770+ ACCESS_ONCE_RW(ads->ds_ctl0) = 0;
45771+ ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
45772+ ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
45773 return;
45774 }
45775
45776@@ -277,7 +277,7 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
45777 break;
45778 }
45779
45780- ACCESS_ONCE(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
45781+ ACCESS_ONCE_RW(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
45782 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
45783 | SM(i->txpower, AR_XmitPower)
45784 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
45785@@ -287,19 +287,19 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
45786 | (i->flags & ATH9K_TXDESC_RTSENA ? AR_RTSEnable :
45787 (i->flags & ATH9K_TXDESC_CTSENA ? AR_CTSEnable : 0));
45788
45789- ACCESS_ONCE(ads->ds_ctl1) = ctl1;
45790- ACCESS_ONCE(ads->ds_ctl6) = ctl6;
45791+ ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
45792+ ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
45793
45794 if (i->aggr == AGGR_BUF_MIDDLE || i->aggr == AGGR_BUF_LAST)
45795 return;
45796
45797- ACCESS_ONCE(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
45798+ ACCESS_ONCE_RW(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
45799 | set11nPktDurRTSCTS(i->rates, 1);
45800
45801- ACCESS_ONCE(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
45802+ ACCESS_ONCE_RW(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
45803 | set11nPktDurRTSCTS(i->rates, 3);
45804
45805- ACCESS_ONCE(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
45806+ ACCESS_ONCE_RW(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
45807 | set11nRateFlags(i->rates, 1)
45808 | set11nRateFlags(i->rates, 2)
45809 | set11nRateFlags(i->rates, 3)
45810diff --git a/drivers/net/wireless/ath/ath9k/ar9003_mac.c b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
45811index f6c5c1b..6058354 100644
45812--- a/drivers/net/wireless/ath/ath9k/ar9003_mac.c
45813+++ b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
45814@@ -39,47 +39,47 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
45815 (i->qcu << AR_TxQcuNum_S) | desc_len;
45816
45817 checksum += val;
45818- ACCESS_ONCE(ads->info) = val;
45819+ ACCESS_ONCE_RW(ads->info) = val;
45820
45821 checksum += i->link;
45822- ACCESS_ONCE(ads->link) = i->link;
45823+ ACCESS_ONCE_RW(ads->link) = i->link;
45824
45825 checksum += i->buf_addr[0];
45826- ACCESS_ONCE(ads->data0) = i->buf_addr[0];
45827+ ACCESS_ONCE_RW(ads->data0) = i->buf_addr[0];
45828 checksum += i->buf_addr[1];
45829- ACCESS_ONCE(ads->data1) = i->buf_addr[1];
45830+ ACCESS_ONCE_RW(ads->data1) = i->buf_addr[1];
45831 checksum += i->buf_addr[2];
45832- ACCESS_ONCE(ads->data2) = i->buf_addr[2];
45833+ ACCESS_ONCE_RW(ads->data2) = i->buf_addr[2];
45834 checksum += i->buf_addr[3];
45835- ACCESS_ONCE(ads->data3) = i->buf_addr[3];
45836+ ACCESS_ONCE_RW(ads->data3) = i->buf_addr[3];
45837
45838 checksum += (val = (i->buf_len[0] << AR_BufLen_S) & AR_BufLen);
45839- ACCESS_ONCE(ads->ctl3) = val;
45840+ ACCESS_ONCE_RW(ads->ctl3) = val;
45841 checksum += (val = (i->buf_len[1] << AR_BufLen_S) & AR_BufLen);
45842- ACCESS_ONCE(ads->ctl5) = val;
45843+ ACCESS_ONCE_RW(ads->ctl5) = val;
45844 checksum += (val = (i->buf_len[2] << AR_BufLen_S) & AR_BufLen);
45845- ACCESS_ONCE(ads->ctl7) = val;
45846+ ACCESS_ONCE_RW(ads->ctl7) = val;
45847 checksum += (val = (i->buf_len[3] << AR_BufLen_S) & AR_BufLen);
45848- ACCESS_ONCE(ads->ctl9) = val;
45849+ ACCESS_ONCE_RW(ads->ctl9) = val;
45850
45851 checksum = (u16) (((checksum & 0xffff) + (checksum >> 16)) & 0xffff);
45852- ACCESS_ONCE(ads->ctl10) = checksum;
45853+ ACCESS_ONCE_RW(ads->ctl10) = checksum;
45854
45855 if (i->is_first || i->is_last) {
45856- ACCESS_ONCE(ads->ctl13) = set11nTries(i->rates, 0)
45857+ ACCESS_ONCE_RW(ads->ctl13) = set11nTries(i->rates, 0)
45858 | set11nTries(i->rates, 1)
45859 | set11nTries(i->rates, 2)
45860 | set11nTries(i->rates, 3)
45861 | (i->dur_update ? AR_DurUpdateEna : 0)
45862 | SM(0, AR_BurstDur);
45863
45864- ACCESS_ONCE(ads->ctl14) = set11nRate(i->rates, 0)
45865+ ACCESS_ONCE_RW(ads->ctl14) = set11nRate(i->rates, 0)
45866 | set11nRate(i->rates, 1)
45867 | set11nRate(i->rates, 2)
45868 | set11nRate(i->rates, 3);
45869 } else {
45870- ACCESS_ONCE(ads->ctl13) = 0;
45871- ACCESS_ONCE(ads->ctl14) = 0;
45872+ ACCESS_ONCE_RW(ads->ctl13) = 0;
45873+ ACCESS_ONCE_RW(ads->ctl14) = 0;
45874 }
45875
45876 ads->ctl20 = 0;
45877@@ -89,17 +89,17 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
45878
45879 ctl17 = SM(i->keytype, AR_EncrType);
45880 if (!i->is_first) {
45881- ACCESS_ONCE(ads->ctl11) = 0;
45882- ACCESS_ONCE(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
45883- ACCESS_ONCE(ads->ctl15) = 0;
45884- ACCESS_ONCE(ads->ctl16) = 0;
45885- ACCESS_ONCE(ads->ctl17) = ctl17;
45886- ACCESS_ONCE(ads->ctl18) = 0;
45887- ACCESS_ONCE(ads->ctl19) = 0;
45888+ ACCESS_ONCE_RW(ads->ctl11) = 0;
45889+ ACCESS_ONCE_RW(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
45890+ ACCESS_ONCE_RW(ads->ctl15) = 0;
45891+ ACCESS_ONCE_RW(ads->ctl16) = 0;
45892+ ACCESS_ONCE_RW(ads->ctl17) = ctl17;
45893+ ACCESS_ONCE_RW(ads->ctl18) = 0;
45894+ ACCESS_ONCE_RW(ads->ctl19) = 0;
45895 return;
45896 }
45897
45898- ACCESS_ONCE(ads->ctl11) = (i->pkt_len & AR_FrameLen)
45899+ ACCESS_ONCE_RW(ads->ctl11) = (i->pkt_len & AR_FrameLen)
45900 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
45901 | SM(i->txpower, AR_XmitPower)
45902 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
45903@@ -135,22 +135,22 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
45904 val = (i->flags & ATH9K_TXDESC_PAPRD) >> ATH9K_TXDESC_PAPRD_S;
45905 ctl12 |= SM(val, AR_PAPRDChainMask);
45906
45907- ACCESS_ONCE(ads->ctl12) = ctl12;
45908- ACCESS_ONCE(ads->ctl17) = ctl17;
45909+ ACCESS_ONCE_RW(ads->ctl12) = ctl12;
45910+ ACCESS_ONCE_RW(ads->ctl17) = ctl17;
45911
45912- ACCESS_ONCE(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
45913+ ACCESS_ONCE_RW(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
45914 | set11nPktDurRTSCTS(i->rates, 1);
45915
45916- ACCESS_ONCE(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
45917+ ACCESS_ONCE_RW(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
45918 | set11nPktDurRTSCTS(i->rates, 3);
45919
45920- ACCESS_ONCE(ads->ctl18) = set11nRateFlags(i->rates, 0)
45921+ ACCESS_ONCE_RW(ads->ctl18) = set11nRateFlags(i->rates, 0)
45922 | set11nRateFlags(i->rates, 1)
45923 | set11nRateFlags(i->rates, 2)
45924 | set11nRateFlags(i->rates, 3)
45925 | SM(i->rtscts_rate, AR_RTSCTSRate);
45926
45927- ACCESS_ONCE(ads->ctl19) = AR_Not_Sounding;
45928+ ACCESS_ONCE_RW(ads->ctl19) = AR_Not_Sounding;
45929 }
45930
45931 static u16 ar9003_calc_ptr_chksum(struct ar9003_txc *ads)
45932diff --git a/drivers/net/wireless/ath/ath9k/hw.h b/drivers/net/wireless/ath/ath9k/hw.h
45933index 69a907b..91e071c 100644
45934--- a/drivers/net/wireless/ath/ath9k/hw.h
45935+++ b/drivers/net/wireless/ath/ath9k/hw.h
45936@@ -657,7 +657,7 @@ struct ath_hw_private_ops {
45937
45938 /* ANI */
45939 void (*ani_cache_ini_regs)(struct ath_hw *ah);
45940-};
45941+} __no_const;
45942
45943 /**
45944 * struct ath_spec_scan - parameters for Atheros spectral scan
45945@@ -729,7 +729,7 @@ struct ath_hw_ops {
45946 #ifdef CONFIG_ATH9K_BTCOEX_SUPPORT
45947 void (*set_bt_ant_diversity)(struct ath_hw *hw, bool enable);
45948 #endif
45949-};
45950+} __no_const;
45951
45952 struct ath_nf_limits {
45953 s16 max;
45954diff --git a/drivers/net/wireless/b43/phy_lp.c b/drivers/net/wireless/b43/phy_lp.c
45955index 92190da..f3a4c4c 100644
45956--- a/drivers/net/wireless/b43/phy_lp.c
45957+++ b/drivers/net/wireless/b43/phy_lp.c
45958@@ -2514,7 +2514,7 @@ static int lpphy_b2063_tune(struct b43_wldev *dev,
45959 {
45960 struct ssb_bus *bus = dev->dev->sdev->bus;
45961
45962- static const struct b206x_channel *chandata = NULL;
45963+ const struct b206x_channel *chandata = NULL;
45964 u32 crystal_freq = bus->chipco.pmu.crystalfreq * 1000;
45965 u32 freqref, vco_freq, val1, val2, val3, timeout, timeoutref, count;
45966 u16 old_comm15, scale;
45967diff --git a/drivers/net/wireless/iwlegacy/3945-mac.c b/drivers/net/wireless/iwlegacy/3945-mac.c
45968index 9581d07..84f6a76 100644
45969--- a/drivers/net/wireless/iwlegacy/3945-mac.c
45970+++ b/drivers/net/wireless/iwlegacy/3945-mac.c
45971@@ -3639,7 +3639,9 @@ il3945_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
45972 */
45973 if (il3945_mod_params.disable_hw_scan) {
45974 D_INFO("Disabling hw_scan\n");
45975- il3945_mac_ops.hw_scan = NULL;
45976+ pax_open_kernel();
45977+ *(void **)&il3945_mac_ops.hw_scan = NULL;
45978+ pax_close_kernel();
45979 }
45980
45981 D_INFO("*** LOAD DRIVER ***\n");
45982diff --git a/drivers/net/wireless/iwlwifi/dvm/debugfs.c b/drivers/net/wireless/iwlwifi/dvm/debugfs.c
45983index d94f8ab..5b568c8 100644
45984--- a/drivers/net/wireless/iwlwifi/dvm/debugfs.c
45985+++ b/drivers/net/wireless/iwlwifi/dvm/debugfs.c
45986@@ -188,7 +188,7 @@ static ssize_t iwl_dbgfs_sram_write(struct file *file,
45987 {
45988 struct iwl_priv *priv = file->private_data;
45989 char buf[64];
45990- int buf_size;
45991+ size_t buf_size;
45992 u32 offset, len;
45993
45994 memset(buf, 0, sizeof(buf));
45995@@ -458,7 +458,7 @@ static ssize_t iwl_dbgfs_rx_handlers_write(struct file *file,
45996 struct iwl_priv *priv = file->private_data;
45997
45998 char buf[8];
45999- int buf_size;
46000+ size_t buf_size;
46001 u32 reset_flag;
46002
46003 memset(buf, 0, sizeof(buf));
46004@@ -539,7 +539,7 @@ static ssize_t iwl_dbgfs_disable_ht40_write(struct file *file,
46005 {
46006 struct iwl_priv *priv = file->private_data;
46007 char buf[8];
46008- int buf_size;
46009+ size_t buf_size;
46010 int ht40;
46011
46012 memset(buf, 0, sizeof(buf));
46013@@ -591,7 +591,7 @@ static ssize_t iwl_dbgfs_sleep_level_override_write(struct file *file,
46014 {
46015 struct iwl_priv *priv = file->private_data;
46016 char buf[8];
46017- int buf_size;
46018+ size_t buf_size;
46019 int value;
46020
46021 memset(buf, 0, sizeof(buf));
46022@@ -683,10 +683,10 @@ DEBUGFS_READ_FILE_OPS(temperature);
46023 DEBUGFS_READ_WRITE_FILE_OPS(sleep_level_override);
46024 DEBUGFS_READ_FILE_OPS(current_sleep_command);
46025
46026-static const char *fmt_value = " %-30s %10u\n";
46027-static const char *fmt_hex = " %-30s 0x%02X\n";
46028-static const char *fmt_table = " %-30s %10u %10u %10u %10u\n";
46029-static const char *fmt_header =
46030+static const char fmt_value[] = " %-30s %10u\n";
46031+static const char fmt_hex[] = " %-30s 0x%02X\n";
46032+static const char fmt_table[] = " %-30s %10u %10u %10u %10u\n";
46033+static const char fmt_header[] =
46034 "%-32s current cumulative delta max\n";
46035
46036 static int iwl_statistics_flag(struct iwl_priv *priv, char *buf, int bufsz)
46037@@ -1856,7 +1856,7 @@ static ssize_t iwl_dbgfs_clear_ucode_statistics_write(struct file *file,
46038 {
46039 struct iwl_priv *priv = file->private_data;
46040 char buf[8];
46041- int buf_size;
46042+ size_t buf_size;
46043 int clear;
46044
46045 memset(buf, 0, sizeof(buf));
46046@@ -1901,7 +1901,7 @@ static ssize_t iwl_dbgfs_ucode_tracing_write(struct file *file,
46047 {
46048 struct iwl_priv *priv = file->private_data;
46049 char buf[8];
46050- int buf_size;
46051+ size_t buf_size;
46052 int trace;
46053
46054 memset(buf, 0, sizeof(buf));
46055@@ -1972,7 +1972,7 @@ static ssize_t iwl_dbgfs_missed_beacon_write(struct file *file,
46056 {
46057 struct iwl_priv *priv = file->private_data;
46058 char buf[8];
46059- int buf_size;
46060+ size_t buf_size;
46061 int missed;
46062
46063 memset(buf, 0, sizeof(buf));
46064@@ -2013,7 +2013,7 @@ static ssize_t iwl_dbgfs_plcp_delta_write(struct file *file,
46065
46066 struct iwl_priv *priv = file->private_data;
46067 char buf[8];
46068- int buf_size;
46069+ size_t buf_size;
46070 int plcp;
46071
46072 memset(buf, 0, sizeof(buf));
46073@@ -2073,7 +2073,7 @@ static ssize_t iwl_dbgfs_txfifo_flush_write(struct file *file,
46074
46075 struct iwl_priv *priv = file->private_data;
46076 char buf[8];
46077- int buf_size;
46078+ size_t buf_size;
46079 int flush;
46080
46081 memset(buf, 0, sizeof(buf));
46082@@ -2163,7 +2163,7 @@ static ssize_t iwl_dbgfs_protection_mode_write(struct file *file,
46083
46084 struct iwl_priv *priv = file->private_data;
46085 char buf[8];
46086- int buf_size;
46087+ size_t buf_size;
46088 int rts;
46089
46090 if (!priv->cfg->ht_params)
46091@@ -2205,7 +2205,7 @@ static ssize_t iwl_dbgfs_echo_test_write(struct file *file,
46092 {
46093 struct iwl_priv *priv = file->private_data;
46094 char buf[8];
46095- int buf_size;
46096+ size_t buf_size;
46097
46098 memset(buf, 0, sizeof(buf));
46099 buf_size = min(count, sizeof(buf) - 1);
46100@@ -2239,7 +2239,7 @@ static ssize_t iwl_dbgfs_log_event_write(struct file *file,
46101 struct iwl_priv *priv = file->private_data;
46102 u32 event_log_flag;
46103 char buf[8];
46104- int buf_size;
46105+ size_t buf_size;
46106
46107 /* check that the interface is up */
46108 if (!iwl_is_ready(priv))
46109@@ -2293,7 +2293,7 @@ static ssize_t iwl_dbgfs_calib_disabled_write(struct file *file,
46110 struct iwl_priv *priv = file->private_data;
46111 char buf[8];
46112 u32 calib_disabled;
46113- int buf_size;
46114+ size_t buf_size;
46115
46116 memset(buf, 0, sizeof(buf));
46117 buf_size = min(count, sizeof(buf) - 1);
46118diff --git a/drivers/net/wireless/iwlwifi/dvm/main.c b/drivers/net/wireless/iwlwifi/dvm/main.c
46119index 7aad766..06addb4 100644
46120--- a/drivers/net/wireless/iwlwifi/dvm/main.c
46121+++ b/drivers/net/wireless/iwlwifi/dvm/main.c
46122@@ -1123,7 +1123,7 @@ static void iwl_option_config(struct iwl_priv *priv)
46123 static int iwl_eeprom_init_hw_params(struct iwl_priv *priv)
46124 {
46125 struct iwl_nvm_data *data = priv->nvm_data;
46126- char *debug_msg;
46127+ static const char debug_msg[] = "Device SKU: 24GHz %s %s, 52GHz %s %s, 11.n %s %s\n";
46128
46129 if (data->sku_cap_11n_enable &&
46130 !priv->cfg->ht_params) {
46131@@ -1137,7 +1137,6 @@ static int iwl_eeprom_init_hw_params(struct iwl_priv *priv)
46132 return -EINVAL;
46133 }
46134
46135- debug_msg = "Device SKU: 24GHz %s %s, 52GHz %s %s, 11.n %s %s\n";
46136 IWL_DEBUG_INFO(priv, debug_msg,
46137 data->sku_cap_band_24GHz_enable ? "" : "NOT", "enabled",
46138 data->sku_cap_band_52GHz_enable ? "" : "NOT", "enabled",
46139diff --git a/drivers/net/wireless/iwlwifi/pcie/trans.c b/drivers/net/wireless/iwlwifi/pcie/trans.c
46140index 6bc3100..dd1b80d 100644
46141--- a/drivers/net/wireless/iwlwifi/pcie/trans.c
46142+++ b/drivers/net/wireless/iwlwifi/pcie/trans.c
46143@@ -1249,7 +1249,7 @@ static ssize_t iwl_dbgfs_interrupt_write(struct file *file,
46144 struct isr_statistics *isr_stats = &trans_pcie->isr_stats;
46145
46146 char buf[8];
46147- int buf_size;
46148+ size_t buf_size;
46149 u32 reset_flag;
46150
46151 memset(buf, 0, sizeof(buf));
46152@@ -1270,7 +1270,7 @@ static ssize_t iwl_dbgfs_csr_write(struct file *file,
46153 {
46154 struct iwl_trans *trans = file->private_data;
46155 char buf[8];
46156- int buf_size;
46157+ size_t buf_size;
46158 int csr;
46159
46160 memset(buf, 0, sizeof(buf));
46161diff --git a/drivers/net/wireless/mac80211_hwsim.c b/drivers/net/wireless/mac80211_hwsim.c
46162index 2cd3f54..e936f90 100644
46163--- a/drivers/net/wireless/mac80211_hwsim.c
46164+++ b/drivers/net/wireless/mac80211_hwsim.c
46165@@ -2196,25 +2196,19 @@ static int __init init_mac80211_hwsim(void)
46166
46167 if (channels > 1) {
46168 hwsim_if_comb.num_different_channels = channels;
46169- mac80211_hwsim_ops.hw_scan = mac80211_hwsim_hw_scan;
46170- mac80211_hwsim_ops.cancel_hw_scan =
46171- mac80211_hwsim_cancel_hw_scan;
46172- mac80211_hwsim_ops.sw_scan_start = NULL;
46173- mac80211_hwsim_ops.sw_scan_complete = NULL;
46174- mac80211_hwsim_ops.remain_on_channel =
46175- mac80211_hwsim_roc;
46176- mac80211_hwsim_ops.cancel_remain_on_channel =
46177- mac80211_hwsim_croc;
46178- mac80211_hwsim_ops.add_chanctx =
46179- mac80211_hwsim_add_chanctx;
46180- mac80211_hwsim_ops.remove_chanctx =
46181- mac80211_hwsim_remove_chanctx;
46182- mac80211_hwsim_ops.change_chanctx =
46183- mac80211_hwsim_change_chanctx;
46184- mac80211_hwsim_ops.assign_vif_chanctx =
46185- mac80211_hwsim_assign_vif_chanctx;
46186- mac80211_hwsim_ops.unassign_vif_chanctx =
46187- mac80211_hwsim_unassign_vif_chanctx;
46188+ pax_open_kernel();
46189+ *(void **)&mac80211_hwsim_ops.hw_scan = mac80211_hwsim_hw_scan;
46190+ *(void **)&mac80211_hwsim_ops.cancel_hw_scan = mac80211_hwsim_cancel_hw_scan;
46191+ *(void **)&mac80211_hwsim_ops.sw_scan_start = NULL;
46192+ *(void **)&mac80211_hwsim_ops.sw_scan_complete = NULL;
46193+ *(void **)&mac80211_hwsim_ops.remain_on_channel = mac80211_hwsim_roc;
46194+ *(void **)&mac80211_hwsim_ops.cancel_remain_on_channel = mac80211_hwsim_croc;
46195+ *(void **)&mac80211_hwsim_ops.add_chanctx = mac80211_hwsim_add_chanctx;
46196+ *(void **)&mac80211_hwsim_ops.remove_chanctx = mac80211_hwsim_remove_chanctx;
46197+ *(void **)&mac80211_hwsim_ops.change_chanctx = mac80211_hwsim_change_chanctx;
46198+ *(void **)&mac80211_hwsim_ops.assign_vif_chanctx = mac80211_hwsim_assign_vif_chanctx;
46199+ *(void **)&mac80211_hwsim_ops.unassign_vif_chanctx = mac80211_hwsim_unassign_vif_chanctx;
46200+ pax_close_kernel();
46201 }
46202
46203 spin_lock_init(&hwsim_radio_lock);
46204diff --git a/drivers/net/wireless/rndis_wlan.c b/drivers/net/wireless/rndis_wlan.c
46205index 8169a85..7fa3b47 100644
46206--- a/drivers/net/wireless/rndis_wlan.c
46207+++ b/drivers/net/wireless/rndis_wlan.c
46208@@ -1238,7 +1238,7 @@ static int set_rts_threshold(struct usbnet *usbdev, u32 rts_threshold)
46209
46210 netdev_dbg(usbdev->net, "%s(): %i\n", __func__, rts_threshold);
46211
46212- if (rts_threshold < 0 || rts_threshold > 2347)
46213+ if (rts_threshold > 2347)
46214 rts_threshold = 2347;
46215
46216 tmp = cpu_to_le32(rts_threshold);
46217diff --git a/drivers/net/wireless/rt2x00/rt2x00.h b/drivers/net/wireless/rt2x00/rt2x00.h
46218index fe4c572..99dedfa 100644
46219--- a/drivers/net/wireless/rt2x00/rt2x00.h
46220+++ b/drivers/net/wireless/rt2x00/rt2x00.h
46221@@ -387,7 +387,7 @@ struct rt2x00_intf {
46222 * for hardware which doesn't support hardware
46223 * sequence counting.
46224 */
46225- atomic_t seqno;
46226+ atomic_unchecked_t seqno;
46227 };
46228
46229 static inline struct rt2x00_intf* vif_to_intf(struct ieee80211_vif *vif)
46230diff --git a/drivers/net/wireless/rt2x00/rt2x00queue.c b/drivers/net/wireless/rt2x00/rt2x00queue.c
46231index 66a2db8..70cad04 100644
46232--- a/drivers/net/wireless/rt2x00/rt2x00queue.c
46233+++ b/drivers/net/wireless/rt2x00/rt2x00queue.c
46234@@ -252,9 +252,9 @@ static void rt2x00queue_create_tx_descriptor_seq(struct rt2x00_dev *rt2x00dev,
46235 * sequence counter given by mac80211.
46236 */
46237 if (test_bit(ENTRY_TXD_FIRST_FRAGMENT, &txdesc->flags))
46238- seqno = atomic_add_return(0x10, &intf->seqno);
46239+ seqno = atomic_add_return_unchecked(0x10, &intf->seqno);
46240 else
46241- seqno = atomic_read(&intf->seqno);
46242+ seqno = atomic_read_unchecked(&intf->seqno);
46243
46244 hdr->seq_ctrl &= cpu_to_le16(IEEE80211_SCTL_FRAG);
46245 hdr->seq_ctrl |= cpu_to_le16(seqno);
46246diff --git a/drivers/net/wireless/ti/wl1251/sdio.c b/drivers/net/wireless/ti/wl1251/sdio.c
46247index e2b3d9c..67a5184 100644
46248--- a/drivers/net/wireless/ti/wl1251/sdio.c
46249+++ b/drivers/net/wireless/ti/wl1251/sdio.c
46250@@ -271,13 +271,17 @@ static int wl1251_sdio_probe(struct sdio_func *func,
46251
46252 irq_set_irq_type(wl->irq, IRQ_TYPE_EDGE_RISING);
46253
46254- wl1251_sdio_ops.enable_irq = wl1251_enable_line_irq;
46255- wl1251_sdio_ops.disable_irq = wl1251_disable_line_irq;
46256+ pax_open_kernel();
46257+ *(void **)&wl1251_sdio_ops.enable_irq = wl1251_enable_line_irq;
46258+ *(void **)&wl1251_sdio_ops.disable_irq = wl1251_disable_line_irq;
46259+ pax_close_kernel();
46260
46261 wl1251_info("using dedicated interrupt line");
46262 } else {
46263- wl1251_sdio_ops.enable_irq = wl1251_sdio_enable_irq;
46264- wl1251_sdio_ops.disable_irq = wl1251_sdio_disable_irq;
46265+ pax_open_kernel();
46266+ *(void **)&wl1251_sdio_ops.enable_irq = wl1251_sdio_enable_irq;
46267+ *(void **)&wl1251_sdio_ops.disable_irq = wl1251_sdio_disable_irq;
46268+ pax_close_kernel();
46269
46270 wl1251_info("using SDIO interrupt");
46271 }
46272diff --git a/drivers/net/wireless/ti/wl12xx/main.c b/drivers/net/wireless/ti/wl12xx/main.c
46273index 1c627da..69f7d17 100644
46274--- a/drivers/net/wireless/ti/wl12xx/main.c
46275+++ b/drivers/net/wireless/ti/wl12xx/main.c
46276@@ -656,7 +656,9 @@ static int wl12xx_identify_chip(struct wl1271 *wl)
46277 sizeof(wl->conf.mem));
46278
46279 /* read data preparation is only needed by wl127x */
46280- wl->ops->prepare_read = wl127x_prepare_read;
46281+ pax_open_kernel();
46282+ *(void **)&wl->ops->prepare_read = wl127x_prepare_read;
46283+ pax_close_kernel();
46284
46285 wlcore_set_min_fw_ver(wl, WL127X_CHIP_VER,
46286 WL127X_IFTYPE_SR_VER, WL127X_MAJOR_SR_VER,
46287@@ -681,7 +683,9 @@ static int wl12xx_identify_chip(struct wl1271 *wl)
46288 sizeof(wl->conf.mem));
46289
46290 /* read data preparation is only needed by wl127x */
46291- wl->ops->prepare_read = wl127x_prepare_read;
46292+ pax_open_kernel();
46293+ *(void **)&wl->ops->prepare_read = wl127x_prepare_read;
46294+ pax_close_kernel();
46295
46296 wlcore_set_min_fw_ver(wl, WL127X_CHIP_VER,
46297 WL127X_IFTYPE_SR_VER, WL127X_MAJOR_SR_VER,
46298diff --git a/drivers/net/wireless/ti/wl18xx/main.c b/drivers/net/wireless/ti/wl18xx/main.c
46299index 7aa0eb8..5a9ef38 100644
46300--- a/drivers/net/wireless/ti/wl18xx/main.c
46301+++ b/drivers/net/wireless/ti/wl18xx/main.c
46302@@ -1730,8 +1730,10 @@ static int wl18xx_setup(struct wl1271 *wl)
46303 }
46304
46305 if (!checksum_param) {
46306- wl18xx_ops.set_rx_csum = NULL;
46307- wl18xx_ops.init_vif = NULL;
46308+ pax_open_kernel();
46309+ *(void **)&wl18xx_ops.set_rx_csum = NULL;
46310+ *(void **)&wl18xx_ops.init_vif = NULL;
46311+ pax_close_kernel();
46312 }
46313
46314 /* Enable 11a Band only if we have 5G antennas */
46315diff --git a/drivers/net/wireless/zd1211rw/zd_usb.c b/drivers/net/wireless/zd1211rw/zd_usb.c
46316index 7ef0b4a..ff65c28 100644
46317--- a/drivers/net/wireless/zd1211rw/zd_usb.c
46318+++ b/drivers/net/wireless/zd1211rw/zd_usb.c
46319@@ -386,7 +386,7 @@ static inline void handle_regs_int(struct urb *urb)
46320 {
46321 struct zd_usb *usb = urb->context;
46322 struct zd_usb_interrupt *intr = &usb->intr;
46323- int len;
46324+ unsigned int len;
46325 u16 int_num;
46326
46327 ZD_ASSERT(in_interrupt());
46328diff --git a/drivers/nfc/nfcwilink.c b/drivers/nfc/nfcwilink.c
46329index 59f95d8..53e0e7f 100644
46330--- a/drivers/nfc/nfcwilink.c
46331+++ b/drivers/nfc/nfcwilink.c
46332@@ -513,7 +513,7 @@ static struct nci_ops nfcwilink_ops = {
46333
46334 static int nfcwilink_probe(struct platform_device *pdev)
46335 {
46336- static struct nfcwilink *drv;
46337+ struct nfcwilink *drv;
46338 int rc;
46339 __u32 protocols;
46340
46341diff --git a/drivers/oprofile/buffer_sync.c b/drivers/oprofile/buffer_sync.c
46342index d93b2b6..ae50401 100644
46343--- a/drivers/oprofile/buffer_sync.c
46344+++ b/drivers/oprofile/buffer_sync.c
46345@@ -332,7 +332,7 @@ static void add_data(struct op_entry *entry, struct mm_struct *mm)
46346 if (cookie == NO_COOKIE)
46347 offset = pc;
46348 if (cookie == INVALID_COOKIE) {
46349- atomic_inc(&oprofile_stats.sample_lost_no_mapping);
46350+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
46351 offset = pc;
46352 }
46353 if (cookie != last_cookie) {
46354@@ -376,14 +376,14 @@ add_sample(struct mm_struct *mm, struct op_sample *s, int in_kernel)
46355 /* add userspace sample */
46356
46357 if (!mm) {
46358- atomic_inc(&oprofile_stats.sample_lost_no_mm);
46359+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mm);
46360 return 0;
46361 }
46362
46363 cookie = lookup_dcookie(mm, s->eip, &offset);
46364
46365 if (cookie == INVALID_COOKIE) {
46366- atomic_inc(&oprofile_stats.sample_lost_no_mapping);
46367+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
46368 return 0;
46369 }
46370
46371@@ -552,7 +552,7 @@ void sync_buffer(int cpu)
46372 /* ignore backtraces if failed to add a sample */
46373 if (state == sb_bt_start) {
46374 state = sb_bt_ignore;
46375- atomic_inc(&oprofile_stats.bt_lost_no_mapping);
46376+ atomic_inc_unchecked(&oprofile_stats.bt_lost_no_mapping);
46377 }
46378 }
46379 release_mm(mm);
46380diff --git a/drivers/oprofile/event_buffer.c b/drivers/oprofile/event_buffer.c
46381index c0cc4e7..44d4e54 100644
46382--- a/drivers/oprofile/event_buffer.c
46383+++ b/drivers/oprofile/event_buffer.c
46384@@ -53,7 +53,7 @@ void add_event_entry(unsigned long value)
46385 }
46386
46387 if (buffer_pos == buffer_size) {
46388- atomic_inc(&oprofile_stats.event_lost_overflow);
46389+ atomic_inc_unchecked(&oprofile_stats.event_lost_overflow);
46390 return;
46391 }
46392
46393diff --git a/drivers/oprofile/oprof.c b/drivers/oprofile/oprof.c
46394index ed2c3ec..deda85a 100644
46395--- a/drivers/oprofile/oprof.c
46396+++ b/drivers/oprofile/oprof.c
46397@@ -110,7 +110,7 @@ static void switch_worker(struct work_struct *work)
46398 if (oprofile_ops.switch_events())
46399 return;
46400
46401- atomic_inc(&oprofile_stats.multiplex_counter);
46402+ atomic_inc_unchecked(&oprofile_stats.multiplex_counter);
46403 start_switch_worker();
46404 }
46405
46406diff --git a/drivers/oprofile/oprofile_files.c b/drivers/oprofile/oprofile_files.c
46407index ee2cfce..7f8f699 100644
46408--- a/drivers/oprofile/oprofile_files.c
46409+++ b/drivers/oprofile/oprofile_files.c
46410@@ -27,7 +27,7 @@ unsigned long oprofile_time_slice;
46411
46412 #ifdef CONFIG_OPROFILE_EVENT_MULTIPLEX
46413
46414-static ssize_t timeout_read(struct file *file, char __user *buf,
46415+static ssize_t __intentional_overflow(-1) timeout_read(struct file *file, char __user *buf,
46416 size_t count, loff_t *offset)
46417 {
46418 return oprofilefs_ulong_to_user(jiffies_to_msecs(oprofile_time_slice),
46419diff --git a/drivers/oprofile/oprofile_stats.c b/drivers/oprofile/oprofile_stats.c
46420index 59659ce..6c860a0 100644
46421--- a/drivers/oprofile/oprofile_stats.c
46422+++ b/drivers/oprofile/oprofile_stats.c
46423@@ -30,11 +30,11 @@ void oprofile_reset_stats(void)
46424 cpu_buf->sample_invalid_eip = 0;
46425 }
46426
46427- atomic_set(&oprofile_stats.sample_lost_no_mm, 0);
46428- atomic_set(&oprofile_stats.sample_lost_no_mapping, 0);
46429- atomic_set(&oprofile_stats.event_lost_overflow, 0);
46430- atomic_set(&oprofile_stats.bt_lost_no_mapping, 0);
46431- atomic_set(&oprofile_stats.multiplex_counter, 0);
46432+ atomic_set_unchecked(&oprofile_stats.sample_lost_no_mm, 0);
46433+ atomic_set_unchecked(&oprofile_stats.sample_lost_no_mapping, 0);
46434+ atomic_set_unchecked(&oprofile_stats.event_lost_overflow, 0);
46435+ atomic_set_unchecked(&oprofile_stats.bt_lost_no_mapping, 0);
46436+ atomic_set_unchecked(&oprofile_stats.multiplex_counter, 0);
46437 }
46438
46439
46440diff --git a/drivers/oprofile/oprofile_stats.h b/drivers/oprofile/oprofile_stats.h
46441index 1fc622b..8c48fc3 100644
46442--- a/drivers/oprofile/oprofile_stats.h
46443+++ b/drivers/oprofile/oprofile_stats.h
46444@@ -13,11 +13,11 @@
46445 #include <linux/atomic.h>
46446
46447 struct oprofile_stat_struct {
46448- atomic_t sample_lost_no_mm;
46449- atomic_t sample_lost_no_mapping;
46450- atomic_t bt_lost_no_mapping;
46451- atomic_t event_lost_overflow;
46452- atomic_t multiplex_counter;
46453+ atomic_unchecked_t sample_lost_no_mm;
46454+ atomic_unchecked_t sample_lost_no_mapping;
46455+ atomic_unchecked_t bt_lost_no_mapping;
46456+ atomic_unchecked_t event_lost_overflow;
46457+ atomic_unchecked_t multiplex_counter;
46458 };
46459
46460 extern struct oprofile_stat_struct oprofile_stats;
46461diff --git a/drivers/oprofile/oprofilefs.c b/drivers/oprofile/oprofilefs.c
46462index 3f49345..c750d0b 100644
46463--- a/drivers/oprofile/oprofilefs.c
46464+++ b/drivers/oprofile/oprofilefs.c
46465@@ -176,8 +176,8 @@ int oprofilefs_create_ro_ulong(struct dentry *root,
46466
46467 static ssize_t atomic_read_file(struct file *file, char __user *buf, size_t count, loff_t *offset)
46468 {
46469- atomic_t *val = file->private_data;
46470- return oprofilefs_ulong_to_user(atomic_read(val), buf, count, offset);
46471+ atomic_unchecked_t *val = file->private_data;
46472+ return oprofilefs_ulong_to_user(atomic_read_unchecked(val), buf, count, offset);
46473 }
46474
46475
46476@@ -189,7 +189,7 @@ static const struct file_operations atomic_ro_fops = {
46477
46478
46479 int oprofilefs_create_ro_atomic(struct dentry *root,
46480- char const *name, atomic_t *val)
46481+ char const *name, atomic_unchecked_t *val)
46482 {
46483 return __oprofilefs_create_file(root, name,
46484 &atomic_ro_fops, 0444, val);
46485diff --git a/drivers/oprofile/timer_int.c b/drivers/oprofile/timer_int.c
46486index 61be1d9..dec05d7 100644
46487--- a/drivers/oprofile/timer_int.c
46488+++ b/drivers/oprofile/timer_int.c
46489@@ -93,7 +93,7 @@ static int oprofile_cpu_notify(struct notifier_block *self,
46490 return NOTIFY_OK;
46491 }
46492
46493-static struct notifier_block __refdata oprofile_cpu_notifier = {
46494+static struct notifier_block oprofile_cpu_notifier = {
46495 .notifier_call = oprofile_cpu_notify,
46496 };
46497
46498diff --git a/drivers/parport/procfs.c b/drivers/parport/procfs.c
46499index 92ed045..62d39bd7 100644
46500--- a/drivers/parport/procfs.c
46501+++ b/drivers/parport/procfs.c
46502@@ -64,7 +64,7 @@ static int do_active_device(ctl_table *table, int write,
46503
46504 *ppos += len;
46505
46506- return copy_to_user(result, buffer, len) ? -EFAULT : 0;
46507+ return (len > sizeof buffer || copy_to_user(result, buffer, len)) ? -EFAULT : 0;
46508 }
46509
46510 #ifdef CONFIG_PARPORT_1284
46511@@ -106,7 +106,7 @@ static int do_autoprobe(ctl_table *table, int write,
46512
46513 *ppos += len;
46514
46515- return copy_to_user (result, buffer, len) ? -EFAULT : 0;
46516+ return (len > sizeof buffer || copy_to_user (result, buffer, len)) ? -EFAULT : 0;
46517 }
46518 #endif /* IEEE1284.3 support. */
46519
46520diff --git a/drivers/pci/hotplug/acpiphp_ibm.c b/drivers/pci/hotplug/acpiphp_ibm.c
46521index 2f5786c..61ab4d1 100644
46522--- a/drivers/pci/hotplug/acpiphp_ibm.c
46523+++ b/drivers/pci/hotplug/acpiphp_ibm.c
46524@@ -463,7 +463,9 @@ static int __init ibm_acpiphp_init(void)
46525 goto init_cleanup;
46526 }
46527
46528- ibm_apci_table_attr.size = ibm_get_table_from_acpi(NULL);
46529+ pax_open_kernel();
46530+ *(size_t *)&ibm_apci_table_attr.size = ibm_get_table_from_acpi(NULL);
46531+ pax_close_kernel();
46532 retval = sysfs_create_bin_file(sysdir, &ibm_apci_table_attr);
46533
46534 return retval;
46535diff --git a/drivers/pci/hotplug/cpcihp_generic.c b/drivers/pci/hotplug/cpcihp_generic.c
46536index a6a71c4..c91097b 100644
46537--- a/drivers/pci/hotplug/cpcihp_generic.c
46538+++ b/drivers/pci/hotplug/cpcihp_generic.c
46539@@ -73,7 +73,6 @@ static u16 port;
46540 static unsigned int enum_bit;
46541 static u8 enum_mask;
46542
46543-static struct cpci_hp_controller_ops generic_hpc_ops;
46544 static struct cpci_hp_controller generic_hpc;
46545
46546 static int __init validate_parameters(void)
46547@@ -139,6 +138,10 @@ static int query_enum(void)
46548 return ((value & enum_mask) == enum_mask);
46549 }
46550
46551+static struct cpci_hp_controller_ops generic_hpc_ops = {
46552+ .query_enum = query_enum,
46553+};
46554+
46555 static int __init cpcihp_generic_init(void)
46556 {
46557 int status;
46558@@ -165,7 +168,6 @@ static int __init cpcihp_generic_init(void)
46559 pci_dev_put(dev);
46560
46561 memset(&generic_hpc, 0, sizeof (struct cpci_hp_controller));
46562- generic_hpc_ops.query_enum = query_enum;
46563 generic_hpc.ops = &generic_hpc_ops;
46564
46565 status = cpci_hp_register_controller(&generic_hpc);
46566diff --git a/drivers/pci/hotplug/cpcihp_zt5550.c b/drivers/pci/hotplug/cpcihp_zt5550.c
46567index 449b4bb..257e2e8 100644
46568--- a/drivers/pci/hotplug/cpcihp_zt5550.c
46569+++ b/drivers/pci/hotplug/cpcihp_zt5550.c
46570@@ -59,7 +59,6 @@
46571 /* local variables */
46572 static bool debug;
46573 static bool poll;
46574-static struct cpci_hp_controller_ops zt5550_hpc_ops;
46575 static struct cpci_hp_controller zt5550_hpc;
46576
46577 /* Primary cPCI bus bridge device */
46578@@ -205,6 +204,10 @@ static int zt5550_hc_disable_irq(void)
46579 return 0;
46580 }
46581
46582+static struct cpci_hp_controller_ops zt5550_hpc_ops = {
46583+ .query_enum = zt5550_hc_query_enum,
46584+};
46585+
46586 static int zt5550_hc_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
46587 {
46588 int status;
46589@@ -216,16 +219,17 @@ static int zt5550_hc_init_one (struct pci_dev *pdev, const struct pci_device_id
46590 dbg("returned from zt5550_hc_config");
46591
46592 memset(&zt5550_hpc, 0, sizeof (struct cpci_hp_controller));
46593- zt5550_hpc_ops.query_enum = zt5550_hc_query_enum;
46594 zt5550_hpc.ops = &zt5550_hpc_ops;
46595 if(!poll) {
46596 zt5550_hpc.irq = hc_dev->irq;
46597 zt5550_hpc.irq_flags = IRQF_SHARED;
46598 zt5550_hpc.dev_id = hc_dev;
46599
46600- zt5550_hpc_ops.enable_irq = zt5550_hc_enable_irq;
46601- zt5550_hpc_ops.disable_irq = zt5550_hc_disable_irq;
46602- zt5550_hpc_ops.check_irq = zt5550_hc_check_irq;
46603+ pax_open_kernel();
46604+ *(void **)&zt5550_hpc_ops.enable_irq = zt5550_hc_enable_irq;
46605+ *(void **)&zt5550_hpc_ops.disable_irq = zt5550_hc_disable_irq;
46606+ *(void **)&zt5550_hpc_ops.check_irq = zt5550_hc_check_irq;
46607+ pax_open_kernel();
46608 } else {
46609 info("using ENUM# polling mode");
46610 }
46611diff --git a/drivers/pci/hotplug/cpqphp_nvram.c b/drivers/pci/hotplug/cpqphp_nvram.c
46612index 76ba8a1..20ca857 100644
46613--- a/drivers/pci/hotplug/cpqphp_nvram.c
46614+++ b/drivers/pci/hotplug/cpqphp_nvram.c
46615@@ -428,9 +428,13 @@ static u32 store_HRT (void __iomem *rom_start)
46616
46617 void compaq_nvram_init (void __iomem *rom_start)
46618 {
46619+
46620+#ifndef CONFIG_PAX_KERNEXEC
46621 if (rom_start) {
46622 compaq_int15_entry_point = (rom_start + ROM_INT15_PHY_ADDR - ROM_PHY_ADDR);
46623 }
46624+#endif
46625+
46626 dbg("int15 entry = %p\n", compaq_int15_entry_point);
46627
46628 /* initialize our int15 lock */
46629diff --git a/drivers/pci/hotplug/pci_hotplug_core.c b/drivers/pci/hotplug/pci_hotplug_core.c
46630index ec20f74..c1d961e 100644
46631--- a/drivers/pci/hotplug/pci_hotplug_core.c
46632+++ b/drivers/pci/hotplug/pci_hotplug_core.c
46633@@ -441,8 +441,10 @@ int __pci_hp_register(struct hotplug_slot *slot, struct pci_bus *bus,
46634 return -EINVAL;
46635 }
46636
46637- slot->ops->owner = owner;
46638- slot->ops->mod_name = mod_name;
46639+ pax_open_kernel();
46640+ *(struct module **)&slot->ops->owner = owner;
46641+ *(const char **)&slot->ops->mod_name = mod_name;
46642+ pax_close_kernel();
46643
46644 mutex_lock(&pci_hp_mutex);
46645 /*
46646diff --git a/drivers/pci/hotplug/pciehp_core.c b/drivers/pci/hotplug/pciehp_core.c
46647index f4a18f5..ff2463c 100644
46648--- a/drivers/pci/hotplug/pciehp_core.c
46649+++ b/drivers/pci/hotplug/pciehp_core.c
46650@@ -92,7 +92,7 @@ static int init_slot(struct controller *ctrl)
46651 struct slot *slot = ctrl->slot;
46652 struct hotplug_slot *hotplug = NULL;
46653 struct hotplug_slot_info *info = NULL;
46654- struct hotplug_slot_ops *ops = NULL;
46655+ hotplug_slot_ops_no_const *ops = NULL;
46656 char name[SLOT_NAME_SIZE];
46657 int retval = -ENOMEM;
46658
46659diff --git a/drivers/pci/pci-sysfs.c b/drivers/pci/pci-sysfs.c
46660index 7128cfd..a0640d6 100644
46661--- a/drivers/pci/pci-sysfs.c
46662+++ b/drivers/pci/pci-sysfs.c
46663@@ -1083,7 +1083,7 @@ static int pci_create_attr(struct pci_dev *pdev, int num, int write_combine)
46664 {
46665 /* allocate attribute structure, piggyback attribute name */
46666 int name_len = write_combine ? 13 : 10;
46667- struct bin_attribute *res_attr;
46668+ bin_attribute_no_const *res_attr;
46669 int retval;
46670
46671 res_attr = kzalloc(sizeof(*res_attr) + name_len, GFP_ATOMIC);
46672@@ -1268,7 +1268,7 @@ static struct device_attribute reset_attr = __ATTR(reset, 0200, NULL, reset_stor
46673 static int pci_create_capabilities_sysfs(struct pci_dev *dev)
46674 {
46675 int retval;
46676- struct bin_attribute *attr;
46677+ bin_attribute_no_const *attr;
46678
46679 /* If the device has VPD, try to expose it in sysfs. */
46680 if (dev->vpd) {
46681@@ -1315,7 +1315,7 @@ int __must_check pci_create_sysfs_dev_files (struct pci_dev *pdev)
46682 {
46683 int retval;
46684 int rom_size = 0;
46685- struct bin_attribute *attr;
46686+ bin_attribute_no_const *attr;
46687
46688 if (!sysfs_initialized)
46689 return -EACCES;
46690diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h
46691index 8a00c06..18a9715 100644
46692--- a/drivers/pci/pci.h
46693+++ b/drivers/pci/pci.h
46694@@ -95,7 +95,7 @@ struct pci_vpd_ops {
46695 struct pci_vpd {
46696 unsigned int len;
46697 const struct pci_vpd_ops *ops;
46698- struct bin_attribute *attr; /* descriptor for sysfs VPD entry */
46699+ bin_attribute_no_const *attr; /* descriptor for sysfs VPD entry */
46700 };
46701
46702 int pci_vpd_pci22_init(struct pci_dev *dev);
46703diff --git a/drivers/pci/pcie/aspm.c b/drivers/pci/pcie/aspm.c
46704index 403a443..034e050 100644
46705--- a/drivers/pci/pcie/aspm.c
46706+++ b/drivers/pci/pcie/aspm.c
46707@@ -27,9 +27,9 @@
46708 #define MODULE_PARAM_PREFIX "pcie_aspm."
46709
46710 /* Note: those are not register definitions */
46711-#define ASPM_STATE_L0S_UP (1) /* Upstream direction L0s state */
46712-#define ASPM_STATE_L0S_DW (2) /* Downstream direction L0s state */
46713-#define ASPM_STATE_L1 (4) /* L1 state */
46714+#define ASPM_STATE_L0S_UP (1U) /* Upstream direction L0s state */
46715+#define ASPM_STATE_L0S_DW (2U) /* Downstream direction L0s state */
46716+#define ASPM_STATE_L1 (4U) /* L1 state */
46717 #define ASPM_STATE_L0S (ASPM_STATE_L0S_UP | ASPM_STATE_L0S_DW)
46718 #define ASPM_STATE_ALL (ASPM_STATE_L0S | ASPM_STATE_L1)
46719
46720diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
46721index 7ef0f86..17b710f 100644
46722--- a/drivers/pci/probe.c
46723+++ b/drivers/pci/probe.c
46724@@ -175,7 +175,7 @@ int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type,
46725 struct pci_bus_region region, inverted_region;
46726 bool bar_too_big = false, bar_disabled = false;
46727
46728- mask = type ? PCI_ROM_ADDRESS_MASK : ~0;
46729+ mask = type ? (u32)PCI_ROM_ADDRESS_MASK : ~0;
46730
46731 /* No printks while decoding is disabled! */
46732 if (!dev->mmio_always_on) {
46733diff --git a/drivers/pci/proc.c b/drivers/pci/proc.c
46734index cdc7836..528635c 100644
46735--- a/drivers/pci/proc.c
46736+++ b/drivers/pci/proc.c
46737@@ -434,7 +434,16 @@ static const struct file_operations proc_bus_pci_dev_operations = {
46738 static int __init pci_proc_init(void)
46739 {
46740 struct pci_dev *dev = NULL;
46741+
46742+#ifdef CONFIG_GRKERNSEC_PROC_ADD
46743+#ifdef CONFIG_GRKERNSEC_PROC_USER
46744+ proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR, NULL);
46745+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
46746+ proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
46747+#endif
46748+#else
46749 proc_bus_pci_dir = proc_mkdir("bus/pci", NULL);
46750+#endif
46751 proc_create("devices", 0, proc_bus_pci_dir,
46752 &proc_bus_pci_dev_operations);
46753 proc_initialized = 1;
46754diff --git a/drivers/platform/x86/asus-wmi.c b/drivers/platform/x86/asus-wmi.c
46755index 19c313b..ed28b38 100644
46756--- a/drivers/platform/x86/asus-wmi.c
46757+++ b/drivers/platform/x86/asus-wmi.c
46758@@ -1618,6 +1618,10 @@ static int show_dsts(struct seq_file *m, void *data)
46759 int err;
46760 u32 retval = -1;
46761
46762+#ifdef CONFIG_GRKERNSEC_KMEM
46763+ return -EPERM;
46764+#endif
46765+
46766 err = asus_wmi_get_devstate(asus, asus->debug.dev_id, &retval);
46767
46768 if (err < 0)
46769@@ -1634,6 +1638,10 @@ static int show_devs(struct seq_file *m, void *data)
46770 int err;
46771 u32 retval = -1;
46772
46773+#ifdef CONFIG_GRKERNSEC_KMEM
46774+ return -EPERM;
46775+#endif
46776+
46777 err = asus_wmi_set_devstate(asus->debug.dev_id, asus->debug.ctrl_param,
46778 &retval);
46779
46780@@ -1658,6 +1666,10 @@ static int show_call(struct seq_file *m, void *data)
46781 union acpi_object *obj;
46782 acpi_status status;
46783
46784+#ifdef CONFIG_GRKERNSEC_KMEM
46785+ return -EPERM;
46786+#endif
46787+
46788 status = wmi_evaluate_method(ASUS_WMI_MGMT_GUID,
46789 1, asus->debug.method_id,
46790 &input, &output);
46791diff --git a/drivers/platform/x86/chromeos_laptop.c b/drivers/platform/x86/chromeos_laptop.c
46792index 3e5b4497..dcdfb70 100644
46793--- a/drivers/platform/x86/chromeos_laptop.c
46794+++ b/drivers/platform/x86/chromeos_laptop.c
46795@@ -301,7 +301,7 @@ static int __init setup_tsl2563_als(const struct dmi_system_id *id)
46796 return 0;
46797 }
46798
46799-static struct dmi_system_id __initdata chromeos_laptop_dmi_table[] = {
46800+static struct dmi_system_id __initconst chromeos_laptop_dmi_table[] = {
46801 {
46802 .ident = "Samsung Series 5 550 - Touchpad",
46803 .matches = {
46804diff --git a/drivers/platform/x86/msi-laptop.c b/drivers/platform/x86/msi-laptop.c
46805index 62f8030..c7f2a45 100644
46806--- a/drivers/platform/x86/msi-laptop.c
46807+++ b/drivers/platform/x86/msi-laptop.c
46808@@ -1000,12 +1000,14 @@ static int __init load_scm_model_init(struct platform_device *sdev)
46809
46810 if (!quirks->ec_read_only) {
46811 /* allow userland write sysfs file */
46812- dev_attr_bluetooth.store = store_bluetooth;
46813- dev_attr_wlan.store = store_wlan;
46814- dev_attr_threeg.store = store_threeg;
46815- dev_attr_bluetooth.attr.mode |= S_IWUSR;
46816- dev_attr_wlan.attr.mode |= S_IWUSR;
46817- dev_attr_threeg.attr.mode |= S_IWUSR;
46818+ pax_open_kernel();
46819+ *(void **)&dev_attr_bluetooth.store = store_bluetooth;
46820+ *(void **)&dev_attr_wlan.store = store_wlan;
46821+ *(void **)&dev_attr_threeg.store = store_threeg;
46822+ *(umode_t *)&dev_attr_bluetooth.attr.mode |= S_IWUSR;
46823+ *(umode_t *)&dev_attr_wlan.attr.mode |= S_IWUSR;
46824+ *(umode_t *)&dev_attr_threeg.attr.mode |= S_IWUSR;
46825+ pax_close_kernel();
46826 }
46827
46828 /* disable hardware control by fn key */
46829diff --git a/drivers/platform/x86/msi-wmi.c b/drivers/platform/x86/msi-wmi.c
46830index 70222f2..8c8ce66 100644
46831--- a/drivers/platform/x86/msi-wmi.c
46832+++ b/drivers/platform/x86/msi-wmi.c
46833@@ -183,7 +183,7 @@ static const struct backlight_ops msi_backlight_ops = {
46834 static void msi_wmi_notify(u32 value, void *context)
46835 {
46836 struct acpi_buffer response = { ACPI_ALLOCATE_BUFFER, NULL };
46837- static struct key_entry *key;
46838+ struct key_entry *key;
46839 union acpi_object *obj;
46840 acpi_status status;
46841
46842diff --git a/drivers/platform/x86/sony-laptop.c b/drivers/platform/x86/sony-laptop.c
46843index 3484dd2..13ee730 100644
46844--- a/drivers/platform/x86/sony-laptop.c
46845+++ b/drivers/platform/x86/sony-laptop.c
46846@@ -2448,7 +2448,7 @@ static void sony_nc_gfx_switch_cleanup(struct platform_device *pd)
46847 }
46848
46849 /* High speed charging function */
46850-static struct device_attribute *hsc_handle;
46851+static device_attribute_no_const *hsc_handle;
46852
46853 static ssize_t sony_nc_highspeed_charging_store(struct device *dev,
46854 struct device_attribute *attr,
46855diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c
46856index 4e86e97..04d50d1 100644
46857--- a/drivers/platform/x86/thinkpad_acpi.c
46858+++ b/drivers/platform/x86/thinkpad_acpi.c
46859@@ -2091,7 +2091,7 @@ static int hotkey_mask_get(void)
46860 return 0;
46861 }
46862
46863-void static hotkey_mask_warn_incomplete_mask(void)
46864+static void hotkey_mask_warn_incomplete_mask(void)
46865 {
46866 /* log only what the user can fix... */
46867 const u32 wantedmask = hotkey_driver_mask &
46868@@ -2318,11 +2318,6 @@ static void hotkey_read_nvram(struct tp_nvram_state *n, const u32 m)
46869 }
46870 }
46871
46872-static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
46873- struct tp_nvram_state *newn,
46874- const u32 event_mask)
46875-{
46876-
46877 #define TPACPI_COMPARE_KEY(__scancode, __member) \
46878 do { \
46879 if ((event_mask & (1 << __scancode)) && \
46880@@ -2336,36 +2331,42 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
46881 tpacpi_hotkey_send_key(__scancode); \
46882 } while (0)
46883
46884- void issue_volchange(const unsigned int oldvol,
46885- const unsigned int newvol)
46886- {
46887- unsigned int i = oldvol;
46888+static void issue_volchange(const unsigned int oldvol,
46889+ const unsigned int newvol,
46890+ const u32 event_mask)
46891+{
46892+ unsigned int i = oldvol;
46893
46894- while (i > newvol) {
46895- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
46896- i--;
46897- }
46898- while (i < newvol) {
46899- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
46900- i++;
46901- }
46902+ while (i > newvol) {
46903+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
46904+ i--;
46905 }
46906+ while (i < newvol) {
46907+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
46908+ i++;
46909+ }
46910+}
46911
46912- void issue_brightnesschange(const unsigned int oldbrt,
46913- const unsigned int newbrt)
46914- {
46915- unsigned int i = oldbrt;
46916+static void issue_brightnesschange(const unsigned int oldbrt,
46917+ const unsigned int newbrt,
46918+ const u32 event_mask)
46919+{
46920+ unsigned int i = oldbrt;
46921
46922- while (i > newbrt) {
46923- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
46924- i--;
46925- }
46926- while (i < newbrt) {
46927- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
46928- i++;
46929- }
46930+ while (i > newbrt) {
46931+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
46932+ i--;
46933+ }
46934+ while (i < newbrt) {
46935+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
46936+ i++;
46937 }
46938+}
46939
46940+static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
46941+ struct tp_nvram_state *newn,
46942+ const u32 event_mask)
46943+{
46944 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_THINKPAD, thinkpad_toggle);
46945 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNSPACE, zoom_toggle);
46946 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF7, display_toggle);
46947@@ -2399,7 +2400,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
46948 oldn->volume_level != newn->volume_level) {
46949 /* recently muted, or repeated mute keypress, or
46950 * multiple presses ending in mute */
46951- issue_volchange(oldn->volume_level, newn->volume_level);
46952+ issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
46953 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_MUTE);
46954 }
46955 } else {
46956@@ -2409,7 +2410,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
46957 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
46958 }
46959 if (oldn->volume_level != newn->volume_level) {
46960- issue_volchange(oldn->volume_level, newn->volume_level);
46961+ issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
46962 } else if (oldn->volume_toggle != newn->volume_toggle) {
46963 /* repeated vol up/down keypress at end of scale ? */
46964 if (newn->volume_level == 0)
46965@@ -2422,7 +2423,8 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
46966 /* handle brightness */
46967 if (oldn->brightness_level != newn->brightness_level) {
46968 issue_brightnesschange(oldn->brightness_level,
46969- newn->brightness_level);
46970+ newn->brightness_level,
46971+ event_mask);
46972 } else if (oldn->brightness_toggle != newn->brightness_toggle) {
46973 /* repeated key presses that didn't change state */
46974 if (newn->brightness_level == 0)
46975@@ -2431,10 +2433,10 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
46976 && !tp_features.bright_unkfw)
46977 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
46978 }
46979+}
46980
46981 #undef TPACPI_COMPARE_KEY
46982 #undef TPACPI_MAY_SEND_KEY
46983-}
46984
46985 /*
46986 * Polling driver
46987diff --git a/drivers/pnp/pnpbios/bioscalls.c b/drivers/pnp/pnpbios/bioscalls.c
46988index 769d265..a3a05ca 100644
46989--- a/drivers/pnp/pnpbios/bioscalls.c
46990+++ b/drivers/pnp/pnpbios/bioscalls.c
46991@@ -58,7 +58,7 @@ do { \
46992 set_desc_limit(&gdt[(selname) >> 3], (size) - 1); \
46993 } while(0)
46994
46995-static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
46996+static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
46997 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
46998
46999 /*
47000@@ -95,7 +95,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
47001
47002 cpu = get_cpu();
47003 save_desc_40 = get_cpu_gdt_table(cpu)[0x40 / 8];
47004+
47005+ pax_open_kernel();
47006 get_cpu_gdt_table(cpu)[0x40 / 8] = bad_bios_desc;
47007+ pax_close_kernel();
47008
47009 /* On some boxes IRQ's during PnP BIOS calls are deadly. */
47010 spin_lock_irqsave(&pnp_bios_lock, flags);
47011@@ -133,7 +136,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
47012 :"memory");
47013 spin_unlock_irqrestore(&pnp_bios_lock, flags);
47014
47015+ pax_open_kernel();
47016 get_cpu_gdt_table(cpu)[0x40 / 8] = save_desc_40;
47017+ pax_close_kernel();
47018+
47019 put_cpu();
47020
47021 /* If we get here and this is set then the PnP BIOS faulted on us. */
47022@@ -467,7 +473,7 @@ int pnp_bios_read_escd(char *data, u32 nvram_base)
47023 return status;
47024 }
47025
47026-void pnpbios_calls_init(union pnp_bios_install_struct *header)
47027+void __init pnpbios_calls_init(union pnp_bios_install_struct *header)
47028 {
47029 int i;
47030
47031@@ -475,6 +481,8 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
47032 pnp_bios_callpoint.offset = header->fields.pm16offset;
47033 pnp_bios_callpoint.segment = PNP_CS16;
47034
47035+ pax_open_kernel();
47036+
47037 for_each_possible_cpu(i) {
47038 struct desc_struct *gdt = get_cpu_gdt_table(i);
47039 if (!gdt)
47040@@ -486,4 +494,6 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
47041 set_desc_base(&gdt[GDT_ENTRY_PNPBIOS_DS],
47042 (unsigned long)__va(header->fields.pm16dseg));
47043 }
47044+
47045+ pax_close_kernel();
47046 }
47047diff --git a/drivers/pnp/resource.c b/drivers/pnp/resource.c
47048index d95e101..67f0c3f 100644
47049--- a/drivers/pnp/resource.c
47050+++ b/drivers/pnp/resource.c
47051@@ -360,7 +360,7 @@ int pnp_check_irq(struct pnp_dev *dev, struct resource *res)
47052 return 1;
47053
47054 /* check if the resource is valid */
47055- if (*irq < 0 || *irq > 15)
47056+ if (*irq > 15)
47057 return 0;
47058
47059 /* check if the resource is reserved */
47060@@ -424,7 +424,7 @@ int pnp_check_dma(struct pnp_dev *dev, struct resource *res)
47061 return 1;
47062
47063 /* check if the resource is valid */
47064- if (*dma < 0 || *dma == 4 || *dma > 7)
47065+ if (*dma == 4 || *dma > 7)
47066 return 0;
47067
47068 /* check if the resource is reserved */
47069diff --git a/drivers/power/pda_power.c b/drivers/power/pda_power.c
47070index 0c52e2a..3421ab7 100644
47071--- a/drivers/power/pda_power.c
47072+++ b/drivers/power/pda_power.c
47073@@ -37,7 +37,11 @@ static int polling;
47074
47075 #if IS_ENABLED(CONFIG_USB_PHY)
47076 static struct usb_phy *transceiver;
47077-static struct notifier_block otg_nb;
47078+static int otg_handle_notification(struct notifier_block *nb,
47079+ unsigned long event, void *unused);
47080+static struct notifier_block otg_nb = {
47081+ .notifier_call = otg_handle_notification
47082+};
47083 #endif
47084
47085 static struct regulator *ac_draw;
47086@@ -369,7 +373,6 @@ static int pda_power_probe(struct platform_device *pdev)
47087
47088 #if IS_ENABLED(CONFIG_USB_PHY)
47089 if (!IS_ERR_OR_NULL(transceiver) && pdata->use_otg_notifier) {
47090- otg_nb.notifier_call = otg_handle_notification;
47091 ret = usb_register_notifier(transceiver, &otg_nb);
47092 if (ret) {
47093 dev_err(dev, "failure to register otg notifier\n");
47094diff --git a/drivers/power/power_supply.h b/drivers/power/power_supply.h
47095index cc439fd..8fa30df 100644
47096--- a/drivers/power/power_supply.h
47097+++ b/drivers/power/power_supply.h
47098@@ -16,12 +16,12 @@ struct power_supply;
47099
47100 #ifdef CONFIG_SYSFS
47101
47102-extern void power_supply_init_attrs(struct device_type *dev_type);
47103+extern void power_supply_init_attrs(void);
47104 extern int power_supply_uevent(struct device *dev, struct kobj_uevent_env *env);
47105
47106 #else
47107
47108-static inline void power_supply_init_attrs(struct device_type *dev_type) {}
47109+static inline void power_supply_init_attrs(void) {}
47110 #define power_supply_uevent NULL
47111
47112 #endif /* CONFIG_SYSFS */
47113diff --git a/drivers/power/power_supply_core.c b/drivers/power/power_supply_core.c
47114index 557af94..84dc1fe 100644
47115--- a/drivers/power/power_supply_core.c
47116+++ b/drivers/power/power_supply_core.c
47117@@ -24,7 +24,10 @@
47118 struct class *power_supply_class;
47119 EXPORT_SYMBOL_GPL(power_supply_class);
47120
47121-static struct device_type power_supply_dev_type;
47122+extern const struct attribute_group *power_supply_attr_groups[];
47123+static struct device_type power_supply_dev_type = {
47124+ .groups = power_supply_attr_groups,
47125+};
47126
47127 static bool __power_supply_is_supplied_by(struct power_supply *supplier,
47128 struct power_supply *supply)
47129@@ -584,7 +587,7 @@ static int __init power_supply_class_init(void)
47130 return PTR_ERR(power_supply_class);
47131
47132 power_supply_class->dev_uevent = power_supply_uevent;
47133- power_supply_init_attrs(&power_supply_dev_type);
47134+ power_supply_init_attrs();
47135
47136 return 0;
47137 }
47138diff --git a/drivers/power/power_supply_sysfs.c b/drivers/power/power_supply_sysfs.c
47139index 44420d1..967126e 100644
47140--- a/drivers/power/power_supply_sysfs.c
47141+++ b/drivers/power/power_supply_sysfs.c
47142@@ -230,17 +230,15 @@ static struct attribute_group power_supply_attr_group = {
47143 .is_visible = power_supply_attr_is_visible,
47144 };
47145
47146-static const struct attribute_group *power_supply_attr_groups[] = {
47147+const struct attribute_group *power_supply_attr_groups[] = {
47148 &power_supply_attr_group,
47149 NULL,
47150 };
47151
47152-void power_supply_init_attrs(struct device_type *dev_type)
47153+void power_supply_init_attrs(void)
47154 {
47155 int i;
47156
47157- dev_type->groups = power_supply_attr_groups;
47158-
47159 for (i = 0; i < ARRAY_SIZE(power_supply_attrs); i++)
47160 __power_supply_attrs[i] = &power_supply_attrs[i].attr;
47161 }
47162diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
47163index a01b8b3..37c2afe 100644
47164--- a/drivers/regulator/core.c
47165+++ b/drivers/regulator/core.c
47166@@ -3307,7 +3307,7 @@ regulator_register(const struct regulator_desc *regulator_desc,
47167 {
47168 const struct regulation_constraints *constraints = NULL;
47169 const struct regulator_init_data *init_data;
47170- static atomic_t regulator_no = ATOMIC_INIT(0);
47171+ static atomic_unchecked_t regulator_no = ATOMIC_INIT(0);
47172 struct regulator_dev *rdev;
47173 struct device *dev;
47174 int ret, i;
47175@@ -3377,7 +3377,7 @@ regulator_register(const struct regulator_desc *regulator_desc,
47176 rdev->dev.of_node = config->of_node;
47177 rdev->dev.parent = dev;
47178 dev_set_name(&rdev->dev, "regulator.%d",
47179- atomic_inc_return(&regulator_no) - 1);
47180+ atomic_inc_return_unchecked(&regulator_no) - 1);
47181 ret = device_register(&rdev->dev);
47182 if (ret != 0) {
47183 put_device(&rdev->dev);
47184diff --git a/drivers/regulator/max8660.c b/drivers/regulator/max8660.c
47185index 144bcac..d20e7db 100644
47186--- a/drivers/regulator/max8660.c
47187+++ b/drivers/regulator/max8660.c
47188@@ -420,8 +420,10 @@ static int max8660_probe(struct i2c_client *client,
47189 max8660->shadow_regs[MAX8660_OVER1] = 5;
47190 } else {
47191 /* Otherwise devices can be toggled via software */
47192- max8660_dcdc_ops.enable = max8660_dcdc_enable;
47193- max8660_dcdc_ops.disable = max8660_dcdc_disable;
47194+ pax_open_kernel();
47195+ *(void **)&max8660_dcdc_ops.enable = max8660_dcdc_enable;
47196+ *(void **)&max8660_dcdc_ops.disable = max8660_dcdc_disable;
47197+ pax_close_kernel();
47198 }
47199
47200 /*
47201diff --git a/drivers/regulator/max8973-regulator.c b/drivers/regulator/max8973-regulator.c
47202index 5b77ab7..a62f061 100644
47203--- a/drivers/regulator/max8973-regulator.c
47204+++ b/drivers/regulator/max8973-regulator.c
47205@@ -406,9 +406,11 @@ static int max8973_probe(struct i2c_client *client,
47206 if (!pdata || !pdata->enable_ext_control) {
47207 max->desc.enable_reg = MAX8973_VOUT;
47208 max->desc.enable_mask = MAX8973_VOUT_ENABLE;
47209- max->ops.enable = regulator_enable_regmap;
47210- max->ops.disable = regulator_disable_regmap;
47211- max->ops.is_enabled = regulator_is_enabled_regmap;
47212+ pax_open_kernel();
47213+ *(void **)&max->ops.enable = regulator_enable_regmap;
47214+ *(void **)&max->ops.disable = regulator_disable_regmap;
47215+ *(void **)&max->ops.is_enabled = regulator_is_enabled_regmap;
47216+ pax_close_kernel();
47217 }
47218
47219 if (pdata) {
47220diff --git a/drivers/regulator/mc13892-regulator.c b/drivers/regulator/mc13892-regulator.c
47221index 1037e07..e64dea1 100644
47222--- a/drivers/regulator/mc13892-regulator.c
47223+++ b/drivers/regulator/mc13892-regulator.c
47224@@ -582,10 +582,12 @@ static int mc13892_regulator_probe(struct platform_device *pdev)
47225 }
47226 mc13xxx_unlock(mc13892);
47227
47228- mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
47229+ pax_open_kernel();
47230+ *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
47231 = mc13892_vcam_set_mode;
47232- mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
47233+ *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
47234 = mc13892_vcam_get_mode;
47235+ pax_close_kernel();
47236
47237 mc13xxx_data = mc13xxx_parse_regulators_dt(pdev, mc13892_regulators,
47238 ARRAY_SIZE(mc13892_regulators));
47239diff --git a/drivers/rtc/rtc-cmos.c b/drivers/rtc/rtc-cmos.c
47240index 24e733c..bfbaa3e 100644
47241--- a/drivers/rtc/rtc-cmos.c
47242+++ b/drivers/rtc/rtc-cmos.c
47243@@ -731,7 +731,9 @@ cmos_do_probe(struct device *dev, struct resource *ports, int rtc_irq)
47244 hpet_rtc_timer_init();
47245
47246 /* export at least the first block of NVRAM */
47247- nvram.size = address_space - NVRAM_OFFSET;
47248+ pax_open_kernel();
47249+ *(size_t *)&nvram.size = address_space - NVRAM_OFFSET;
47250+ pax_close_kernel();
47251 retval = sysfs_create_bin_file(&dev->kobj, &nvram);
47252 if (retval < 0) {
47253 dev_dbg(dev, "can't create nvram file? %d\n", retval);
47254diff --git a/drivers/rtc/rtc-dev.c b/drivers/rtc/rtc-dev.c
47255index d049393..bb20be0 100644
47256--- a/drivers/rtc/rtc-dev.c
47257+++ b/drivers/rtc/rtc-dev.c
47258@@ -16,6 +16,7 @@
47259 #include <linux/module.h>
47260 #include <linux/rtc.h>
47261 #include <linux/sched.h>
47262+#include <linux/grsecurity.h>
47263 #include "rtc-core.h"
47264
47265 static dev_t rtc_devt;
47266@@ -347,6 +348,8 @@ static long rtc_dev_ioctl(struct file *file,
47267 if (copy_from_user(&tm, uarg, sizeof(tm)))
47268 return -EFAULT;
47269
47270+ gr_log_timechange();
47271+
47272 return rtc_set_time(rtc, &tm);
47273
47274 case RTC_PIE_ON:
47275diff --git a/drivers/rtc/rtc-ds1307.c b/drivers/rtc/rtc-ds1307.c
47276index ca18fd1..055e42d 100644
47277--- a/drivers/rtc/rtc-ds1307.c
47278+++ b/drivers/rtc/rtc-ds1307.c
47279@@ -107,7 +107,7 @@ struct ds1307 {
47280 u8 offset; /* register's offset */
47281 u8 regs[11];
47282 u16 nvram_offset;
47283- struct bin_attribute *nvram;
47284+ bin_attribute_no_const *nvram;
47285 enum ds_type type;
47286 unsigned long flags;
47287 #define HAS_NVRAM 0 /* bit 0 == sysfs file active */
47288diff --git a/drivers/rtc/rtc-m48t59.c b/drivers/rtc/rtc-m48t59.c
47289index fcb0329..d77b7f2 100644
47290--- a/drivers/rtc/rtc-m48t59.c
47291+++ b/drivers/rtc/rtc-m48t59.c
47292@@ -483,7 +483,9 @@ static int m48t59_rtc_probe(struct platform_device *pdev)
47293 if (IS_ERR(m48t59->rtc))
47294 return PTR_ERR(m48t59->rtc);
47295
47296- m48t59_nvram_attr.size = pdata->offset;
47297+ pax_open_kernel();
47298+ *(size_t *)&m48t59_nvram_attr.size = pdata->offset;
47299+ pax_close_kernel();
47300
47301 ret = sysfs_create_bin_file(&pdev->dev.kobj, &m48t59_nvram_attr);
47302 if (ret)
47303diff --git a/drivers/scsi/aic7xxx/aic79xx_pci.c b/drivers/scsi/aic7xxx/aic79xx_pci.c
47304index 14b5f8d..cc9bd26 100644
47305--- a/drivers/scsi/aic7xxx/aic79xx_pci.c
47306+++ b/drivers/scsi/aic7xxx/aic79xx_pci.c
47307@@ -827,7 +827,7 @@ ahd_pci_intr(struct ahd_softc *ahd)
47308 for (bit = 0; bit < 8; bit++) {
47309
47310 if ((pci_status[i] & (0x1 << bit)) != 0) {
47311- static const char *s;
47312+ const char *s;
47313
47314 s = pci_status_strings[bit];
47315 if (i == 7/*TARG*/ && bit == 3)
47316@@ -887,23 +887,15 @@ ahd_pci_split_intr(struct ahd_softc *ahd, u_int intstat)
47317
47318 for (bit = 0; bit < 8; bit++) {
47319
47320- if ((split_status[i] & (0x1 << bit)) != 0) {
47321- static const char *s;
47322-
47323- s = split_status_strings[bit];
47324- printk(s, ahd_name(ahd),
47325+ if ((split_status[i] & (0x1 << bit)) != 0)
47326+ printk(split_status_strings[bit], ahd_name(ahd),
47327 split_status_source[i]);
47328- }
47329
47330 if (i > 1)
47331 continue;
47332
47333- if ((sg_split_status[i] & (0x1 << bit)) != 0) {
47334- static const char *s;
47335-
47336- s = split_status_strings[bit];
47337- printk(s, ahd_name(ahd), "SG");
47338- }
47339+ if ((sg_split_status[i] & (0x1 << bit)) != 0)
47340+ printk(split_status_strings[bit], ahd_name(ahd), "SG");
47341 }
47342 }
47343 /*
47344diff --git a/drivers/scsi/bfa/bfa_fcpim.h b/drivers/scsi/bfa/bfa_fcpim.h
47345index e693af6..2e525b6 100644
47346--- a/drivers/scsi/bfa/bfa_fcpim.h
47347+++ b/drivers/scsi/bfa/bfa_fcpim.h
47348@@ -36,7 +36,7 @@ struct bfa_iotag_s {
47349
47350 struct bfa_itn_s {
47351 bfa_isr_func_t isr;
47352-};
47353+} __no_const;
47354
47355 void bfa_itn_create(struct bfa_s *bfa, struct bfa_rport_s *rport,
47356 void (*isr)(struct bfa_s *bfa, struct bfi_msg_s *m));
47357diff --git a/drivers/scsi/bfa/bfa_fcs.c b/drivers/scsi/bfa/bfa_fcs.c
47358index a3ab5cc..8143622 100644
47359--- a/drivers/scsi/bfa/bfa_fcs.c
47360+++ b/drivers/scsi/bfa/bfa_fcs.c
47361@@ -38,10 +38,21 @@ struct bfa_fcs_mod_s {
47362 #define BFA_FCS_MODULE(_mod) { _mod ## _modinit, _mod ## _modexit }
47363
47364 static struct bfa_fcs_mod_s fcs_modules[] = {
47365- { bfa_fcs_port_attach, NULL, NULL },
47366- { bfa_fcs_uf_attach, NULL, NULL },
47367- { bfa_fcs_fabric_attach, bfa_fcs_fabric_modinit,
47368- bfa_fcs_fabric_modexit },
47369+ {
47370+ .attach = bfa_fcs_port_attach,
47371+ .modinit = NULL,
47372+ .modexit = NULL
47373+ },
47374+ {
47375+ .attach = bfa_fcs_uf_attach,
47376+ .modinit = NULL,
47377+ .modexit = NULL
47378+ },
47379+ {
47380+ .attach = bfa_fcs_fabric_attach,
47381+ .modinit = bfa_fcs_fabric_modinit,
47382+ .modexit = bfa_fcs_fabric_modexit
47383+ },
47384 };
47385
47386 /*
47387diff --git a/drivers/scsi/bfa/bfa_fcs_lport.c b/drivers/scsi/bfa/bfa_fcs_lport.c
47388index f5e4e61..a0acaf6 100644
47389--- a/drivers/scsi/bfa/bfa_fcs_lport.c
47390+++ b/drivers/scsi/bfa/bfa_fcs_lport.c
47391@@ -89,15 +89,26 @@ static struct {
47392 void (*offline) (struct bfa_fcs_lport_s *port);
47393 } __port_action[] = {
47394 {
47395- bfa_fcs_lport_unknown_init, bfa_fcs_lport_unknown_online,
47396- bfa_fcs_lport_unknown_offline}, {
47397- bfa_fcs_lport_fab_init, bfa_fcs_lport_fab_online,
47398- bfa_fcs_lport_fab_offline}, {
47399- bfa_fcs_lport_n2n_init, bfa_fcs_lport_n2n_online,
47400- bfa_fcs_lport_n2n_offline}, {
47401- bfa_fcs_lport_loop_init, bfa_fcs_lport_loop_online,
47402- bfa_fcs_lport_loop_offline},
47403- };
47404+ .init = bfa_fcs_lport_unknown_init,
47405+ .online = bfa_fcs_lport_unknown_online,
47406+ .offline = bfa_fcs_lport_unknown_offline
47407+ },
47408+ {
47409+ .init = bfa_fcs_lport_fab_init,
47410+ .online = bfa_fcs_lport_fab_online,
47411+ .offline = bfa_fcs_lport_fab_offline
47412+ },
47413+ {
47414+ .init = bfa_fcs_lport_n2n_init,
47415+ .online = bfa_fcs_lport_n2n_online,
47416+ .offline = bfa_fcs_lport_n2n_offline
47417+ },
47418+ {
47419+ .init = bfa_fcs_lport_loop_init,
47420+ .online = bfa_fcs_lport_loop_online,
47421+ .offline = bfa_fcs_lport_loop_offline
47422+ },
47423+};
47424
47425 /*
47426 * fcs_port_sm FCS logical port state machine
47427diff --git a/drivers/scsi/bfa/bfa_ioc.h b/drivers/scsi/bfa/bfa_ioc.h
47428index 90814fe..4384138 100644
47429--- a/drivers/scsi/bfa/bfa_ioc.h
47430+++ b/drivers/scsi/bfa/bfa_ioc.h
47431@@ -258,7 +258,7 @@ struct bfa_ioc_cbfn_s {
47432 bfa_ioc_disable_cbfn_t disable_cbfn;
47433 bfa_ioc_hbfail_cbfn_t hbfail_cbfn;
47434 bfa_ioc_reset_cbfn_t reset_cbfn;
47435-};
47436+} __no_const;
47437
47438 /*
47439 * IOC event notification mechanism.
47440@@ -352,7 +352,7 @@ struct bfa_ioc_hwif_s {
47441 void (*ioc_set_alt_fwstate) (struct bfa_ioc_s *ioc,
47442 enum bfi_ioc_state fwstate);
47443 enum bfi_ioc_state (*ioc_get_alt_fwstate) (struct bfa_ioc_s *ioc);
47444-};
47445+} __no_const;
47446
47447 /*
47448 * Queue element to wait for room in request queue. FIFO order is
47449diff --git a/drivers/scsi/bfa/bfa_modules.h b/drivers/scsi/bfa/bfa_modules.h
47450index a14c784..6de6790 100644
47451--- a/drivers/scsi/bfa/bfa_modules.h
47452+++ b/drivers/scsi/bfa/bfa_modules.h
47453@@ -78,12 +78,12 @@ enum {
47454 \
47455 extern struct bfa_module_s hal_mod_ ## __mod; \
47456 struct bfa_module_s hal_mod_ ## __mod = { \
47457- bfa_ ## __mod ## _meminfo, \
47458- bfa_ ## __mod ## _attach, \
47459- bfa_ ## __mod ## _detach, \
47460- bfa_ ## __mod ## _start, \
47461- bfa_ ## __mod ## _stop, \
47462- bfa_ ## __mod ## _iocdisable, \
47463+ .meminfo = bfa_ ## __mod ## _meminfo, \
47464+ .attach = bfa_ ## __mod ## _attach, \
47465+ .detach = bfa_ ## __mod ## _detach, \
47466+ .start = bfa_ ## __mod ## _start, \
47467+ .stop = bfa_ ## __mod ## _stop, \
47468+ .iocdisable = bfa_ ## __mod ## _iocdisable, \
47469 }
47470
47471 #define BFA_CACHELINE_SZ (256)
47472diff --git a/drivers/scsi/fcoe/fcoe_sysfs.c b/drivers/scsi/fcoe/fcoe_sysfs.c
47473index c9382d6..6619864 100644
47474--- a/drivers/scsi/fcoe/fcoe_sysfs.c
47475+++ b/drivers/scsi/fcoe/fcoe_sysfs.c
47476@@ -33,8 +33,8 @@
47477 */
47478 #include "libfcoe.h"
47479
47480-static atomic_t ctlr_num;
47481-static atomic_t fcf_num;
47482+static atomic_unchecked_t ctlr_num;
47483+static atomic_unchecked_t fcf_num;
47484
47485 /*
47486 * fcoe_fcf_dev_loss_tmo: the default number of seconds that fcoe sysfs
47487@@ -681,7 +681,7 @@ struct fcoe_ctlr_device *fcoe_ctlr_device_add(struct device *parent,
47488 if (!ctlr)
47489 goto out;
47490
47491- ctlr->id = atomic_inc_return(&ctlr_num) - 1;
47492+ ctlr->id = atomic_inc_return_unchecked(&ctlr_num) - 1;
47493 ctlr->f = f;
47494 ctlr->mode = FIP_CONN_TYPE_FABRIC;
47495 INIT_LIST_HEAD(&ctlr->fcfs);
47496@@ -898,7 +898,7 @@ struct fcoe_fcf_device *fcoe_fcf_device_add(struct fcoe_ctlr_device *ctlr,
47497 fcf->dev.parent = &ctlr->dev;
47498 fcf->dev.bus = &fcoe_bus_type;
47499 fcf->dev.type = &fcoe_fcf_device_type;
47500- fcf->id = atomic_inc_return(&fcf_num) - 1;
47501+ fcf->id = atomic_inc_return_unchecked(&fcf_num) - 1;
47502 fcf->state = FCOE_FCF_STATE_UNKNOWN;
47503
47504 fcf->dev_loss_tmo = ctlr->fcf_dev_loss_tmo;
47505@@ -934,8 +934,8 @@ int __init fcoe_sysfs_setup(void)
47506 {
47507 int error;
47508
47509- atomic_set(&ctlr_num, 0);
47510- atomic_set(&fcf_num, 0);
47511+ atomic_set_unchecked(&ctlr_num, 0);
47512+ atomic_set_unchecked(&fcf_num, 0);
47513
47514 error = bus_register(&fcoe_bus_type);
47515 if (error)
47516diff --git a/drivers/scsi/hosts.c b/drivers/scsi/hosts.c
47517index 3cafe0d..f1e87f8 100644
47518--- a/drivers/scsi/hosts.c
47519+++ b/drivers/scsi/hosts.c
47520@@ -42,7 +42,7 @@
47521 #include "scsi_logging.h"
47522
47523
47524-static atomic_t scsi_host_next_hn = ATOMIC_INIT(0); /* host_no for next new host */
47525+static atomic_unchecked_t scsi_host_next_hn = ATOMIC_INIT(0); /* host_no for next new host */
47526
47527
47528 static void scsi_host_cls_release(struct device *dev)
47529@@ -361,7 +361,7 @@ struct Scsi_Host *scsi_host_alloc(struct scsi_host_template *sht, int privsize)
47530 * subtract one because we increment first then return, but we need to
47531 * know what the next host number was before increment
47532 */
47533- shost->host_no = atomic_inc_return(&scsi_host_next_hn) - 1;
47534+ shost->host_no = atomic_inc_return_unchecked(&scsi_host_next_hn) - 1;
47535 shost->dma_channel = 0xff;
47536
47537 /* These three are default values which can be overridden */
47538diff --git a/drivers/scsi/hpsa.c b/drivers/scsi/hpsa.c
47539index 0eb0940..3ca9b79 100644
47540--- a/drivers/scsi/hpsa.c
47541+++ b/drivers/scsi/hpsa.c
47542@@ -579,7 +579,7 @@ static inline u32 next_command(struct ctlr_info *h, u8 q)
47543 unsigned long flags;
47544
47545 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
47546- return h->access.command_completed(h, q);
47547+ return h->access->command_completed(h, q);
47548
47549 if ((rq->head[rq->current_entry] & 1) == rq->wraparound) {
47550 a = rq->head[rq->current_entry];
47551@@ -3445,7 +3445,7 @@ static void start_io(struct ctlr_info *h)
47552 while (!list_empty(&h->reqQ)) {
47553 c = list_entry(h->reqQ.next, struct CommandList, list);
47554 /* can't do anything if fifo is full */
47555- if ((h->access.fifo_full(h))) {
47556+ if ((h->access->fifo_full(h))) {
47557 dev_warn(&h->pdev->dev, "fifo full\n");
47558 break;
47559 }
47560@@ -3467,7 +3467,7 @@ static void start_io(struct ctlr_info *h)
47561
47562 /* Tell the controller execute command */
47563 spin_unlock_irqrestore(&h->lock, flags);
47564- h->access.submit_command(h, c);
47565+ h->access->submit_command(h, c);
47566 spin_lock_irqsave(&h->lock, flags);
47567 }
47568 spin_unlock_irqrestore(&h->lock, flags);
47569@@ -3475,17 +3475,17 @@ static void start_io(struct ctlr_info *h)
47570
47571 static inline unsigned long get_next_completion(struct ctlr_info *h, u8 q)
47572 {
47573- return h->access.command_completed(h, q);
47574+ return h->access->command_completed(h, q);
47575 }
47576
47577 static inline bool interrupt_pending(struct ctlr_info *h)
47578 {
47579- return h->access.intr_pending(h);
47580+ return h->access->intr_pending(h);
47581 }
47582
47583 static inline long interrupt_not_for_us(struct ctlr_info *h)
47584 {
47585- return (h->access.intr_pending(h) == 0) ||
47586+ return (h->access->intr_pending(h) == 0) ||
47587 (h->interrupts_enabled == 0);
47588 }
47589
47590@@ -4387,7 +4387,7 @@ static int hpsa_pci_init(struct ctlr_info *h)
47591 if (prod_index < 0)
47592 return -ENODEV;
47593 h->product_name = products[prod_index].product_name;
47594- h->access = *(products[prod_index].access);
47595+ h->access = products[prod_index].access;
47596
47597 pci_disable_link_state(h->pdev, PCIE_LINK_STATE_L0S |
47598 PCIE_LINK_STATE_L1 | PCIE_LINK_STATE_CLKPM);
47599@@ -4669,7 +4669,7 @@ static void controller_lockup_detected(struct ctlr_info *h)
47600
47601 assert_spin_locked(&lockup_detector_lock);
47602 remove_ctlr_from_lockup_detector_list(h);
47603- h->access.set_intr_mask(h, HPSA_INTR_OFF);
47604+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
47605 spin_lock_irqsave(&h->lock, flags);
47606 h->lockup_detected = readl(h->vaddr + SA5_SCRATCHPAD_OFFSET);
47607 spin_unlock_irqrestore(&h->lock, flags);
47608@@ -4846,7 +4846,7 @@ reinit_after_soft_reset:
47609 }
47610
47611 /* make sure the board interrupts are off */
47612- h->access.set_intr_mask(h, HPSA_INTR_OFF);
47613+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
47614
47615 if (hpsa_request_irq(h, do_hpsa_intr_msi, do_hpsa_intr_intx))
47616 goto clean2;
47617@@ -4880,7 +4880,7 @@ reinit_after_soft_reset:
47618 * fake ones to scoop up any residual completions.
47619 */
47620 spin_lock_irqsave(&h->lock, flags);
47621- h->access.set_intr_mask(h, HPSA_INTR_OFF);
47622+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
47623 spin_unlock_irqrestore(&h->lock, flags);
47624 free_irqs(h);
47625 rc = hpsa_request_irq(h, hpsa_msix_discard_completions,
47626@@ -4899,9 +4899,9 @@ reinit_after_soft_reset:
47627 dev_info(&h->pdev->dev, "Board READY.\n");
47628 dev_info(&h->pdev->dev,
47629 "Waiting for stale completions to drain.\n");
47630- h->access.set_intr_mask(h, HPSA_INTR_ON);
47631+ h->access->set_intr_mask(h, HPSA_INTR_ON);
47632 msleep(10000);
47633- h->access.set_intr_mask(h, HPSA_INTR_OFF);
47634+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
47635
47636 rc = controller_reset_failed(h->cfgtable);
47637 if (rc)
47638@@ -4922,7 +4922,7 @@ reinit_after_soft_reset:
47639 }
47640
47641 /* Turn the interrupts on so we can service requests */
47642- h->access.set_intr_mask(h, HPSA_INTR_ON);
47643+ h->access->set_intr_mask(h, HPSA_INTR_ON);
47644
47645 hpsa_hba_inquiry(h);
47646 hpsa_register_scsi(h); /* hook ourselves into SCSI subsystem */
47647@@ -4977,7 +4977,7 @@ static void hpsa_shutdown(struct pci_dev *pdev)
47648 * To write all data in the battery backed cache to disks
47649 */
47650 hpsa_flush_cache(h);
47651- h->access.set_intr_mask(h, HPSA_INTR_OFF);
47652+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
47653 hpsa_free_irqs_and_disable_msix(h);
47654 }
47655
47656@@ -5145,7 +5145,7 @@ static void hpsa_enter_performant_mode(struct ctlr_info *h, u32 use_short_tags)
47657 return;
47658 }
47659 /* Change the access methods to the performant access methods */
47660- h->access = SA5_performant_access;
47661+ h->access = &SA5_performant_access;
47662 h->transMethod = CFGTBL_Trans_Performant;
47663 }
47664
47665diff --git a/drivers/scsi/hpsa.h b/drivers/scsi/hpsa.h
47666index bc85e72..d463049 100644
47667--- a/drivers/scsi/hpsa.h
47668+++ b/drivers/scsi/hpsa.h
47669@@ -79,7 +79,7 @@ struct ctlr_info {
47670 unsigned int msix_vector;
47671 unsigned int msi_vector;
47672 int intr_mode; /* either PERF_MODE_INT or SIMPLE_MODE_INT */
47673- struct access_method access;
47674+ struct access_method *access;
47675
47676 /* queue and queue Info */
47677 struct list_head reqQ;
47678@@ -381,19 +381,19 @@ static bool SA5_performant_intr_pending(struct ctlr_info *h)
47679 }
47680
47681 static struct access_method SA5_access = {
47682- SA5_submit_command,
47683- SA5_intr_mask,
47684- SA5_fifo_full,
47685- SA5_intr_pending,
47686- SA5_completed,
47687+ .submit_command = SA5_submit_command,
47688+ .set_intr_mask = SA5_intr_mask,
47689+ .fifo_full = SA5_fifo_full,
47690+ .intr_pending = SA5_intr_pending,
47691+ .command_completed = SA5_completed,
47692 };
47693
47694 static struct access_method SA5_performant_access = {
47695- SA5_submit_command,
47696- SA5_performant_intr_mask,
47697- SA5_fifo_full,
47698- SA5_performant_intr_pending,
47699- SA5_performant_completed,
47700+ .submit_command = SA5_submit_command,
47701+ .set_intr_mask = SA5_performant_intr_mask,
47702+ .fifo_full = SA5_fifo_full,
47703+ .intr_pending = SA5_performant_intr_pending,
47704+ .command_completed = SA5_performant_completed,
47705 };
47706
47707 struct board_type {
47708diff --git a/drivers/scsi/libfc/fc_exch.c b/drivers/scsi/libfc/fc_exch.c
47709index 5879929..32b241d 100644
47710--- a/drivers/scsi/libfc/fc_exch.c
47711+++ b/drivers/scsi/libfc/fc_exch.c
47712@@ -100,12 +100,12 @@ struct fc_exch_mgr {
47713 u16 pool_max_index;
47714
47715 struct {
47716- atomic_t no_free_exch;
47717- atomic_t no_free_exch_xid;
47718- atomic_t xid_not_found;
47719- atomic_t xid_busy;
47720- atomic_t seq_not_found;
47721- atomic_t non_bls_resp;
47722+ atomic_unchecked_t no_free_exch;
47723+ atomic_unchecked_t no_free_exch_xid;
47724+ atomic_unchecked_t xid_not_found;
47725+ atomic_unchecked_t xid_busy;
47726+ atomic_unchecked_t seq_not_found;
47727+ atomic_unchecked_t non_bls_resp;
47728 } stats;
47729 };
47730
47731@@ -736,7 +736,7 @@ static struct fc_exch *fc_exch_em_alloc(struct fc_lport *lport,
47732 /* allocate memory for exchange */
47733 ep = mempool_alloc(mp->ep_pool, GFP_ATOMIC);
47734 if (!ep) {
47735- atomic_inc(&mp->stats.no_free_exch);
47736+ atomic_inc_unchecked(&mp->stats.no_free_exch);
47737 goto out;
47738 }
47739 memset(ep, 0, sizeof(*ep));
47740@@ -797,7 +797,7 @@ out:
47741 return ep;
47742 err:
47743 spin_unlock_bh(&pool->lock);
47744- atomic_inc(&mp->stats.no_free_exch_xid);
47745+ atomic_inc_unchecked(&mp->stats.no_free_exch_xid);
47746 mempool_free(ep, mp->ep_pool);
47747 return NULL;
47748 }
47749@@ -940,7 +940,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
47750 xid = ntohs(fh->fh_ox_id); /* we originated exch */
47751 ep = fc_exch_find(mp, xid);
47752 if (!ep) {
47753- atomic_inc(&mp->stats.xid_not_found);
47754+ atomic_inc_unchecked(&mp->stats.xid_not_found);
47755 reject = FC_RJT_OX_ID;
47756 goto out;
47757 }
47758@@ -970,7 +970,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
47759 ep = fc_exch_find(mp, xid);
47760 if ((f_ctl & FC_FC_FIRST_SEQ) && fc_sof_is_init(fr_sof(fp))) {
47761 if (ep) {
47762- atomic_inc(&mp->stats.xid_busy);
47763+ atomic_inc_unchecked(&mp->stats.xid_busy);
47764 reject = FC_RJT_RX_ID;
47765 goto rel;
47766 }
47767@@ -981,7 +981,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
47768 }
47769 xid = ep->xid; /* get our XID */
47770 } else if (!ep) {
47771- atomic_inc(&mp->stats.xid_not_found);
47772+ atomic_inc_unchecked(&mp->stats.xid_not_found);
47773 reject = FC_RJT_RX_ID; /* XID not found */
47774 goto out;
47775 }
47776@@ -998,7 +998,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
47777 } else {
47778 sp = &ep->seq;
47779 if (sp->id != fh->fh_seq_id) {
47780- atomic_inc(&mp->stats.seq_not_found);
47781+ atomic_inc_unchecked(&mp->stats.seq_not_found);
47782 if (f_ctl & FC_FC_END_SEQ) {
47783 /*
47784 * Update sequence_id based on incoming last
47785@@ -1448,22 +1448,22 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
47786
47787 ep = fc_exch_find(mp, ntohs(fh->fh_ox_id));
47788 if (!ep) {
47789- atomic_inc(&mp->stats.xid_not_found);
47790+ atomic_inc_unchecked(&mp->stats.xid_not_found);
47791 goto out;
47792 }
47793 if (ep->esb_stat & ESB_ST_COMPLETE) {
47794- atomic_inc(&mp->stats.xid_not_found);
47795+ atomic_inc_unchecked(&mp->stats.xid_not_found);
47796 goto rel;
47797 }
47798 if (ep->rxid == FC_XID_UNKNOWN)
47799 ep->rxid = ntohs(fh->fh_rx_id);
47800 if (ep->sid != 0 && ep->sid != ntoh24(fh->fh_d_id)) {
47801- atomic_inc(&mp->stats.xid_not_found);
47802+ atomic_inc_unchecked(&mp->stats.xid_not_found);
47803 goto rel;
47804 }
47805 if (ep->did != ntoh24(fh->fh_s_id) &&
47806 ep->did != FC_FID_FLOGI) {
47807- atomic_inc(&mp->stats.xid_not_found);
47808+ atomic_inc_unchecked(&mp->stats.xid_not_found);
47809 goto rel;
47810 }
47811 sof = fr_sof(fp);
47812@@ -1472,7 +1472,7 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
47813 sp->ssb_stat |= SSB_ST_RESP;
47814 sp->id = fh->fh_seq_id;
47815 } else if (sp->id != fh->fh_seq_id) {
47816- atomic_inc(&mp->stats.seq_not_found);
47817+ atomic_inc_unchecked(&mp->stats.seq_not_found);
47818 goto rel;
47819 }
47820
47821@@ -1536,9 +1536,9 @@ static void fc_exch_recv_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
47822 sp = fc_seq_lookup_orig(mp, fp); /* doesn't hold sequence */
47823
47824 if (!sp)
47825- atomic_inc(&mp->stats.xid_not_found);
47826+ atomic_inc_unchecked(&mp->stats.xid_not_found);
47827 else
47828- atomic_inc(&mp->stats.non_bls_resp);
47829+ atomic_inc_unchecked(&mp->stats.non_bls_resp);
47830
47831 fc_frame_free(fp);
47832 }
47833@@ -2185,13 +2185,13 @@ void fc_exch_update_stats(struct fc_lport *lport)
47834
47835 list_for_each_entry(ema, &lport->ema_list, ema_list) {
47836 mp = ema->mp;
47837- st->fc_no_free_exch += atomic_read(&mp->stats.no_free_exch);
47838+ st->fc_no_free_exch += atomic_read_unchecked(&mp->stats.no_free_exch);
47839 st->fc_no_free_exch_xid +=
47840- atomic_read(&mp->stats.no_free_exch_xid);
47841- st->fc_xid_not_found += atomic_read(&mp->stats.xid_not_found);
47842- st->fc_xid_busy += atomic_read(&mp->stats.xid_busy);
47843- st->fc_seq_not_found += atomic_read(&mp->stats.seq_not_found);
47844- st->fc_non_bls_resp += atomic_read(&mp->stats.non_bls_resp);
47845+ atomic_read_unchecked(&mp->stats.no_free_exch_xid);
47846+ st->fc_xid_not_found += atomic_read_unchecked(&mp->stats.xid_not_found);
47847+ st->fc_xid_busy += atomic_read_unchecked(&mp->stats.xid_busy);
47848+ st->fc_seq_not_found += atomic_read_unchecked(&mp->stats.seq_not_found);
47849+ st->fc_non_bls_resp += atomic_read_unchecked(&mp->stats.non_bls_resp);
47850 }
47851 }
47852 EXPORT_SYMBOL(fc_exch_update_stats);
47853diff --git a/drivers/scsi/libsas/sas_ata.c b/drivers/scsi/libsas/sas_ata.c
47854index d289583..b745eec 100644
47855--- a/drivers/scsi/libsas/sas_ata.c
47856+++ b/drivers/scsi/libsas/sas_ata.c
47857@@ -554,7 +554,7 @@ static struct ata_port_operations sas_sata_ops = {
47858 .postreset = ata_std_postreset,
47859 .error_handler = ata_std_error_handler,
47860 .post_internal_cmd = sas_ata_post_internal,
47861- .qc_defer = ata_std_qc_defer,
47862+ .qc_defer = ata_std_qc_defer,
47863 .qc_prep = ata_noop_qc_prep,
47864 .qc_issue = sas_ata_qc_issue,
47865 .qc_fill_rtf = sas_ata_qc_fill_rtf,
47866diff --git a/drivers/scsi/lpfc/lpfc.h b/drivers/scsi/lpfc/lpfc.h
47867index 4e1b75c..0bbdfa9 100644
47868--- a/drivers/scsi/lpfc/lpfc.h
47869+++ b/drivers/scsi/lpfc/lpfc.h
47870@@ -432,7 +432,7 @@ struct lpfc_vport {
47871 struct dentry *debug_nodelist;
47872 struct dentry *vport_debugfs_root;
47873 struct lpfc_debugfs_trc *disc_trc;
47874- atomic_t disc_trc_cnt;
47875+ atomic_unchecked_t disc_trc_cnt;
47876 #endif
47877 uint8_t stat_data_enabled;
47878 uint8_t stat_data_blocked;
47879@@ -865,8 +865,8 @@ struct lpfc_hba {
47880 struct timer_list fabric_block_timer;
47881 unsigned long bit_flags;
47882 #define FABRIC_COMANDS_BLOCKED 0
47883- atomic_t num_rsrc_err;
47884- atomic_t num_cmd_success;
47885+ atomic_unchecked_t num_rsrc_err;
47886+ atomic_unchecked_t num_cmd_success;
47887 unsigned long last_rsrc_error_time;
47888 unsigned long last_ramp_down_time;
47889 unsigned long last_ramp_up_time;
47890@@ -902,7 +902,7 @@ struct lpfc_hba {
47891
47892 struct dentry *debug_slow_ring_trc;
47893 struct lpfc_debugfs_trc *slow_ring_trc;
47894- atomic_t slow_ring_trc_cnt;
47895+ atomic_unchecked_t slow_ring_trc_cnt;
47896 /* iDiag debugfs sub-directory */
47897 struct dentry *idiag_root;
47898 struct dentry *idiag_pci_cfg;
47899diff --git a/drivers/scsi/lpfc/lpfc_debugfs.c b/drivers/scsi/lpfc/lpfc_debugfs.c
47900index 60084e6..0e2e700 100644
47901--- a/drivers/scsi/lpfc/lpfc_debugfs.c
47902+++ b/drivers/scsi/lpfc/lpfc_debugfs.c
47903@@ -106,7 +106,7 @@ MODULE_PARM_DESC(lpfc_debugfs_mask_disc_trc,
47904
47905 #include <linux/debugfs.h>
47906
47907-static atomic_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
47908+static atomic_unchecked_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
47909 static unsigned long lpfc_debugfs_start_time = 0L;
47910
47911 /* iDiag */
47912@@ -147,7 +147,7 @@ lpfc_debugfs_disc_trc_data(struct lpfc_vport *vport, char *buf, int size)
47913 lpfc_debugfs_enable = 0;
47914
47915 len = 0;
47916- index = (atomic_read(&vport->disc_trc_cnt) + 1) &
47917+ index = (atomic_read_unchecked(&vport->disc_trc_cnt) + 1) &
47918 (lpfc_debugfs_max_disc_trc - 1);
47919 for (i = index; i < lpfc_debugfs_max_disc_trc; i++) {
47920 dtp = vport->disc_trc + i;
47921@@ -213,7 +213,7 @@ lpfc_debugfs_slow_ring_trc_data(struct lpfc_hba *phba, char *buf, int size)
47922 lpfc_debugfs_enable = 0;
47923
47924 len = 0;
47925- index = (atomic_read(&phba->slow_ring_trc_cnt) + 1) &
47926+ index = (atomic_read_unchecked(&phba->slow_ring_trc_cnt) + 1) &
47927 (lpfc_debugfs_max_slow_ring_trc - 1);
47928 for (i = index; i < lpfc_debugfs_max_slow_ring_trc; i++) {
47929 dtp = phba->slow_ring_trc + i;
47930@@ -646,14 +646,14 @@ lpfc_debugfs_disc_trc(struct lpfc_vport *vport, int mask, char *fmt,
47931 !vport || !vport->disc_trc)
47932 return;
47933
47934- index = atomic_inc_return(&vport->disc_trc_cnt) &
47935+ index = atomic_inc_return_unchecked(&vport->disc_trc_cnt) &
47936 (lpfc_debugfs_max_disc_trc - 1);
47937 dtp = vport->disc_trc + index;
47938 dtp->fmt = fmt;
47939 dtp->data1 = data1;
47940 dtp->data2 = data2;
47941 dtp->data3 = data3;
47942- dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
47943+ dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
47944 dtp->jif = jiffies;
47945 #endif
47946 return;
47947@@ -684,14 +684,14 @@ lpfc_debugfs_slow_ring_trc(struct lpfc_hba *phba, char *fmt,
47948 !phba || !phba->slow_ring_trc)
47949 return;
47950
47951- index = atomic_inc_return(&phba->slow_ring_trc_cnt) &
47952+ index = atomic_inc_return_unchecked(&phba->slow_ring_trc_cnt) &
47953 (lpfc_debugfs_max_slow_ring_trc - 1);
47954 dtp = phba->slow_ring_trc + index;
47955 dtp->fmt = fmt;
47956 dtp->data1 = data1;
47957 dtp->data2 = data2;
47958 dtp->data3 = data3;
47959- dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
47960+ dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
47961 dtp->jif = jiffies;
47962 #endif
47963 return;
47964@@ -4168,7 +4168,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
47965 "slow_ring buffer\n");
47966 goto debug_failed;
47967 }
47968- atomic_set(&phba->slow_ring_trc_cnt, 0);
47969+ atomic_set_unchecked(&phba->slow_ring_trc_cnt, 0);
47970 memset(phba->slow_ring_trc, 0,
47971 (sizeof(struct lpfc_debugfs_trc) *
47972 lpfc_debugfs_max_slow_ring_trc));
47973@@ -4214,7 +4214,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
47974 "buffer\n");
47975 goto debug_failed;
47976 }
47977- atomic_set(&vport->disc_trc_cnt, 0);
47978+ atomic_set_unchecked(&vport->disc_trc_cnt, 0);
47979
47980 snprintf(name, sizeof(name), "discovery_trace");
47981 vport->debug_disc_trc =
47982diff --git a/drivers/scsi/lpfc/lpfc_init.c b/drivers/scsi/lpfc/lpfc_init.c
47983index 647f5bf..d0068b9 100644
47984--- a/drivers/scsi/lpfc/lpfc_init.c
47985+++ b/drivers/scsi/lpfc/lpfc_init.c
47986@@ -10952,8 +10952,10 @@ lpfc_init(void)
47987 "misc_register returned with status %d", error);
47988
47989 if (lpfc_enable_npiv) {
47990- lpfc_transport_functions.vport_create = lpfc_vport_create;
47991- lpfc_transport_functions.vport_delete = lpfc_vport_delete;
47992+ pax_open_kernel();
47993+ *(void **)&lpfc_transport_functions.vport_create = lpfc_vport_create;
47994+ *(void **)&lpfc_transport_functions.vport_delete = lpfc_vport_delete;
47995+ pax_close_kernel();
47996 }
47997 lpfc_transport_template =
47998 fc_attach_transport(&lpfc_transport_functions);
47999diff --git a/drivers/scsi/lpfc/lpfc_scsi.c b/drivers/scsi/lpfc/lpfc_scsi.c
48000index c913e8c..d34a119 100644
48001--- a/drivers/scsi/lpfc/lpfc_scsi.c
48002+++ b/drivers/scsi/lpfc/lpfc_scsi.c
48003@@ -353,7 +353,7 @@ lpfc_rampdown_queue_depth(struct lpfc_hba *phba)
48004 uint32_t evt_posted;
48005
48006 spin_lock_irqsave(&phba->hbalock, flags);
48007- atomic_inc(&phba->num_rsrc_err);
48008+ atomic_inc_unchecked(&phba->num_rsrc_err);
48009 phba->last_rsrc_error_time = jiffies;
48010
48011 if ((phba->last_ramp_down_time + QUEUE_RAMP_DOWN_INTERVAL) > jiffies) {
48012@@ -394,7 +394,7 @@ lpfc_rampup_queue_depth(struct lpfc_vport *vport,
48013 unsigned long flags;
48014 struct lpfc_hba *phba = vport->phba;
48015 uint32_t evt_posted;
48016- atomic_inc(&phba->num_cmd_success);
48017+ atomic_inc_unchecked(&phba->num_cmd_success);
48018
48019 if (vport->cfg_lun_queue_depth <= queue_depth)
48020 return;
48021@@ -438,8 +438,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
48022 unsigned long num_rsrc_err, num_cmd_success;
48023 int i;
48024
48025- num_rsrc_err = atomic_read(&phba->num_rsrc_err);
48026- num_cmd_success = atomic_read(&phba->num_cmd_success);
48027+ num_rsrc_err = atomic_read_unchecked(&phba->num_rsrc_err);
48028+ num_cmd_success = atomic_read_unchecked(&phba->num_cmd_success);
48029
48030 /*
48031 * The error and success command counters are global per
48032@@ -467,8 +467,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
48033 }
48034 }
48035 lpfc_destroy_vport_work_array(phba, vports);
48036- atomic_set(&phba->num_rsrc_err, 0);
48037- atomic_set(&phba->num_cmd_success, 0);
48038+ atomic_set_unchecked(&phba->num_rsrc_err, 0);
48039+ atomic_set_unchecked(&phba->num_cmd_success, 0);
48040 }
48041
48042 /**
48043@@ -502,8 +502,8 @@ lpfc_ramp_up_queue_handler(struct lpfc_hba *phba)
48044 }
48045 }
48046 lpfc_destroy_vport_work_array(phba, vports);
48047- atomic_set(&phba->num_rsrc_err, 0);
48048- atomic_set(&phba->num_cmd_success, 0);
48049+ atomic_set_unchecked(&phba->num_rsrc_err, 0);
48050+ atomic_set_unchecked(&phba->num_cmd_success, 0);
48051 }
48052
48053 /**
48054diff --git a/drivers/scsi/mpt2sas/mpt2sas_scsih.c b/drivers/scsi/mpt2sas/mpt2sas_scsih.c
48055index 7f0af4f..193ac3e 100644
48056--- a/drivers/scsi/mpt2sas/mpt2sas_scsih.c
48057+++ b/drivers/scsi/mpt2sas/mpt2sas_scsih.c
48058@@ -1557,7 +1557,7 @@ _scsih_get_resync(struct device *dev)
48059 {
48060 struct scsi_device *sdev = to_scsi_device(dev);
48061 struct MPT2SAS_ADAPTER *ioc = shost_priv(sdev->host);
48062- static struct _raid_device *raid_device;
48063+ struct _raid_device *raid_device;
48064 unsigned long flags;
48065 Mpi2RaidVolPage0_t vol_pg0;
48066 Mpi2ConfigReply_t mpi_reply;
48067@@ -1609,7 +1609,7 @@ _scsih_get_state(struct device *dev)
48068 {
48069 struct scsi_device *sdev = to_scsi_device(dev);
48070 struct MPT2SAS_ADAPTER *ioc = shost_priv(sdev->host);
48071- static struct _raid_device *raid_device;
48072+ struct _raid_device *raid_device;
48073 unsigned long flags;
48074 Mpi2RaidVolPage0_t vol_pg0;
48075 Mpi2ConfigReply_t mpi_reply;
48076@@ -6637,7 +6637,7 @@ _scsih_sas_ir_operation_status_event(struct MPT2SAS_ADAPTER *ioc,
48077 struct fw_event_work *fw_event)
48078 {
48079 Mpi2EventDataIrOperationStatus_t *event_data = fw_event->event_data;
48080- static struct _raid_device *raid_device;
48081+ struct _raid_device *raid_device;
48082 unsigned long flags;
48083 u16 handle;
48084
48085@@ -7108,7 +7108,7 @@ _scsih_scan_for_devices_after_reset(struct MPT2SAS_ADAPTER *ioc)
48086 u64 sas_address;
48087 struct _sas_device *sas_device;
48088 struct _sas_node *expander_device;
48089- static struct _raid_device *raid_device;
48090+ struct _raid_device *raid_device;
48091 u8 retry_count;
48092 unsigned long flags;
48093
48094diff --git a/drivers/scsi/pmcraid.c b/drivers/scsi/pmcraid.c
48095index a38f71b..f3bc572 100644
48096--- a/drivers/scsi/pmcraid.c
48097+++ b/drivers/scsi/pmcraid.c
48098@@ -200,8 +200,8 @@ static int pmcraid_slave_alloc(struct scsi_device *scsi_dev)
48099 res->scsi_dev = scsi_dev;
48100 scsi_dev->hostdata = res;
48101 res->change_detected = 0;
48102- atomic_set(&res->read_failures, 0);
48103- atomic_set(&res->write_failures, 0);
48104+ atomic_set_unchecked(&res->read_failures, 0);
48105+ atomic_set_unchecked(&res->write_failures, 0);
48106 rc = 0;
48107 }
48108 spin_unlock_irqrestore(&pinstance->resource_lock, lock_flags);
48109@@ -2676,9 +2676,9 @@ static int pmcraid_error_handler(struct pmcraid_cmd *cmd)
48110
48111 /* If this was a SCSI read/write command keep count of errors */
48112 if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_READ_CMD)
48113- atomic_inc(&res->read_failures);
48114+ atomic_inc_unchecked(&res->read_failures);
48115 else if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_WRITE_CMD)
48116- atomic_inc(&res->write_failures);
48117+ atomic_inc_unchecked(&res->write_failures);
48118
48119 if (!RES_IS_GSCSI(res->cfg_entry) &&
48120 masked_ioasc != PMCRAID_IOASC_HW_DEVICE_BUS_STATUS_ERROR) {
48121@@ -3534,7 +3534,7 @@ static int pmcraid_queuecommand_lck(
48122 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
48123 * hrrq_id assigned here in queuecommand
48124 */
48125- ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
48126+ ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
48127 pinstance->num_hrrq;
48128 cmd->cmd_done = pmcraid_io_done;
48129
48130@@ -3846,7 +3846,7 @@ static long pmcraid_ioctl_passthrough(
48131 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
48132 * hrrq_id assigned here in queuecommand
48133 */
48134- ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
48135+ ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
48136 pinstance->num_hrrq;
48137
48138 if (request_size) {
48139@@ -4484,7 +4484,7 @@ static void pmcraid_worker_function(struct work_struct *workp)
48140
48141 pinstance = container_of(workp, struct pmcraid_instance, worker_q);
48142 /* add resources only after host is added into system */
48143- if (!atomic_read(&pinstance->expose_resources))
48144+ if (!atomic_read_unchecked(&pinstance->expose_resources))
48145 return;
48146
48147 fw_version = be16_to_cpu(pinstance->inq_data->fw_version);
48148@@ -5311,8 +5311,8 @@ static int pmcraid_init_instance(struct pci_dev *pdev, struct Scsi_Host *host,
48149 init_waitqueue_head(&pinstance->reset_wait_q);
48150
48151 atomic_set(&pinstance->outstanding_cmds, 0);
48152- atomic_set(&pinstance->last_message_id, 0);
48153- atomic_set(&pinstance->expose_resources, 0);
48154+ atomic_set_unchecked(&pinstance->last_message_id, 0);
48155+ atomic_set_unchecked(&pinstance->expose_resources, 0);
48156
48157 INIT_LIST_HEAD(&pinstance->free_res_q);
48158 INIT_LIST_HEAD(&pinstance->used_res_q);
48159@@ -6025,7 +6025,7 @@ static int pmcraid_probe(struct pci_dev *pdev,
48160 /* Schedule worker thread to handle CCN and take care of adding and
48161 * removing devices to OS
48162 */
48163- atomic_set(&pinstance->expose_resources, 1);
48164+ atomic_set_unchecked(&pinstance->expose_resources, 1);
48165 schedule_work(&pinstance->worker_q);
48166 return rc;
48167
48168diff --git a/drivers/scsi/pmcraid.h b/drivers/scsi/pmcraid.h
48169index e1d150f..6c6df44 100644
48170--- a/drivers/scsi/pmcraid.h
48171+++ b/drivers/scsi/pmcraid.h
48172@@ -748,7 +748,7 @@ struct pmcraid_instance {
48173 struct pmcraid_isr_param hrrq_vector[PMCRAID_NUM_MSIX_VECTORS];
48174
48175 /* Message id as filled in last fired IOARCB, used to identify HRRQ */
48176- atomic_t last_message_id;
48177+ atomic_unchecked_t last_message_id;
48178
48179 /* configuration table */
48180 struct pmcraid_config_table *cfg_table;
48181@@ -777,7 +777,7 @@ struct pmcraid_instance {
48182 atomic_t outstanding_cmds;
48183
48184 /* should add/delete resources to mid-layer now ?*/
48185- atomic_t expose_resources;
48186+ atomic_unchecked_t expose_resources;
48187
48188
48189
48190@@ -813,8 +813,8 @@ struct pmcraid_resource_entry {
48191 struct pmcraid_config_table_entry_ext cfg_entry_ext;
48192 };
48193 struct scsi_device *scsi_dev; /* Link scsi_device structure */
48194- atomic_t read_failures; /* count of failed READ commands */
48195- atomic_t write_failures; /* count of failed WRITE commands */
48196+ atomic_unchecked_t read_failures; /* count of failed READ commands */
48197+ atomic_unchecked_t write_failures; /* count of failed WRITE commands */
48198
48199 /* To indicate add/delete/modify during CCN */
48200 u8 change_detected;
48201diff --git a/drivers/scsi/qla2xxx/qla_attr.c b/drivers/scsi/qla2xxx/qla_attr.c
48202index 5f174b8..98d32b0 100644
48203--- a/drivers/scsi/qla2xxx/qla_attr.c
48204+++ b/drivers/scsi/qla2xxx/qla_attr.c
48205@@ -2040,7 +2040,7 @@ qla24xx_vport_disable(struct fc_vport *fc_vport, bool disable)
48206 return 0;
48207 }
48208
48209-struct fc_function_template qla2xxx_transport_functions = {
48210+fc_function_template_no_const qla2xxx_transport_functions = {
48211
48212 .show_host_node_name = 1,
48213 .show_host_port_name = 1,
48214@@ -2088,7 +2088,7 @@ struct fc_function_template qla2xxx_transport_functions = {
48215 .bsg_timeout = qla24xx_bsg_timeout,
48216 };
48217
48218-struct fc_function_template qla2xxx_transport_vport_functions = {
48219+fc_function_template_no_const qla2xxx_transport_vport_functions = {
48220
48221 .show_host_node_name = 1,
48222 .show_host_port_name = 1,
48223diff --git a/drivers/scsi/qla2xxx/qla_gbl.h b/drivers/scsi/qla2xxx/qla_gbl.h
48224index 4446bf5..9a3574d 100644
48225--- a/drivers/scsi/qla2xxx/qla_gbl.h
48226+++ b/drivers/scsi/qla2xxx/qla_gbl.h
48227@@ -538,8 +538,8 @@ extern void qla2x00_get_sym_node_name(scsi_qla_host_t *, uint8_t *);
48228 struct device_attribute;
48229 extern struct device_attribute *qla2x00_host_attrs[];
48230 struct fc_function_template;
48231-extern struct fc_function_template qla2xxx_transport_functions;
48232-extern struct fc_function_template qla2xxx_transport_vport_functions;
48233+extern fc_function_template_no_const qla2xxx_transport_functions;
48234+extern fc_function_template_no_const qla2xxx_transport_vport_functions;
48235 extern void qla2x00_alloc_sysfs_attr(scsi_qla_host_t *);
48236 extern void qla2x00_free_sysfs_attr(scsi_qla_host_t *);
48237 extern void qla2x00_init_host_attr(scsi_qla_host_t *);
48238diff --git a/drivers/scsi/qla2xxx/qla_os.c b/drivers/scsi/qla2xxx/qla_os.c
48239index 9f01bbb..5e1dcee 100644
48240--- a/drivers/scsi/qla2xxx/qla_os.c
48241+++ b/drivers/scsi/qla2xxx/qla_os.c
48242@@ -1572,8 +1572,10 @@ qla2x00_config_dma_addressing(struct qla_hw_data *ha)
48243 !pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(64))) {
48244 /* Ok, a 64bit DMA mask is applicable. */
48245 ha->flags.enable_64bit_addressing = 1;
48246- ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
48247- ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
48248+ pax_open_kernel();
48249+ *(void **)&ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
48250+ *(void **)&ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
48251+ pax_close_kernel();
48252 return;
48253 }
48254 }
48255diff --git a/drivers/scsi/qla4xxx/ql4_def.h b/drivers/scsi/qla4xxx/ql4_def.h
48256index 41327d4..feb03d479 100644
48257--- a/drivers/scsi/qla4xxx/ql4_def.h
48258+++ b/drivers/scsi/qla4xxx/ql4_def.h
48259@@ -296,7 +296,7 @@ struct ddb_entry {
48260 * (4000 only) */
48261 atomic_t relogin_timer; /* Max Time to wait for
48262 * relogin to complete */
48263- atomic_t relogin_retry_count; /* Num of times relogin has been
48264+ atomic_unchecked_t relogin_retry_count; /* Num of times relogin has been
48265 * retried */
48266 uint32_t default_time2wait; /* Default Min time between
48267 * relogins (+aens) */
48268diff --git a/drivers/scsi/qla4xxx/ql4_os.c b/drivers/scsi/qla4xxx/ql4_os.c
48269index f8a0a26..ec03cee 100644
48270--- a/drivers/scsi/qla4xxx/ql4_os.c
48271+++ b/drivers/scsi/qla4xxx/ql4_os.c
48272@@ -3066,12 +3066,12 @@ static void qla4xxx_check_relogin_flash_ddb(struct iscsi_cls_session *cls_sess)
48273 */
48274 if (!iscsi_is_session_online(cls_sess)) {
48275 /* Reset retry relogin timer */
48276- atomic_inc(&ddb_entry->relogin_retry_count);
48277+ atomic_inc_unchecked(&ddb_entry->relogin_retry_count);
48278 DEBUG2(ql4_printk(KERN_INFO, ha,
48279 "%s: index[%d] relogin timed out-retrying"
48280 " relogin (%d), retry (%d)\n", __func__,
48281 ddb_entry->fw_ddb_index,
48282- atomic_read(&ddb_entry->relogin_retry_count),
48283+ atomic_read_unchecked(&ddb_entry->relogin_retry_count),
48284 ddb_entry->default_time2wait + 4));
48285 set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags);
48286 atomic_set(&ddb_entry->retry_relogin_timer,
48287@@ -5209,7 +5209,7 @@ static void qla4xxx_setup_flash_ddb_entry(struct scsi_qla_host *ha,
48288
48289 atomic_set(&ddb_entry->retry_relogin_timer, INVALID_ENTRY);
48290 atomic_set(&ddb_entry->relogin_timer, 0);
48291- atomic_set(&ddb_entry->relogin_retry_count, 0);
48292+ atomic_set_unchecked(&ddb_entry->relogin_retry_count, 0);
48293 def_timeout = le16_to_cpu(ddb_entry->fw_ddb_entry.def_timeout);
48294 ddb_entry->default_relogin_timeout =
48295 (def_timeout > LOGIN_TOV) && (def_timeout < LOGIN_TOV * 10) ?
48296diff --git a/drivers/scsi/scsi.c b/drivers/scsi/scsi.c
48297index eaa808e..95f8841 100644
48298--- a/drivers/scsi/scsi.c
48299+++ b/drivers/scsi/scsi.c
48300@@ -661,7 +661,7 @@ int scsi_dispatch_cmd(struct scsi_cmnd *cmd)
48301 unsigned long timeout;
48302 int rtn = 0;
48303
48304- atomic_inc(&cmd->device->iorequest_cnt);
48305+ atomic_inc_unchecked(&cmd->device->iorequest_cnt);
48306
48307 /* check if the device is still usable */
48308 if (unlikely(cmd->device->sdev_state == SDEV_DEL)) {
48309diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
48310index d1549b7..2f60767 100644
48311--- a/drivers/scsi/scsi_lib.c
48312+++ b/drivers/scsi/scsi_lib.c
48313@@ -1474,7 +1474,7 @@ static void scsi_kill_request(struct request *req, struct request_queue *q)
48314 shost = sdev->host;
48315 scsi_init_cmd_errh(cmd);
48316 cmd->result = DID_NO_CONNECT << 16;
48317- atomic_inc(&cmd->device->iorequest_cnt);
48318+ atomic_inc_unchecked(&cmd->device->iorequest_cnt);
48319
48320 /*
48321 * SCSI request completion path will do scsi_device_unbusy(),
48322@@ -1500,9 +1500,9 @@ static void scsi_softirq_done(struct request *rq)
48323
48324 INIT_LIST_HEAD(&cmd->eh_entry);
48325
48326- atomic_inc(&cmd->device->iodone_cnt);
48327+ atomic_inc_unchecked(&cmd->device->iodone_cnt);
48328 if (cmd->result)
48329- atomic_inc(&cmd->device->ioerr_cnt);
48330+ atomic_inc_unchecked(&cmd->device->ioerr_cnt);
48331
48332 disposition = scsi_decide_disposition(cmd);
48333 if (disposition != SUCCESS &&
48334diff --git a/drivers/scsi/scsi_sysfs.c b/drivers/scsi/scsi_sysfs.c
48335index 40c6394..62356c2 100644
48336--- a/drivers/scsi/scsi_sysfs.c
48337+++ b/drivers/scsi/scsi_sysfs.c
48338@@ -687,7 +687,7 @@ show_iostat_##field(struct device *dev, struct device_attribute *attr, \
48339 char *buf) \
48340 { \
48341 struct scsi_device *sdev = to_scsi_device(dev); \
48342- unsigned long long count = atomic_read(&sdev->field); \
48343+ unsigned long long count = atomic_read_unchecked(&sdev->field); \
48344 return snprintf(buf, 20, "0x%llx\n", count); \
48345 } \
48346 static DEVICE_ATTR(field, S_IRUGO, show_iostat_##field, NULL)
48347diff --git a/drivers/scsi/scsi_tgt_lib.c b/drivers/scsi/scsi_tgt_lib.c
48348index 84a1fdf..693b0d6 100644
48349--- a/drivers/scsi/scsi_tgt_lib.c
48350+++ b/drivers/scsi/scsi_tgt_lib.c
48351@@ -362,7 +362,7 @@ static int scsi_map_user_pages(struct scsi_tgt_cmd *tcmd, struct scsi_cmnd *cmd,
48352 int err;
48353
48354 dprintk("%lx %u\n", uaddr, len);
48355- err = blk_rq_map_user(q, rq, NULL, (void *)uaddr, len, GFP_KERNEL);
48356+ err = blk_rq_map_user(q, rq, NULL, (void __user *)uaddr, len, GFP_KERNEL);
48357 if (err) {
48358 /*
48359 * TODO: need to fixup sg_tablesize, max_segment_size,
48360diff --git a/drivers/scsi/scsi_transport_fc.c b/drivers/scsi/scsi_transport_fc.c
48361index 4628fd5..a94a1c2 100644
48362--- a/drivers/scsi/scsi_transport_fc.c
48363+++ b/drivers/scsi/scsi_transport_fc.c
48364@@ -497,7 +497,7 @@ static DECLARE_TRANSPORT_CLASS(fc_vport_class,
48365 * Netlink Infrastructure
48366 */
48367
48368-static atomic_t fc_event_seq;
48369+static atomic_unchecked_t fc_event_seq;
48370
48371 /**
48372 * fc_get_event_number - Obtain the next sequential FC event number
48373@@ -510,7 +510,7 @@ static atomic_t fc_event_seq;
48374 u32
48375 fc_get_event_number(void)
48376 {
48377- return atomic_add_return(1, &fc_event_seq);
48378+ return atomic_add_return_unchecked(1, &fc_event_seq);
48379 }
48380 EXPORT_SYMBOL(fc_get_event_number);
48381
48382@@ -654,7 +654,7 @@ static __init int fc_transport_init(void)
48383 {
48384 int error;
48385
48386- atomic_set(&fc_event_seq, 0);
48387+ atomic_set_unchecked(&fc_event_seq, 0);
48388
48389 error = transport_class_register(&fc_host_class);
48390 if (error)
48391@@ -844,7 +844,7 @@ static int fc_str_to_dev_loss(const char *buf, unsigned long *val)
48392 char *cp;
48393
48394 *val = simple_strtoul(buf, &cp, 0);
48395- if ((*cp && (*cp != '\n')) || (*val < 0))
48396+ if (*cp && (*cp != '\n'))
48397 return -EINVAL;
48398 /*
48399 * Check for overflow; dev_loss_tmo is u32
48400diff --git a/drivers/scsi/scsi_transport_iscsi.c b/drivers/scsi/scsi_transport_iscsi.c
48401index e4a989f..293090c 100644
48402--- a/drivers/scsi/scsi_transport_iscsi.c
48403+++ b/drivers/scsi/scsi_transport_iscsi.c
48404@@ -79,7 +79,7 @@ struct iscsi_internal {
48405 struct transport_container session_cont;
48406 };
48407
48408-static atomic_t iscsi_session_nr; /* sysfs session id for next new session */
48409+static atomic_unchecked_t iscsi_session_nr; /* sysfs session id for next new session */
48410 static struct workqueue_struct *iscsi_eh_timer_workq;
48411
48412 static DEFINE_IDA(iscsi_sess_ida);
48413@@ -1737,7 +1737,7 @@ int iscsi_add_session(struct iscsi_cls_session *session, unsigned int target_id)
48414 int err;
48415
48416 ihost = shost->shost_data;
48417- session->sid = atomic_add_return(1, &iscsi_session_nr);
48418+ session->sid = atomic_add_return_unchecked(1, &iscsi_session_nr);
48419
48420 if (target_id == ISCSI_MAX_TARGET) {
48421 id = ida_simple_get(&iscsi_sess_ida, 0, 0, GFP_KERNEL);
48422@@ -4077,7 +4077,7 @@ static __init int iscsi_transport_init(void)
48423 printk(KERN_INFO "Loading iSCSI transport class v%s.\n",
48424 ISCSI_TRANSPORT_VERSION);
48425
48426- atomic_set(&iscsi_session_nr, 0);
48427+ atomic_set_unchecked(&iscsi_session_nr, 0);
48428
48429 err = class_register(&iscsi_transport_class);
48430 if (err)
48431diff --git a/drivers/scsi/scsi_transport_srp.c b/drivers/scsi/scsi_transport_srp.c
48432index f379c7f..e8fc69c 100644
48433--- a/drivers/scsi/scsi_transport_srp.c
48434+++ b/drivers/scsi/scsi_transport_srp.c
48435@@ -33,7 +33,7 @@
48436 #include "scsi_transport_srp_internal.h"
48437
48438 struct srp_host_attrs {
48439- atomic_t next_port_id;
48440+ atomic_unchecked_t next_port_id;
48441 };
48442 #define to_srp_host_attrs(host) ((struct srp_host_attrs *)(host)->shost_data)
48443
48444@@ -61,7 +61,7 @@ static int srp_host_setup(struct transport_container *tc, struct device *dev,
48445 struct Scsi_Host *shost = dev_to_shost(dev);
48446 struct srp_host_attrs *srp_host = to_srp_host_attrs(shost);
48447
48448- atomic_set(&srp_host->next_port_id, 0);
48449+ atomic_set_unchecked(&srp_host->next_port_id, 0);
48450 return 0;
48451 }
48452
48453@@ -210,7 +210,7 @@ struct srp_rport *srp_rport_add(struct Scsi_Host *shost,
48454 memcpy(rport->port_id, ids->port_id, sizeof(rport->port_id));
48455 rport->roles = ids->roles;
48456
48457- id = atomic_inc_return(&to_srp_host_attrs(shost)->next_port_id);
48458+ id = atomic_inc_return_unchecked(&to_srp_host_attrs(shost)->next_port_id);
48459 dev_set_name(&rport->dev, "port-%d:%d", shost->host_no, id);
48460
48461 transport_setup_device(&rport->dev);
48462diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
48463index dbc024b..6e3b837 100644
48464--- a/drivers/scsi/sd.c
48465+++ b/drivers/scsi/sd.c
48466@@ -2943,7 +2943,7 @@ static int sd_probe(struct device *dev)
48467 sdkp->disk = gd;
48468 sdkp->index = index;
48469 atomic_set(&sdkp->openers, 0);
48470- atomic_set(&sdkp->device->ioerr_cnt, 0);
48471+ atomic_set_unchecked(&sdkp->device->ioerr_cnt, 0);
48472
48473 if (!sdp->request_queue->rq_timeout) {
48474 if (sdp->type != TYPE_MOD)
48475diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
48476index df5e961..df6b97f 100644
48477--- a/drivers/scsi/sg.c
48478+++ b/drivers/scsi/sg.c
48479@@ -1102,7 +1102,7 @@ sg_ioctl(struct file *filp, unsigned int cmd_in, unsigned long arg)
48480 sdp->disk->disk_name,
48481 MKDEV(SCSI_GENERIC_MAJOR, sdp->index),
48482 NULL,
48483- (char *)arg);
48484+ (char __user *)arg);
48485 case BLKTRACESTART:
48486 return blk_trace_startstop(sdp->device->request_queue, 1);
48487 case BLKTRACESTOP:
48488diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
48489index 9e039c6..ae9e800 100644
48490--- a/drivers/spi/spi.c
48491+++ b/drivers/spi/spi.c
48492@@ -1762,7 +1762,7 @@ int spi_bus_unlock(struct spi_master *master)
48493 EXPORT_SYMBOL_GPL(spi_bus_unlock);
48494
48495 /* portable code must never pass more than 32 bytes */
48496-#define SPI_BUFSIZ max(32,SMP_CACHE_BYTES)
48497+#define SPI_BUFSIZ max(32UL,SMP_CACHE_BYTES)
48498
48499 static u8 *buf;
48500
48501diff --git a/drivers/staging/android/timed_output.c b/drivers/staging/android/timed_output.c
48502index 2c61783..4d49e4e 100644
48503--- a/drivers/staging/android/timed_output.c
48504+++ b/drivers/staging/android/timed_output.c
48505@@ -25,7 +25,7 @@
48506 #include "timed_output.h"
48507
48508 static struct class *timed_output_class;
48509-static atomic_t device_count;
48510+static atomic_unchecked_t device_count;
48511
48512 static ssize_t enable_show(struct device *dev, struct device_attribute *attr,
48513 char *buf)
48514@@ -63,7 +63,7 @@ static int create_timed_output_class(void)
48515 timed_output_class = class_create(THIS_MODULE, "timed_output");
48516 if (IS_ERR(timed_output_class))
48517 return PTR_ERR(timed_output_class);
48518- atomic_set(&device_count, 0);
48519+ atomic_set_unchecked(&device_count, 0);
48520 timed_output_class->dev_groups = timed_output_groups;
48521 }
48522
48523@@ -81,7 +81,7 @@ int timed_output_dev_register(struct timed_output_dev *tdev)
48524 if (ret < 0)
48525 return ret;
48526
48527- tdev->index = atomic_inc_return(&device_count);
48528+ tdev->index = atomic_inc_return_unchecked(&device_count);
48529 tdev->dev = device_create(timed_output_class, NULL,
48530 MKDEV(0, tdev->index), NULL, "%s", tdev->name);
48531 if (IS_ERR(tdev->dev))
48532diff --git a/drivers/staging/gdm724x/gdm_tty.c b/drivers/staging/gdm724x/gdm_tty.c
48533index 0247a20..cb9595c 100644
48534--- a/drivers/staging/gdm724x/gdm_tty.c
48535+++ b/drivers/staging/gdm724x/gdm_tty.c
48536@@ -45,7 +45,7 @@
48537 #define gdm_tty_send_control(n, r, v, d, l) (\
48538 n->tty_dev->send_control(n->tty_dev->priv_dev, r, v, d, l))
48539
48540-#define GDM_TTY_READY(gdm) (gdm && gdm->tty_dev && gdm->port.count)
48541+#define GDM_TTY_READY(gdm) (gdm && gdm->tty_dev && atomic_read(&gdm->port.count))
48542
48543 static struct tty_driver *gdm_driver[TTY_MAX_COUNT];
48544 static struct gdm *gdm_table[TTY_MAX_COUNT][GDM_TTY_MINOR];
48545diff --git a/drivers/staging/lustre/lnet/selftest/brw_test.c b/drivers/staging/lustre/lnet/selftest/brw_test.c
48546index ef5064e..fce01db 100644
48547--- a/drivers/staging/lustre/lnet/selftest/brw_test.c
48548+++ b/drivers/staging/lustre/lnet/selftest/brw_test.c
48549@@ -478,13 +478,11 @@ brw_server_handle(struct srpc_server_rpc *rpc)
48550 return 0;
48551 }
48552
48553-sfw_test_client_ops_t brw_test_client;
48554-void brw_init_test_client(void)
48555-{
48556- brw_test_client.tso_init = brw_client_init;
48557- brw_test_client.tso_fini = brw_client_fini;
48558- brw_test_client.tso_prep_rpc = brw_client_prep_rpc;
48559- brw_test_client.tso_done_rpc = brw_client_done_rpc;
48560+sfw_test_client_ops_t brw_test_client = {
48561+ .tso_init = brw_client_init,
48562+ .tso_fini = brw_client_fini,
48563+ .tso_prep_rpc = brw_client_prep_rpc,
48564+ .tso_done_rpc = brw_client_done_rpc,
48565 };
48566
48567 srpc_service_t brw_test_service;
48568diff --git a/drivers/staging/lustre/lnet/selftest/framework.c b/drivers/staging/lustre/lnet/selftest/framework.c
48569index 483c785..e1a2a7b 100644
48570--- a/drivers/staging/lustre/lnet/selftest/framework.c
48571+++ b/drivers/staging/lustre/lnet/selftest/framework.c
48572@@ -1635,12 +1635,10 @@ static srpc_service_t sfw_services[] =
48573
48574 extern sfw_test_client_ops_t ping_test_client;
48575 extern srpc_service_t ping_test_service;
48576-extern void ping_init_test_client(void);
48577 extern void ping_init_test_service(void);
48578
48579 extern sfw_test_client_ops_t brw_test_client;
48580 extern srpc_service_t brw_test_service;
48581-extern void brw_init_test_client(void);
48582 extern void brw_init_test_service(void);
48583
48584
48585@@ -1684,12 +1682,10 @@ sfw_startup (void)
48586 INIT_LIST_HEAD(&sfw_data.fw_zombie_rpcs);
48587 INIT_LIST_HEAD(&sfw_data.fw_zombie_sessions);
48588
48589- brw_init_test_client();
48590 brw_init_test_service();
48591 rc = sfw_register_test(&brw_test_service, &brw_test_client);
48592 LASSERT (rc == 0);
48593
48594- ping_init_test_client();
48595 ping_init_test_service();
48596 rc = sfw_register_test(&ping_test_service, &ping_test_client);
48597 LASSERT (rc == 0);
48598diff --git a/drivers/staging/lustre/lnet/selftest/ping_test.c b/drivers/staging/lustre/lnet/selftest/ping_test.c
48599index f0f9194..b589047 100644
48600--- a/drivers/staging/lustre/lnet/selftest/ping_test.c
48601+++ b/drivers/staging/lustre/lnet/selftest/ping_test.c
48602@@ -210,14 +210,12 @@ ping_server_handle(struct srpc_server_rpc *rpc)
48603 return 0;
48604 }
48605
48606-sfw_test_client_ops_t ping_test_client;
48607-void ping_init_test_client(void)
48608-{
48609- ping_test_client.tso_init = ping_client_init;
48610- ping_test_client.tso_fini = ping_client_fini;
48611- ping_test_client.tso_prep_rpc = ping_client_prep_rpc;
48612- ping_test_client.tso_done_rpc = ping_client_done_rpc;
48613-}
48614+sfw_test_client_ops_t ping_test_client = {
48615+ .tso_init = ping_client_init,
48616+ .tso_fini = ping_client_fini,
48617+ .tso_prep_rpc = ping_client_prep_rpc,
48618+ .tso_done_rpc = ping_client_done_rpc,
48619+};
48620
48621 srpc_service_t ping_test_service;
48622 void ping_init_test_service(void)
48623diff --git a/drivers/staging/lustre/lustre/include/lustre_dlm.h b/drivers/staging/lustre/lustre/include/lustre_dlm.h
48624index 7020d9c..0d3b580 100644
48625--- a/drivers/staging/lustre/lustre/include/lustre_dlm.h
48626+++ b/drivers/staging/lustre/lustre/include/lustre_dlm.h
48627@@ -1141,7 +1141,7 @@ struct ldlm_callback_suite {
48628 ldlm_completion_callback lcs_completion;
48629 ldlm_blocking_callback lcs_blocking;
48630 ldlm_glimpse_callback lcs_glimpse;
48631-};
48632+} __no_const;
48633
48634 /* ldlm_lockd.c */
48635 int ldlm_del_waiting_lock(struct ldlm_lock *lock);
48636diff --git a/drivers/staging/lustre/lustre/include/obd.h b/drivers/staging/lustre/lustre/include/obd.h
48637index a612255..9a9e2dd 100644
48638--- a/drivers/staging/lustre/lustre/include/obd.h
48639+++ b/drivers/staging/lustre/lustre/include/obd.h
48640@@ -1417,7 +1417,7 @@ struct md_ops {
48641 * lprocfs_alloc_md_stats() in obdclass/lprocfs_status.c. Also, add a
48642 * wrapper function in include/linux/obd_class.h.
48643 */
48644-};
48645+} __no_const;
48646
48647 struct lsm_operations {
48648 void (*lsm_free)(struct lov_stripe_md *);
48649diff --git a/drivers/staging/lustre/lustre/ldlm/ldlm_flock.c b/drivers/staging/lustre/lustre/ldlm/ldlm_flock.c
48650index c68ed27..f9c00f4 100644
48651--- a/drivers/staging/lustre/lustre/ldlm/ldlm_flock.c
48652+++ b/drivers/staging/lustre/lustre/ldlm/ldlm_flock.c
48653@@ -249,7 +249,7 @@ ldlm_process_flock_lock(struct ldlm_lock *req, __u64 *flags, int first_enq,
48654 int added = (mode == LCK_NL);
48655 int overlaps = 0;
48656 int splitted = 0;
48657- const struct ldlm_callback_suite null_cbs = { NULL };
48658+ const struct ldlm_callback_suite null_cbs = { };
48659 int rc;
48660
48661 CDEBUG(D_DLMTRACE, "flags %#llx owner "LPU64" pid %u mode %u start "
48662diff --git a/drivers/staging/lustre/lustre/libcfs/linux/linux-proc.c b/drivers/staging/lustre/lustre/libcfs/linux/linux-proc.c
48663index fc6c977..df1f956 100644
48664--- a/drivers/staging/lustre/lustre/libcfs/linux/linux-proc.c
48665+++ b/drivers/staging/lustre/lustre/libcfs/linux/linux-proc.c
48666@@ -219,7 +219,7 @@ DECLARE_PROC_HANDLER(proc_debug_mb)
48667 int LL_PROC_PROTO(proc_console_max_delay_cs)
48668 {
48669 int rc, max_delay_cs;
48670- ctl_table_t dummy = *table;
48671+ ctl_table_no_const dummy = *table;
48672 cfs_duration_t d;
48673
48674 dummy.data = &max_delay_cs;
48675@@ -250,7 +250,7 @@ int LL_PROC_PROTO(proc_console_max_delay_cs)
48676 int LL_PROC_PROTO(proc_console_min_delay_cs)
48677 {
48678 int rc, min_delay_cs;
48679- ctl_table_t dummy = *table;
48680+ ctl_table_no_const dummy = *table;
48681 cfs_duration_t d;
48682
48683 dummy.data = &min_delay_cs;
48684@@ -281,7 +281,7 @@ int LL_PROC_PROTO(proc_console_min_delay_cs)
48685 int LL_PROC_PROTO(proc_console_backoff)
48686 {
48687 int rc, backoff;
48688- ctl_table_t dummy = *table;
48689+ ctl_table_no_const dummy = *table;
48690
48691 dummy.data = &backoff;
48692 dummy.proc_handler = &proc_dointvec;
48693diff --git a/drivers/staging/lustre/lustre/libcfs/module.c b/drivers/staging/lustre/lustre/libcfs/module.c
48694index f3108c7..cd4f9da 100644
48695--- a/drivers/staging/lustre/lustre/libcfs/module.c
48696+++ b/drivers/staging/lustre/lustre/libcfs/module.c
48697@@ -348,11 +348,11 @@ out:
48698
48699
48700 struct cfs_psdev_ops libcfs_psdev_ops = {
48701- libcfs_psdev_open,
48702- libcfs_psdev_release,
48703- NULL,
48704- NULL,
48705- libcfs_ioctl
48706+ .p_open = libcfs_psdev_open,
48707+ .p_close = libcfs_psdev_release,
48708+ .p_read = NULL,
48709+ .p_write = NULL,
48710+ .p_ioctl = libcfs_ioctl
48711 };
48712
48713 extern int insert_proc(void);
48714diff --git a/drivers/staging/media/solo6x10/solo6x10-core.c b/drivers/staging/media/solo6x10/solo6x10-core.c
48715index 3675020..e80d92c 100644
48716--- a/drivers/staging/media/solo6x10/solo6x10-core.c
48717+++ b/drivers/staging/media/solo6x10/solo6x10-core.c
48718@@ -434,7 +434,7 @@ static void solo_device_release(struct device *dev)
48719
48720 static int solo_sysfs_init(struct solo_dev *solo_dev)
48721 {
48722- struct bin_attribute *sdram_attr = &solo_dev->sdram_attr;
48723+ bin_attribute_no_const *sdram_attr = &solo_dev->sdram_attr;
48724 struct device *dev = &solo_dev->dev;
48725 const char *driver;
48726 int i;
48727diff --git a/drivers/staging/media/solo6x10/solo6x10-g723.c b/drivers/staging/media/solo6x10/solo6x10-g723.c
48728index 1db18c7..35e6afc 100644
48729--- a/drivers/staging/media/solo6x10/solo6x10-g723.c
48730+++ b/drivers/staging/media/solo6x10/solo6x10-g723.c
48731@@ -355,7 +355,7 @@ static int solo_snd_pcm_init(struct solo_dev *solo_dev)
48732
48733 int solo_g723_init(struct solo_dev *solo_dev)
48734 {
48735- static struct snd_device_ops ops = { NULL };
48736+ static struct snd_device_ops ops = { };
48737 struct snd_card *card;
48738 struct snd_kcontrol_new kctl;
48739 char name[32];
48740diff --git a/drivers/staging/media/solo6x10/solo6x10-p2m.c b/drivers/staging/media/solo6x10/solo6x10-p2m.c
48741index 3335941..2b26186 100644
48742--- a/drivers/staging/media/solo6x10/solo6x10-p2m.c
48743+++ b/drivers/staging/media/solo6x10/solo6x10-p2m.c
48744@@ -77,7 +77,7 @@ int solo_p2m_dma_desc(struct solo_dev *solo_dev,
48745
48746 /* Get next ID. According to Softlogic, 6110 has problems on !=0 P2M */
48747 if (solo_dev->type != SOLO_DEV_6110 && multi_p2m) {
48748- p2m_id = atomic_inc_return(&solo_dev->p2m_count) % SOLO_NR_P2M;
48749+ p2m_id = atomic_inc_return_unchecked(&solo_dev->p2m_count) % SOLO_NR_P2M;
48750 if (p2m_id < 0)
48751 p2m_id = -p2m_id;
48752 }
48753diff --git a/drivers/staging/media/solo6x10/solo6x10.h b/drivers/staging/media/solo6x10/solo6x10.h
48754index 6f91d2e..3f011d2 100644
48755--- a/drivers/staging/media/solo6x10/solo6x10.h
48756+++ b/drivers/staging/media/solo6x10/solo6x10.h
48757@@ -238,7 +238,7 @@ struct solo_dev {
48758
48759 /* P2M DMA Engine */
48760 struct solo_p2m_dev p2m_dev[SOLO_NR_P2M];
48761- atomic_t p2m_count;
48762+ atomic_unchecked_t p2m_count;
48763 int p2m_jiffies;
48764 unsigned int p2m_timeouts;
48765
48766diff --git a/drivers/staging/octeon/ethernet-rx.c b/drivers/staging/octeon/ethernet-rx.c
48767index e14a1bb..9cb9bbe 100644
48768--- a/drivers/staging/octeon/ethernet-rx.c
48769+++ b/drivers/staging/octeon/ethernet-rx.c
48770@@ -419,11 +419,11 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
48771 /* Increment RX stats for virtual ports */
48772 if (work->ipprt >= CVMX_PIP_NUM_INPUT_PORTS) {
48773 #ifdef CONFIG_64BIT
48774- atomic64_add(1, (atomic64_t *)&priv->stats.rx_packets);
48775- atomic64_add(skb->len, (atomic64_t *)&priv->stats.rx_bytes);
48776+ atomic64_add_unchecked(1, (atomic64_unchecked_t *)&priv->stats.rx_packets);
48777+ atomic64_add_unchecked(skb->len, (atomic64_unchecked_t *)&priv->stats.rx_bytes);
48778 #else
48779- atomic_add(1, (atomic_t *)&priv->stats.rx_packets);
48780- atomic_add(skb->len, (atomic_t *)&priv->stats.rx_bytes);
48781+ atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_packets);
48782+ atomic_add_unchecked(skb->len, (atomic_unchecked_t *)&priv->stats.rx_bytes);
48783 #endif
48784 }
48785 netif_receive_skb(skb);
48786@@ -434,9 +434,9 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
48787 dev->name);
48788 */
48789 #ifdef CONFIG_64BIT
48790- atomic64_add(1, (atomic64_t *)&priv->stats.rx_dropped);
48791+ atomic64_unchecked_add(1, (atomic64_unchecked_t *)&priv->stats.rx_dropped);
48792 #else
48793- atomic_add(1, (atomic_t *)&priv->stats.rx_dropped);
48794+ atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_dropped);
48795 #endif
48796 dev_kfree_skb_irq(skb);
48797 }
48798diff --git a/drivers/staging/octeon/ethernet.c b/drivers/staging/octeon/ethernet.c
48799index c3a90e7..023619a 100644
48800--- a/drivers/staging/octeon/ethernet.c
48801+++ b/drivers/staging/octeon/ethernet.c
48802@@ -252,11 +252,11 @@ static struct net_device_stats *cvm_oct_common_get_stats(struct net_device *dev)
48803 * since the RX tasklet also increments it.
48804 */
48805 #ifdef CONFIG_64BIT
48806- atomic64_add(rx_status.dropped_packets,
48807- (atomic64_t *)&priv->stats.rx_dropped);
48808+ atomic64_add_unchecked(rx_status.dropped_packets,
48809+ (atomic64_unchecked_t *)&priv->stats.rx_dropped);
48810 #else
48811- atomic_add(rx_status.dropped_packets,
48812- (atomic_t *)&priv->stats.rx_dropped);
48813+ atomic_add_unchecked(rx_status.dropped_packets,
48814+ (atomic_unchecked_t *)&priv->stats.rx_dropped);
48815 #endif
48816 }
48817
48818diff --git a/drivers/staging/rtl8188eu/include/hal_intf.h b/drivers/staging/rtl8188eu/include/hal_intf.h
48819index 439c3c9..2d74293 100644
48820--- a/drivers/staging/rtl8188eu/include/hal_intf.h
48821+++ b/drivers/staging/rtl8188eu/include/hal_intf.h
48822@@ -271,7 +271,7 @@ struct hal_ops {
48823 s32 (*c2h_handler)(struct adapter *padapter,
48824 struct c2h_evt_hdr *c2h_evt);
48825 c2h_id_filter c2h_id_filter_ccx;
48826-};
48827+} __no_const;
48828
48829 enum rt_eeprom_type {
48830 EEPROM_93C46,
48831diff --git a/drivers/staging/rtl8188eu/include/rtw_io.h b/drivers/staging/rtl8188eu/include/rtw_io.h
48832index eb6f0e5..e6a0958 100644
48833--- a/drivers/staging/rtl8188eu/include/rtw_io.h
48834+++ b/drivers/staging/rtl8188eu/include/rtw_io.h
48835@@ -126,7 +126,7 @@ struct _io_ops {
48836 u32 (*_write_scsi)(struct intf_hdl *pintfhdl,u32 cnt, u8 *pmem);
48837 void (*_read_port_cancel)(struct intf_hdl *pintfhdl);
48838 void (*_write_port_cancel)(struct intf_hdl *pintfhdl);
48839-};
48840+} __no_const;
48841
48842 struct io_req {
48843 struct list_head list;
48844diff --git a/drivers/staging/rtl8712/rtl871x_io.h b/drivers/staging/rtl8712/rtl871x_io.h
48845index dc23395..cf7e9b1 100644
48846--- a/drivers/staging/rtl8712/rtl871x_io.h
48847+++ b/drivers/staging/rtl8712/rtl871x_io.h
48848@@ -108,7 +108,7 @@ struct _io_ops {
48849 u8 *pmem);
48850 u32 (*_write_port)(struct intf_hdl *pintfhdl, u32 addr, u32 cnt,
48851 u8 *pmem);
48852-};
48853+} __no_const;
48854
48855 struct io_req {
48856 struct list_head list;
48857diff --git a/drivers/staging/sbe-2t3e3/netdev.c b/drivers/staging/sbe-2t3e3/netdev.c
48858index 1f5088b..0e59820 100644
48859--- a/drivers/staging/sbe-2t3e3/netdev.c
48860+++ b/drivers/staging/sbe-2t3e3/netdev.c
48861@@ -51,7 +51,7 @@ static int t3e3_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
48862 t3e3_if_config(sc, cmd_2t3e3, (char *)&param, &resp, &rlen);
48863
48864 if (rlen)
48865- if (copy_to_user(data, &resp, rlen))
48866+ if (rlen > sizeof resp || copy_to_user(data, &resp, rlen))
48867 return -EFAULT;
48868
48869 return 0;
48870diff --git a/drivers/staging/usbip/vhci.h b/drivers/staging/usbip/vhci.h
48871index a863a98..d272795 100644
48872--- a/drivers/staging/usbip/vhci.h
48873+++ b/drivers/staging/usbip/vhci.h
48874@@ -83,7 +83,7 @@ struct vhci_hcd {
48875 unsigned resuming:1;
48876 unsigned long re_timeout;
48877
48878- atomic_t seqnum;
48879+ atomic_unchecked_t seqnum;
48880
48881 /*
48882 * NOTE:
48883diff --git a/drivers/staging/usbip/vhci_hcd.c b/drivers/staging/usbip/vhci_hcd.c
48884index d7974cb..d78076b 100644
48885--- a/drivers/staging/usbip/vhci_hcd.c
48886+++ b/drivers/staging/usbip/vhci_hcd.c
48887@@ -441,7 +441,7 @@ static void vhci_tx_urb(struct urb *urb)
48888
48889 spin_lock(&vdev->priv_lock);
48890
48891- priv->seqnum = atomic_inc_return(&the_controller->seqnum);
48892+ priv->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
48893 if (priv->seqnum == 0xffff)
48894 dev_info(&urb->dev->dev, "seqnum max\n");
48895
48896@@ -687,7 +687,7 @@ static int vhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
48897 return -ENOMEM;
48898 }
48899
48900- unlink->seqnum = atomic_inc_return(&the_controller->seqnum);
48901+ unlink->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
48902 if (unlink->seqnum == 0xffff)
48903 pr_info("seqnum max\n");
48904
48905@@ -891,7 +891,7 @@ static int vhci_start(struct usb_hcd *hcd)
48906 vdev->rhport = rhport;
48907 }
48908
48909- atomic_set(&vhci->seqnum, 0);
48910+ atomic_set_unchecked(&vhci->seqnum, 0);
48911 spin_lock_init(&vhci->lock);
48912
48913 hcd->power_budget = 0; /* no limit */
48914diff --git a/drivers/staging/usbip/vhci_rx.c b/drivers/staging/usbip/vhci_rx.c
48915index d07fcb5..358e1e1 100644
48916--- a/drivers/staging/usbip/vhci_rx.c
48917+++ b/drivers/staging/usbip/vhci_rx.c
48918@@ -80,7 +80,7 @@ static void vhci_recv_ret_submit(struct vhci_device *vdev,
48919 if (!urb) {
48920 pr_err("cannot find a urb of seqnum %u\n", pdu->base.seqnum);
48921 pr_info("max seqnum %d\n",
48922- atomic_read(&the_controller->seqnum));
48923+ atomic_read_unchecked(&the_controller->seqnum));
48924 usbip_event_add(ud, VDEV_EVENT_ERROR_TCP);
48925 return;
48926 }
48927diff --git a/drivers/staging/vt6655/hostap.c b/drivers/staging/vt6655/hostap.c
48928index 8acff44..bdb2fca 100644
48929--- a/drivers/staging/vt6655/hostap.c
48930+++ b/drivers/staging/vt6655/hostap.c
48931@@ -69,14 +69,13 @@ static int msglevel = MSG_LEVEL_INFO;
48932 *
48933 */
48934
48935+static net_device_ops_no_const apdev_netdev_ops;
48936+
48937 static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
48938 {
48939 PSDevice apdev_priv;
48940 struct net_device *dev = pDevice->dev;
48941 int ret;
48942- const struct net_device_ops apdev_netdev_ops = {
48943- .ndo_start_xmit = pDevice->tx_80211,
48944- };
48945
48946 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
48947
48948@@ -88,6 +87,8 @@ static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
48949 *apdev_priv = *pDevice;
48950 eth_hw_addr_inherit(pDevice->apdev, dev);
48951
48952+ /* only half broken now */
48953+ apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
48954 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
48955
48956 pDevice->apdev->type = ARPHRD_IEEE80211;
48957diff --git a/drivers/staging/vt6656/hostap.c b/drivers/staging/vt6656/hostap.c
48958index c699a30..b90a5fd 100644
48959--- a/drivers/staging/vt6656/hostap.c
48960+++ b/drivers/staging/vt6656/hostap.c
48961@@ -60,14 +60,13 @@ static int msglevel =MSG_LEVEL_INFO;
48962 *
48963 */
48964
48965+static net_device_ops_no_const apdev_netdev_ops;
48966+
48967 static int hostap_enable_hostapd(struct vnt_private *pDevice, int rtnl_locked)
48968 {
48969 struct vnt_private *apdev_priv;
48970 struct net_device *dev = pDevice->dev;
48971 int ret;
48972- const struct net_device_ops apdev_netdev_ops = {
48973- .ndo_start_xmit = pDevice->tx_80211,
48974- };
48975
48976 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
48977
48978@@ -79,6 +78,8 @@ static int hostap_enable_hostapd(struct vnt_private *pDevice, int rtnl_locked)
48979 *apdev_priv = *pDevice;
48980 memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN);
48981
48982+ /* only half broken now */
48983+ apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
48984 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
48985
48986 pDevice->apdev->type = ARPHRD_IEEE80211;
48987diff --git a/drivers/target/sbp/sbp_target.c b/drivers/target/sbp/sbp_target.c
48988index e51b09a..5ebac31 100644
48989--- a/drivers/target/sbp/sbp_target.c
48990+++ b/drivers/target/sbp/sbp_target.c
48991@@ -62,7 +62,7 @@ static const u32 sbp_unit_directory_template[] = {
48992
48993 #define SESSION_MAINTENANCE_INTERVAL HZ
48994
48995-static atomic_t login_id = ATOMIC_INIT(0);
48996+static atomic_unchecked_t login_id = ATOMIC_INIT(0);
48997
48998 static void session_maintenance_work(struct work_struct *);
48999 static int sbp_run_transaction(struct fw_card *, int, int, int, int,
49000@@ -444,7 +444,7 @@ static void sbp_management_request_login(
49001 login->lun = se_lun;
49002 login->status_fifo_addr = sbp2_pointer_to_addr(&req->orb.status_fifo);
49003 login->exclusive = LOGIN_ORB_EXCLUSIVE(be32_to_cpu(req->orb.misc));
49004- login->login_id = atomic_inc_return(&login_id);
49005+ login->login_id = atomic_inc_return_unchecked(&login_id);
49006
49007 login->tgt_agt = sbp_target_agent_register(login);
49008 if (IS_ERR(login->tgt_agt)) {
49009diff --git a/drivers/target/target_core_device.c b/drivers/target/target_core_device.c
49010index e5e3965..a7b487c 100644
49011--- a/drivers/target/target_core_device.c
49012+++ b/drivers/target/target_core_device.c
49013@@ -1436,7 +1436,7 @@ struct se_device *target_alloc_device(struct se_hba *hba, const char *name)
49014 spin_lock_init(&dev->se_tmr_lock);
49015 spin_lock_init(&dev->qf_cmd_lock);
49016 sema_init(&dev->caw_sem, 1);
49017- atomic_set(&dev->dev_ordered_id, 0);
49018+ atomic_set_unchecked(&dev->dev_ordered_id, 0);
49019 INIT_LIST_HEAD(&dev->t10_wwn.t10_vpd_list);
49020 spin_lock_init(&dev->t10_wwn.t10_vpd_lock);
49021 INIT_LIST_HEAD(&dev->t10_pr.registration_list);
49022diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c
49023index 0b0009b..215e88e 100644
49024--- a/drivers/target/target_core_transport.c
49025+++ b/drivers/target/target_core_transport.c
49026@@ -1137,7 +1137,7 @@ transport_check_alloc_task_attr(struct se_cmd *cmd)
49027 * Used to determine when ORDERED commands should go from
49028 * Dormant to Active status.
49029 */
49030- cmd->se_ordered_id = atomic_inc_return(&dev->dev_ordered_id);
49031+ cmd->se_ordered_id = atomic_inc_return_unchecked(&dev->dev_ordered_id);
49032 smp_mb__after_atomic_inc();
49033 pr_debug("Allocated se_ordered_id: %u for Task Attr: 0x%02x on %s\n",
49034 cmd->se_ordered_id, cmd->sam_task_attr,
49035diff --git a/drivers/tty/cyclades.c b/drivers/tty/cyclades.c
49036index 33f83fe..d80f8e1 100644
49037--- a/drivers/tty/cyclades.c
49038+++ b/drivers/tty/cyclades.c
49039@@ -1570,10 +1570,10 @@ static int cy_open(struct tty_struct *tty, struct file *filp)
49040 printk(KERN_DEBUG "cyc:cy_open ttyC%d, count = %d\n", info->line,
49041 info->port.count);
49042 #endif
49043- info->port.count++;
49044+ atomic_inc(&info->port.count);
49045 #ifdef CY_DEBUG_COUNT
49046 printk(KERN_DEBUG "cyc:cy_open (%d): incrementing count to %d\n",
49047- current->pid, info->port.count);
49048+ current->pid, atomic_read(&info->port.count));
49049 #endif
49050
49051 /*
49052@@ -3972,7 +3972,7 @@ static int cyclades_proc_show(struct seq_file *m, void *v)
49053 for (j = 0; j < cy_card[i].nports; j++) {
49054 info = &cy_card[i].ports[j];
49055
49056- if (info->port.count) {
49057+ if (atomic_read(&info->port.count)) {
49058 /* XXX is the ldisc num worth this? */
49059 struct tty_struct *tty;
49060 struct tty_ldisc *ld;
49061diff --git a/drivers/tty/hvc/hvc_console.c b/drivers/tty/hvc/hvc_console.c
49062index 9eba119..5070303 100644
49063--- a/drivers/tty/hvc/hvc_console.c
49064+++ b/drivers/tty/hvc/hvc_console.c
49065@@ -338,7 +338,7 @@ static int hvc_open(struct tty_struct *tty, struct file * filp)
49066
49067 spin_lock_irqsave(&hp->port.lock, flags);
49068 /* Check and then increment for fast path open. */
49069- if (hp->port.count++ > 0) {
49070+ if (atomic_inc_return(&hp->port.count) > 1) {
49071 spin_unlock_irqrestore(&hp->port.lock, flags);
49072 hvc_kick();
49073 return 0;
49074@@ -393,7 +393,7 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
49075
49076 spin_lock_irqsave(&hp->port.lock, flags);
49077
49078- if (--hp->port.count == 0) {
49079+ if (atomic_dec_return(&hp->port.count) == 0) {
49080 spin_unlock_irqrestore(&hp->port.lock, flags);
49081 /* We are done with the tty pointer now. */
49082 tty_port_tty_set(&hp->port, NULL);
49083@@ -415,9 +415,9 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
49084 */
49085 tty_wait_until_sent_from_close(tty, HVC_CLOSE_WAIT);
49086 } else {
49087- if (hp->port.count < 0)
49088+ if (atomic_read(&hp->port.count) < 0)
49089 printk(KERN_ERR "hvc_close %X: oops, count is %d\n",
49090- hp->vtermno, hp->port.count);
49091+ hp->vtermno, atomic_read(&hp->port.count));
49092 spin_unlock_irqrestore(&hp->port.lock, flags);
49093 }
49094 }
49095@@ -447,12 +447,12 @@ static void hvc_hangup(struct tty_struct *tty)
49096 * open->hangup case this can be called after the final close so prevent
49097 * that from happening for now.
49098 */
49099- if (hp->port.count <= 0) {
49100+ if (atomic_read(&hp->port.count) <= 0) {
49101 spin_unlock_irqrestore(&hp->port.lock, flags);
49102 return;
49103 }
49104
49105- hp->port.count = 0;
49106+ atomic_set(&hp->port.count, 0);
49107 spin_unlock_irqrestore(&hp->port.lock, flags);
49108 tty_port_tty_set(&hp->port, NULL);
49109
49110@@ -500,7 +500,7 @@ static int hvc_write(struct tty_struct *tty, const unsigned char *buf, int count
49111 return -EPIPE;
49112
49113 /* FIXME what's this (unprotected) check for? */
49114- if (hp->port.count <= 0)
49115+ if (atomic_read(&hp->port.count) <= 0)
49116 return -EIO;
49117
49118 spin_lock_irqsave(&hp->lock, flags);
49119diff --git a/drivers/tty/hvc/hvcs.c b/drivers/tty/hvc/hvcs.c
49120index 81e939e..95ead10 100644
49121--- a/drivers/tty/hvc/hvcs.c
49122+++ b/drivers/tty/hvc/hvcs.c
49123@@ -83,6 +83,7 @@
49124 #include <asm/hvcserver.h>
49125 #include <asm/uaccess.h>
49126 #include <asm/vio.h>
49127+#include <asm/local.h>
49128
49129 /*
49130 * 1.3.0 -> 1.3.1 In hvcs_open memset(..,0x00,..) instead of memset(..,0x3F,00).
49131@@ -416,7 +417,7 @@ static ssize_t hvcs_vterm_state_store(struct device *dev, struct device_attribut
49132
49133 spin_lock_irqsave(&hvcsd->lock, flags);
49134
49135- if (hvcsd->port.count > 0) {
49136+ if (atomic_read(&hvcsd->port.count) > 0) {
49137 spin_unlock_irqrestore(&hvcsd->lock, flags);
49138 printk(KERN_INFO "HVCS: vterm state unchanged. "
49139 "The hvcs device node is still in use.\n");
49140@@ -1127,7 +1128,7 @@ static int hvcs_install(struct tty_driver *driver, struct tty_struct *tty)
49141 }
49142 }
49143
49144- hvcsd->port.count = 0;
49145+ atomic_set(&hvcsd->port.count, 0);
49146 hvcsd->port.tty = tty;
49147 tty->driver_data = hvcsd;
49148
49149@@ -1180,7 +1181,7 @@ static int hvcs_open(struct tty_struct *tty, struct file *filp)
49150 unsigned long flags;
49151
49152 spin_lock_irqsave(&hvcsd->lock, flags);
49153- hvcsd->port.count++;
49154+ atomic_inc(&hvcsd->port.count);
49155 hvcsd->todo_mask |= HVCS_SCHED_READ;
49156 spin_unlock_irqrestore(&hvcsd->lock, flags);
49157
49158@@ -1216,7 +1217,7 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
49159 hvcsd = tty->driver_data;
49160
49161 spin_lock_irqsave(&hvcsd->lock, flags);
49162- if (--hvcsd->port.count == 0) {
49163+ if (atomic_dec_and_test(&hvcsd->port.count)) {
49164
49165 vio_disable_interrupts(hvcsd->vdev);
49166
49167@@ -1241,10 +1242,10 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
49168
49169 free_irq(irq, hvcsd);
49170 return;
49171- } else if (hvcsd->port.count < 0) {
49172+ } else if (atomic_read(&hvcsd->port.count) < 0) {
49173 printk(KERN_ERR "HVCS: vty-server@%X open_count: %d"
49174 " is missmanaged.\n",
49175- hvcsd->vdev->unit_address, hvcsd->port.count);
49176+ hvcsd->vdev->unit_address, atomic_read(&hvcsd->port.count));
49177 }
49178
49179 spin_unlock_irqrestore(&hvcsd->lock, flags);
49180@@ -1266,7 +1267,7 @@ static void hvcs_hangup(struct tty_struct * tty)
49181
49182 spin_lock_irqsave(&hvcsd->lock, flags);
49183 /* Preserve this so that we know how many kref refs to put */
49184- temp_open_count = hvcsd->port.count;
49185+ temp_open_count = atomic_read(&hvcsd->port.count);
49186
49187 /*
49188 * Don't kref put inside the spinlock because the destruction
49189@@ -1281,7 +1282,7 @@ static void hvcs_hangup(struct tty_struct * tty)
49190 tty->driver_data = NULL;
49191 hvcsd->port.tty = NULL;
49192
49193- hvcsd->port.count = 0;
49194+ atomic_set(&hvcsd->port.count, 0);
49195
49196 /* This will drop any buffered data on the floor which is OK in a hangup
49197 * scenario. */
49198@@ -1352,7 +1353,7 @@ static int hvcs_write(struct tty_struct *tty,
49199 * the middle of a write operation? This is a crummy place to do this
49200 * but we want to keep it all in the spinlock.
49201 */
49202- if (hvcsd->port.count <= 0) {
49203+ if (atomic_read(&hvcsd->port.count) <= 0) {
49204 spin_unlock_irqrestore(&hvcsd->lock, flags);
49205 return -ENODEV;
49206 }
49207@@ -1426,7 +1427,7 @@ static int hvcs_write_room(struct tty_struct *tty)
49208 {
49209 struct hvcs_struct *hvcsd = tty->driver_data;
49210
49211- if (!hvcsd || hvcsd->port.count <= 0)
49212+ if (!hvcsd || atomic_read(&hvcsd->port.count) <= 0)
49213 return 0;
49214
49215 return HVCS_BUFF_LEN - hvcsd->chars_in_buffer;
49216diff --git a/drivers/tty/hvc/hvsi.c b/drivers/tty/hvc/hvsi.c
49217index 4190199..48f2920 100644
49218--- a/drivers/tty/hvc/hvsi.c
49219+++ b/drivers/tty/hvc/hvsi.c
49220@@ -85,7 +85,7 @@ struct hvsi_struct {
49221 int n_outbuf;
49222 uint32_t vtermno;
49223 uint32_t virq;
49224- atomic_t seqno; /* HVSI packet sequence number */
49225+ atomic_unchecked_t seqno; /* HVSI packet sequence number */
49226 uint16_t mctrl;
49227 uint8_t state; /* HVSI protocol state */
49228 uint8_t flags;
49229@@ -295,7 +295,7 @@ static int hvsi_version_respond(struct hvsi_struct *hp, uint16_t query_seqno)
49230
49231 packet.hdr.type = VS_QUERY_RESPONSE_PACKET_HEADER;
49232 packet.hdr.len = sizeof(struct hvsi_query_response);
49233- packet.hdr.seqno = atomic_inc_return(&hp->seqno);
49234+ packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
49235 packet.verb = VSV_SEND_VERSION_NUMBER;
49236 packet.u.version = HVSI_VERSION;
49237 packet.query_seqno = query_seqno+1;
49238@@ -555,7 +555,7 @@ static int hvsi_query(struct hvsi_struct *hp, uint16_t verb)
49239
49240 packet.hdr.type = VS_QUERY_PACKET_HEADER;
49241 packet.hdr.len = sizeof(struct hvsi_query);
49242- packet.hdr.seqno = atomic_inc_return(&hp->seqno);
49243+ packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
49244 packet.verb = verb;
49245
49246 pr_debug("%s: sending %i bytes\n", __func__, packet.hdr.len);
49247@@ -597,7 +597,7 @@ static int hvsi_set_mctrl(struct hvsi_struct *hp, uint16_t mctrl)
49248 int wrote;
49249
49250 packet.hdr.type = VS_CONTROL_PACKET_HEADER,
49251- packet.hdr.seqno = atomic_inc_return(&hp->seqno);
49252+ packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
49253 packet.hdr.len = sizeof(struct hvsi_control);
49254 packet.verb = VSV_SET_MODEM_CTL;
49255 packet.mask = HVSI_TSDTR;
49256@@ -680,7 +680,7 @@ static int hvsi_put_chars(struct hvsi_struct *hp, const char *buf, int count)
49257 BUG_ON(count > HVSI_MAX_OUTGOING_DATA);
49258
49259 packet.hdr.type = VS_DATA_PACKET_HEADER;
49260- packet.hdr.seqno = atomic_inc_return(&hp->seqno);
49261+ packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
49262 packet.hdr.len = count + sizeof(struct hvsi_header);
49263 memcpy(&packet.data, buf, count);
49264
49265@@ -697,7 +697,7 @@ static void hvsi_close_protocol(struct hvsi_struct *hp)
49266 struct hvsi_control packet __ALIGNED__;
49267
49268 packet.hdr.type = VS_CONTROL_PACKET_HEADER;
49269- packet.hdr.seqno = atomic_inc_return(&hp->seqno);
49270+ packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
49271 packet.hdr.len = 6;
49272 packet.verb = VSV_CLOSE_PROTOCOL;
49273
49274diff --git a/drivers/tty/hvc/hvsi_lib.c b/drivers/tty/hvc/hvsi_lib.c
49275index ac27671..0f627ee 100644
49276--- a/drivers/tty/hvc/hvsi_lib.c
49277+++ b/drivers/tty/hvc/hvsi_lib.c
49278@@ -9,7 +9,7 @@
49279
49280 static int hvsi_send_packet(struct hvsi_priv *pv, struct hvsi_header *packet)
49281 {
49282- packet->seqno = atomic_inc_return(&pv->seqno);
49283+ packet->seqno = atomic_inc_return_unchecked(&pv->seqno);
49284
49285 /* Assumes that always succeeds, works in practice */
49286 return pv->put_chars(pv->termno, (char *)packet, packet->len);
49287@@ -21,7 +21,7 @@ static void hvsi_start_handshake(struct hvsi_priv *pv)
49288
49289 /* Reset state */
49290 pv->established = 0;
49291- atomic_set(&pv->seqno, 0);
49292+ atomic_set_unchecked(&pv->seqno, 0);
49293
49294 pr_devel("HVSI@%x: Handshaking started\n", pv->termno);
49295
49296@@ -265,7 +265,7 @@ int hvsilib_read_mctrl(struct hvsi_priv *pv)
49297 pv->mctrl_update = 0;
49298 q.hdr.type = VS_QUERY_PACKET_HEADER;
49299 q.hdr.len = sizeof(struct hvsi_query);
49300- q.hdr.seqno = atomic_inc_return(&pv->seqno);
49301+ q.hdr.seqno = atomic_inc_return_unchecked(&pv->seqno);
49302 q.verb = VSV_SEND_MODEM_CTL_STATUS;
49303 rc = hvsi_send_packet(pv, &q.hdr);
49304 if (rc <= 0) {
49305diff --git a/drivers/tty/ipwireless/tty.c b/drivers/tty/ipwireless/tty.c
49306index 8fd72ff..34a0bed 100644
49307--- a/drivers/tty/ipwireless/tty.c
49308+++ b/drivers/tty/ipwireless/tty.c
49309@@ -29,6 +29,7 @@
49310 #include <linux/tty_driver.h>
49311 #include <linux/tty_flip.h>
49312 #include <linux/uaccess.h>
49313+#include <asm/local.h>
49314
49315 #include "tty.h"
49316 #include "network.h"
49317@@ -99,10 +100,10 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
49318 mutex_unlock(&tty->ipw_tty_mutex);
49319 return -ENODEV;
49320 }
49321- if (tty->port.count == 0)
49322+ if (atomic_read(&tty->port.count) == 0)
49323 tty->tx_bytes_queued = 0;
49324
49325- tty->port.count++;
49326+ atomic_inc(&tty->port.count);
49327
49328 tty->port.tty = linux_tty;
49329 linux_tty->driver_data = tty;
49330@@ -118,9 +119,7 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
49331
49332 static void do_ipw_close(struct ipw_tty *tty)
49333 {
49334- tty->port.count--;
49335-
49336- if (tty->port.count == 0) {
49337+ if (atomic_dec_return(&tty->port.count) == 0) {
49338 struct tty_struct *linux_tty = tty->port.tty;
49339
49340 if (linux_tty != NULL) {
49341@@ -141,7 +140,7 @@ static void ipw_hangup(struct tty_struct *linux_tty)
49342 return;
49343
49344 mutex_lock(&tty->ipw_tty_mutex);
49345- if (tty->port.count == 0) {
49346+ if (atomic_read(&tty->port.count) == 0) {
49347 mutex_unlock(&tty->ipw_tty_mutex);
49348 return;
49349 }
49350@@ -164,7 +163,7 @@ void ipwireless_tty_received(struct ipw_tty *tty, unsigned char *data,
49351
49352 mutex_lock(&tty->ipw_tty_mutex);
49353
49354- if (!tty->port.count) {
49355+ if (!atomic_read(&tty->port.count)) {
49356 mutex_unlock(&tty->ipw_tty_mutex);
49357 return;
49358 }
49359@@ -206,7 +205,7 @@ static int ipw_write(struct tty_struct *linux_tty,
49360 return -ENODEV;
49361
49362 mutex_lock(&tty->ipw_tty_mutex);
49363- if (!tty->port.count) {
49364+ if (!atomic_read(&tty->port.count)) {
49365 mutex_unlock(&tty->ipw_tty_mutex);
49366 return -EINVAL;
49367 }
49368@@ -246,7 +245,7 @@ static int ipw_write_room(struct tty_struct *linux_tty)
49369 if (!tty)
49370 return -ENODEV;
49371
49372- if (!tty->port.count)
49373+ if (!atomic_read(&tty->port.count))
49374 return -EINVAL;
49375
49376 room = IPWIRELESS_TX_QUEUE_SIZE - tty->tx_bytes_queued;
49377@@ -288,7 +287,7 @@ static int ipw_chars_in_buffer(struct tty_struct *linux_tty)
49378 if (!tty)
49379 return 0;
49380
49381- if (!tty->port.count)
49382+ if (!atomic_read(&tty->port.count))
49383 return 0;
49384
49385 return tty->tx_bytes_queued;
49386@@ -369,7 +368,7 @@ static int ipw_tiocmget(struct tty_struct *linux_tty)
49387 if (!tty)
49388 return -ENODEV;
49389
49390- if (!tty->port.count)
49391+ if (!atomic_read(&tty->port.count))
49392 return -EINVAL;
49393
49394 return get_control_lines(tty);
49395@@ -385,7 +384,7 @@ ipw_tiocmset(struct tty_struct *linux_tty,
49396 if (!tty)
49397 return -ENODEV;
49398
49399- if (!tty->port.count)
49400+ if (!atomic_read(&tty->port.count))
49401 return -EINVAL;
49402
49403 return set_control_lines(tty, set, clear);
49404@@ -399,7 +398,7 @@ static int ipw_ioctl(struct tty_struct *linux_tty,
49405 if (!tty)
49406 return -ENODEV;
49407
49408- if (!tty->port.count)
49409+ if (!atomic_read(&tty->port.count))
49410 return -EINVAL;
49411
49412 /* FIXME: Exactly how is the tty object locked here .. */
49413@@ -555,7 +554,7 @@ void ipwireless_tty_free(struct ipw_tty *tty)
49414 * are gone */
49415 mutex_lock(&ttyj->ipw_tty_mutex);
49416 }
49417- while (ttyj->port.count)
49418+ while (atomic_read(&ttyj->port.count))
49419 do_ipw_close(ttyj);
49420 ipwireless_disassociate_network_ttys(network,
49421 ttyj->channel_idx);
49422diff --git a/drivers/tty/moxa.c b/drivers/tty/moxa.c
49423index 1deaca4..c8582d4 100644
49424--- a/drivers/tty/moxa.c
49425+++ b/drivers/tty/moxa.c
49426@@ -1189,7 +1189,7 @@ static int moxa_open(struct tty_struct *tty, struct file *filp)
49427 }
49428
49429 ch = &brd->ports[port % MAX_PORTS_PER_BOARD];
49430- ch->port.count++;
49431+ atomic_inc(&ch->port.count);
49432 tty->driver_data = ch;
49433 tty_port_tty_set(&ch->port, tty);
49434 mutex_lock(&ch->port.mutex);
49435diff --git a/drivers/tty/n_gsm.c b/drivers/tty/n_gsm.c
49436index c0f76da..d974c32 100644
49437--- a/drivers/tty/n_gsm.c
49438+++ b/drivers/tty/n_gsm.c
49439@@ -1632,7 +1632,7 @@ static struct gsm_dlci *gsm_dlci_alloc(struct gsm_mux *gsm, int addr)
49440 spin_lock_init(&dlci->lock);
49441 mutex_init(&dlci->mutex);
49442 dlci->fifo = &dlci->_fifo;
49443- if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL) < 0) {
49444+ if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL)) {
49445 kfree(dlci);
49446 return NULL;
49447 }
49448@@ -2935,7 +2935,7 @@ static int gsmtty_open(struct tty_struct *tty, struct file *filp)
49449 struct gsm_dlci *dlci = tty->driver_data;
49450 struct tty_port *port = &dlci->port;
49451
49452- port->count++;
49453+ atomic_inc(&port->count);
49454 dlci_get(dlci);
49455 dlci_get(dlci->gsm->dlci[0]);
49456 mux_get(dlci->gsm);
49457diff --git a/drivers/tty/n_tty.c b/drivers/tty/n_tty.c
49458index d4a89db..dbe8d8c 100644
49459--- a/drivers/tty/n_tty.c
49460+++ b/drivers/tty/n_tty.c
49461@@ -114,7 +114,7 @@ struct n_tty_data {
49462 int minimum_to_wake;
49463
49464 /* consumer-published */
49465- size_t read_tail;
49466+ size_t read_tail __intentional_overflow(-1);
49467 size_t line_start;
49468
49469 /* protected by output lock */
49470@@ -2509,6 +2509,7 @@ void n_tty_inherit_ops(struct tty_ldisc_ops *ops)
49471 {
49472 *ops = tty_ldisc_N_TTY;
49473 ops->owner = NULL;
49474- ops->refcount = ops->flags = 0;
49475+ atomic_set(&ops->refcount, 0);
49476+ ops->flags = 0;
49477 }
49478 EXPORT_SYMBOL_GPL(n_tty_inherit_ops);
49479diff --git a/drivers/tty/pty.c b/drivers/tty/pty.c
49480index 25c9bc7..24077b7 100644
49481--- a/drivers/tty/pty.c
49482+++ b/drivers/tty/pty.c
49483@@ -790,8 +790,10 @@ static void __init unix98_pty_init(void)
49484 panic("Couldn't register Unix98 pts driver");
49485
49486 /* Now create the /dev/ptmx special device */
49487+ pax_open_kernel();
49488 tty_default_fops(&ptmx_fops);
49489- ptmx_fops.open = ptmx_open;
49490+ *(void **)&ptmx_fops.open = ptmx_open;
49491+ pax_close_kernel();
49492
49493 cdev_init(&ptmx_cdev, &ptmx_fops);
49494 if (cdev_add(&ptmx_cdev, MKDEV(TTYAUX_MAJOR, 2), 1) ||
49495diff --git a/drivers/tty/rocket.c b/drivers/tty/rocket.c
49496index 354564e..fe50d9a 100644
49497--- a/drivers/tty/rocket.c
49498+++ b/drivers/tty/rocket.c
49499@@ -914,7 +914,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
49500 tty->driver_data = info;
49501 tty_port_tty_set(port, tty);
49502
49503- if (port->count++ == 0) {
49504+ if (atomic_inc_return(&port->count) == 1) {
49505 atomic_inc(&rp_num_ports_open);
49506
49507 #ifdef ROCKET_DEBUG_OPEN
49508@@ -923,7 +923,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
49509 #endif
49510 }
49511 #ifdef ROCKET_DEBUG_OPEN
49512- printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, info->port.count);
49513+ printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, atomic-read(&info->port.count));
49514 #endif
49515
49516 /*
49517@@ -1515,7 +1515,7 @@ static void rp_hangup(struct tty_struct *tty)
49518 spin_unlock_irqrestore(&info->port.lock, flags);
49519 return;
49520 }
49521- if (info->port.count)
49522+ if (atomic_read(&info->port.count))
49523 atomic_dec(&rp_num_ports_open);
49524 clear_bit((info->aiop * 8) + info->chan, (void *) &xmit_flags[info->board]);
49525 spin_unlock_irqrestore(&info->port.lock, flags);
49526diff --git a/drivers/tty/serial/ioc4_serial.c b/drivers/tty/serial/ioc4_serial.c
49527index 1274499..f541382 100644
49528--- a/drivers/tty/serial/ioc4_serial.c
49529+++ b/drivers/tty/serial/ioc4_serial.c
49530@@ -437,7 +437,7 @@ struct ioc4_soft {
49531 } is_intr_info[MAX_IOC4_INTR_ENTS];
49532
49533 /* Number of entries active in the above array */
49534- atomic_t is_num_intrs;
49535+ atomic_unchecked_t is_num_intrs;
49536 } is_intr_type[IOC4_NUM_INTR_TYPES];
49537
49538 /* is_ir_lock must be held while
49539@@ -974,7 +974,7 @@ intr_connect(struct ioc4_soft *soft, int type,
49540 BUG_ON(!((type == IOC4_SIO_INTR_TYPE)
49541 || (type == IOC4_OTHER_INTR_TYPE)));
49542
49543- i = atomic_inc_return(&soft-> is_intr_type[type].is_num_intrs) - 1;
49544+ i = atomic_inc_return_unchecked(&soft-> is_intr_type[type].is_num_intrs) - 1;
49545 BUG_ON(!(i < MAX_IOC4_INTR_ENTS || (printk("i %d\n", i), 0)));
49546
49547 /* Save off the lower level interrupt handler */
49548@@ -1001,7 +1001,7 @@ static irqreturn_t ioc4_intr(int irq, void *arg)
49549
49550 soft = arg;
49551 for (intr_type = 0; intr_type < IOC4_NUM_INTR_TYPES; intr_type++) {
49552- num_intrs = (int)atomic_read(
49553+ num_intrs = (int)atomic_read_unchecked(
49554 &soft->is_intr_type[intr_type].is_num_intrs);
49555
49556 this_mir = this_ir = pending_intrs(soft, intr_type);
49557diff --git a/drivers/tty/serial/kgdboc.c b/drivers/tty/serial/kgdboc.c
49558index a260cde..6b2b5ce 100644
49559--- a/drivers/tty/serial/kgdboc.c
49560+++ b/drivers/tty/serial/kgdboc.c
49561@@ -24,8 +24,9 @@
49562 #define MAX_CONFIG_LEN 40
49563
49564 static struct kgdb_io kgdboc_io_ops;
49565+static struct kgdb_io kgdboc_io_ops_console;
49566
49567-/* -1 = init not run yet, 0 = unconfigured, 1 = configured. */
49568+/* -1 = init not run yet, 0 = unconfigured, 1/2 = configured. */
49569 static int configured = -1;
49570
49571 static char config[MAX_CONFIG_LEN];
49572@@ -151,6 +152,8 @@ static void cleanup_kgdboc(void)
49573 kgdboc_unregister_kbd();
49574 if (configured == 1)
49575 kgdb_unregister_io_module(&kgdboc_io_ops);
49576+ else if (configured == 2)
49577+ kgdb_unregister_io_module(&kgdboc_io_ops_console);
49578 }
49579
49580 static int configure_kgdboc(void)
49581@@ -160,13 +163,13 @@ static int configure_kgdboc(void)
49582 int err;
49583 char *cptr = config;
49584 struct console *cons;
49585+ int is_console = 0;
49586
49587 err = kgdboc_option_setup(config);
49588 if (err || !strlen(config) || isspace(config[0]))
49589 goto noconfig;
49590
49591 err = -ENODEV;
49592- kgdboc_io_ops.is_console = 0;
49593 kgdb_tty_driver = NULL;
49594
49595 kgdboc_use_kms = 0;
49596@@ -187,7 +190,7 @@ static int configure_kgdboc(void)
49597 int idx;
49598 if (cons->device && cons->device(cons, &idx) == p &&
49599 idx == tty_line) {
49600- kgdboc_io_ops.is_console = 1;
49601+ is_console = 1;
49602 break;
49603 }
49604 cons = cons->next;
49605@@ -197,7 +200,13 @@ static int configure_kgdboc(void)
49606 kgdb_tty_line = tty_line;
49607
49608 do_register:
49609- err = kgdb_register_io_module(&kgdboc_io_ops);
49610+ if (is_console) {
49611+ err = kgdb_register_io_module(&kgdboc_io_ops_console);
49612+ configured = 2;
49613+ } else {
49614+ err = kgdb_register_io_module(&kgdboc_io_ops);
49615+ configured = 1;
49616+ }
49617 if (err)
49618 goto noconfig;
49619
49620@@ -205,8 +214,6 @@ do_register:
49621 if (err)
49622 goto nmi_con_failed;
49623
49624- configured = 1;
49625-
49626 return 0;
49627
49628 nmi_con_failed:
49629@@ -223,7 +230,7 @@ noconfig:
49630 static int __init init_kgdboc(void)
49631 {
49632 /* Already configured? */
49633- if (configured == 1)
49634+ if (configured >= 1)
49635 return 0;
49636
49637 return configure_kgdboc();
49638@@ -272,7 +279,7 @@ static int param_set_kgdboc_var(const char *kmessage, struct kernel_param *kp)
49639 if (config[len - 1] == '\n')
49640 config[len - 1] = '\0';
49641
49642- if (configured == 1)
49643+ if (configured >= 1)
49644 cleanup_kgdboc();
49645
49646 /* Go and configure with the new params. */
49647@@ -312,6 +319,15 @@ static struct kgdb_io kgdboc_io_ops = {
49648 .post_exception = kgdboc_post_exp_handler,
49649 };
49650
49651+static struct kgdb_io kgdboc_io_ops_console = {
49652+ .name = "kgdboc",
49653+ .read_char = kgdboc_get_char,
49654+ .write_char = kgdboc_put_char,
49655+ .pre_exception = kgdboc_pre_exp_handler,
49656+ .post_exception = kgdboc_post_exp_handler,
49657+ .is_console = 1
49658+};
49659+
49660 #ifdef CONFIG_KGDB_SERIAL_CONSOLE
49661 /* This is only available if kgdboc is a built in for early debugging */
49662 static int __init kgdboc_early_init(char *opt)
49663diff --git a/drivers/tty/serial/msm_serial.c b/drivers/tty/serial/msm_serial.c
49664index b5d779c..3622cfe 100644
49665--- a/drivers/tty/serial/msm_serial.c
49666+++ b/drivers/tty/serial/msm_serial.c
49667@@ -897,7 +897,7 @@ static struct uart_driver msm_uart_driver = {
49668 .cons = MSM_CONSOLE,
49669 };
49670
49671-static atomic_t msm_uart_next_id = ATOMIC_INIT(0);
49672+static atomic_unchecked_t msm_uart_next_id = ATOMIC_INIT(0);
49673
49674 static const struct of_device_id msm_uartdm_table[] = {
49675 { .compatible = "qcom,msm-uartdm" },
49676@@ -912,7 +912,7 @@ static int __init msm_serial_probe(struct platform_device *pdev)
49677 int irq;
49678
49679 if (pdev->id == -1)
49680- pdev->id = atomic_inc_return(&msm_uart_next_id) - 1;
49681+ pdev->id = atomic_inc_return_unchecked(&msm_uart_next_id) - 1;
49682
49683 if (unlikely(pdev->id < 0 || pdev->id >= UART_NR))
49684 return -ENXIO;
49685diff --git a/drivers/tty/serial/samsung.c b/drivers/tty/serial/samsung.c
49686index f3dfa19..342f2ff 100644
49687--- a/drivers/tty/serial/samsung.c
49688+++ b/drivers/tty/serial/samsung.c
49689@@ -456,11 +456,16 @@ static void s3c24xx_serial_shutdown(struct uart_port *port)
49690 }
49691 }
49692
49693+static int s3c64xx_serial_startup(struct uart_port *port);
49694 static int s3c24xx_serial_startup(struct uart_port *port)
49695 {
49696 struct s3c24xx_uart_port *ourport = to_ourport(port);
49697 int ret;
49698
49699+ /* Startup sequence is different for s3c64xx and higher SoC's */
49700+ if (s3c24xx_serial_has_interrupt_mask(port))
49701+ return s3c64xx_serial_startup(port);
49702+
49703 dbg("s3c24xx_serial_startup: port=%p (%08lx,%p)\n",
49704 port->mapbase, port->membase);
49705
49706@@ -1127,10 +1132,6 @@ static int s3c24xx_serial_init_port(struct s3c24xx_uart_port *ourport,
49707 /* setup info for port */
49708 port->dev = &platdev->dev;
49709
49710- /* Startup sequence is different for s3c64xx and higher SoC's */
49711- if (s3c24xx_serial_has_interrupt_mask(port))
49712- s3c24xx_serial_ops.startup = s3c64xx_serial_startup;
49713-
49714 port->uartclk = 1;
49715
49716 if (cfg->uart_flags & UPF_CONS_FLOW) {
49717diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c
49718index 0f02351..07c59c5 100644
49719--- a/drivers/tty/serial/serial_core.c
49720+++ b/drivers/tty/serial/serial_core.c
49721@@ -1448,7 +1448,7 @@ static void uart_hangup(struct tty_struct *tty)
49722 uart_flush_buffer(tty);
49723 uart_shutdown(tty, state);
49724 spin_lock_irqsave(&port->lock, flags);
49725- port->count = 0;
49726+ atomic_set(&port->count, 0);
49727 clear_bit(ASYNCB_NORMAL_ACTIVE, &port->flags);
49728 spin_unlock_irqrestore(&port->lock, flags);
49729 tty_port_tty_set(port, NULL);
49730@@ -1544,7 +1544,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
49731 goto end;
49732 }
49733
49734- port->count++;
49735+ atomic_inc(&port->count);
49736 if (!state->uart_port || state->uart_port->flags & UPF_DEAD) {
49737 retval = -ENXIO;
49738 goto err_dec_count;
49739@@ -1572,7 +1572,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
49740 /*
49741 * Make sure the device is in D0 state.
49742 */
49743- if (port->count == 1)
49744+ if (atomic_read(&port->count) == 1)
49745 uart_change_pm(state, UART_PM_STATE_ON);
49746
49747 /*
49748@@ -1590,7 +1590,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
49749 end:
49750 return retval;
49751 err_dec_count:
49752- port->count--;
49753+ atomic_inc(&port->count);
49754 mutex_unlock(&port->mutex);
49755 goto end;
49756 }
49757diff --git a/drivers/tty/synclink.c b/drivers/tty/synclink.c
49758index e1ce141..6d4ed80 100644
49759--- a/drivers/tty/synclink.c
49760+++ b/drivers/tty/synclink.c
49761@@ -3090,7 +3090,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
49762
49763 if (debug_level >= DEBUG_LEVEL_INFO)
49764 printk("%s(%d):mgsl_close(%s) entry, count=%d\n",
49765- __FILE__,__LINE__, info->device_name, info->port.count);
49766+ __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
49767
49768 if (tty_port_close_start(&info->port, tty, filp) == 0)
49769 goto cleanup;
49770@@ -3108,7 +3108,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
49771 cleanup:
49772 if (debug_level >= DEBUG_LEVEL_INFO)
49773 printk("%s(%d):mgsl_close(%s) exit, count=%d\n", __FILE__,__LINE__,
49774- tty->driver->name, info->port.count);
49775+ tty->driver->name, atomic_read(&info->port.count));
49776
49777 } /* end of mgsl_close() */
49778
49779@@ -3207,8 +3207,8 @@ static void mgsl_hangup(struct tty_struct *tty)
49780
49781 mgsl_flush_buffer(tty);
49782 shutdown(info);
49783-
49784- info->port.count = 0;
49785+
49786+ atomic_set(&info->port.count, 0);
49787 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
49788 info->port.tty = NULL;
49789
49790@@ -3297,12 +3297,12 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
49791
49792 if (debug_level >= DEBUG_LEVEL_INFO)
49793 printk("%s(%d):block_til_ready before block on %s count=%d\n",
49794- __FILE__,__LINE__, tty->driver->name, port->count );
49795+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
49796
49797 spin_lock_irqsave(&info->irq_spinlock, flags);
49798 if (!tty_hung_up_p(filp)) {
49799 extra_count = true;
49800- port->count--;
49801+ atomic_dec(&port->count);
49802 }
49803 spin_unlock_irqrestore(&info->irq_spinlock, flags);
49804 port->blocked_open++;
49805@@ -3331,7 +3331,7 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
49806
49807 if (debug_level >= DEBUG_LEVEL_INFO)
49808 printk("%s(%d):block_til_ready blocking on %s count=%d\n",
49809- __FILE__,__LINE__, tty->driver->name, port->count );
49810+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
49811
49812 tty_unlock(tty);
49813 schedule();
49814@@ -3343,12 +3343,12 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
49815
49816 /* FIXME: Racy on hangup during close wait */
49817 if (extra_count)
49818- port->count++;
49819+ atomic_inc(&port->count);
49820 port->blocked_open--;
49821
49822 if (debug_level >= DEBUG_LEVEL_INFO)
49823 printk("%s(%d):block_til_ready after blocking on %s count=%d\n",
49824- __FILE__,__LINE__, tty->driver->name, port->count );
49825+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
49826
49827 if (!retval)
49828 port->flags |= ASYNC_NORMAL_ACTIVE;
49829@@ -3400,7 +3400,7 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
49830
49831 if (debug_level >= DEBUG_LEVEL_INFO)
49832 printk("%s(%d):mgsl_open(%s), old ref count = %d\n",
49833- __FILE__,__LINE__,tty->driver->name, info->port.count);
49834+ __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
49835
49836 /* If port is closing, signal caller to try again */
49837 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
49838@@ -3419,10 +3419,10 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
49839 spin_unlock_irqrestore(&info->netlock, flags);
49840 goto cleanup;
49841 }
49842- info->port.count++;
49843+ atomic_inc(&info->port.count);
49844 spin_unlock_irqrestore(&info->netlock, flags);
49845
49846- if (info->port.count == 1) {
49847+ if (atomic_read(&info->port.count) == 1) {
49848 /* 1st open on this device, init hardware */
49849 retval = startup(info);
49850 if (retval < 0)
49851@@ -3446,8 +3446,8 @@ cleanup:
49852 if (retval) {
49853 if (tty->count == 1)
49854 info->port.tty = NULL; /* tty layer will release tty struct */
49855- if(info->port.count)
49856- info->port.count--;
49857+ if (atomic_read(&info->port.count))
49858+ atomic_dec(&info->port.count);
49859 }
49860
49861 return retval;
49862@@ -7665,7 +7665,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
49863 unsigned short new_crctype;
49864
49865 /* return error if TTY interface open */
49866- if (info->port.count)
49867+ if (atomic_read(&info->port.count))
49868 return -EBUSY;
49869
49870 switch (encoding)
49871@@ -7760,7 +7760,7 @@ static int hdlcdev_open(struct net_device *dev)
49872
49873 /* arbitrate between network and tty opens */
49874 spin_lock_irqsave(&info->netlock, flags);
49875- if (info->port.count != 0 || info->netcount != 0) {
49876+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
49877 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
49878 spin_unlock_irqrestore(&info->netlock, flags);
49879 return -EBUSY;
49880@@ -7846,7 +7846,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
49881 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
49882
49883 /* return error if TTY interface open */
49884- if (info->port.count)
49885+ if (atomic_read(&info->port.count))
49886 return -EBUSY;
49887
49888 if (cmd != SIOCWANDEV)
49889diff --git a/drivers/tty/synclink_gt.c b/drivers/tty/synclink_gt.c
49890index 1abf946..1ee34fc 100644
49891--- a/drivers/tty/synclink_gt.c
49892+++ b/drivers/tty/synclink_gt.c
49893@@ -670,7 +670,7 @@ static int open(struct tty_struct *tty, struct file *filp)
49894 tty->driver_data = info;
49895 info->port.tty = tty;
49896
49897- DBGINFO(("%s open, old ref count = %d\n", info->device_name, info->port.count));
49898+ DBGINFO(("%s open, old ref count = %d\n", info->device_name, atomic_read(&info->port.count)));
49899
49900 /* If port is closing, signal caller to try again */
49901 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
49902@@ -691,10 +691,10 @@ static int open(struct tty_struct *tty, struct file *filp)
49903 mutex_unlock(&info->port.mutex);
49904 goto cleanup;
49905 }
49906- info->port.count++;
49907+ atomic_inc(&info->port.count);
49908 spin_unlock_irqrestore(&info->netlock, flags);
49909
49910- if (info->port.count == 1) {
49911+ if (atomic_read(&info->port.count) == 1) {
49912 /* 1st open on this device, init hardware */
49913 retval = startup(info);
49914 if (retval < 0) {
49915@@ -715,8 +715,8 @@ cleanup:
49916 if (retval) {
49917 if (tty->count == 1)
49918 info->port.tty = NULL; /* tty layer will release tty struct */
49919- if(info->port.count)
49920- info->port.count--;
49921+ if(atomic_read(&info->port.count))
49922+ atomic_dec(&info->port.count);
49923 }
49924
49925 DBGINFO(("%s open rc=%d\n", info->device_name, retval));
49926@@ -729,7 +729,7 @@ static void close(struct tty_struct *tty, struct file *filp)
49927
49928 if (sanity_check(info, tty->name, "close"))
49929 return;
49930- DBGINFO(("%s close entry, count=%d\n", info->device_name, info->port.count));
49931+ DBGINFO(("%s close entry, count=%d\n", info->device_name, atomic_read(&info->port.count)));
49932
49933 if (tty_port_close_start(&info->port, tty, filp) == 0)
49934 goto cleanup;
49935@@ -746,7 +746,7 @@ static void close(struct tty_struct *tty, struct file *filp)
49936 tty_port_close_end(&info->port, tty);
49937 info->port.tty = NULL;
49938 cleanup:
49939- DBGINFO(("%s close exit, count=%d\n", tty->driver->name, info->port.count));
49940+ DBGINFO(("%s close exit, count=%d\n", tty->driver->name, atomic_read(&info->port.count)));
49941 }
49942
49943 static void hangup(struct tty_struct *tty)
49944@@ -764,7 +764,7 @@ static void hangup(struct tty_struct *tty)
49945 shutdown(info);
49946
49947 spin_lock_irqsave(&info->port.lock, flags);
49948- info->port.count = 0;
49949+ atomic_set(&info->port.count, 0);
49950 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
49951 info->port.tty = NULL;
49952 spin_unlock_irqrestore(&info->port.lock, flags);
49953@@ -1449,7 +1449,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
49954 unsigned short new_crctype;
49955
49956 /* return error if TTY interface open */
49957- if (info->port.count)
49958+ if (atomic_read(&info->port.count))
49959 return -EBUSY;
49960
49961 DBGINFO(("%s hdlcdev_attach\n", info->device_name));
49962@@ -1544,7 +1544,7 @@ static int hdlcdev_open(struct net_device *dev)
49963
49964 /* arbitrate between network and tty opens */
49965 spin_lock_irqsave(&info->netlock, flags);
49966- if (info->port.count != 0 || info->netcount != 0) {
49967+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
49968 DBGINFO(("%s hdlc_open busy\n", dev->name));
49969 spin_unlock_irqrestore(&info->netlock, flags);
49970 return -EBUSY;
49971@@ -1629,7 +1629,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
49972 DBGINFO(("%s hdlcdev_ioctl\n", dev->name));
49973
49974 /* return error if TTY interface open */
49975- if (info->port.count)
49976+ if (atomic_read(&info->port.count))
49977 return -EBUSY;
49978
49979 if (cmd != SIOCWANDEV)
49980@@ -2413,7 +2413,7 @@ static irqreturn_t slgt_interrupt(int dummy, void *dev_id)
49981 if (port == NULL)
49982 continue;
49983 spin_lock(&port->lock);
49984- if ((port->port.count || port->netcount) &&
49985+ if ((atomic_read(&port->port.count) || port->netcount) &&
49986 port->pending_bh && !port->bh_running &&
49987 !port->bh_requested) {
49988 DBGISR(("%s bh queued\n", port->device_name));
49989@@ -3302,7 +3302,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
49990 spin_lock_irqsave(&info->lock, flags);
49991 if (!tty_hung_up_p(filp)) {
49992 extra_count = true;
49993- port->count--;
49994+ atomic_dec(&port->count);
49995 }
49996 spin_unlock_irqrestore(&info->lock, flags);
49997 port->blocked_open++;
49998@@ -3339,7 +3339,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
49999 remove_wait_queue(&port->open_wait, &wait);
50000
50001 if (extra_count)
50002- port->count++;
50003+ atomic_inc(&port->count);
50004 port->blocked_open--;
50005
50006 if (!retval)
50007diff --git a/drivers/tty/synclinkmp.c b/drivers/tty/synclinkmp.c
50008index dc6e969..5dc8786 100644
50009--- a/drivers/tty/synclinkmp.c
50010+++ b/drivers/tty/synclinkmp.c
50011@@ -750,7 +750,7 @@ static int open(struct tty_struct *tty, struct file *filp)
50012
50013 if (debug_level >= DEBUG_LEVEL_INFO)
50014 printk("%s(%d):%s open(), old ref count = %d\n",
50015- __FILE__,__LINE__,tty->driver->name, info->port.count);
50016+ __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
50017
50018 /* If port is closing, signal caller to try again */
50019 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
50020@@ -769,10 +769,10 @@ static int open(struct tty_struct *tty, struct file *filp)
50021 spin_unlock_irqrestore(&info->netlock, flags);
50022 goto cleanup;
50023 }
50024- info->port.count++;
50025+ atomic_inc(&info->port.count);
50026 spin_unlock_irqrestore(&info->netlock, flags);
50027
50028- if (info->port.count == 1) {
50029+ if (atomic_read(&info->port.count) == 1) {
50030 /* 1st open on this device, init hardware */
50031 retval = startup(info);
50032 if (retval < 0)
50033@@ -796,8 +796,8 @@ cleanup:
50034 if (retval) {
50035 if (tty->count == 1)
50036 info->port.tty = NULL; /* tty layer will release tty struct */
50037- if(info->port.count)
50038- info->port.count--;
50039+ if(atomic_read(&info->port.count))
50040+ atomic_dec(&info->port.count);
50041 }
50042
50043 return retval;
50044@@ -815,7 +815,7 @@ static void close(struct tty_struct *tty, struct file *filp)
50045
50046 if (debug_level >= DEBUG_LEVEL_INFO)
50047 printk("%s(%d):%s close() entry, count=%d\n",
50048- __FILE__,__LINE__, info->device_name, info->port.count);
50049+ __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
50050
50051 if (tty_port_close_start(&info->port, tty, filp) == 0)
50052 goto cleanup;
50053@@ -834,7 +834,7 @@ static void close(struct tty_struct *tty, struct file *filp)
50054 cleanup:
50055 if (debug_level >= DEBUG_LEVEL_INFO)
50056 printk("%s(%d):%s close() exit, count=%d\n", __FILE__,__LINE__,
50057- tty->driver->name, info->port.count);
50058+ tty->driver->name, atomic_read(&info->port.count));
50059 }
50060
50061 /* Called by tty_hangup() when a hangup is signaled.
50062@@ -857,7 +857,7 @@ static void hangup(struct tty_struct *tty)
50063 shutdown(info);
50064
50065 spin_lock_irqsave(&info->port.lock, flags);
50066- info->port.count = 0;
50067+ atomic_set(&info->port.count, 0);
50068 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
50069 info->port.tty = NULL;
50070 spin_unlock_irqrestore(&info->port.lock, flags);
50071@@ -1565,7 +1565,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
50072 unsigned short new_crctype;
50073
50074 /* return error if TTY interface open */
50075- if (info->port.count)
50076+ if (atomic_read(&info->port.count))
50077 return -EBUSY;
50078
50079 switch (encoding)
50080@@ -1660,7 +1660,7 @@ static int hdlcdev_open(struct net_device *dev)
50081
50082 /* arbitrate between network and tty opens */
50083 spin_lock_irqsave(&info->netlock, flags);
50084- if (info->port.count != 0 || info->netcount != 0) {
50085+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
50086 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
50087 spin_unlock_irqrestore(&info->netlock, flags);
50088 return -EBUSY;
50089@@ -1746,7 +1746,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
50090 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
50091
50092 /* return error if TTY interface open */
50093- if (info->port.count)
50094+ if (atomic_read(&info->port.count))
50095 return -EBUSY;
50096
50097 if (cmd != SIOCWANDEV)
50098@@ -2620,7 +2620,7 @@ static irqreturn_t synclinkmp_interrupt(int dummy, void *dev_id)
50099 * do not request bottom half processing if the
50100 * device is not open in a normal mode.
50101 */
50102- if ( port && (port->port.count || port->netcount) &&
50103+ if ( port && (atomic_read(&port->port.count) || port->netcount) &&
50104 port->pending_bh && !port->bh_running &&
50105 !port->bh_requested ) {
50106 if ( debug_level >= DEBUG_LEVEL_ISR )
50107@@ -3318,12 +3318,12 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
50108
50109 if (debug_level >= DEBUG_LEVEL_INFO)
50110 printk("%s(%d):%s block_til_ready() before block, count=%d\n",
50111- __FILE__,__LINE__, tty->driver->name, port->count );
50112+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
50113
50114 spin_lock_irqsave(&info->lock, flags);
50115 if (!tty_hung_up_p(filp)) {
50116 extra_count = true;
50117- port->count--;
50118+ atomic_dec(&port->count);
50119 }
50120 spin_unlock_irqrestore(&info->lock, flags);
50121 port->blocked_open++;
50122@@ -3352,7 +3352,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
50123
50124 if (debug_level >= DEBUG_LEVEL_INFO)
50125 printk("%s(%d):%s block_til_ready() count=%d\n",
50126- __FILE__,__LINE__, tty->driver->name, port->count );
50127+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
50128
50129 tty_unlock(tty);
50130 schedule();
50131@@ -3363,12 +3363,12 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
50132 remove_wait_queue(&port->open_wait, &wait);
50133
50134 if (extra_count)
50135- port->count++;
50136+ atomic_inc(&port->count);
50137 port->blocked_open--;
50138
50139 if (debug_level >= DEBUG_LEVEL_INFO)
50140 printk("%s(%d):%s block_til_ready() after, count=%d\n",
50141- __FILE__,__LINE__, tty->driver->name, port->count );
50142+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
50143
50144 if (!retval)
50145 port->flags |= ASYNC_NORMAL_ACTIVE;
50146diff --git a/drivers/tty/sysrq.c b/drivers/tty/sysrq.c
50147index 40a9fe9..a3f10cc 100644
50148--- a/drivers/tty/sysrq.c
50149+++ b/drivers/tty/sysrq.c
50150@@ -1075,7 +1075,7 @@ EXPORT_SYMBOL(unregister_sysrq_key);
50151 static ssize_t write_sysrq_trigger(struct file *file, const char __user *buf,
50152 size_t count, loff_t *ppos)
50153 {
50154- if (count) {
50155+ if (count && capable(CAP_SYS_ADMIN)) {
50156 char c;
50157
50158 if (get_user(c, buf))
50159diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c
50160index c74a00a..02cf211a 100644
50161--- a/drivers/tty/tty_io.c
50162+++ b/drivers/tty/tty_io.c
50163@@ -3474,7 +3474,7 @@ EXPORT_SYMBOL_GPL(get_current_tty);
50164
50165 void tty_default_fops(struct file_operations *fops)
50166 {
50167- *fops = tty_fops;
50168+ memcpy((void *)fops, &tty_fops, sizeof(tty_fops));
50169 }
50170
50171 /*
50172diff --git a/drivers/tty/tty_ldisc.c b/drivers/tty/tty_ldisc.c
50173index 6458e11..6cfc218 100644
50174--- a/drivers/tty/tty_ldisc.c
50175+++ b/drivers/tty/tty_ldisc.c
50176@@ -72,7 +72,7 @@ int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc)
50177 raw_spin_lock_irqsave(&tty_ldiscs_lock, flags);
50178 tty_ldiscs[disc] = new_ldisc;
50179 new_ldisc->num = disc;
50180- new_ldisc->refcount = 0;
50181+ atomic_set(&new_ldisc->refcount, 0);
50182 raw_spin_unlock_irqrestore(&tty_ldiscs_lock, flags);
50183
50184 return ret;
50185@@ -100,7 +100,7 @@ int tty_unregister_ldisc(int disc)
50186 return -EINVAL;
50187
50188 raw_spin_lock_irqsave(&tty_ldiscs_lock, flags);
50189- if (tty_ldiscs[disc]->refcount)
50190+ if (atomic_read(&tty_ldiscs[disc]->refcount))
50191 ret = -EBUSY;
50192 else
50193 tty_ldiscs[disc] = NULL;
50194@@ -121,7 +121,7 @@ static struct tty_ldisc_ops *get_ldops(int disc)
50195 if (ldops) {
50196 ret = ERR_PTR(-EAGAIN);
50197 if (try_module_get(ldops->owner)) {
50198- ldops->refcount++;
50199+ atomic_inc(&ldops->refcount);
50200 ret = ldops;
50201 }
50202 }
50203@@ -134,7 +134,7 @@ static void put_ldops(struct tty_ldisc_ops *ldops)
50204 unsigned long flags;
50205
50206 raw_spin_lock_irqsave(&tty_ldiscs_lock, flags);
50207- ldops->refcount--;
50208+ atomic_dec(&ldops->refcount);
50209 module_put(ldops->owner);
50210 raw_spin_unlock_irqrestore(&tty_ldiscs_lock, flags);
50211 }
50212diff --git a/drivers/tty/tty_port.c b/drivers/tty/tty_port.c
50213index f597e88..b7f68ed 100644
50214--- a/drivers/tty/tty_port.c
50215+++ b/drivers/tty/tty_port.c
50216@@ -232,7 +232,7 @@ void tty_port_hangup(struct tty_port *port)
50217 unsigned long flags;
50218
50219 spin_lock_irqsave(&port->lock, flags);
50220- port->count = 0;
50221+ atomic_set(&port->count, 0);
50222 port->flags &= ~ASYNC_NORMAL_ACTIVE;
50223 tty = port->tty;
50224 if (tty)
50225@@ -390,7 +390,7 @@ int tty_port_block_til_ready(struct tty_port *port,
50226 /* The port lock protects the port counts */
50227 spin_lock_irqsave(&port->lock, flags);
50228 if (!tty_hung_up_p(filp))
50229- port->count--;
50230+ atomic_dec(&port->count);
50231 port->blocked_open++;
50232 spin_unlock_irqrestore(&port->lock, flags);
50233
50234@@ -432,7 +432,7 @@ int tty_port_block_til_ready(struct tty_port *port,
50235 we must not mess that up further */
50236 spin_lock_irqsave(&port->lock, flags);
50237 if (!tty_hung_up_p(filp))
50238- port->count++;
50239+ atomic_inc(&port->count);
50240 port->blocked_open--;
50241 if (retval == 0)
50242 port->flags |= ASYNC_NORMAL_ACTIVE;
50243@@ -466,19 +466,19 @@ int tty_port_close_start(struct tty_port *port,
50244 return 0;
50245 }
50246
50247- if (tty->count == 1 && port->count != 1) {
50248+ if (tty->count == 1 && atomic_read(&port->count) != 1) {
50249 printk(KERN_WARNING
50250 "tty_port_close_start: tty->count = 1 port count = %d.\n",
50251- port->count);
50252- port->count = 1;
50253+ atomic_read(&port->count));
50254+ atomic_set(&port->count, 1);
50255 }
50256- if (--port->count < 0) {
50257+ if (atomic_dec_return(&port->count) < 0) {
50258 printk(KERN_WARNING "tty_port_close_start: count = %d\n",
50259- port->count);
50260- port->count = 0;
50261+ atomic_read(&port->count));
50262+ atomic_set(&port->count, 0);
50263 }
50264
50265- if (port->count) {
50266+ if (atomic_read(&port->count)) {
50267 spin_unlock_irqrestore(&port->lock, flags);
50268 if (port->ops->drop)
50269 port->ops->drop(port);
50270@@ -564,7 +564,7 @@ int tty_port_open(struct tty_port *port, struct tty_struct *tty,
50271 {
50272 spin_lock_irq(&port->lock);
50273 if (!tty_hung_up_p(filp))
50274- ++port->count;
50275+ atomic_inc(&port->count);
50276 spin_unlock_irq(&port->lock);
50277 tty_port_tty_set(port, tty);
50278
50279diff --git a/drivers/tty/vt/keyboard.c b/drivers/tty/vt/keyboard.c
50280index d0e3a44..5f8b754 100644
50281--- a/drivers/tty/vt/keyboard.c
50282+++ b/drivers/tty/vt/keyboard.c
50283@@ -641,6 +641,16 @@ static void k_spec(struct vc_data *vc, unsigned char value, char up_flag)
50284 kbd->kbdmode == VC_OFF) &&
50285 value != KVAL(K_SAK))
50286 return; /* SAK is allowed even in raw mode */
50287+
50288+#if defined(CONFIG_GRKERNSEC_PROC) || defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
50289+ {
50290+ void *func = fn_handler[value];
50291+ if (func == fn_show_state || func == fn_show_ptregs ||
50292+ func == fn_show_mem)
50293+ return;
50294+ }
50295+#endif
50296+
50297 fn_handler[value](vc);
50298 }
50299
50300@@ -1776,9 +1786,6 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
50301 if (copy_from_user(&tmp, user_kbe, sizeof(struct kbentry)))
50302 return -EFAULT;
50303
50304- if (!capable(CAP_SYS_TTY_CONFIG))
50305- perm = 0;
50306-
50307 switch (cmd) {
50308 case KDGKBENT:
50309 /* Ensure another thread doesn't free it under us */
50310@@ -1793,6 +1800,9 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
50311 spin_unlock_irqrestore(&kbd_event_lock, flags);
50312 return put_user(val, &user_kbe->kb_value);
50313 case KDSKBENT:
50314+ if (!capable(CAP_SYS_TTY_CONFIG))
50315+ perm = 0;
50316+
50317 if (!perm)
50318 return -EPERM;
50319 if (!i && v == K_NOSUCHMAP) {
50320@@ -1883,9 +1893,6 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
50321 int i, j, k;
50322 int ret;
50323
50324- if (!capable(CAP_SYS_TTY_CONFIG))
50325- perm = 0;
50326-
50327 kbs = kmalloc(sizeof(*kbs), GFP_KERNEL);
50328 if (!kbs) {
50329 ret = -ENOMEM;
50330@@ -1919,6 +1926,9 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
50331 kfree(kbs);
50332 return ((p && *p) ? -EOVERFLOW : 0);
50333 case KDSKBSENT:
50334+ if (!capable(CAP_SYS_TTY_CONFIG))
50335+ perm = 0;
50336+
50337 if (!perm) {
50338 ret = -EPERM;
50339 goto reterr;
50340diff --git a/drivers/uio/uio.c b/drivers/uio/uio.c
50341index 0e808cf..d7d274b 100644
50342--- a/drivers/uio/uio.c
50343+++ b/drivers/uio/uio.c
50344@@ -25,6 +25,7 @@
50345 #include <linux/kobject.h>
50346 #include <linux/cdev.h>
50347 #include <linux/uio_driver.h>
50348+#include <asm/local.h>
50349
50350 #define UIO_MAX_DEVICES (1U << MINORBITS)
50351
50352@@ -32,7 +33,7 @@ struct uio_device {
50353 struct module *owner;
50354 struct device *dev;
50355 int minor;
50356- atomic_t event;
50357+ atomic_unchecked_t event;
50358 struct fasync_struct *async_queue;
50359 wait_queue_head_t wait;
50360 struct uio_info *info;
50361@@ -243,7 +244,7 @@ static ssize_t event_show(struct device *dev,
50362 struct device_attribute *attr, char *buf)
50363 {
50364 struct uio_device *idev = dev_get_drvdata(dev);
50365- return sprintf(buf, "%u\n", (unsigned int)atomic_read(&idev->event));
50366+ return sprintf(buf, "%u\n", (unsigned int)atomic_read_unchecked(&idev->event));
50367 }
50368 static DEVICE_ATTR_RO(event);
50369
50370@@ -401,7 +402,7 @@ void uio_event_notify(struct uio_info *info)
50371 {
50372 struct uio_device *idev = info->uio_dev;
50373
50374- atomic_inc(&idev->event);
50375+ atomic_inc_unchecked(&idev->event);
50376 wake_up_interruptible(&idev->wait);
50377 kill_fasync(&idev->async_queue, SIGIO, POLL_IN);
50378 }
50379@@ -454,7 +455,7 @@ static int uio_open(struct inode *inode, struct file *filep)
50380 }
50381
50382 listener->dev = idev;
50383- listener->event_count = atomic_read(&idev->event);
50384+ listener->event_count = atomic_read_unchecked(&idev->event);
50385 filep->private_data = listener;
50386
50387 if (idev->info->open) {
50388@@ -505,7 +506,7 @@ static unsigned int uio_poll(struct file *filep, poll_table *wait)
50389 return -EIO;
50390
50391 poll_wait(filep, &idev->wait, wait);
50392- if (listener->event_count != atomic_read(&idev->event))
50393+ if (listener->event_count != atomic_read_unchecked(&idev->event))
50394 return POLLIN | POLLRDNORM;
50395 return 0;
50396 }
50397@@ -530,7 +531,7 @@ static ssize_t uio_read(struct file *filep, char __user *buf,
50398 do {
50399 set_current_state(TASK_INTERRUPTIBLE);
50400
50401- event_count = atomic_read(&idev->event);
50402+ event_count = atomic_read_unchecked(&idev->event);
50403 if (event_count != listener->event_count) {
50404 if (copy_to_user(buf, &event_count, count))
50405 retval = -EFAULT;
50406@@ -587,9 +588,13 @@ static ssize_t uio_write(struct file *filep, const char __user *buf,
50407 static int uio_find_mem_index(struct vm_area_struct *vma)
50408 {
50409 struct uio_device *idev = vma->vm_private_data;
50410+ unsigned long size;
50411
50412 if (vma->vm_pgoff < MAX_UIO_MAPS) {
50413- if (idev->info->mem[vma->vm_pgoff].size == 0)
50414+ size = idev->info->mem[vma->vm_pgoff].size;
50415+ if (size == 0)
50416+ return -1;
50417+ if (vma->vm_end - vma->vm_start > size)
50418 return -1;
50419 return (int)vma->vm_pgoff;
50420 }
50421@@ -647,6 +652,8 @@ static int uio_mmap_physical(struct vm_area_struct *vma)
50422 return -EINVAL;
50423 mem = idev->info->mem + mi;
50424
50425+ if (mem->addr & ~PAGE_MASK)
50426+ return -ENODEV;
50427 if (vma->vm_end - vma->vm_start > mem->size)
50428 return -EINVAL;
50429
50430@@ -818,7 +825,7 @@ int __uio_register_device(struct module *owner,
50431 idev->owner = owner;
50432 idev->info = info;
50433 init_waitqueue_head(&idev->wait);
50434- atomic_set(&idev->event, 0);
50435+ atomic_set_unchecked(&idev->event, 0);
50436
50437 ret = uio_get_minor(idev);
50438 if (ret)
50439diff --git a/drivers/usb/atm/cxacru.c b/drivers/usb/atm/cxacru.c
50440index 8a7eb77..c00402f 100644
50441--- a/drivers/usb/atm/cxacru.c
50442+++ b/drivers/usb/atm/cxacru.c
50443@@ -473,7 +473,7 @@ static ssize_t cxacru_sysfs_store_adsl_config(struct device *dev,
50444 ret = sscanf(buf + pos, "%x=%x%n", &index, &value, &tmp);
50445 if (ret < 2)
50446 return -EINVAL;
50447- if (index < 0 || index > 0x7f)
50448+ if (index > 0x7f)
50449 return -EINVAL;
50450 pos += tmp;
50451
50452diff --git a/drivers/usb/atm/usbatm.c b/drivers/usb/atm/usbatm.c
50453index 25a7bfc..57f3cf5 100644
50454--- a/drivers/usb/atm/usbatm.c
50455+++ b/drivers/usb/atm/usbatm.c
50456@@ -331,7 +331,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
50457 if (printk_ratelimit())
50458 atm_warn(instance, "%s: OAM not supported (vpi %d, vci %d)!\n",
50459 __func__, vpi, vci);
50460- atomic_inc(&vcc->stats->rx_err);
50461+ atomic_inc_unchecked(&vcc->stats->rx_err);
50462 return;
50463 }
50464
50465@@ -358,7 +358,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
50466 if (length > ATM_MAX_AAL5_PDU) {
50467 atm_rldbg(instance, "%s: bogus length %u (vcc: 0x%p)!\n",
50468 __func__, length, vcc);
50469- atomic_inc(&vcc->stats->rx_err);
50470+ atomic_inc_unchecked(&vcc->stats->rx_err);
50471 goto out;
50472 }
50473
50474@@ -367,14 +367,14 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
50475 if (sarb->len < pdu_length) {
50476 atm_rldbg(instance, "%s: bogus pdu_length %u (sarb->len: %u, vcc: 0x%p)!\n",
50477 __func__, pdu_length, sarb->len, vcc);
50478- atomic_inc(&vcc->stats->rx_err);
50479+ atomic_inc_unchecked(&vcc->stats->rx_err);
50480 goto out;
50481 }
50482
50483 if (crc32_be(~0, skb_tail_pointer(sarb) - pdu_length, pdu_length) != 0xc704dd7b) {
50484 atm_rldbg(instance, "%s: packet failed crc check (vcc: 0x%p)!\n",
50485 __func__, vcc);
50486- atomic_inc(&vcc->stats->rx_err);
50487+ atomic_inc_unchecked(&vcc->stats->rx_err);
50488 goto out;
50489 }
50490
50491@@ -386,7 +386,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
50492 if (printk_ratelimit())
50493 atm_err(instance, "%s: no memory for skb (length: %u)!\n",
50494 __func__, length);
50495- atomic_inc(&vcc->stats->rx_drop);
50496+ atomic_inc_unchecked(&vcc->stats->rx_drop);
50497 goto out;
50498 }
50499
50500@@ -414,7 +414,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
50501
50502 vcc->push(vcc, skb);
50503
50504- atomic_inc(&vcc->stats->rx);
50505+ atomic_inc_unchecked(&vcc->stats->rx);
50506 out:
50507 skb_trim(sarb, 0);
50508 }
50509@@ -612,7 +612,7 @@ static void usbatm_tx_process(unsigned long data)
50510 struct atm_vcc *vcc = UDSL_SKB(skb)->atm.vcc;
50511
50512 usbatm_pop(vcc, skb);
50513- atomic_inc(&vcc->stats->tx);
50514+ atomic_inc_unchecked(&vcc->stats->tx);
50515
50516 skb = skb_dequeue(&instance->sndqueue);
50517 }
50518@@ -756,11 +756,11 @@ static int usbatm_atm_proc_read(struct atm_dev *atm_dev, loff_t * pos, char *pag
50519 if (!left--)
50520 return sprintf(page,
50521 "AAL5: tx %d ( %d err ), rx %d ( %d err, %d drop )\n",
50522- atomic_read(&atm_dev->stats.aal5.tx),
50523- atomic_read(&atm_dev->stats.aal5.tx_err),
50524- atomic_read(&atm_dev->stats.aal5.rx),
50525- atomic_read(&atm_dev->stats.aal5.rx_err),
50526- atomic_read(&atm_dev->stats.aal5.rx_drop));
50527+ atomic_read_unchecked(&atm_dev->stats.aal5.tx),
50528+ atomic_read_unchecked(&atm_dev->stats.aal5.tx_err),
50529+ atomic_read_unchecked(&atm_dev->stats.aal5.rx),
50530+ atomic_read_unchecked(&atm_dev->stats.aal5.rx_err),
50531+ atomic_read_unchecked(&atm_dev->stats.aal5.rx_drop));
50532
50533 if (!left--) {
50534 if (instance->disconnected)
50535diff --git a/drivers/usb/core/devices.c b/drivers/usb/core/devices.c
50536index 2a3bbdf..91d72cf 100644
50537--- a/drivers/usb/core/devices.c
50538+++ b/drivers/usb/core/devices.c
50539@@ -126,7 +126,7 @@ static const char format_endpt[] =
50540 * time it gets called.
50541 */
50542 static struct device_connect_event {
50543- atomic_t count;
50544+ atomic_unchecked_t count;
50545 wait_queue_head_t wait;
50546 } device_event = {
50547 .count = ATOMIC_INIT(1),
50548@@ -164,7 +164,7 @@ static const struct class_info clas_info[] = {
50549
50550 void usbfs_conn_disc_event(void)
50551 {
50552- atomic_add(2, &device_event.count);
50553+ atomic_add_unchecked(2, &device_event.count);
50554 wake_up(&device_event.wait);
50555 }
50556
50557@@ -652,7 +652,7 @@ static unsigned int usb_device_poll(struct file *file,
50558
50559 poll_wait(file, &device_event.wait, wait);
50560
50561- event_count = atomic_read(&device_event.count);
50562+ event_count = atomic_read_unchecked(&device_event.count);
50563 if (file->f_version != event_count) {
50564 file->f_version = event_count;
50565 return POLLIN | POLLRDNORM;
50566diff --git a/drivers/usb/core/devio.c b/drivers/usb/core/devio.c
50567index 71dc5d7..d4c488f 100644
50568--- a/drivers/usb/core/devio.c
50569+++ b/drivers/usb/core/devio.c
50570@@ -187,7 +187,7 @@ static ssize_t usbdev_read(struct file *file, char __user *buf, size_t nbytes,
50571 struct dev_state *ps = file->private_data;
50572 struct usb_device *dev = ps->dev;
50573 ssize_t ret = 0;
50574- unsigned len;
50575+ size_t len;
50576 loff_t pos;
50577 int i;
50578
50579@@ -229,22 +229,22 @@ static ssize_t usbdev_read(struct file *file, char __user *buf, size_t nbytes,
50580 for (i = 0; nbytes && i < dev->descriptor.bNumConfigurations; i++) {
50581 struct usb_config_descriptor *config =
50582 (struct usb_config_descriptor *)dev->rawdescriptors[i];
50583- unsigned int length = le16_to_cpu(config->wTotalLength);
50584+ size_t length = le16_to_cpu(config->wTotalLength);
50585
50586 if (*ppos < pos + length) {
50587
50588 /* The descriptor may claim to be longer than it
50589 * really is. Here is the actual allocated length. */
50590- unsigned alloclen =
50591+ size_t alloclen =
50592 le16_to_cpu(dev->config[i].desc.wTotalLength);
50593
50594- len = length - (*ppos - pos);
50595+ len = length + pos - *ppos;
50596 if (len > nbytes)
50597 len = nbytes;
50598
50599 /* Simply don't write (skip over) unallocated parts */
50600 if (alloclen > (*ppos - pos)) {
50601- alloclen -= (*ppos - pos);
50602+ alloclen = alloclen + pos - *ppos;
50603 if (copy_to_user(buf,
50604 dev->rawdescriptors[i] + (*ppos - pos),
50605 min(len, alloclen))) {
50606diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c
50607index f20a044..d1059aa 100644
50608--- a/drivers/usb/core/hcd.c
50609+++ b/drivers/usb/core/hcd.c
50610@@ -1552,7 +1552,7 @@ int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags)
50611 */
50612 usb_get_urb(urb);
50613 atomic_inc(&urb->use_count);
50614- atomic_inc(&urb->dev->urbnum);
50615+ atomic_inc_unchecked(&urb->dev->urbnum);
50616 usbmon_urb_submit(&hcd->self, urb);
50617
50618 /* NOTE requirements on root-hub callers (usbfs and the hub
50619@@ -1579,7 +1579,7 @@ int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags)
50620 urb->hcpriv = NULL;
50621 INIT_LIST_HEAD(&urb->urb_list);
50622 atomic_dec(&urb->use_count);
50623- atomic_dec(&urb->dev->urbnum);
50624+ atomic_dec_unchecked(&urb->dev->urbnum);
50625 if (atomic_read(&urb->reject))
50626 wake_up(&usb_kill_urb_queue);
50627 usb_put_urb(urb);
50628diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c
50629index c5c3667..e54e5cd 100644
50630--- a/drivers/usb/core/hub.c
50631+++ b/drivers/usb/core/hub.c
50632@@ -27,6 +27,7 @@
50633 #include <linux/freezer.h>
50634 #include <linux/random.h>
50635 #include <linux/pm_qos.h>
50636+#include <linux/grsecurity.h>
50637
50638 #include <asm/uaccess.h>
50639 #include <asm/byteorder.h>
50640@@ -4467,6 +4468,10 @@ static void hub_port_connect_change(struct usb_hub *hub, int port1,
50641 goto done;
50642 return;
50643 }
50644+
50645+ if (gr_handle_new_usb())
50646+ goto done;
50647+
50648 if (hub_is_superspeed(hub->hdev))
50649 unit_load = 150;
50650 else
50651diff --git a/drivers/usb/core/message.c b/drivers/usb/core/message.c
50652index 82927e1..4993dbf 100644
50653--- a/drivers/usb/core/message.c
50654+++ b/drivers/usb/core/message.c
50655@@ -129,7 +129,7 @@ static int usb_internal_control_msg(struct usb_device *usb_dev,
50656 * Return: If successful, the number of bytes transferred. Otherwise, a negative
50657 * error number.
50658 */
50659-int usb_control_msg(struct usb_device *dev, unsigned int pipe, __u8 request,
50660+int __intentional_overflow(-1) usb_control_msg(struct usb_device *dev, unsigned int pipe, __u8 request,
50661 __u8 requesttype, __u16 value, __u16 index, void *data,
50662 __u16 size, int timeout)
50663 {
50664@@ -181,7 +181,7 @@ EXPORT_SYMBOL_GPL(usb_control_msg);
50665 * If successful, 0. Otherwise a negative error number. The number of actual
50666 * bytes transferred will be stored in the @actual_length paramater.
50667 */
50668-int usb_interrupt_msg(struct usb_device *usb_dev, unsigned int pipe,
50669+int __intentional_overflow(-1) usb_interrupt_msg(struct usb_device *usb_dev, unsigned int pipe,
50670 void *data, int len, int *actual_length, int timeout)
50671 {
50672 return usb_bulk_msg(usb_dev, pipe, data, len, actual_length, timeout);
50673@@ -221,7 +221,7 @@ EXPORT_SYMBOL_GPL(usb_interrupt_msg);
50674 * bytes transferred will be stored in the @actual_length paramater.
50675 *
50676 */
50677-int usb_bulk_msg(struct usb_device *usb_dev, unsigned int pipe,
50678+int __intentional_overflow(-1) usb_bulk_msg(struct usb_device *usb_dev, unsigned int pipe,
50679 void *data, int len, int *actual_length, int timeout)
50680 {
50681 struct urb *urb;
50682diff --git a/drivers/usb/core/sysfs.c b/drivers/usb/core/sysfs.c
50683index ca516ac..6c36ee4 100644
50684--- a/drivers/usb/core/sysfs.c
50685+++ b/drivers/usb/core/sysfs.c
50686@@ -236,7 +236,7 @@ static ssize_t urbnum_show(struct device *dev, struct device_attribute *attr,
50687 struct usb_device *udev;
50688
50689 udev = to_usb_device(dev);
50690- return sprintf(buf, "%d\n", atomic_read(&udev->urbnum));
50691+ return sprintf(buf, "%d\n", atomic_read_unchecked(&udev->urbnum));
50692 }
50693 static DEVICE_ATTR_RO(urbnum);
50694
50695diff --git a/drivers/usb/core/usb.c b/drivers/usb/core/usb.c
50696index 0a6ee2e..6f8d7e8 100644
50697--- a/drivers/usb/core/usb.c
50698+++ b/drivers/usb/core/usb.c
50699@@ -433,7 +433,7 @@ struct usb_device *usb_alloc_dev(struct usb_device *parent,
50700 set_dev_node(&dev->dev, dev_to_node(bus->controller));
50701 dev->state = USB_STATE_ATTACHED;
50702 dev->lpm_disable_count = 1;
50703- atomic_set(&dev->urbnum, 0);
50704+ atomic_set_unchecked(&dev->urbnum, 0);
50705
50706 INIT_LIST_HEAD(&dev->ep0.urb_list);
50707 dev->ep0.desc.bLength = USB_DT_ENDPOINT_SIZE;
50708diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c
50709index 02e44fc..3c4fe64 100644
50710--- a/drivers/usb/dwc3/gadget.c
50711+++ b/drivers/usb/dwc3/gadget.c
50712@@ -532,8 +532,6 @@ static int __dwc3_gadget_ep_enable(struct dwc3_ep *dep,
50713 if (!usb_endpoint_xfer_isoc(desc))
50714 return 0;
50715
50716- memset(&trb_link, 0, sizeof(trb_link));
50717-
50718 /* Link TRB for ISOC. The HWO bit is never reset */
50719 trb_st_hw = &dep->trb_pool[0];
50720
50721diff --git a/drivers/usb/early/ehci-dbgp.c b/drivers/usb/early/ehci-dbgp.c
50722index 5e29dde..eca992f 100644
50723--- a/drivers/usb/early/ehci-dbgp.c
50724+++ b/drivers/usb/early/ehci-dbgp.c
50725@@ -98,7 +98,8 @@ static inline u32 dbgp_len_update(u32 x, u32 len)
50726
50727 #ifdef CONFIG_KGDB
50728 static struct kgdb_io kgdbdbgp_io_ops;
50729-#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops)
50730+static struct kgdb_io kgdbdbgp_io_ops_console;
50731+#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops || dbg_io_ops == &kgdbdbgp_io_ops_console)
50732 #else
50733 #define dbgp_kgdb_mode (0)
50734 #endif
50735@@ -1047,6 +1048,13 @@ static struct kgdb_io kgdbdbgp_io_ops = {
50736 .write_char = kgdbdbgp_write_char,
50737 };
50738
50739+static struct kgdb_io kgdbdbgp_io_ops_console = {
50740+ .name = "kgdbdbgp",
50741+ .read_char = kgdbdbgp_read_char,
50742+ .write_char = kgdbdbgp_write_char,
50743+ .is_console = 1
50744+};
50745+
50746 static int kgdbdbgp_wait_time;
50747
50748 static int __init kgdbdbgp_parse_config(char *str)
50749@@ -1062,8 +1070,10 @@ static int __init kgdbdbgp_parse_config(char *str)
50750 ptr++;
50751 kgdbdbgp_wait_time = simple_strtoul(ptr, &ptr, 10);
50752 }
50753- kgdb_register_io_module(&kgdbdbgp_io_ops);
50754- kgdbdbgp_io_ops.is_console = early_dbgp_console.index != -1;
50755+ if (early_dbgp_console.index != -1)
50756+ kgdb_register_io_module(&kgdbdbgp_io_ops_console);
50757+ else
50758+ kgdb_register_io_module(&kgdbdbgp_io_ops);
50759
50760 return 0;
50761 }
50762diff --git a/drivers/usb/gadget/u_serial.c b/drivers/usb/gadget/u_serial.c
50763index b369292..9f3ba40 100644
50764--- a/drivers/usb/gadget/u_serial.c
50765+++ b/drivers/usb/gadget/u_serial.c
50766@@ -733,9 +733,9 @@ static int gs_open(struct tty_struct *tty, struct file *file)
50767 spin_lock_irq(&port->port_lock);
50768
50769 /* already open? Great. */
50770- if (port->port.count) {
50771+ if (atomic_read(&port->port.count)) {
50772 status = 0;
50773- port->port.count++;
50774+ atomic_inc(&port->port.count);
50775
50776 /* currently opening/closing? wait ... */
50777 } else if (port->openclose) {
50778@@ -794,7 +794,7 @@ static int gs_open(struct tty_struct *tty, struct file *file)
50779 tty->driver_data = port;
50780 port->port.tty = tty;
50781
50782- port->port.count = 1;
50783+ atomic_set(&port->port.count, 1);
50784 port->openclose = false;
50785
50786 /* if connected, start the I/O stream */
50787@@ -836,11 +836,11 @@ static void gs_close(struct tty_struct *tty, struct file *file)
50788
50789 spin_lock_irq(&port->port_lock);
50790
50791- if (port->port.count != 1) {
50792- if (port->port.count == 0)
50793+ if (atomic_read(&port->port.count) != 1) {
50794+ if (atomic_read(&port->port.count) == 0)
50795 WARN_ON(1);
50796 else
50797- --port->port.count;
50798+ atomic_dec(&port->port.count);
50799 goto exit;
50800 }
50801
50802@@ -850,7 +850,7 @@ static void gs_close(struct tty_struct *tty, struct file *file)
50803 * and sleep if necessary
50804 */
50805 port->openclose = true;
50806- port->port.count = 0;
50807+ atomic_set(&port->port.count, 0);
50808
50809 gser = port->port_usb;
50810 if (gser && gser->disconnect)
50811@@ -1066,7 +1066,7 @@ static int gs_closed(struct gs_port *port)
50812 int cond;
50813
50814 spin_lock_irq(&port->port_lock);
50815- cond = (port->port.count == 0) && !port->openclose;
50816+ cond = (atomic_read(&port->port.count) == 0) && !port->openclose;
50817 spin_unlock_irq(&port->port_lock);
50818 return cond;
50819 }
50820@@ -1209,7 +1209,7 @@ int gserial_connect(struct gserial *gser, u8 port_num)
50821 /* if it's already open, start I/O ... and notify the serial
50822 * protocol about open/close status (connect/disconnect).
50823 */
50824- if (port->port.count) {
50825+ if (atomic_read(&port->port.count)) {
50826 pr_debug("gserial_connect: start ttyGS%d\n", port->port_num);
50827 gs_start_io(port);
50828 if (gser->connect)
50829@@ -1256,7 +1256,7 @@ void gserial_disconnect(struct gserial *gser)
50830
50831 port->port_usb = NULL;
50832 gser->ioport = NULL;
50833- if (port->port.count > 0 || port->openclose) {
50834+ if (atomic_read(&port->port.count) > 0 || port->openclose) {
50835 wake_up_interruptible(&port->drain_wait);
50836 if (port->port.tty)
50837 tty_hangup(port->port.tty);
50838@@ -1272,7 +1272,7 @@ void gserial_disconnect(struct gserial *gser)
50839
50840 /* finally, free any unused/unusable I/O buffers */
50841 spin_lock_irqsave(&port->port_lock, flags);
50842- if (port->port.count == 0 && !port->openclose)
50843+ if (atomic_read(&port->port.count) == 0 && !port->openclose)
50844 gs_buf_free(&port->port_write_buf);
50845 gs_free_requests(gser->out, &port->read_pool, NULL);
50846 gs_free_requests(gser->out, &port->read_queue, NULL);
50847diff --git a/drivers/usb/host/ehci-hub.c b/drivers/usb/host/ehci-hub.c
50848index 835fc08..f8b22bf 100644
50849--- a/drivers/usb/host/ehci-hub.c
50850+++ b/drivers/usb/host/ehci-hub.c
50851@@ -762,7 +762,7 @@ static struct urb *request_single_step_set_feature_urb(
50852 urb->transfer_flags = URB_DIR_IN;
50853 usb_get_urb(urb);
50854 atomic_inc(&urb->use_count);
50855- atomic_inc(&urb->dev->urbnum);
50856+ atomic_inc_unchecked(&urb->dev->urbnum);
50857 urb->setup_dma = dma_map_single(
50858 hcd->self.controller,
50859 urb->setup_packet,
50860@@ -829,7 +829,7 @@ static int ehset_single_step_set_feature(struct usb_hcd *hcd, int port)
50861 urb->status = -EINPROGRESS;
50862 usb_get_urb(urb);
50863 atomic_inc(&urb->use_count);
50864- atomic_inc(&urb->dev->urbnum);
50865+ atomic_inc_unchecked(&urb->dev->urbnum);
50866 retval = submit_single_step_set_feature(hcd, urb, 0);
50867 if (!retval && !wait_for_completion_timeout(&done,
50868 msecs_to_jiffies(2000))) {
50869diff --git a/drivers/usb/misc/appledisplay.c b/drivers/usb/misc/appledisplay.c
50870index ba6a5d6..f88f7f3 100644
50871--- a/drivers/usb/misc/appledisplay.c
50872+++ b/drivers/usb/misc/appledisplay.c
50873@@ -83,7 +83,7 @@ struct appledisplay {
50874 spinlock_t lock;
50875 };
50876
50877-static atomic_t count_displays = ATOMIC_INIT(0);
50878+static atomic_unchecked_t count_displays = ATOMIC_INIT(0);
50879 static struct workqueue_struct *wq;
50880
50881 static void appledisplay_complete(struct urb *urb)
50882@@ -281,7 +281,7 @@ static int appledisplay_probe(struct usb_interface *iface,
50883
50884 /* Register backlight device */
50885 snprintf(bl_name, sizeof(bl_name), "appledisplay%d",
50886- atomic_inc_return(&count_displays) - 1);
50887+ atomic_inc_return_unchecked(&count_displays) - 1);
50888 memset(&props, 0, sizeof(struct backlight_properties));
50889 props.type = BACKLIGHT_RAW;
50890 props.max_brightness = 0xff;
50891diff --git a/drivers/usb/serial/console.c b/drivers/usb/serial/console.c
50892index c69bb50..215ef37 100644
50893--- a/drivers/usb/serial/console.c
50894+++ b/drivers/usb/serial/console.c
50895@@ -124,7 +124,7 @@ static int usb_console_setup(struct console *co, char *options)
50896
50897 info->port = port;
50898
50899- ++port->port.count;
50900+ atomic_inc(&port->port.count);
50901 if (!test_bit(ASYNCB_INITIALIZED, &port->port.flags)) {
50902 if (serial->type->set_termios) {
50903 /*
50904@@ -170,7 +170,7 @@ static int usb_console_setup(struct console *co, char *options)
50905 }
50906 /* Now that any required fake tty operations are completed restore
50907 * the tty port count */
50908- --port->port.count;
50909+ atomic_dec(&port->port.count);
50910 /* The console is special in terms of closing the device so
50911 * indicate this port is now acting as a system console. */
50912 port->port.console = 1;
50913@@ -183,7 +183,7 @@ static int usb_console_setup(struct console *co, char *options)
50914 free_tty:
50915 kfree(tty);
50916 reset_open_count:
50917- port->port.count = 0;
50918+ atomic_set(&port->port.count, 0);
50919 usb_autopm_put_interface(serial->interface);
50920 error_get_interface:
50921 usb_serial_put(serial);
50922@@ -194,7 +194,7 @@ static int usb_console_setup(struct console *co, char *options)
50923 static void usb_console_write(struct console *co,
50924 const char *buf, unsigned count)
50925 {
50926- static struct usbcons_info *info = &usbcons_info;
50927+ struct usbcons_info *info = &usbcons_info;
50928 struct usb_serial_port *port = info->port;
50929 struct usb_serial *serial;
50930 int retval = -ENODEV;
50931diff --git a/drivers/usb/storage/usb.h b/drivers/usb/storage/usb.h
50932index 75f70f0..d467e1a 100644
50933--- a/drivers/usb/storage/usb.h
50934+++ b/drivers/usb/storage/usb.h
50935@@ -63,7 +63,7 @@ struct us_unusual_dev {
50936 __u8 useProtocol;
50937 __u8 useTransport;
50938 int (*initFunction)(struct us_data *);
50939-};
50940+} __do_const;
50941
50942
50943 /* Dynamic bitflag definitions (us->dflags): used in set_bit() etc. */
50944diff --git a/drivers/usb/wusbcore/wa-hc.h b/drivers/usb/wusbcore/wa-hc.h
50945index cf250c2..ad9d904 100644
50946--- a/drivers/usb/wusbcore/wa-hc.h
50947+++ b/drivers/usb/wusbcore/wa-hc.h
50948@@ -199,7 +199,7 @@ struct wahc {
50949 spinlock_t xfer_list_lock;
50950 struct work_struct xfer_enqueue_work;
50951 struct work_struct xfer_error_work;
50952- atomic_t xfer_id_count;
50953+ atomic_unchecked_t xfer_id_count;
50954 };
50955
50956
50957@@ -255,7 +255,7 @@ static inline void wa_init(struct wahc *wa)
50958 spin_lock_init(&wa->xfer_list_lock);
50959 INIT_WORK(&wa->xfer_enqueue_work, wa_urb_enqueue_run);
50960 INIT_WORK(&wa->xfer_error_work, wa_process_errored_transfers_run);
50961- atomic_set(&wa->xfer_id_count, 1);
50962+ atomic_set_unchecked(&wa->xfer_id_count, 1);
50963 }
50964
50965 /**
50966diff --git a/drivers/usb/wusbcore/wa-xfer.c b/drivers/usb/wusbcore/wa-xfer.c
50967index 3dcf66f..8faaf6e 100644
50968--- a/drivers/usb/wusbcore/wa-xfer.c
50969+++ b/drivers/usb/wusbcore/wa-xfer.c
50970@@ -300,7 +300,7 @@ out:
50971 */
50972 static void wa_xfer_id_init(struct wa_xfer *xfer)
50973 {
50974- xfer->id = atomic_add_return(1, &xfer->wa->xfer_id_count);
50975+ xfer->id = atomic_add_return_unchecked(1, &xfer->wa->xfer_id_count);
50976 }
50977
50978 /*
50979diff --git a/drivers/vfio/vfio.c b/drivers/vfio/vfio.c
50980index 1eab4ac..e21efc9 100644
50981--- a/drivers/vfio/vfio.c
50982+++ b/drivers/vfio/vfio.c
50983@@ -488,7 +488,7 @@ static int vfio_group_nb_add_dev(struct vfio_group *group, struct device *dev)
50984 return 0;
50985
50986 /* TODO Prevent device auto probing */
50987- WARN("Device %s added to live group %d!\n", dev_name(dev),
50988+ WARN(1, "Device %s added to live group %d!\n", dev_name(dev),
50989 iommu_group_id(group->iommu_group));
50990
50991 return 0;
50992diff --git a/drivers/vhost/vringh.c b/drivers/vhost/vringh.c
50993index 5174eba..86e764a 100644
50994--- a/drivers/vhost/vringh.c
50995+++ b/drivers/vhost/vringh.c
50996@@ -800,7 +800,7 @@ static inline int getu16_kern(u16 *val, const u16 *p)
50997
50998 static inline int putu16_kern(u16 *p, u16 val)
50999 {
51000- ACCESS_ONCE(*p) = val;
51001+ ACCESS_ONCE_RW(*p) = val;
51002 return 0;
51003 }
51004
51005diff --git a/drivers/video/arcfb.c b/drivers/video/arcfb.c
51006index e43401a..dd49b3f 100644
51007--- a/drivers/video/arcfb.c
51008+++ b/drivers/video/arcfb.c
51009@@ -458,7 +458,7 @@ static ssize_t arcfb_write(struct fb_info *info, const char __user *buf,
51010 return -ENOSPC;
51011
51012 err = 0;
51013- if ((count + p) > fbmemlength) {
51014+ if (count > (fbmemlength - p)) {
51015 count = fbmemlength - p;
51016 err = -ENOSPC;
51017 }
51018diff --git a/drivers/video/aty/aty128fb.c b/drivers/video/aty/aty128fb.c
51019index a4dfe8c..297ddd9 100644
51020--- a/drivers/video/aty/aty128fb.c
51021+++ b/drivers/video/aty/aty128fb.c
51022@@ -149,7 +149,7 @@ enum {
51023 };
51024
51025 /* Must match above enum */
51026-static char * const r128_family[] = {
51027+static const char * const r128_family[] = {
51028 "AGP",
51029 "PCI",
51030 "PRO AGP",
51031diff --git a/drivers/video/aty/atyfb_base.c b/drivers/video/aty/atyfb_base.c
51032index 9b0f12c..024673d 100644
51033--- a/drivers/video/aty/atyfb_base.c
51034+++ b/drivers/video/aty/atyfb_base.c
51035@@ -1326,10 +1326,14 @@ static int atyfb_set_par(struct fb_info *info)
51036 par->accel_flags = var->accel_flags; /* hack */
51037
51038 if (var->accel_flags) {
51039- info->fbops->fb_sync = atyfb_sync;
51040+ pax_open_kernel();
51041+ *(void **)&info->fbops->fb_sync = atyfb_sync;
51042+ pax_close_kernel();
51043 info->flags &= ~FBINFO_HWACCEL_DISABLED;
51044 } else {
51045- info->fbops->fb_sync = NULL;
51046+ pax_open_kernel();
51047+ *(void **)&info->fbops->fb_sync = NULL;
51048+ pax_close_kernel();
51049 info->flags |= FBINFO_HWACCEL_DISABLED;
51050 }
51051
51052diff --git a/drivers/video/aty/mach64_cursor.c b/drivers/video/aty/mach64_cursor.c
51053index 95ec042..e6affdd 100644
51054--- a/drivers/video/aty/mach64_cursor.c
51055+++ b/drivers/video/aty/mach64_cursor.c
51056@@ -7,6 +7,7 @@
51057 #include <linux/string.h>
51058
51059 #include <asm/io.h>
51060+#include <asm/pgtable.h>
51061
51062 #ifdef __sparc__
51063 #include <asm/fbio.h>
51064@@ -208,7 +209,9 @@ int aty_init_cursor(struct fb_info *info)
51065 info->sprite.buf_align = 16; /* and 64 lines tall. */
51066 info->sprite.flags = FB_PIXMAP_IO;
51067
51068- info->fbops->fb_cursor = atyfb_cursor;
51069+ pax_open_kernel();
51070+ *(void **)&info->fbops->fb_cursor = atyfb_cursor;
51071+ pax_close_kernel();
51072
51073 return 0;
51074 }
51075diff --git a/drivers/video/backlight/kb3886_bl.c b/drivers/video/backlight/kb3886_bl.c
51076index bca6ccc..252107e 100644
51077--- a/drivers/video/backlight/kb3886_bl.c
51078+++ b/drivers/video/backlight/kb3886_bl.c
51079@@ -78,7 +78,7 @@ static struct kb3886bl_machinfo *bl_machinfo;
51080 static unsigned long kb3886bl_flags;
51081 #define KB3886BL_SUSPENDED 0x01
51082
51083-static struct dmi_system_id __initdata kb3886bl_device_table[] = {
51084+static const struct dmi_system_id __initconst kb3886bl_device_table[] = {
51085 {
51086 .ident = "Sahara Touch-iT",
51087 .matches = {
51088diff --git a/drivers/video/fb_defio.c b/drivers/video/fb_defio.c
51089index 900aa4e..6d49418 100644
51090--- a/drivers/video/fb_defio.c
51091+++ b/drivers/video/fb_defio.c
51092@@ -206,7 +206,9 @@ void fb_deferred_io_init(struct fb_info *info)
51093
51094 BUG_ON(!fbdefio);
51095 mutex_init(&fbdefio->lock);
51096- info->fbops->fb_mmap = fb_deferred_io_mmap;
51097+ pax_open_kernel();
51098+ *(void **)&info->fbops->fb_mmap = fb_deferred_io_mmap;
51099+ pax_close_kernel();
51100 INIT_DELAYED_WORK(&info->deferred_work, fb_deferred_io_work);
51101 INIT_LIST_HEAD(&fbdefio->pagelist);
51102 if (fbdefio->delay == 0) /* set a default of 1 s */
51103@@ -237,7 +239,7 @@ void fb_deferred_io_cleanup(struct fb_info *info)
51104 page->mapping = NULL;
51105 }
51106
51107- info->fbops->fb_mmap = NULL;
51108+ *(void **)&info->fbops->fb_mmap = NULL;
51109 mutex_destroy(&fbdefio->lock);
51110 }
51111 EXPORT_SYMBOL_GPL(fb_deferred_io_cleanup);
51112diff --git a/drivers/video/fbmem.c b/drivers/video/fbmem.c
51113index dacaf74..8478a46 100644
51114--- a/drivers/video/fbmem.c
51115+++ b/drivers/video/fbmem.c
51116@@ -433,7 +433,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
51117 image->dx += image->width + 8;
51118 }
51119 } else if (rotate == FB_ROTATE_UD) {
51120- for (x = 0; x < num && image->dx >= 0; x++) {
51121+ for (x = 0; x < num && (__s32)image->dx >= 0; x++) {
51122 info->fbops->fb_imageblit(info, image);
51123 image->dx -= image->width + 8;
51124 }
51125@@ -445,7 +445,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
51126 image->dy += image->height + 8;
51127 }
51128 } else if (rotate == FB_ROTATE_CCW) {
51129- for (x = 0; x < num && image->dy >= 0; x++) {
51130+ for (x = 0; x < num && (__s32)image->dy >= 0; x++) {
51131 info->fbops->fb_imageblit(info, image);
51132 image->dy -= image->height + 8;
51133 }
51134@@ -1175,7 +1175,7 @@ static long do_fb_ioctl(struct fb_info *info, unsigned int cmd,
51135 return -EFAULT;
51136 if (con2fb.console < 1 || con2fb.console > MAX_NR_CONSOLES)
51137 return -EINVAL;
51138- if (con2fb.framebuffer < 0 || con2fb.framebuffer >= FB_MAX)
51139+ if (con2fb.framebuffer >= FB_MAX)
51140 return -EINVAL;
51141 if (!registered_fb[con2fb.framebuffer])
51142 request_module("fb%d", con2fb.framebuffer);
51143diff --git a/drivers/video/hyperv_fb.c b/drivers/video/hyperv_fb.c
51144index 8d456dc..b4fa44b 100644
51145--- a/drivers/video/hyperv_fb.c
51146+++ b/drivers/video/hyperv_fb.c
51147@@ -233,7 +233,7 @@ static uint screen_fb_size;
51148 static inline int synthvid_send(struct hv_device *hdev,
51149 struct synthvid_msg *msg)
51150 {
51151- static atomic64_t request_id = ATOMIC64_INIT(0);
51152+ static atomic64_unchecked_t request_id = ATOMIC64_INIT(0);
51153 int ret;
51154
51155 msg->pipe_hdr.type = PIPE_MSG_DATA;
51156@@ -241,7 +241,7 @@ static inline int synthvid_send(struct hv_device *hdev,
51157
51158 ret = vmbus_sendpacket(hdev->channel, msg,
51159 msg->vid_hdr.size + sizeof(struct pipe_msg_hdr),
51160- atomic64_inc_return(&request_id),
51161+ atomic64_inc_return_unchecked(&request_id),
51162 VM_PKT_DATA_INBAND, 0);
51163
51164 if (ret)
51165diff --git a/drivers/video/i810/i810_accel.c b/drivers/video/i810/i810_accel.c
51166index 7672d2e..b56437f 100644
51167--- a/drivers/video/i810/i810_accel.c
51168+++ b/drivers/video/i810/i810_accel.c
51169@@ -73,6 +73,7 @@ static inline int wait_for_space(struct fb_info *info, u32 space)
51170 }
51171 }
51172 printk("ringbuffer lockup!!!\n");
51173+ printk("head:%u tail:%u iring.size:%u space:%u\n", head, tail, par->iring.size, space);
51174 i810_report_error(mmio);
51175 par->dev_flags |= LOCKUP;
51176 info->pixmap.scan_align = 1;
51177diff --git a/drivers/video/logo/logo_linux_clut224.ppm b/drivers/video/logo/logo_linux_clut224.ppm
51178index 3c14e43..2630570 100644
51179--- a/drivers/video/logo/logo_linux_clut224.ppm
51180+++ b/drivers/video/logo/logo_linux_clut224.ppm
51181@@ -2,1603 +2,1123 @@ P3
51182 # Standard 224-color Linux logo
51183 80 80
51184 255
51185- 0 0 0 0 0 0 0 0 0 0 0 0
51186- 0 0 0 0 0 0 0 0 0 0 0 0
51187- 0 0 0 0 0 0 0 0 0 0 0 0
51188- 0 0 0 0 0 0 0 0 0 0 0 0
51189- 0 0 0 0 0 0 0 0 0 0 0 0
51190- 0 0 0 0 0 0 0 0 0 0 0 0
51191- 0 0 0 0 0 0 0 0 0 0 0 0
51192- 0 0 0 0 0 0 0 0 0 0 0 0
51193- 0 0 0 0 0 0 0 0 0 0 0 0
51194- 6 6 6 6 6 6 10 10 10 10 10 10
51195- 10 10 10 6 6 6 6 6 6 6 6 6
51196- 0 0 0 0 0 0 0 0 0 0 0 0
51197- 0 0 0 0 0 0 0 0 0 0 0 0
51198- 0 0 0 0 0 0 0 0 0 0 0 0
51199- 0 0 0 0 0 0 0 0 0 0 0 0
51200- 0 0 0 0 0 0 0 0 0 0 0 0
51201- 0 0 0 0 0 0 0 0 0 0 0 0
51202- 0 0 0 0 0 0 0 0 0 0 0 0
51203- 0 0 0 0 0 0 0 0 0 0 0 0
51204- 0 0 0 0 0 0 0 0 0 0 0 0
51205- 0 0 0 0 0 0 0 0 0 0 0 0
51206- 0 0 0 0 0 0 0 0 0 0 0 0
51207- 0 0 0 0 0 0 0 0 0 0 0 0
51208- 0 0 0 0 0 0 0 0 0 0 0 0
51209- 0 0 0 0 0 0 0 0 0 0 0 0
51210- 0 0 0 0 0 0 0 0 0 0 0 0
51211- 0 0 0 0 0 0 0 0 0 0 0 0
51212- 0 0 0 0 0 0 0 0 0 0 0 0
51213- 0 0 0 6 6 6 10 10 10 14 14 14
51214- 22 22 22 26 26 26 30 30 30 34 34 34
51215- 30 30 30 30 30 30 26 26 26 18 18 18
51216- 14 14 14 10 10 10 6 6 6 0 0 0
51217- 0 0 0 0 0 0 0 0 0 0 0 0
51218- 0 0 0 0 0 0 0 0 0 0 0 0
51219- 0 0 0 0 0 0 0 0 0 0 0 0
51220- 0 0 0 0 0 0 0 0 0 0 0 0
51221- 0 0 0 0 0 0 0 0 0 0 0 0
51222- 0 0 0 0 0 0 0 0 0 0 0 0
51223- 0 0 0 0 0 0 0 0 0 0 0 0
51224- 0 0 0 0 0 0 0 0 0 0 0 0
51225- 0 0 0 0 0 0 0 0 0 0 0 0
51226- 0 0 0 0 0 1 0 0 1 0 0 0
51227- 0 0 0 0 0 0 0 0 0 0 0 0
51228- 0 0 0 0 0 0 0 0 0 0 0 0
51229- 0 0 0 0 0 0 0 0 0 0 0 0
51230- 0 0 0 0 0 0 0 0 0 0 0 0
51231- 0 0 0 0 0 0 0 0 0 0 0 0
51232- 0 0 0 0 0 0 0 0 0 0 0 0
51233- 6 6 6 14 14 14 26 26 26 42 42 42
51234- 54 54 54 66 66 66 78 78 78 78 78 78
51235- 78 78 78 74 74 74 66 66 66 54 54 54
51236- 42 42 42 26 26 26 18 18 18 10 10 10
51237- 6 6 6 0 0 0 0 0 0 0 0 0
51238- 0 0 0 0 0 0 0 0 0 0 0 0
51239- 0 0 0 0 0 0 0 0 0 0 0 0
51240- 0 0 0 0 0 0 0 0 0 0 0 0
51241- 0 0 0 0 0 0 0 0 0 0 0 0
51242- 0 0 0 0 0 0 0 0 0 0 0 0
51243- 0 0 0 0 0 0 0 0 0 0 0 0
51244- 0 0 0 0 0 0 0 0 0 0 0 0
51245- 0 0 0 0 0 0 0 0 0 0 0 0
51246- 0 0 1 0 0 0 0 0 0 0 0 0
51247- 0 0 0 0 0 0 0 0 0 0 0 0
51248- 0 0 0 0 0 0 0 0 0 0 0 0
51249- 0 0 0 0 0 0 0 0 0 0 0 0
51250- 0 0 0 0 0 0 0 0 0 0 0 0
51251- 0 0 0 0 0 0 0 0 0 0 0 0
51252- 0 0 0 0 0 0 0 0 0 10 10 10
51253- 22 22 22 42 42 42 66 66 66 86 86 86
51254- 66 66 66 38 38 38 38 38 38 22 22 22
51255- 26 26 26 34 34 34 54 54 54 66 66 66
51256- 86 86 86 70 70 70 46 46 46 26 26 26
51257- 14 14 14 6 6 6 0 0 0 0 0 0
51258- 0 0 0 0 0 0 0 0 0 0 0 0
51259- 0 0 0 0 0 0 0 0 0 0 0 0
51260- 0 0 0 0 0 0 0 0 0 0 0 0
51261- 0 0 0 0 0 0 0 0 0 0 0 0
51262- 0 0 0 0 0 0 0 0 0 0 0 0
51263- 0 0 0 0 0 0 0 0 0 0 0 0
51264- 0 0 0 0 0 0 0 0 0 0 0 0
51265- 0 0 0 0 0 0 0 0 0 0 0 0
51266- 0 0 1 0 0 1 0 0 1 0 0 0
51267- 0 0 0 0 0 0 0 0 0 0 0 0
51268- 0 0 0 0 0 0 0 0 0 0 0 0
51269- 0 0 0 0 0 0 0 0 0 0 0 0
51270- 0 0 0 0 0 0 0 0 0 0 0 0
51271- 0 0 0 0 0 0 0 0 0 0 0 0
51272- 0 0 0 0 0 0 10 10 10 26 26 26
51273- 50 50 50 82 82 82 58 58 58 6 6 6
51274- 2 2 6 2 2 6 2 2 6 2 2 6
51275- 2 2 6 2 2 6 2 2 6 2 2 6
51276- 6 6 6 54 54 54 86 86 86 66 66 66
51277- 38 38 38 18 18 18 6 6 6 0 0 0
51278- 0 0 0 0 0 0 0 0 0 0 0 0
51279- 0 0 0 0 0 0 0 0 0 0 0 0
51280- 0 0 0 0 0 0 0 0 0 0 0 0
51281- 0 0 0 0 0 0 0 0 0 0 0 0
51282- 0 0 0 0 0 0 0 0 0 0 0 0
51283- 0 0 0 0 0 0 0 0 0 0 0 0
51284- 0 0 0 0 0 0 0 0 0 0 0 0
51285- 0 0 0 0 0 0 0 0 0 0 0 0
51286- 0 0 0 0 0 0 0 0 0 0 0 0
51287- 0 0 0 0 0 0 0 0 0 0 0 0
51288- 0 0 0 0 0 0 0 0 0 0 0 0
51289- 0 0 0 0 0 0 0 0 0 0 0 0
51290- 0 0 0 0 0 0 0 0 0 0 0 0
51291- 0 0 0 0 0 0 0 0 0 0 0 0
51292- 0 0 0 6 6 6 22 22 22 50 50 50
51293- 78 78 78 34 34 34 2 2 6 2 2 6
51294- 2 2 6 2 2 6 2 2 6 2 2 6
51295- 2 2 6 2 2 6 2 2 6 2 2 6
51296- 2 2 6 2 2 6 6 6 6 70 70 70
51297- 78 78 78 46 46 46 22 22 22 6 6 6
51298- 0 0 0 0 0 0 0 0 0 0 0 0
51299- 0 0 0 0 0 0 0 0 0 0 0 0
51300- 0 0 0 0 0 0 0 0 0 0 0 0
51301- 0 0 0 0 0 0 0 0 0 0 0 0
51302- 0 0 0 0 0 0 0 0 0 0 0 0
51303- 0 0 0 0 0 0 0 0 0 0 0 0
51304- 0 0 0 0 0 0 0 0 0 0 0 0
51305- 0 0 0 0 0 0 0 0 0 0 0 0
51306- 0 0 1 0 0 1 0 0 1 0 0 0
51307- 0 0 0 0 0 0 0 0 0 0 0 0
51308- 0 0 0 0 0 0 0 0 0 0 0 0
51309- 0 0 0 0 0 0 0 0 0 0 0 0
51310- 0 0 0 0 0 0 0 0 0 0 0 0
51311- 0 0 0 0 0 0 0 0 0 0 0 0
51312- 6 6 6 18 18 18 42 42 42 82 82 82
51313- 26 26 26 2 2 6 2 2 6 2 2 6
51314- 2 2 6 2 2 6 2 2 6 2 2 6
51315- 2 2 6 2 2 6 2 2 6 14 14 14
51316- 46 46 46 34 34 34 6 6 6 2 2 6
51317- 42 42 42 78 78 78 42 42 42 18 18 18
51318- 6 6 6 0 0 0 0 0 0 0 0 0
51319- 0 0 0 0 0 0 0 0 0 0 0 0
51320- 0 0 0 0 0 0 0 0 0 0 0 0
51321- 0 0 0 0 0 0 0 0 0 0 0 0
51322- 0 0 0 0 0 0 0 0 0 0 0 0
51323- 0 0 0 0 0 0 0 0 0 0 0 0
51324- 0 0 0 0 0 0 0 0 0 0 0 0
51325- 0 0 0 0 0 0 0 0 0 0 0 0
51326- 0 0 1 0 0 0 0 0 1 0 0 0
51327- 0 0 0 0 0 0 0 0 0 0 0 0
51328- 0 0 0 0 0 0 0 0 0 0 0 0
51329- 0 0 0 0 0 0 0 0 0 0 0 0
51330- 0 0 0 0 0 0 0 0 0 0 0 0
51331- 0 0 0 0 0 0 0 0 0 0 0 0
51332- 10 10 10 30 30 30 66 66 66 58 58 58
51333- 2 2 6 2 2 6 2 2 6 2 2 6
51334- 2 2 6 2 2 6 2 2 6 2 2 6
51335- 2 2 6 2 2 6 2 2 6 26 26 26
51336- 86 86 86 101 101 101 46 46 46 10 10 10
51337- 2 2 6 58 58 58 70 70 70 34 34 34
51338- 10 10 10 0 0 0 0 0 0 0 0 0
51339- 0 0 0 0 0 0 0 0 0 0 0 0
51340- 0 0 0 0 0 0 0 0 0 0 0 0
51341- 0 0 0 0 0 0 0 0 0 0 0 0
51342- 0 0 0 0 0 0 0 0 0 0 0 0
51343- 0 0 0 0 0 0 0 0 0 0 0 0
51344- 0 0 0 0 0 0 0 0 0 0 0 0
51345- 0 0 0 0 0 0 0 0 0 0 0 0
51346- 0 0 1 0 0 1 0 0 1 0 0 0
51347- 0 0 0 0 0 0 0 0 0 0 0 0
51348- 0 0 0 0 0 0 0 0 0 0 0 0
51349- 0 0 0 0 0 0 0 0 0 0 0 0
51350- 0 0 0 0 0 0 0 0 0 0 0 0
51351- 0 0 0 0 0 0 0 0 0 0 0 0
51352- 14 14 14 42 42 42 86 86 86 10 10 10
51353- 2 2 6 2 2 6 2 2 6 2 2 6
51354- 2 2 6 2 2 6 2 2 6 2 2 6
51355- 2 2 6 2 2 6 2 2 6 30 30 30
51356- 94 94 94 94 94 94 58 58 58 26 26 26
51357- 2 2 6 6 6 6 78 78 78 54 54 54
51358- 22 22 22 6 6 6 0 0 0 0 0 0
51359- 0 0 0 0 0 0 0 0 0 0 0 0
51360- 0 0 0 0 0 0 0 0 0 0 0 0
51361- 0 0 0 0 0 0 0 0 0 0 0 0
51362- 0 0 0 0 0 0 0 0 0 0 0 0
51363- 0 0 0 0 0 0 0 0 0 0 0 0
51364- 0 0 0 0 0 0 0 0 0 0 0 0
51365- 0 0 0 0 0 0 0 0 0 0 0 0
51366- 0 0 0 0 0 0 0 0 0 0 0 0
51367- 0 0 0 0 0 0 0 0 0 0 0 0
51368- 0 0 0 0 0 0 0 0 0 0 0 0
51369- 0 0 0 0 0 0 0 0 0 0 0 0
51370- 0 0 0 0 0 0 0 0 0 0 0 0
51371- 0 0 0 0 0 0 0 0 0 6 6 6
51372- 22 22 22 62 62 62 62 62 62 2 2 6
51373- 2 2 6 2 2 6 2 2 6 2 2 6
51374- 2 2 6 2 2 6 2 2 6 2 2 6
51375- 2 2 6 2 2 6 2 2 6 26 26 26
51376- 54 54 54 38 38 38 18 18 18 10 10 10
51377- 2 2 6 2 2 6 34 34 34 82 82 82
51378- 38 38 38 14 14 14 0 0 0 0 0 0
51379- 0 0 0 0 0 0 0 0 0 0 0 0
51380- 0 0 0 0 0 0 0 0 0 0 0 0
51381- 0 0 0 0 0 0 0 0 0 0 0 0
51382- 0 0 0 0 0 0 0 0 0 0 0 0
51383- 0 0 0 0 0 0 0 0 0 0 0 0
51384- 0 0 0 0 0 0 0 0 0 0 0 0
51385- 0 0 0 0 0 0 0 0 0 0 0 0
51386- 0 0 0 0 0 1 0 0 1 0 0 0
51387- 0 0 0 0 0 0 0 0 0 0 0 0
51388- 0 0 0 0 0 0 0 0 0 0 0 0
51389- 0 0 0 0 0 0 0 0 0 0 0 0
51390- 0 0 0 0 0 0 0 0 0 0 0 0
51391- 0 0 0 0 0 0 0 0 0 6 6 6
51392- 30 30 30 78 78 78 30 30 30 2 2 6
51393- 2 2 6 2 2 6 2 2 6 2 2 6
51394- 2 2 6 2 2 6 2 2 6 2 2 6
51395- 2 2 6 2 2 6 2 2 6 10 10 10
51396- 10 10 10 2 2 6 2 2 6 2 2 6
51397- 2 2 6 2 2 6 2 2 6 78 78 78
51398- 50 50 50 18 18 18 6 6 6 0 0 0
51399- 0 0 0 0 0 0 0 0 0 0 0 0
51400- 0 0 0 0 0 0 0 0 0 0 0 0
51401- 0 0 0 0 0 0 0 0 0 0 0 0
51402- 0 0 0 0 0 0 0 0 0 0 0 0
51403- 0 0 0 0 0 0 0 0 0 0 0 0
51404- 0 0 0 0 0 0 0 0 0 0 0 0
51405- 0 0 0 0 0 0 0 0 0 0 0 0
51406- 0 0 1 0 0 0 0 0 0 0 0 0
51407- 0 0 0 0 0 0 0 0 0 0 0 0
51408- 0 0 0 0 0 0 0 0 0 0 0 0
51409- 0 0 0 0 0 0 0 0 0 0 0 0
51410- 0 0 0 0 0 0 0 0 0 0 0 0
51411- 0 0 0 0 0 0 0 0 0 10 10 10
51412- 38 38 38 86 86 86 14 14 14 2 2 6
51413- 2 2 6 2 2 6 2 2 6 2 2 6
51414- 2 2 6 2 2 6 2 2 6 2 2 6
51415- 2 2 6 2 2 6 2 2 6 2 2 6
51416- 2 2 6 2 2 6 2 2 6 2 2 6
51417- 2 2 6 2 2 6 2 2 6 54 54 54
51418- 66 66 66 26 26 26 6 6 6 0 0 0
51419- 0 0 0 0 0 0 0 0 0 0 0 0
51420- 0 0 0 0 0 0 0 0 0 0 0 0
51421- 0 0 0 0 0 0 0 0 0 0 0 0
51422- 0 0 0 0 0 0 0 0 0 0 0 0
51423- 0 0 0 0 0 0 0 0 0 0 0 0
51424- 0 0 0 0 0 0 0 0 0 0 0 0
51425- 0 0 0 0 0 0 0 0 0 0 0 0
51426- 0 0 0 0 0 1 0 0 1 0 0 0
51427- 0 0 0 0 0 0 0 0 0 0 0 0
51428- 0 0 0 0 0 0 0 0 0 0 0 0
51429- 0 0 0 0 0 0 0 0 0 0 0 0
51430- 0 0 0 0 0 0 0 0 0 0 0 0
51431- 0 0 0 0 0 0 0 0 0 14 14 14
51432- 42 42 42 82 82 82 2 2 6 2 2 6
51433- 2 2 6 6 6 6 10 10 10 2 2 6
51434- 2 2 6 2 2 6 2 2 6 2 2 6
51435- 2 2 6 2 2 6 2 2 6 6 6 6
51436- 14 14 14 10 10 10 2 2 6 2 2 6
51437- 2 2 6 2 2 6 2 2 6 18 18 18
51438- 82 82 82 34 34 34 10 10 10 0 0 0
51439- 0 0 0 0 0 0 0 0 0 0 0 0
51440- 0 0 0 0 0 0 0 0 0 0 0 0
51441- 0 0 0 0 0 0 0 0 0 0 0 0
51442- 0 0 0 0 0 0 0 0 0 0 0 0
51443- 0 0 0 0 0 0 0 0 0 0 0 0
51444- 0 0 0 0 0 0 0 0 0 0 0 0
51445- 0 0 0 0 0 0 0 0 0 0 0 0
51446- 0 0 1 0 0 0 0 0 0 0 0 0
51447- 0 0 0 0 0 0 0 0 0 0 0 0
51448- 0 0 0 0 0 0 0 0 0 0 0 0
51449- 0 0 0 0 0 0 0 0 0 0 0 0
51450- 0 0 0 0 0 0 0 0 0 0 0 0
51451- 0 0 0 0 0 0 0 0 0 14 14 14
51452- 46 46 46 86 86 86 2 2 6 2 2 6
51453- 6 6 6 6 6 6 22 22 22 34 34 34
51454- 6 6 6 2 2 6 2 2 6 2 2 6
51455- 2 2 6 2 2 6 18 18 18 34 34 34
51456- 10 10 10 50 50 50 22 22 22 2 2 6
51457- 2 2 6 2 2 6 2 2 6 10 10 10
51458- 86 86 86 42 42 42 14 14 14 0 0 0
51459- 0 0 0 0 0 0 0 0 0 0 0 0
51460- 0 0 0 0 0 0 0 0 0 0 0 0
51461- 0 0 0 0 0 0 0 0 0 0 0 0
51462- 0 0 0 0 0 0 0 0 0 0 0 0
51463- 0 0 0 0 0 0 0 0 0 0 0 0
51464- 0 0 0 0 0 0 0 0 0 0 0 0
51465- 0 0 0 0 0 0 0 0 0 0 0 0
51466- 0 0 1 0 0 1 0 0 1 0 0 0
51467- 0 0 0 0 0 0 0 0 0 0 0 0
51468- 0 0 0 0 0 0 0 0 0 0 0 0
51469- 0 0 0 0 0 0 0 0 0 0 0 0
51470- 0 0 0 0 0 0 0 0 0 0 0 0
51471- 0 0 0 0 0 0 0 0 0 14 14 14
51472- 46 46 46 86 86 86 2 2 6 2 2 6
51473- 38 38 38 116 116 116 94 94 94 22 22 22
51474- 22 22 22 2 2 6 2 2 6 2 2 6
51475- 14 14 14 86 86 86 138 138 138 162 162 162
51476-154 154 154 38 38 38 26 26 26 6 6 6
51477- 2 2 6 2 2 6 2 2 6 2 2 6
51478- 86 86 86 46 46 46 14 14 14 0 0 0
51479- 0 0 0 0 0 0 0 0 0 0 0 0
51480- 0 0 0 0 0 0 0 0 0 0 0 0
51481- 0 0 0 0 0 0 0 0 0 0 0 0
51482- 0 0 0 0 0 0 0 0 0 0 0 0
51483- 0 0 0 0 0 0 0 0 0 0 0 0
51484- 0 0 0 0 0 0 0 0 0 0 0 0
51485- 0 0 0 0 0 0 0 0 0 0 0 0
51486- 0 0 0 0 0 0 0 0 0 0 0 0
51487- 0 0 0 0 0 0 0 0 0 0 0 0
51488- 0 0 0 0 0 0 0 0 0 0 0 0
51489- 0 0 0 0 0 0 0 0 0 0 0 0
51490- 0 0 0 0 0 0 0 0 0 0 0 0
51491- 0 0 0 0 0 0 0 0 0 14 14 14
51492- 46 46 46 86 86 86 2 2 6 14 14 14
51493-134 134 134 198 198 198 195 195 195 116 116 116
51494- 10 10 10 2 2 6 2 2 6 6 6 6
51495-101 98 89 187 187 187 210 210 210 218 218 218
51496-214 214 214 134 134 134 14 14 14 6 6 6
51497- 2 2 6 2 2 6 2 2 6 2 2 6
51498- 86 86 86 50 50 50 18 18 18 6 6 6
51499- 0 0 0 0 0 0 0 0 0 0 0 0
51500- 0 0 0 0 0 0 0 0 0 0 0 0
51501- 0 0 0 0 0 0 0 0 0 0 0 0
51502- 0 0 0 0 0 0 0 0 0 0 0 0
51503- 0 0 0 0 0 0 0 0 0 0 0 0
51504- 0 0 0 0 0 0 0 0 0 0 0 0
51505- 0 0 0 0 0 0 0 0 1 0 0 0
51506- 0 0 1 0 0 1 0 0 1 0 0 0
51507- 0 0 0 0 0 0 0 0 0 0 0 0
51508- 0 0 0 0 0 0 0 0 0 0 0 0
51509- 0 0 0 0 0 0 0 0 0 0 0 0
51510- 0 0 0 0 0 0 0 0 0 0 0 0
51511- 0 0 0 0 0 0 0 0 0 14 14 14
51512- 46 46 46 86 86 86 2 2 6 54 54 54
51513-218 218 218 195 195 195 226 226 226 246 246 246
51514- 58 58 58 2 2 6 2 2 6 30 30 30
51515-210 210 210 253 253 253 174 174 174 123 123 123
51516-221 221 221 234 234 234 74 74 74 2 2 6
51517- 2 2 6 2 2 6 2 2 6 2 2 6
51518- 70 70 70 58 58 58 22 22 22 6 6 6
51519- 0 0 0 0 0 0 0 0 0 0 0 0
51520- 0 0 0 0 0 0 0 0 0 0 0 0
51521- 0 0 0 0 0 0 0 0 0 0 0 0
51522- 0 0 0 0 0 0 0 0 0 0 0 0
51523- 0 0 0 0 0 0 0 0 0 0 0 0
51524- 0 0 0 0 0 0 0 0 0 0 0 0
51525- 0 0 0 0 0 0 0 0 0 0 0 0
51526- 0 0 0 0 0 0 0 0 0 0 0 0
51527- 0 0 0 0 0 0 0 0 0 0 0 0
51528- 0 0 0 0 0 0 0 0 0 0 0 0
51529- 0 0 0 0 0 0 0 0 0 0 0 0
51530- 0 0 0 0 0 0 0 0 0 0 0 0
51531- 0 0 0 0 0 0 0 0 0 14 14 14
51532- 46 46 46 82 82 82 2 2 6 106 106 106
51533-170 170 170 26 26 26 86 86 86 226 226 226
51534-123 123 123 10 10 10 14 14 14 46 46 46
51535-231 231 231 190 190 190 6 6 6 70 70 70
51536- 90 90 90 238 238 238 158 158 158 2 2 6
51537- 2 2 6 2 2 6 2 2 6 2 2 6
51538- 70 70 70 58 58 58 22 22 22 6 6 6
51539- 0 0 0 0 0 0 0 0 0 0 0 0
51540- 0 0 0 0 0 0 0 0 0 0 0 0
51541- 0 0 0 0 0 0 0 0 0 0 0 0
51542- 0 0 0 0 0 0 0 0 0 0 0 0
51543- 0 0 0 0 0 0 0 0 0 0 0 0
51544- 0 0 0 0 0 0 0 0 0 0 0 0
51545- 0 0 0 0 0 0 0 0 1 0 0 0
51546- 0 0 1 0 0 1 0 0 1 0 0 0
51547- 0 0 0 0 0 0 0 0 0 0 0 0
51548- 0 0 0 0 0 0 0 0 0 0 0 0
51549- 0 0 0 0 0 0 0 0 0 0 0 0
51550- 0 0 0 0 0 0 0 0 0 0 0 0
51551- 0 0 0 0 0 0 0 0 0 14 14 14
51552- 42 42 42 86 86 86 6 6 6 116 116 116
51553-106 106 106 6 6 6 70 70 70 149 149 149
51554-128 128 128 18 18 18 38 38 38 54 54 54
51555-221 221 221 106 106 106 2 2 6 14 14 14
51556- 46 46 46 190 190 190 198 198 198 2 2 6
51557- 2 2 6 2 2 6 2 2 6 2 2 6
51558- 74 74 74 62 62 62 22 22 22 6 6 6
51559- 0 0 0 0 0 0 0 0 0 0 0 0
51560- 0 0 0 0 0 0 0 0 0 0 0 0
51561- 0 0 0 0 0 0 0 0 0 0 0 0
51562- 0 0 0 0 0 0 0 0 0 0 0 0
51563- 0 0 0 0 0 0 0 0 0 0 0 0
51564- 0 0 0 0 0 0 0 0 0 0 0 0
51565- 0 0 0 0 0 0 0 0 1 0 0 0
51566- 0 0 1 0 0 0 0 0 1 0 0 0
51567- 0 0 0 0 0 0 0 0 0 0 0 0
51568- 0 0 0 0 0 0 0 0 0 0 0 0
51569- 0 0 0 0 0 0 0 0 0 0 0 0
51570- 0 0 0 0 0 0 0 0 0 0 0 0
51571- 0 0 0 0 0 0 0 0 0 14 14 14
51572- 42 42 42 94 94 94 14 14 14 101 101 101
51573-128 128 128 2 2 6 18 18 18 116 116 116
51574-118 98 46 121 92 8 121 92 8 98 78 10
51575-162 162 162 106 106 106 2 2 6 2 2 6
51576- 2 2 6 195 195 195 195 195 195 6 6 6
51577- 2 2 6 2 2 6 2 2 6 2 2 6
51578- 74 74 74 62 62 62 22 22 22 6 6 6
51579- 0 0 0 0 0 0 0 0 0 0 0 0
51580- 0 0 0 0 0 0 0 0 0 0 0 0
51581- 0 0 0 0 0 0 0 0 0 0 0 0
51582- 0 0 0 0 0 0 0 0 0 0 0 0
51583- 0 0 0 0 0 0 0 0 0 0 0 0
51584- 0 0 0 0 0 0 0 0 0 0 0 0
51585- 0 0 0 0 0 0 0 0 1 0 0 1
51586- 0 0 1 0 0 0 0 0 1 0 0 0
51587- 0 0 0 0 0 0 0 0 0 0 0 0
51588- 0 0 0 0 0 0 0 0 0 0 0 0
51589- 0 0 0 0 0 0 0 0 0 0 0 0
51590- 0 0 0 0 0 0 0 0 0 0 0 0
51591- 0 0 0 0 0 0 0 0 0 10 10 10
51592- 38 38 38 90 90 90 14 14 14 58 58 58
51593-210 210 210 26 26 26 54 38 6 154 114 10
51594-226 170 11 236 186 11 225 175 15 184 144 12
51595-215 174 15 175 146 61 37 26 9 2 2 6
51596- 70 70 70 246 246 246 138 138 138 2 2 6
51597- 2 2 6 2 2 6 2 2 6 2 2 6
51598- 70 70 70 66 66 66 26 26 26 6 6 6
51599- 0 0 0 0 0 0 0 0 0 0 0 0
51600- 0 0 0 0 0 0 0 0 0 0 0 0
51601- 0 0 0 0 0 0 0 0 0 0 0 0
51602- 0 0 0 0 0 0 0 0 0 0 0 0
51603- 0 0 0 0 0 0 0 0 0 0 0 0
51604- 0 0 0 0 0 0 0 0 0 0 0 0
51605- 0 0 0 0 0 0 0 0 0 0 0 0
51606- 0 0 0 0 0 0 0 0 0 0 0 0
51607- 0 0 0 0 0 0 0 0 0 0 0 0
51608- 0 0 0 0 0 0 0 0 0 0 0 0
51609- 0 0 0 0 0 0 0 0 0 0 0 0
51610- 0 0 0 0 0 0 0 0 0 0 0 0
51611- 0 0 0 0 0 0 0 0 0 10 10 10
51612- 38 38 38 86 86 86 14 14 14 10 10 10
51613-195 195 195 188 164 115 192 133 9 225 175 15
51614-239 182 13 234 190 10 232 195 16 232 200 30
51615-245 207 45 241 208 19 232 195 16 184 144 12
51616-218 194 134 211 206 186 42 42 42 2 2 6
51617- 2 2 6 2 2 6 2 2 6 2 2 6
51618- 50 50 50 74 74 74 30 30 30 6 6 6
51619- 0 0 0 0 0 0 0 0 0 0 0 0
51620- 0 0 0 0 0 0 0 0 0 0 0 0
51621- 0 0 0 0 0 0 0 0 0 0 0 0
51622- 0 0 0 0 0 0 0 0 0 0 0 0
51623- 0 0 0 0 0 0 0 0 0 0 0 0
51624- 0 0 0 0 0 0 0 0 0 0 0 0
51625- 0 0 0 0 0 0 0 0 0 0 0 0
51626- 0 0 0 0 0 0 0 0 0 0 0 0
51627- 0 0 0 0 0 0 0 0 0 0 0 0
51628- 0 0 0 0 0 0 0 0 0 0 0 0
51629- 0 0 0 0 0 0 0 0 0 0 0 0
51630- 0 0 0 0 0 0 0 0 0 0 0 0
51631- 0 0 0 0 0 0 0 0 0 10 10 10
51632- 34 34 34 86 86 86 14 14 14 2 2 6
51633-121 87 25 192 133 9 219 162 10 239 182 13
51634-236 186 11 232 195 16 241 208 19 244 214 54
51635-246 218 60 246 218 38 246 215 20 241 208 19
51636-241 208 19 226 184 13 121 87 25 2 2 6
51637- 2 2 6 2 2 6 2 2 6 2 2 6
51638- 50 50 50 82 82 82 34 34 34 10 10 10
51639- 0 0 0 0 0 0 0 0 0 0 0 0
51640- 0 0 0 0 0 0 0 0 0 0 0 0
51641- 0 0 0 0 0 0 0 0 0 0 0 0
51642- 0 0 0 0 0 0 0 0 0 0 0 0
51643- 0 0 0 0 0 0 0 0 0 0 0 0
51644- 0 0 0 0 0 0 0 0 0 0 0 0
51645- 0 0 0 0 0 0 0 0 0 0 0 0
51646- 0 0 0 0 0 0 0 0 0 0 0 0
51647- 0 0 0 0 0 0 0 0 0 0 0 0
51648- 0 0 0 0 0 0 0 0 0 0 0 0
51649- 0 0 0 0 0 0 0 0 0 0 0 0
51650- 0 0 0 0 0 0 0 0 0 0 0 0
51651- 0 0 0 0 0 0 0 0 0 10 10 10
51652- 34 34 34 82 82 82 30 30 30 61 42 6
51653-180 123 7 206 145 10 230 174 11 239 182 13
51654-234 190 10 238 202 15 241 208 19 246 218 74
51655-246 218 38 246 215 20 246 215 20 246 215 20
51656-226 184 13 215 174 15 184 144 12 6 6 6
51657- 2 2 6 2 2 6 2 2 6 2 2 6
51658- 26 26 26 94 94 94 42 42 42 14 14 14
51659- 0 0 0 0 0 0 0 0 0 0 0 0
51660- 0 0 0 0 0 0 0 0 0 0 0 0
51661- 0 0 0 0 0 0 0 0 0 0 0 0
51662- 0 0 0 0 0 0 0 0 0 0 0 0
51663- 0 0 0 0 0 0 0 0 0 0 0 0
51664- 0 0 0 0 0 0 0 0 0 0 0 0
51665- 0 0 0 0 0 0 0 0 0 0 0 0
51666- 0 0 0 0 0 0 0 0 0 0 0 0
51667- 0 0 0 0 0 0 0 0 0 0 0 0
51668- 0 0 0 0 0 0 0 0 0 0 0 0
51669- 0 0 0 0 0 0 0 0 0 0 0 0
51670- 0 0 0 0 0 0 0 0 0 0 0 0
51671- 0 0 0 0 0 0 0 0 0 10 10 10
51672- 30 30 30 78 78 78 50 50 50 104 69 6
51673-192 133 9 216 158 10 236 178 12 236 186 11
51674-232 195 16 241 208 19 244 214 54 245 215 43
51675-246 215 20 246 215 20 241 208 19 198 155 10
51676-200 144 11 216 158 10 156 118 10 2 2 6
51677- 2 2 6 2 2 6 2 2 6 2 2 6
51678- 6 6 6 90 90 90 54 54 54 18 18 18
51679- 6 6 6 0 0 0 0 0 0 0 0 0
51680- 0 0 0 0 0 0 0 0 0 0 0 0
51681- 0 0 0 0 0 0 0 0 0 0 0 0
51682- 0 0 0 0 0 0 0 0 0 0 0 0
51683- 0 0 0 0 0 0 0 0 0 0 0 0
51684- 0 0 0 0 0 0 0 0 0 0 0 0
51685- 0 0 0 0 0 0 0 0 0 0 0 0
51686- 0 0 0 0 0 0 0 0 0 0 0 0
51687- 0 0 0 0 0 0 0 0 0 0 0 0
51688- 0 0 0 0 0 0 0 0 0 0 0 0
51689- 0 0 0 0 0 0 0 0 0 0 0 0
51690- 0 0 0 0 0 0 0 0 0 0 0 0
51691- 0 0 0 0 0 0 0 0 0 10 10 10
51692- 30 30 30 78 78 78 46 46 46 22 22 22
51693-137 92 6 210 162 10 239 182 13 238 190 10
51694-238 202 15 241 208 19 246 215 20 246 215 20
51695-241 208 19 203 166 17 185 133 11 210 150 10
51696-216 158 10 210 150 10 102 78 10 2 2 6
51697- 6 6 6 54 54 54 14 14 14 2 2 6
51698- 2 2 6 62 62 62 74 74 74 30 30 30
51699- 10 10 10 0 0 0 0 0 0 0 0 0
51700- 0 0 0 0 0 0 0 0 0 0 0 0
51701- 0 0 0 0 0 0 0 0 0 0 0 0
51702- 0 0 0 0 0 0 0 0 0 0 0 0
51703- 0 0 0 0 0 0 0 0 0 0 0 0
51704- 0 0 0 0 0 0 0 0 0 0 0 0
51705- 0 0 0 0 0 0 0 0 0 0 0 0
51706- 0 0 0 0 0 0 0 0 0 0 0 0
51707- 0 0 0 0 0 0 0 0 0 0 0 0
51708- 0 0 0 0 0 0 0 0 0 0 0 0
51709- 0 0 0 0 0 0 0 0 0 0 0 0
51710- 0 0 0 0 0 0 0 0 0 0 0 0
51711- 0 0 0 0 0 0 0 0 0 10 10 10
51712- 34 34 34 78 78 78 50 50 50 6 6 6
51713- 94 70 30 139 102 15 190 146 13 226 184 13
51714-232 200 30 232 195 16 215 174 15 190 146 13
51715-168 122 10 192 133 9 210 150 10 213 154 11
51716-202 150 34 182 157 106 101 98 89 2 2 6
51717- 2 2 6 78 78 78 116 116 116 58 58 58
51718- 2 2 6 22 22 22 90 90 90 46 46 46
51719- 18 18 18 6 6 6 0 0 0 0 0 0
51720- 0 0 0 0 0 0 0 0 0 0 0 0
51721- 0 0 0 0 0 0 0 0 0 0 0 0
51722- 0 0 0 0 0 0 0 0 0 0 0 0
51723- 0 0 0 0 0 0 0 0 0 0 0 0
51724- 0 0 0 0 0 0 0 0 0 0 0 0
51725- 0 0 0 0 0 0 0 0 0 0 0 0
51726- 0 0 0 0 0 0 0 0 0 0 0 0
51727- 0 0 0 0 0 0 0 0 0 0 0 0
51728- 0 0 0 0 0 0 0 0 0 0 0 0
51729- 0 0 0 0 0 0 0 0 0 0 0 0
51730- 0 0 0 0 0 0 0 0 0 0 0 0
51731- 0 0 0 0 0 0 0 0 0 10 10 10
51732- 38 38 38 86 86 86 50 50 50 6 6 6
51733-128 128 128 174 154 114 156 107 11 168 122 10
51734-198 155 10 184 144 12 197 138 11 200 144 11
51735-206 145 10 206 145 10 197 138 11 188 164 115
51736-195 195 195 198 198 198 174 174 174 14 14 14
51737- 2 2 6 22 22 22 116 116 116 116 116 116
51738- 22 22 22 2 2 6 74 74 74 70 70 70
51739- 30 30 30 10 10 10 0 0 0 0 0 0
51740- 0 0 0 0 0 0 0 0 0 0 0 0
51741- 0 0 0 0 0 0 0 0 0 0 0 0
51742- 0 0 0 0 0 0 0 0 0 0 0 0
51743- 0 0 0 0 0 0 0 0 0 0 0 0
51744- 0 0 0 0 0 0 0 0 0 0 0 0
51745- 0 0 0 0 0 0 0 0 0 0 0 0
51746- 0 0 0 0 0 0 0 0 0 0 0 0
51747- 0 0 0 0 0 0 0 0 0 0 0 0
51748- 0 0 0 0 0 0 0 0 0 0 0 0
51749- 0 0 0 0 0 0 0 0 0 0 0 0
51750- 0 0 0 0 0 0 0 0 0 0 0 0
51751- 0 0 0 0 0 0 6 6 6 18 18 18
51752- 50 50 50 101 101 101 26 26 26 10 10 10
51753-138 138 138 190 190 190 174 154 114 156 107 11
51754-197 138 11 200 144 11 197 138 11 192 133 9
51755-180 123 7 190 142 34 190 178 144 187 187 187
51756-202 202 202 221 221 221 214 214 214 66 66 66
51757- 2 2 6 2 2 6 50 50 50 62 62 62
51758- 6 6 6 2 2 6 10 10 10 90 90 90
51759- 50 50 50 18 18 18 6 6 6 0 0 0
51760- 0 0 0 0 0 0 0 0 0 0 0 0
51761- 0 0 0 0 0 0 0 0 0 0 0 0
51762- 0 0 0 0 0 0 0 0 0 0 0 0
51763- 0 0 0 0 0 0 0 0 0 0 0 0
51764- 0 0 0 0 0 0 0 0 0 0 0 0
51765- 0 0 0 0 0 0 0 0 0 0 0 0
51766- 0 0 0 0 0 0 0 0 0 0 0 0
51767- 0 0 0 0 0 0 0 0 0 0 0 0
51768- 0 0 0 0 0 0 0 0 0 0 0 0
51769- 0 0 0 0 0 0 0 0 0 0 0 0
51770- 0 0 0 0 0 0 0 0 0 0 0 0
51771- 0 0 0 0 0 0 10 10 10 34 34 34
51772- 74 74 74 74 74 74 2 2 6 6 6 6
51773-144 144 144 198 198 198 190 190 190 178 166 146
51774-154 121 60 156 107 11 156 107 11 168 124 44
51775-174 154 114 187 187 187 190 190 190 210 210 210
51776-246 246 246 253 253 253 253 253 253 182 182 182
51777- 6 6 6 2 2 6 2 2 6 2 2 6
51778- 2 2 6 2 2 6 2 2 6 62 62 62
51779- 74 74 74 34 34 34 14 14 14 0 0 0
51780- 0 0 0 0 0 0 0 0 0 0 0 0
51781- 0 0 0 0 0 0 0 0 0 0 0 0
51782- 0 0 0 0 0 0 0 0 0 0 0 0
51783- 0 0 0 0 0 0 0 0 0 0 0 0
51784- 0 0 0 0 0 0 0 0 0 0 0 0
51785- 0 0 0 0 0 0 0 0 0 0 0 0
51786- 0 0 0 0 0 0 0 0 0 0 0 0
51787- 0 0 0 0 0 0 0 0 0 0 0 0
51788- 0 0 0 0 0 0 0 0 0 0 0 0
51789- 0 0 0 0 0 0 0 0 0 0 0 0
51790- 0 0 0 0 0 0 0 0 0 0 0 0
51791- 0 0 0 10 10 10 22 22 22 54 54 54
51792- 94 94 94 18 18 18 2 2 6 46 46 46
51793-234 234 234 221 221 221 190 190 190 190 190 190
51794-190 190 190 187 187 187 187 187 187 190 190 190
51795-190 190 190 195 195 195 214 214 214 242 242 242
51796-253 253 253 253 253 253 253 253 253 253 253 253
51797- 82 82 82 2 2 6 2 2 6 2 2 6
51798- 2 2 6 2 2 6 2 2 6 14 14 14
51799- 86 86 86 54 54 54 22 22 22 6 6 6
51800- 0 0 0 0 0 0 0 0 0 0 0 0
51801- 0 0 0 0 0 0 0 0 0 0 0 0
51802- 0 0 0 0 0 0 0 0 0 0 0 0
51803- 0 0 0 0 0 0 0 0 0 0 0 0
51804- 0 0 0 0 0 0 0 0 0 0 0 0
51805- 0 0 0 0 0 0 0 0 0 0 0 0
51806- 0 0 0 0 0 0 0 0 0 0 0 0
51807- 0 0 0 0 0 0 0 0 0 0 0 0
51808- 0 0 0 0 0 0 0 0 0 0 0 0
51809- 0 0 0 0 0 0 0 0 0 0 0 0
51810- 0 0 0 0 0 0 0 0 0 0 0 0
51811- 6 6 6 18 18 18 46 46 46 90 90 90
51812- 46 46 46 18 18 18 6 6 6 182 182 182
51813-253 253 253 246 246 246 206 206 206 190 190 190
51814-190 190 190 190 190 190 190 190 190 190 190 190
51815-206 206 206 231 231 231 250 250 250 253 253 253
51816-253 253 253 253 253 253 253 253 253 253 253 253
51817-202 202 202 14 14 14 2 2 6 2 2 6
51818- 2 2 6 2 2 6 2 2 6 2 2 6
51819- 42 42 42 86 86 86 42 42 42 18 18 18
51820- 6 6 6 0 0 0 0 0 0 0 0 0
51821- 0 0 0 0 0 0 0 0 0 0 0 0
51822- 0 0 0 0 0 0 0 0 0 0 0 0
51823- 0 0 0 0 0 0 0 0 0 0 0 0
51824- 0 0 0 0 0 0 0 0 0 0 0 0
51825- 0 0 0 0 0 0 0 0 0 0 0 0
51826- 0 0 0 0 0 0 0 0 0 0 0 0
51827- 0 0 0 0 0 0 0 0 0 0 0 0
51828- 0 0 0 0 0 0 0 0 0 0 0 0
51829- 0 0 0 0 0 0 0 0 0 0 0 0
51830- 0 0 0 0 0 0 0 0 0 6 6 6
51831- 14 14 14 38 38 38 74 74 74 66 66 66
51832- 2 2 6 6 6 6 90 90 90 250 250 250
51833-253 253 253 253 253 253 238 238 238 198 198 198
51834-190 190 190 190 190 190 195 195 195 221 221 221
51835-246 246 246 253 253 253 253 253 253 253 253 253
51836-253 253 253 253 253 253 253 253 253 253 253 253
51837-253 253 253 82 82 82 2 2 6 2 2 6
51838- 2 2 6 2 2 6 2 2 6 2 2 6
51839- 2 2 6 78 78 78 70 70 70 34 34 34
51840- 14 14 14 6 6 6 0 0 0 0 0 0
51841- 0 0 0 0 0 0 0 0 0 0 0 0
51842- 0 0 0 0 0 0 0 0 0 0 0 0
51843- 0 0 0 0 0 0 0 0 0 0 0 0
51844- 0 0 0 0 0 0 0 0 0 0 0 0
51845- 0 0 0 0 0 0 0 0 0 0 0 0
51846- 0 0 0 0 0 0 0 0 0 0 0 0
51847- 0 0 0 0 0 0 0 0 0 0 0 0
51848- 0 0 0 0 0 0 0 0 0 0 0 0
51849- 0 0 0 0 0 0 0 0 0 0 0 0
51850- 0 0 0 0 0 0 0 0 0 14 14 14
51851- 34 34 34 66 66 66 78 78 78 6 6 6
51852- 2 2 6 18 18 18 218 218 218 253 253 253
51853-253 253 253 253 253 253 253 253 253 246 246 246
51854-226 226 226 231 231 231 246 246 246 253 253 253
51855-253 253 253 253 253 253 253 253 253 253 253 253
51856-253 253 253 253 253 253 253 253 253 253 253 253
51857-253 253 253 178 178 178 2 2 6 2 2 6
51858- 2 2 6 2 2 6 2 2 6 2 2 6
51859- 2 2 6 18 18 18 90 90 90 62 62 62
51860- 30 30 30 10 10 10 0 0 0 0 0 0
51861- 0 0 0 0 0 0 0 0 0 0 0 0
51862- 0 0 0 0 0 0 0 0 0 0 0 0
51863- 0 0 0 0 0 0 0 0 0 0 0 0
51864- 0 0 0 0 0 0 0 0 0 0 0 0
51865- 0 0 0 0 0 0 0 0 0 0 0 0
51866- 0 0 0 0 0 0 0 0 0 0 0 0
51867- 0 0 0 0 0 0 0 0 0 0 0 0
51868- 0 0 0 0 0 0 0 0 0 0 0 0
51869- 0 0 0 0 0 0 0 0 0 0 0 0
51870- 0 0 0 0 0 0 10 10 10 26 26 26
51871- 58 58 58 90 90 90 18 18 18 2 2 6
51872- 2 2 6 110 110 110 253 253 253 253 253 253
51873-253 253 253 253 253 253 253 253 253 253 253 253
51874-250 250 250 253 253 253 253 253 253 253 253 253
51875-253 253 253 253 253 253 253 253 253 253 253 253
51876-253 253 253 253 253 253 253 253 253 253 253 253
51877-253 253 253 231 231 231 18 18 18 2 2 6
51878- 2 2 6 2 2 6 2 2 6 2 2 6
51879- 2 2 6 2 2 6 18 18 18 94 94 94
51880- 54 54 54 26 26 26 10 10 10 0 0 0
51881- 0 0 0 0 0 0 0 0 0 0 0 0
51882- 0 0 0 0 0 0 0 0 0 0 0 0
51883- 0 0 0 0 0 0 0 0 0 0 0 0
51884- 0 0 0 0 0 0 0 0 0 0 0 0
51885- 0 0 0 0 0 0 0 0 0 0 0 0
51886- 0 0 0 0 0 0 0 0 0 0 0 0
51887- 0 0 0 0 0 0 0 0 0 0 0 0
51888- 0 0 0 0 0 0 0 0 0 0 0 0
51889- 0 0 0 0 0 0 0 0 0 0 0 0
51890- 0 0 0 6 6 6 22 22 22 50 50 50
51891- 90 90 90 26 26 26 2 2 6 2 2 6
51892- 14 14 14 195 195 195 250 250 250 253 253 253
51893-253 253 253 253 253 253 253 253 253 253 253 253
51894-253 253 253 253 253 253 253 253 253 253 253 253
51895-253 253 253 253 253 253 253 253 253 253 253 253
51896-253 253 253 253 253 253 253 253 253 253 253 253
51897-250 250 250 242 242 242 54 54 54 2 2 6
51898- 2 2 6 2 2 6 2 2 6 2 2 6
51899- 2 2 6 2 2 6 2 2 6 38 38 38
51900- 86 86 86 50 50 50 22 22 22 6 6 6
51901- 0 0 0 0 0 0 0 0 0 0 0 0
51902- 0 0 0 0 0 0 0 0 0 0 0 0
51903- 0 0 0 0 0 0 0 0 0 0 0 0
51904- 0 0 0 0 0 0 0 0 0 0 0 0
51905- 0 0 0 0 0 0 0 0 0 0 0 0
51906- 0 0 0 0 0 0 0 0 0 0 0 0
51907- 0 0 0 0 0 0 0 0 0 0 0 0
51908- 0 0 0 0 0 0 0 0 0 0 0 0
51909- 0 0 0 0 0 0 0 0 0 0 0 0
51910- 6 6 6 14 14 14 38 38 38 82 82 82
51911- 34 34 34 2 2 6 2 2 6 2 2 6
51912- 42 42 42 195 195 195 246 246 246 253 253 253
51913-253 253 253 253 253 253 253 253 253 250 250 250
51914-242 242 242 242 242 242 250 250 250 253 253 253
51915-253 253 253 253 253 253 253 253 253 253 253 253
51916-253 253 253 250 250 250 246 246 246 238 238 238
51917-226 226 226 231 231 231 101 101 101 6 6 6
51918- 2 2 6 2 2 6 2 2 6 2 2 6
51919- 2 2 6 2 2 6 2 2 6 2 2 6
51920- 38 38 38 82 82 82 42 42 42 14 14 14
51921- 6 6 6 0 0 0 0 0 0 0 0 0
51922- 0 0 0 0 0 0 0 0 0 0 0 0
51923- 0 0 0 0 0 0 0 0 0 0 0 0
51924- 0 0 0 0 0 0 0 0 0 0 0 0
51925- 0 0 0 0 0 0 0 0 0 0 0 0
51926- 0 0 0 0 0 0 0 0 0 0 0 0
51927- 0 0 0 0 0 0 0 0 0 0 0 0
51928- 0 0 0 0 0 0 0 0 0 0 0 0
51929- 0 0 0 0 0 0 0 0 0 0 0 0
51930- 10 10 10 26 26 26 62 62 62 66 66 66
51931- 2 2 6 2 2 6 2 2 6 6 6 6
51932- 70 70 70 170 170 170 206 206 206 234 234 234
51933-246 246 246 250 250 250 250 250 250 238 238 238
51934-226 226 226 231 231 231 238 238 238 250 250 250
51935-250 250 250 250 250 250 246 246 246 231 231 231
51936-214 214 214 206 206 206 202 202 202 202 202 202
51937-198 198 198 202 202 202 182 182 182 18 18 18
51938- 2 2 6 2 2 6 2 2 6 2 2 6
51939- 2 2 6 2 2 6 2 2 6 2 2 6
51940- 2 2 6 62 62 62 66 66 66 30 30 30
51941- 10 10 10 0 0 0 0 0 0 0 0 0
51942- 0 0 0 0 0 0 0 0 0 0 0 0
51943- 0 0 0 0 0 0 0 0 0 0 0 0
51944- 0 0 0 0 0 0 0 0 0 0 0 0
51945- 0 0 0 0 0 0 0 0 0 0 0 0
51946- 0 0 0 0 0 0 0 0 0 0 0 0
51947- 0 0 0 0 0 0 0 0 0 0 0 0
51948- 0 0 0 0 0 0 0 0 0 0 0 0
51949- 0 0 0 0 0 0 0 0 0 0 0 0
51950- 14 14 14 42 42 42 82 82 82 18 18 18
51951- 2 2 6 2 2 6 2 2 6 10 10 10
51952- 94 94 94 182 182 182 218 218 218 242 242 242
51953-250 250 250 253 253 253 253 253 253 250 250 250
51954-234 234 234 253 253 253 253 253 253 253 253 253
51955-253 253 253 253 253 253 253 253 253 246 246 246
51956-238 238 238 226 226 226 210 210 210 202 202 202
51957-195 195 195 195 195 195 210 210 210 158 158 158
51958- 6 6 6 14 14 14 50 50 50 14 14 14
51959- 2 2 6 2 2 6 2 2 6 2 2 6
51960- 2 2 6 6 6 6 86 86 86 46 46 46
51961- 18 18 18 6 6 6 0 0 0 0 0 0
51962- 0 0 0 0 0 0 0 0 0 0 0 0
51963- 0 0 0 0 0 0 0 0 0 0 0 0
51964- 0 0 0 0 0 0 0 0 0 0 0 0
51965- 0 0 0 0 0 0 0 0 0 0 0 0
51966- 0 0 0 0 0 0 0 0 0 0 0 0
51967- 0 0 0 0 0 0 0 0 0 0 0 0
51968- 0 0 0 0 0 0 0 0 0 0 0 0
51969- 0 0 0 0 0 0 0 0 0 6 6 6
51970- 22 22 22 54 54 54 70 70 70 2 2 6
51971- 2 2 6 10 10 10 2 2 6 22 22 22
51972-166 166 166 231 231 231 250 250 250 253 253 253
51973-253 253 253 253 253 253 253 253 253 250 250 250
51974-242 242 242 253 253 253 253 253 253 253 253 253
51975-253 253 253 253 253 253 253 253 253 253 253 253
51976-253 253 253 253 253 253 253 253 253 246 246 246
51977-231 231 231 206 206 206 198 198 198 226 226 226
51978- 94 94 94 2 2 6 6 6 6 38 38 38
51979- 30 30 30 2 2 6 2 2 6 2 2 6
51980- 2 2 6 2 2 6 62 62 62 66 66 66
51981- 26 26 26 10 10 10 0 0 0 0 0 0
51982- 0 0 0 0 0 0 0 0 0 0 0 0
51983- 0 0 0 0 0 0 0 0 0 0 0 0
51984- 0 0 0 0 0 0 0 0 0 0 0 0
51985- 0 0 0 0 0 0 0 0 0 0 0 0
51986- 0 0 0 0 0 0 0 0 0 0 0 0
51987- 0 0 0 0 0 0 0 0 0 0 0 0
51988- 0 0 0 0 0 0 0 0 0 0 0 0
51989- 0 0 0 0 0 0 0 0 0 10 10 10
51990- 30 30 30 74 74 74 50 50 50 2 2 6
51991- 26 26 26 26 26 26 2 2 6 106 106 106
51992-238 238 238 253 253 253 253 253 253 253 253 253
51993-253 253 253 253 253 253 253 253 253 253 253 253
51994-253 253 253 253 253 253 253 253 253 253 253 253
51995-253 253 253 253 253 253 253 253 253 253 253 253
51996-253 253 253 253 253 253 253 253 253 253 253 253
51997-253 253 253 246 246 246 218 218 218 202 202 202
51998-210 210 210 14 14 14 2 2 6 2 2 6
51999- 30 30 30 22 22 22 2 2 6 2 2 6
52000- 2 2 6 2 2 6 18 18 18 86 86 86
52001- 42 42 42 14 14 14 0 0 0 0 0 0
52002- 0 0 0 0 0 0 0 0 0 0 0 0
52003- 0 0 0 0 0 0 0 0 0 0 0 0
52004- 0 0 0 0 0 0 0 0 0 0 0 0
52005- 0 0 0 0 0 0 0 0 0 0 0 0
52006- 0 0 0 0 0 0 0 0 0 0 0 0
52007- 0 0 0 0 0 0 0 0 0 0 0 0
52008- 0 0 0 0 0 0 0 0 0 0 0 0
52009- 0 0 0 0 0 0 0 0 0 14 14 14
52010- 42 42 42 90 90 90 22 22 22 2 2 6
52011- 42 42 42 2 2 6 18 18 18 218 218 218
52012-253 253 253 253 253 253 253 253 253 253 253 253
52013-253 253 253 253 253 253 253 253 253 253 253 253
52014-253 253 253 253 253 253 253 253 253 253 253 253
52015-253 253 253 253 253 253 253 253 253 253 253 253
52016-253 253 253 253 253 253 253 253 253 253 253 253
52017-253 253 253 253 253 253 250 250 250 221 221 221
52018-218 218 218 101 101 101 2 2 6 14 14 14
52019- 18 18 18 38 38 38 10 10 10 2 2 6
52020- 2 2 6 2 2 6 2 2 6 78 78 78
52021- 58 58 58 22 22 22 6 6 6 0 0 0
52022- 0 0 0 0 0 0 0 0 0 0 0 0
52023- 0 0 0 0 0 0 0 0 0 0 0 0
52024- 0 0 0 0 0 0 0 0 0 0 0 0
52025- 0 0 0 0 0 0 0 0 0 0 0 0
52026- 0 0 0 0 0 0 0 0 0 0 0 0
52027- 0 0 0 0 0 0 0 0 0 0 0 0
52028- 0 0 0 0 0 0 0 0 0 0 0 0
52029- 0 0 0 0 0 0 6 6 6 18 18 18
52030- 54 54 54 82 82 82 2 2 6 26 26 26
52031- 22 22 22 2 2 6 123 123 123 253 253 253
52032-253 253 253 253 253 253 253 253 253 253 253 253
52033-253 253 253 253 253 253 253 253 253 253 253 253
52034-253 253 253 253 253 253 253 253 253 253 253 253
52035-253 253 253 253 253 253 253 253 253 253 253 253
52036-253 253 253 253 253 253 253 253 253 253 253 253
52037-253 253 253 253 253 253 253 253 253 250 250 250
52038-238 238 238 198 198 198 6 6 6 38 38 38
52039- 58 58 58 26 26 26 38 38 38 2 2 6
52040- 2 2 6 2 2 6 2 2 6 46 46 46
52041- 78 78 78 30 30 30 10 10 10 0 0 0
52042- 0 0 0 0 0 0 0 0 0 0 0 0
52043- 0 0 0 0 0 0 0 0 0 0 0 0
52044- 0 0 0 0 0 0 0 0 0 0 0 0
52045- 0 0 0 0 0 0 0 0 0 0 0 0
52046- 0 0 0 0 0 0 0 0 0 0 0 0
52047- 0 0 0 0 0 0 0 0 0 0 0 0
52048- 0 0 0 0 0 0 0 0 0 0 0 0
52049- 0 0 0 0 0 0 10 10 10 30 30 30
52050- 74 74 74 58 58 58 2 2 6 42 42 42
52051- 2 2 6 22 22 22 231 231 231 253 253 253
52052-253 253 253 253 253 253 253 253 253 253 253 253
52053-253 253 253 253 253 253 253 253 253 250 250 250
52054-253 253 253 253 253 253 253 253 253 253 253 253
52055-253 253 253 253 253 253 253 253 253 253 253 253
52056-253 253 253 253 253 253 253 253 253 253 253 253
52057-253 253 253 253 253 253 253 253 253 253 253 253
52058-253 253 253 246 246 246 46 46 46 38 38 38
52059- 42 42 42 14 14 14 38 38 38 14 14 14
52060- 2 2 6 2 2 6 2 2 6 6 6 6
52061- 86 86 86 46 46 46 14 14 14 0 0 0
52062- 0 0 0 0 0 0 0 0 0 0 0 0
52063- 0 0 0 0 0 0 0 0 0 0 0 0
52064- 0 0 0 0 0 0 0 0 0 0 0 0
52065- 0 0 0 0 0 0 0 0 0 0 0 0
52066- 0 0 0 0 0 0 0 0 0 0 0 0
52067- 0 0 0 0 0 0 0 0 0 0 0 0
52068- 0 0 0 0 0 0 0 0 0 0 0 0
52069- 0 0 0 6 6 6 14 14 14 42 42 42
52070- 90 90 90 18 18 18 18 18 18 26 26 26
52071- 2 2 6 116 116 116 253 253 253 253 253 253
52072-253 253 253 253 253 253 253 253 253 253 253 253
52073-253 253 253 253 253 253 250 250 250 238 238 238
52074-253 253 253 253 253 253 253 253 253 253 253 253
52075-253 253 253 253 253 253 253 253 253 253 253 253
52076-253 253 253 253 253 253 253 253 253 253 253 253
52077-253 253 253 253 253 253 253 253 253 253 253 253
52078-253 253 253 253 253 253 94 94 94 6 6 6
52079- 2 2 6 2 2 6 10 10 10 34 34 34
52080- 2 2 6 2 2 6 2 2 6 2 2 6
52081- 74 74 74 58 58 58 22 22 22 6 6 6
52082- 0 0 0 0 0 0 0 0 0 0 0 0
52083- 0 0 0 0 0 0 0 0 0 0 0 0
52084- 0 0 0 0 0 0 0 0 0 0 0 0
52085- 0 0 0 0 0 0 0 0 0 0 0 0
52086- 0 0 0 0 0 0 0 0 0 0 0 0
52087- 0 0 0 0 0 0 0 0 0 0 0 0
52088- 0 0 0 0 0 0 0 0 0 0 0 0
52089- 0 0 0 10 10 10 26 26 26 66 66 66
52090- 82 82 82 2 2 6 38 38 38 6 6 6
52091- 14 14 14 210 210 210 253 253 253 253 253 253
52092-253 253 253 253 253 253 253 253 253 253 253 253
52093-253 253 253 253 253 253 246 246 246 242 242 242
52094-253 253 253 253 253 253 253 253 253 253 253 253
52095-253 253 253 253 253 253 253 253 253 253 253 253
52096-253 253 253 253 253 253 253 253 253 253 253 253
52097-253 253 253 253 253 253 253 253 253 253 253 253
52098-253 253 253 253 253 253 144 144 144 2 2 6
52099- 2 2 6 2 2 6 2 2 6 46 46 46
52100- 2 2 6 2 2 6 2 2 6 2 2 6
52101- 42 42 42 74 74 74 30 30 30 10 10 10
52102- 0 0 0 0 0 0 0 0 0 0 0 0
52103- 0 0 0 0 0 0 0 0 0 0 0 0
52104- 0 0 0 0 0 0 0 0 0 0 0 0
52105- 0 0 0 0 0 0 0 0 0 0 0 0
52106- 0 0 0 0 0 0 0 0 0 0 0 0
52107- 0 0 0 0 0 0 0 0 0 0 0 0
52108- 0 0 0 0 0 0 0 0 0 0 0 0
52109- 6 6 6 14 14 14 42 42 42 90 90 90
52110- 26 26 26 6 6 6 42 42 42 2 2 6
52111- 74 74 74 250 250 250 253 253 253 253 253 253
52112-253 253 253 253 253 253 253 253 253 253 253 253
52113-253 253 253 253 253 253 242 242 242 242 242 242
52114-253 253 253 253 253 253 253 253 253 253 253 253
52115-253 253 253 253 253 253 253 253 253 253 253 253
52116-253 253 253 253 253 253 253 253 253 253 253 253
52117-253 253 253 253 253 253 253 253 253 253 253 253
52118-253 253 253 253 253 253 182 182 182 2 2 6
52119- 2 2 6 2 2 6 2 2 6 46 46 46
52120- 2 2 6 2 2 6 2 2 6 2 2 6
52121- 10 10 10 86 86 86 38 38 38 10 10 10
52122- 0 0 0 0 0 0 0 0 0 0 0 0
52123- 0 0 0 0 0 0 0 0 0 0 0 0
52124- 0 0 0 0 0 0 0 0 0 0 0 0
52125- 0 0 0 0 0 0 0 0 0 0 0 0
52126- 0 0 0 0 0 0 0 0 0 0 0 0
52127- 0 0 0 0 0 0 0 0 0 0 0 0
52128- 0 0 0 0 0 0 0 0 0 0 0 0
52129- 10 10 10 26 26 26 66 66 66 82 82 82
52130- 2 2 6 22 22 22 18 18 18 2 2 6
52131-149 149 149 253 253 253 253 253 253 253 253 253
52132-253 253 253 253 253 253 253 253 253 253 253 253
52133-253 253 253 253 253 253 234 234 234 242 242 242
52134-253 253 253 253 253 253 253 253 253 253 253 253
52135-253 253 253 253 253 253 253 253 253 253 253 253
52136-253 253 253 253 253 253 253 253 253 253 253 253
52137-253 253 253 253 253 253 253 253 253 253 253 253
52138-253 253 253 253 253 253 206 206 206 2 2 6
52139- 2 2 6 2 2 6 2 2 6 38 38 38
52140- 2 2 6 2 2 6 2 2 6 2 2 6
52141- 6 6 6 86 86 86 46 46 46 14 14 14
52142- 0 0 0 0 0 0 0 0 0 0 0 0
52143- 0 0 0 0 0 0 0 0 0 0 0 0
52144- 0 0 0 0 0 0 0 0 0 0 0 0
52145- 0 0 0 0 0 0 0 0 0 0 0 0
52146- 0 0 0 0 0 0 0 0 0 0 0 0
52147- 0 0 0 0 0 0 0 0 0 0 0 0
52148- 0 0 0 0 0 0 0 0 0 6 6 6
52149- 18 18 18 46 46 46 86 86 86 18 18 18
52150- 2 2 6 34 34 34 10 10 10 6 6 6
52151-210 210 210 253 253 253 253 253 253 253 253 253
52152-253 253 253 253 253 253 253 253 253 253 253 253
52153-253 253 253 253 253 253 234 234 234 242 242 242
52154-253 253 253 253 253 253 253 253 253 253 253 253
52155-253 253 253 253 253 253 253 253 253 253 253 253
52156-253 253 253 253 253 253 253 253 253 253 253 253
52157-253 253 253 253 253 253 253 253 253 253 253 253
52158-253 253 253 253 253 253 221 221 221 6 6 6
52159- 2 2 6 2 2 6 6 6 6 30 30 30
52160- 2 2 6 2 2 6 2 2 6 2 2 6
52161- 2 2 6 82 82 82 54 54 54 18 18 18
52162- 6 6 6 0 0 0 0 0 0 0 0 0
52163- 0 0 0 0 0 0 0 0 0 0 0 0
52164- 0 0 0 0 0 0 0 0 0 0 0 0
52165- 0 0 0 0 0 0 0 0 0 0 0 0
52166- 0 0 0 0 0 0 0 0 0 0 0 0
52167- 0 0 0 0 0 0 0 0 0 0 0 0
52168- 0 0 0 0 0 0 0 0 0 10 10 10
52169- 26 26 26 66 66 66 62 62 62 2 2 6
52170- 2 2 6 38 38 38 10 10 10 26 26 26
52171-238 238 238 253 253 253 253 253 253 253 253 253
52172-253 253 253 253 253 253 253 253 253 253 253 253
52173-253 253 253 253 253 253 231 231 231 238 238 238
52174-253 253 253 253 253 253 253 253 253 253 253 253
52175-253 253 253 253 253 253 253 253 253 253 253 253
52176-253 253 253 253 253 253 253 253 253 253 253 253
52177-253 253 253 253 253 253 253 253 253 253 253 253
52178-253 253 253 253 253 253 231 231 231 6 6 6
52179- 2 2 6 2 2 6 10 10 10 30 30 30
52180- 2 2 6 2 2 6 2 2 6 2 2 6
52181- 2 2 6 66 66 66 58 58 58 22 22 22
52182- 6 6 6 0 0 0 0 0 0 0 0 0
52183- 0 0 0 0 0 0 0 0 0 0 0 0
52184- 0 0 0 0 0 0 0 0 0 0 0 0
52185- 0 0 0 0 0 0 0 0 0 0 0 0
52186- 0 0 0 0 0 0 0 0 0 0 0 0
52187- 0 0 0 0 0 0 0 0 0 0 0 0
52188- 0 0 0 0 0 0 0 0 0 10 10 10
52189- 38 38 38 78 78 78 6 6 6 2 2 6
52190- 2 2 6 46 46 46 14 14 14 42 42 42
52191-246 246 246 253 253 253 253 253 253 253 253 253
52192-253 253 253 253 253 253 253 253 253 253 253 253
52193-253 253 253 253 253 253 231 231 231 242 242 242
52194-253 253 253 253 253 253 253 253 253 253 253 253
52195-253 253 253 253 253 253 253 253 253 253 253 253
52196-253 253 253 253 253 253 253 253 253 253 253 253
52197-253 253 253 253 253 253 253 253 253 253 253 253
52198-253 253 253 253 253 253 234 234 234 10 10 10
52199- 2 2 6 2 2 6 22 22 22 14 14 14
52200- 2 2 6 2 2 6 2 2 6 2 2 6
52201- 2 2 6 66 66 66 62 62 62 22 22 22
52202- 6 6 6 0 0 0 0 0 0 0 0 0
52203- 0 0 0 0 0 0 0 0 0 0 0 0
52204- 0 0 0 0 0 0 0 0 0 0 0 0
52205- 0 0 0 0 0 0 0 0 0 0 0 0
52206- 0 0 0 0 0 0 0 0 0 0 0 0
52207- 0 0 0 0 0 0 0 0 0 0 0 0
52208- 0 0 0 0 0 0 6 6 6 18 18 18
52209- 50 50 50 74 74 74 2 2 6 2 2 6
52210- 14 14 14 70 70 70 34 34 34 62 62 62
52211-250 250 250 253 253 253 253 253 253 253 253 253
52212-253 253 253 253 253 253 253 253 253 253 253 253
52213-253 253 253 253 253 253 231 231 231 246 246 246
52214-253 253 253 253 253 253 253 253 253 253 253 253
52215-253 253 253 253 253 253 253 253 253 253 253 253
52216-253 253 253 253 253 253 253 253 253 253 253 253
52217-253 253 253 253 253 253 253 253 253 253 253 253
52218-253 253 253 253 253 253 234 234 234 14 14 14
52219- 2 2 6 2 2 6 30 30 30 2 2 6
52220- 2 2 6 2 2 6 2 2 6 2 2 6
52221- 2 2 6 66 66 66 62 62 62 22 22 22
52222- 6 6 6 0 0 0 0 0 0 0 0 0
52223- 0 0 0 0 0 0 0 0 0 0 0 0
52224- 0 0 0 0 0 0 0 0 0 0 0 0
52225- 0 0 0 0 0 0 0 0 0 0 0 0
52226- 0 0 0 0 0 0 0 0 0 0 0 0
52227- 0 0 0 0 0 0 0 0 0 0 0 0
52228- 0 0 0 0 0 0 6 6 6 18 18 18
52229- 54 54 54 62 62 62 2 2 6 2 2 6
52230- 2 2 6 30 30 30 46 46 46 70 70 70
52231-250 250 250 253 253 253 253 253 253 253 253 253
52232-253 253 253 253 253 253 253 253 253 253 253 253
52233-253 253 253 253 253 253 231 231 231 246 246 246
52234-253 253 253 253 253 253 253 253 253 253 253 253
52235-253 253 253 253 253 253 253 253 253 253 253 253
52236-253 253 253 253 253 253 253 253 253 253 253 253
52237-253 253 253 253 253 253 253 253 253 253 253 253
52238-253 253 253 253 253 253 226 226 226 10 10 10
52239- 2 2 6 6 6 6 30 30 30 2 2 6
52240- 2 2 6 2 2 6 2 2 6 2 2 6
52241- 2 2 6 66 66 66 58 58 58 22 22 22
52242- 6 6 6 0 0 0 0 0 0 0 0 0
52243- 0 0 0 0 0 0 0 0 0 0 0 0
52244- 0 0 0 0 0 0 0 0 0 0 0 0
52245- 0 0 0 0 0 0 0 0 0 0 0 0
52246- 0 0 0 0 0 0 0 0 0 0 0 0
52247- 0 0 0 0 0 0 0 0 0 0 0 0
52248- 0 0 0 0 0 0 6 6 6 22 22 22
52249- 58 58 58 62 62 62 2 2 6 2 2 6
52250- 2 2 6 2 2 6 30 30 30 78 78 78
52251-250 250 250 253 253 253 253 253 253 253 253 253
52252-253 253 253 253 253 253 253 253 253 253 253 253
52253-253 253 253 253 253 253 231 231 231 246 246 246
52254-253 253 253 253 253 253 253 253 253 253 253 253
52255-253 253 253 253 253 253 253 253 253 253 253 253
52256-253 253 253 253 253 253 253 253 253 253 253 253
52257-253 253 253 253 253 253 253 253 253 253 253 253
52258-253 253 253 253 253 253 206 206 206 2 2 6
52259- 22 22 22 34 34 34 18 14 6 22 22 22
52260- 26 26 26 18 18 18 6 6 6 2 2 6
52261- 2 2 6 82 82 82 54 54 54 18 18 18
52262- 6 6 6 0 0 0 0 0 0 0 0 0
52263- 0 0 0 0 0 0 0 0 0 0 0 0
52264- 0 0 0 0 0 0 0 0 0 0 0 0
52265- 0 0 0 0 0 0 0 0 0 0 0 0
52266- 0 0 0 0 0 0 0 0 0 0 0 0
52267- 0 0 0 0 0 0 0 0 0 0 0 0
52268- 0 0 0 0 0 0 6 6 6 26 26 26
52269- 62 62 62 106 106 106 74 54 14 185 133 11
52270-210 162 10 121 92 8 6 6 6 62 62 62
52271-238 238 238 253 253 253 253 253 253 253 253 253
52272-253 253 253 253 253 253 253 253 253 253 253 253
52273-253 253 253 253 253 253 231 231 231 246 246 246
52274-253 253 253 253 253 253 253 253 253 253 253 253
52275-253 253 253 253 253 253 253 253 253 253 253 253
52276-253 253 253 253 253 253 253 253 253 253 253 253
52277-253 253 253 253 253 253 253 253 253 253 253 253
52278-253 253 253 253 253 253 158 158 158 18 18 18
52279- 14 14 14 2 2 6 2 2 6 2 2 6
52280- 6 6 6 18 18 18 66 66 66 38 38 38
52281- 6 6 6 94 94 94 50 50 50 18 18 18
52282- 6 6 6 0 0 0 0 0 0 0 0 0
52283- 0 0 0 0 0 0 0 0 0 0 0 0
52284- 0 0 0 0 0 0 0 0 0 0 0 0
52285- 0 0 0 0 0 0 0 0 0 0 0 0
52286- 0 0 0 0 0 0 0 0 0 0 0 0
52287- 0 0 0 0 0 0 0 0 0 6 6 6
52288- 10 10 10 10 10 10 18 18 18 38 38 38
52289- 78 78 78 142 134 106 216 158 10 242 186 14
52290-246 190 14 246 190 14 156 118 10 10 10 10
52291- 90 90 90 238 238 238 253 253 253 253 253 253
52292-253 253 253 253 253 253 253 253 253 253 253 253
52293-253 253 253 253 253 253 231 231 231 250 250 250
52294-253 253 253 253 253 253 253 253 253 253 253 253
52295-253 253 253 253 253 253 253 253 253 253 253 253
52296-253 253 253 253 253 253 253 253 253 253 253 253
52297-253 253 253 253 253 253 253 253 253 246 230 190
52298-238 204 91 238 204 91 181 142 44 37 26 9
52299- 2 2 6 2 2 6 2 2 6 2 2 6
52300- 2 2 6 2 2 6 38 38 38 46 46 46
52301- 26 26 26 106 106 106 54 54 54 18 18 18
52302- 6 6 6 0 0 0 0 0 0 0 0 0
52303- 0 0 0 0 0 0 0 0 0 0 0 0
52304- 0 0 0 0 0 0 0 0 0 0 0 0
52305- 0 0 0 0 0 0 0 0 0 0 0 0
52306- 0 0 0 0 0 0 0 0 0 0 0 0
52307- 0 0 0 6 6 6 14 14 14 22 22 22
52308- 30 30 30 38 38 38 50 50 50 70 70 70
52309-106 106 106 190 142 34 226 170 11 242 186 14
52310-246 190 14 246 190 14 246 190 14 154 114 10
52311- 6 6 6 74 74 74 226 226 226 253 253 253
52312-253 253 253 253 253 253 253 253 253 253 253 253
52313-253 253 253 253 253 253 231 231 231 250 250 250
52314-253 253 253 253 253 253 253 253 253 253 253 253
52315-253 253 253 253 253 253 253 253 253 253 253 253
52316-253 253 253 253 253 253 253 253 253 253 253 253
52317-253 253 253 253 253 253 253 253 253 228 184 62
52318-241 196 14 241 208 19 232 195 16 38 30 10
52319- 2 2 6 2 2 6 2 2 6 2 2 6
52320- 2 2 6 6 6 6 30 30 30 26 26 26
52321-203 166 17 154 142 90 66 66 66 26 26 26
52322- 6 6 6 0 0 0 0 0 0 0 0 0
52323- 0 0 0 0 0 0 0 0 0 0 0 0
52324- 0 0 0 0 0 0 0 0 0 0 0 0
52325- 0 0 0 0 0 0 0 0 0 0 0 0
52326- 0 0 0 0 0 0 0 0 0 0 0 0
52327- 6 6 6 18 18 18 38 38 38 58 58 58
52328- 78 78 78 86 86 86 101 101 101 123 123 123
52329-175 146 61 210 150 10 234 174 13 246 186 14
52330-246 190 14 246 190 14 246 190 14 238 190 10
52331-102 78 10 2 2 6 46 46 46 198 198 198
52332-253 253 253 253 253 253 253 253 253 253 253 253
52333-253 253 253 253 253 253 234 234 234 242 242 242
52334-253 253 253 253 253 253 253 253 253 253 253 253
52335-253 253 253 253 253 253 253 253 253 253 253 253
52336-253 253 253 253 253 253 253 253 253 253 253 253
52337-253 253 253 253 253 253 253 253 253 224 178 62
52338-242 186 14 241 196 14 210 166 10 22 18 6
52339- 2 2 6 2 2 6 2 2 6 2 2 6
52340- 2 2 6 2 2 6 6 6 6 121 92 8
52341-238 202 15 232 195 16 82 82 82 34 34 34
52342- 10 10 10 0 0 0 0 0 0 0 0 0
52343- 0 0 0 0 0 0 0 0 0 0 0 0
52344- 0 0 0 0 0 0 0 0 0 0 0 0
52345- 0 0 0 0 0 0 0 0 0 0 0 0
52346- 0 0 0 0 0 0 0 0 0 0 0 0
52347- 14 14 14 38 38 38 70 70 70 154 122 46
52348-190 142 34 200 144 11 197 138 11 197 138 11
52349-213 154 11 226 170 11 242 186 14 246 190 14
52350-246 190 14 246 190 14 246 190 14 246 190 14
52351-225 175 15 46 32 6 2 2 6 22 22 22
52352-158 158 158 250 250 250 253 253 253 253 253 253
52353-253 253 253 253 253 253 253 253 253 253 253 253
52354-253 253 253 253 253 253 253 253 253 253 253 253
52355-253 253 253 253 253 253 253 253 253 253 253 253
52356-253 253 253 253 253 253 253 253 253 253 253 253
52357-253 253 253 250 250 250 242 242 242 224 178 62
52358-239 182 13 236 186 11 213 154 11 46 32 6
52359- 2 2 6 2 2 6 2 2 6 2 2 6
52360- 2 2 6 2 2 6 61 42 6 225 175 15
52361-238 190 10 236 186 11 112 100 78 42 42 42
52362- 14 14 14 0 0 0 0 0 0 0 0 0
52363- 0 0 0 0 0 0 0 0 0 0 0 0
52364- 0 0 0 0 0 0 0 0 0 0 0 0
52365- 0 0 0 0 0 0 0 0 0 0 0 0
52366- 0 0 0 0 0 0 0 0 0 6 6 6
52367- 22 22 22 54 54 54 154 122 46 213 154 11
52368-226 170 11 230 174 11 226 170 11 226 170 11
52369-236 178 12 242 186 14 246 190 14 246 190 14
52370-246 190 14 246 190 14 246 190 14 246 190 14
52371-241 196 14 184 144 12 10 10 10 2 2 6
52372- 6 6 6 116 116 116 242 242 242 253 253 253
52373-253 253 253 253 253 253 253 253 253 253 253 253
52374-253 253 253 253 253 253 253 253 253 253 253 253
52375-253 253 253 253 253 253 253 253 253 253 253 253
52376-253 253 253 253 253 253 253 253 253 253 253 253
52377-253 253 253 231 231 231 198 198 198 214 170 54
52378-236 178 12 236 178 12 210 150 10 137 92 6
52379- 18 14 6 2 2 6 2 2 6 2 2 6
52380- 6 6 6 70 47 6 200 144 11 236 178 12
52381-239 182 13 239 182 13 124 112 88 58 58 58
52382- 22 22 22 6 6 6 0 0 0 0 0 0
52383- 0 0 0 0 0 0 0 0 0 0 0 0
52384- 0 0 0 0 0 0 0 0 0 0 0 0
52385- 0 0 0 0 0 0 0 0 0 0 0 0
52386- 0 0 0 0 0 0 0 0 0 10 10 10
52387- 30 30 30 70 70 70 180 133 36 226 170 11
52388-239 182 13 242 186 14 242 186 14 246 186 14
52389-246 190 14 246 190 14 246 190 14 246 190 14
52390-246 190 14 246 190 14 246 190 14 246 190 14
52391-246 190 14 232 195 16 98 70 6 2 2 6
52392- 2 2 6 2 2 6 66 66 66 221 221 221
52393-253 253 253 253 253 253 253 253 253 253 253 253
52394-253 253 253 253 253 253 253 253 253 253 253 253
52395-253 253 253 253 253 253 253 253 253 253 253 253
52396-253 253 253 253 253 253 253 253 253 253 253 253
52397-253 253 253 206 206 206 198 198 198 214 166 58
52398-230 174 11 230 174 11 216 158 10 192 133 9
52399-163 110 8 116 81 8 102 78 10 116 81 8
52400-167 114 7 197 138 11 226 170 11 239 182 13
52401-242 186 14 242 186 14 162 146 94 78 78 78
52402- 34 34 34 14 14 14 6 6 6 0 0 0
52403- 0 0 0 0 0 0 0 0 0 0 0 0
52404- 0 0 0 0 0 0 0 0 0 0 0 0
52405- 0 0 0 0 0 0 0 0 0 0 0 0
52406- 0 0 0 0 0 0 0 0 0 6 6 6
52407- 30 30 30 78 78 78 190 142 34 226 170 11
52408-239 182 13 246 190 14 246 190 14 246 190 14
52409-246 190 14 246 190 14 246 190 14 246 190 14
52410-246 190 14 246 190 14 246 190 14 246 190 14
52411-246 190 14 241 196 14 203 166 17 22 18 6
52412- 2 2 6 2 2 6 2 2 6 38 38 38
52413-218 218 218 253 253 253 253 253 253 253 253 253
52414-253 253 253 253 253 253 253 253 253 253 253 253
52415-253 253 253 253 253 253 253 253 253 253 253 253
52416-253 253 253 253 253 253 253 253 253 253 253 253
52417-250 250 250 206 206 206 198 198 198 202 162 69
52418-226 170 11 236 178 12 224 166 10 210 150 10
52419-200 144 11 197 138 11 192 133 9 197 138 11
52420-210 150 10 226 170 11 242 186 14 246 190 14
52421-246 190 14 246 186 14 225 175 15 124 112 88
52422- 62 62 62 30 30 30 14 14 14 6 6 6
52423- 0 0 0 0 0 0 0 0 0 0 0 0
52424- 0 0 0 0 0 0 0 0 0 0 0 0
52425- 0 0 0 0 0 0 0 0 0 0 0 0
52426- 0 0 0 0 0 0 0 0 0 10 10 10
52427- 30 30 30 78 78 78 174 135 50 224 166 10
52428-239 182 13 246 190 14 246 190 14 246 190 14
52429-246 190 14 246 190 14 246 190 14 246 190 14
52430-246 190 14 246 190 14 246 190 14 246 190 14
52431-246 190 14 246 190 14 241 196 14 139 102 15
52432- 2 2 6 2 2 6 2 2 6 2 2 6
52433- 78 78 78 250 250 250 253 253 253 253 253 253
52434-253 253 253 253 253 253 253 253 253 253 253 253
52435-253 253 253 253 253 253 253 253 253 253 253 253
52436-253 253 253 253 253 253 253 253 253 253 253 253
52437-250 250 250 214 214 214 198 198 198 190 150 46
52438-219 162 10 236 178 12 234 174 13 224 166 10
52439-216 158 10 213 154 11 213 154 11 216 158 10
52440-226 170 11 239 182 13 246 190 14 246 190 14
52441-246 190 14 246 190 14 242 186 14 206 162 42
52442-101 101 101 58 58 58 30 30 30 14 14 14
52443- 6 6 6 0 0 0 0 0 0 0 0 0
52444- 0 0 0 0 0 0 0 0 0 0 0 0
52445- 0 0 0 0 0 0 0 0 0 0 0 0
52446- 0 0 0 0 0 0 0 0 0 10 10 10
52447- 30 30 30 74 74 74 174 135 50 216 158 10
52448-236 178 12 246 190 14 246 190 14 246 190 14
52449-246 190 14 246 190 14 246 190 14 246 190 14
52450-246 190 14 246 190 14 246 190 14 246 190 14
52451-246 190 14 246 190 14 241 196 14 226 184 13
52452- 61 42 6 2 2 6 2 2 6 2 2 6
52453- 22 22 22 238 238 238 253 253 253 253 253 253
52454-253 253 253 253 253 253 253 253 253 253 253 253
52455-253 253 253 253 253 253 253 253 253 253 253 253
52456-253 253 253 253 253 253 253 253 253 253 253 253
52457-253 253 253 226 226 226 187 187 187 180 133 36
52458-216 158 10 236 178 12 239 182 13 236 178 12
52459-230 174 11 226 170 11 226 170 11 230 174 11
52460-236 178 12 242 186 14 246 190 14 246 190 14
52461-246 190 14 246 190 14 246 186 14 239 182 13
52462-206 162 42 106 106 106 66 66 66 34 34 34
52463- 14 14 14 6 6 6 0 0 0 0 0 0
52464- 0 0 0 0 0 0 0 0 0 0 0 0
52465- 0 0 0 0 0 0 0 0 0 0 0 0
52466- 0 0 0 0 0 0 0 0 0 6 6 6
52467- 26 26 26 70 70 70 163 133 67 213 154 11
52468-236 178 12 246 190 14 246 190 14 246 190 14
52469-246 190 14 246 190 14 246 190 14 246 190 14
52470-246 190 14 246 190 14 246 190 14 246 190 14
52471-246 190 14 246 190 14 246 190 14 241 196 14
52472-190 146 13 18 14 6 2 2 6 2 2 6
52473- 46 46 46 246 246 246 253 253 253 253 253 253
52474-253 253 253 253 253 253 253 253 253 253 253 253
52475-253 253 253 253 253 253 253 253 253 253 253 253
52476-253 253 253 253 253 253 253 253 253 253 253 253
52477-253 253 253 221 221 221 86 86 86 156 107 11
52478-216 158 10 236 178 12 242 186 14 246 186 14
52479-242 186 14 239 182 13 239 182 13 242 186 14
52480-242 186 14 246 186 14 246 190 14 246 190 14
52481-246 190 14 246 190 14 246 190 14 246 190 14
52482-242 186 14 225 175 15 142 122 72 66 66 66
52483- 30 30 30 10 10 10 0 0 0 0 0 0
52484- 0 0 0 0 0 0 0 0 0 0 0 0
52485- 0 0 0 0 0 0 0 0 0 0 0 0
52486- 0 0 0 0 0 0 0 0 0 6 6 6
52487- 26 26 26 70 70 70 163 133 67 210 150 10
52488-236 178 12 246 190 14 246 190 14 246 190 14
52489-246 190 14 246 190 14 246 190 14 246 190 14
52490-246 190 14 246 190 14 246 190 14 246 190 14
52491-246 190 14 246 190 14 246 190 14 246 190 14
52492-232 195 16 121 92 8 34 34 34 106 106 106
52493-221 221 221 253 253 253 253 253 253 253 253 253
52494-253 253 253 253 253 253 253 253 253 253 253 253
52495-253 253 253 253 253 253 253 253 253 253 253 253
52496-253 253 253 253 253 253 253 253 253 253 253 253
52497-242 242 242 82 82 82 18 14 6 163 110 8
52498-216 158 10 236 178 12 242 186 14 246 190 14
52499-246 190 14 246 190 14 246 190 14 246 190 14
52500-246 190 14 246 190 14 246 190 14 246 190 14
52501-246 190 14 246 190 14 246 190 14 246 190 14
52502-246 190 14 246 190 14 242 186 14 163 133 67
52503- 46 46 46 18 18 18 6 6 6 0 0 0
52504- 0 0 0 0 0 0 0 0 0 0 0 0
52505- 0 0 0 0 0 0 0 0 0 0 0 0
52506- 0 0 0 0 0 0 0 0 0 10 10 10
52507- 30 30 30 78 78 78 163 133 67 210 150 10
52508-236 178 12 246 186 14 246 190 14 246 190 14
52509-246 190 14 246 190 14 246 190 14 246 190 14
52510-246 190 14 246 190 14 246 190 14 246 190 14
52511-246 190 14 246 190 14 246 190 14 246 190 14
52512-241 196 14 215 174 15 190 178 144 253 253 253
52513-253 253 253 253 253 253 253 253 253 253 253 253
52514-253 253 253 253 253 253 253 253 253 253 253 253
52515-253 253 253 253 253 253 253 253 253 253 253 253
52516-253 253 253 253 253 253 253 253 253 218 218 218
52517- 58 58 58 2 2 6 22 18 6 167 114 7
52518-216 158 10 236 178 12 246 186 14 246 190 14
52519-246 190 14 246 190 14 246 190 14 246 190 14
52520-246 190 14 246 190 14 246 190 14 246 190 14
52521-246 190 14 246 190 14 246 190 14 246 190 14
52522-246 190 14 246 186 14 242 186 14 190 150 46
52523- 54 54 54 22 22 22 6 6 6 0 0 0
52524- 0 0 0 0 0 0 0 0 0 0 0 0
52525- 0 0 0 0 0 0 0 0 0 0 0 0
52526- 0 0 0 0 0 0 0 0 0 14 14 14
52527- 38 38 38 86 86 86 180 133 36 213 154 11
52528-236 178 12 246 186 14 246 190 14 246 190 14
52529-246 190 14 246 190 14 246 190 14 246 190 14
52530-246 190 14 246 190 14 246 190 14 246 190 14
52531-246 190 14 246 190 14 246 190 14 246 190 14
52532-246 190 14 232 195 16 190 146 13 214 214 214
52533-253 253 253 253 253 253 253 253 253 253 253 253
52534-253 253 253 253 253 253 253 253 253 253 253 253
52535-253 253 253 253 253 253 253 253 253 253 253 253
52536-253 253 253 250 250 250 170 170 170 26 26 26
52537- 2 2 6 2 2 6 37 26 9 163 110 8
52538-219 162 10 239 182 13 246 186 14 246 190 14
52539-246 190 14 246 190 14 246 190 14 246 190 14
52540-246 190 14 246 190 14 246 190 14 246 190 14
52541-246 190 14 246 190 14 246 190 14 246 190 14
52542-246 186 14 236 178 12 224 166 10 142 122 72
52543- 46 46 46 18 18 18 6 6 6 0 0 0
52544- 0 0 0 0 0 0 0 0 0 0 0 0
52545- 0 0 0 0 0 0 0 0 0 0 0 0
52546- 0 0 0 0 0 0 6 6 6 18 18 18
52547- 50 50 50 109 106 95 192 133 9 224 166 10
52548-242 186 14 246 190 14 246 190 14 246 190 14
52549-246 190 14 246 190 14 246 190 14 246 190 14
52550-246 190 14 246 190 14 246 190 14 246 190 14
52551-246 190 14 246 190 14 246 190 14 246 190 14
52552-242 186 14 226 184 13 210 162 10 142 110 46
52553-226 226 226 253 253 253 253 253 253 253 253 253
52554-253 253 253 253 253 253 253 253 253 253 253 253
52555-253 253 253 253 253 253 253 253 253 253 253 253
52556-198 198 198 66 66 66 2 2 6 2 2 6
52557- 2 2 6 2 2 6 50 34 6 156 107 11
52558-219 162 10 239 182 13 246 186 14 246 190 14
52559-246 190 14 246 190 14 246 190 14 246 190 14
52560-246 190 14 246 190 14 246 190 14 246 190 14
52561-246 190 14 246 190 14 246 190 14 242 186 14
52562-234 174 13 213 154 11 154 122 46 66 66 66
52563- 30 30 30 10 10 10 0 0 0 0 0 0
52564- 0 0 0 0 0 0 0 0 0 0 0 0
52565- 0 0 0 0 0 0 0 0 0 0 0 0
52566- 0 0 0 0 0 0 6 6 6 22 22 22
52567- 58 58 58 154 121 60 206 145 10 234 174 13
52568-242 186 14 246 186 14 246 190 14 246 190 14
52569-246 190 14 246 190 14 246 190 14 246 190 14
52570-246 190 14 246 190 14 246 190 14 246 190 14
52571-246 190 14 246 190 14 246 190 14 246 190 14
52572-246 186 14 236 178 12 210 162 10 163 110 8
52573- 61 42 6 138 138 138 218 218 218 250 250 250
52574-253 253 253 253 253 253 253 253 253 250 250 250
52575-242 242 242 210 210 210 144 144 144 66 66 66
52576- 6 6 6 2 2 6 2 2 6 2 2 6
52577- 2 2 6 2 2 6 61 42 6 163 110 8
52578-216 158 10 236 178 12 246 190 14 246 190 14
52579-246 190 14 246 190 14 246 190 14 246 190 14
52580-246 190 14 246 190 14 246 190 14 246 190 14
52581-246 190 14 239 182 13 230 174 11 216 158 10
52582-190 142 34 124 112 88 70 70 70 38 38 38
52583- 18 18 18 6 6 6 0 0 0 0 0 0
52584- 0 0 0 0 0 0 0 0 0 0 0 0
52585- 0 0 0 0 0 0 0 0 0 0 0 0
52586- 0 0 0 0 0 0 6 6 6 22 22 22
52587- 62 62 62 168 124 44 206 145 10 224 166 10
52588-236 178 12 239 182 13 242 186 14 242 186 14
52589-246 186 14 246 190 14 246 190 14 246 190 14
52590-246 190 14 246 190 14 246 190 14 246 190 14
52591-246 190 14 246 190 14 246 190 14 246 190 14
52592-246 190 14 236 178 12 216 158 10 175 118 6
52593- 80 54 7 2 2 6 6 6 6 30 30 30
52594- 54 54 54 62 62 62 50 50 50 38 38 38
52595- 14 14 14 2 2 6 2 2 6 2 2 6
52596- 2 2 6 2 2 6 2 2 6 2 2 6
52597- 2 2 6 6 6 6 80 54 7 167 114 7
52598-213 154 11 236 178 12 246 190 14 246 190 14
52599-246 190 14 246 190 14 246 190 14 246 190 14
52600-246 190 14 242 186 14 239 182 13 239 182 13
52601-230 174 11 210 150 10 174 135 50 124 112 88
52602- 82 82 82 54 54 54 34 34 34 18 18 18
52603- 6 6 6 0 0 0 0 0 0 0 0 0
52604- 0 0 0 0 0 0 0 0 0 0 0 0
52605- 0 0 0 0 0 0 0 0 0 0 0 0
52606- 0 0 0 0 0 0 6 6 6 18 18 18
52607- 50 50 50 158 118 36 192 133 9 200 144 11
52608-216 158 10 219 162 10 224 166 10 226 170 11
52609-230 174 11 236 178 12 239 182 13 239 182 13
52610-242 186 14 246 186 14 246 190 14 246 190 14
52611-246 190 14 246 190 14 246 190 14 246 190 14
52612-246 186 14 230 174 11 210 150 10 163 110 8
52613-104 69 6 10 10 10 2 2 6 2 2 6
52614- 2 2 6 2 2 6 2 2 6 2 2 6
52615- 2 2 6 2 2 6 2 2 6 2 2 6
52616- 2 2 6 2 2 6 2 2 6 2 2 6
52617- 2 2 6 6 6 6 91 60 6 167 114 7
52618-206 145 10 230 174 11 242 186 14 246 190 14
52619-246 190 14 246 190 14 246 186 14 242 186 14
52620-239 182 13 230 174 11 224 166 10 213 154 11
52621-180 133 36 124 112 88 86 86 86 58 58 58
52622- 38 38 38 22 22 22 10 10 10 6 6 6
52623- 0 0 0 0 0 0 0 0 0 0 0 0
52624- 0 0 0 0 0 0 0 0 0 0 0 0
52625- 0 0 0 0 0 0 0 0 0 0 0 0
52626- 0 0 0 0 0 0 0 0 0 14 14 14
52627- 34 34 34 70 70 70 138 110 50 158 118 36
52628-167 114 7 180 123 7 192 133 9 197 138 11
52629-200 144 11 206 145 10 213 154 11 219 162 10
52630-224 166 10 230 174 11 239 182 13 242 186 14
52631-246 186 14 246 186 14 246 186 14 246 186 14
52632-239 182 13 216 158 10 185 133 11 152 99 6
52633-104 69 6 18 14 6 2 2 6 2 2 6
52634- 2 2 6 2 2 6 2 2 6 2 2 6
52635- 2 2 6 2 2 6 2 2 6 2 2 6
52636- 2 2 6 2 2 6 2 2 6 2 2 6
52637- 2 2 6 6 6 6 80 54 7 152 99 6
52638-192 133 9 219 162 10 236 178 12 239 182 13
52639-246 186 14 242 186 14 239 182 13 236 178 12
52640-224 166 10 206 145 10 192 133 9 154 121 60
52641- 94 94 94 62 62 62 42 42 42 22 22 22
52642- 14 14 14 6 6 6 0 0 0 0 0 0
52643- 0 0 0 0 0 0 0 0 0 0 0 0
52644- 0 0 0 0 0 0 0 0 0 0 0 0
52645- 0 0 0 0 0 0 0 0 0 0 0 0
52646- 0 0 0 0 0 0 0 0 0 6 6 6
52647- 18 18 18 34 34 34 58 58 58 78 78 78
52648-101 98 89 124 112 88 142 110 46 156 107 11
52649-163 110 8 167 114 7 175 118 6 180 123 7
52650-185 133 11 197 138 11 210 150 10 219 162 10
52651-226 170 11 236 178 12 236 178 12 234 174 13
52652-219 162 10 197 138 11 163 110 8 130 83 6
52653- 91 60 6 10 10 10 2 2 6 2 2 6
52654- 18 18 18 38 38 38 38 38 38 38 38 38
52655- 38 38 38 38 38 38 38 38 38 38 38 38
52656- 38 38 38 38 38 38 26 26 26 2 2 6
52657- 2 2 6 6 6 6 70 47 6 137 92 6
52658-175 118 6 200 144 11 219 162 10 230 174 11
52659-234 174 13 230 174 11 219 162 10 210 150 10
52660-192 133 9 163 110 8 124 112 88 82 82 82
52661- 50 50 50 30 30 30 14 14 14 6 6 6
52662- 0 0 0 0 0 0 0 0 0 0 0 0
52663- 0 0 0 0 0 0 0 0 0 0 0 0
52664- 0 0 0 0 0 0 0 0 0 0 0 0
52665- 0 0 0 0 0 0 0 0 0 0 0 0
52666- 0 0 0 0 0 0 0 0 0 0 0 0
52667- 6 6 6 14 14 14 22 22 22 34 34 34
52668- 42 42 42 58 58 58 74 74 74 86 86 86
52669-101 98 89 122 102 70 130 98 46 121 87 25
52670-137 92 6 152 99 6 163 110 8 180 123 7
52671-185 133 11 197 138 11 206 145 10 200 144 11
52672-180 123 7 156 107 11 130 83 6 104 69 6
52673- 50 34 6 54 54 54 110 110 110 101 98 89
52674- 86 86 86 82 82 82 78 78 78 78 78 78
52675- 78 78 78 78 78 78 78 78 78 78 78 78
52676- 78 78 78 82 82 82 86 86 86 94 94 94
52677-106 106 106 101 101 101 86 66 34 124 80 6
52678-156 107 11 180 123 7 192 133 9 200 144 11
52679-206 145 10 200 144 11 192 133 9 175 118 6
52680-139 102 15 109 106 95 70 70 70 42 42 42
52681- 22 22 22 10 10 10 0 0 0 0 0 0
52682- 0 0 0 0 0 0 0 0 0 0 0 0
52683- 0 0 0 0 0 0 0 0 0 0 0 0
52684- 0 0 0 0 0 0 0 0 0 0 0 0
52685- 0 0 0 0 0 0 0 0 0 0 0 0
52686- 0 0 0 0 0 0 0 0 0 0 0 0
52687- 0 0 0 0 0 0 6 6 6 10 10 10
52688- 14 14 14 22 22 22 30 30 30 38 38 38
52689- 50 50 50 62 62 62 74 74 74 90 90 90
52690-101 98 89 112 100 78 121 87 25 124 80 6
52691-137 92 6 152 99 6 152 99 6 152 99 6
52692-138 86 6 124 80 6 98 70 6 86 66 30
52693-101 98 89 82 82 82 58 58 58 46 46 46
52694- 38 38 38 34 34 34 34 34 34 34 34 34
52695- 34 34 34 34 34 34 34 34 34 34 34 34
52696- 34 34 34 34 34 34 38 38 38 42 42 42
52697- 54 54 54 82 82 82 94 86 76 91 60 6
52698-134 86 6 156 107 11 167 114 7 175 118 6
52699-175 118 6 167 114 7 152 99 6 121 87 25
52700-101 98 89 62 62 62 34 34 34 18 18 18
52701- 6 6 6 0 0 0 0 0 0 0 0 0
52702- 0 0 0 0 0 0 0 0 0 0 0 0
52703- 0 0 0 0 0 0 0 0 0 0 0 0
52704- 0 0 0 0 0 0 0 0 0 0 0 0
52705- 0 0 0 0 0 0 0 0 0 0 0 0
52706- 0 0 0 0 0 0 0 0 0 0 0 0
52707- 0 0 0 0 0 0 0 0 0 0 0 0
52708- 0 0 0 6 6 6 6 6 6 10 10 10
52709- 18 18 18 22 22 22 30 30 30 42 42 42
52710- 50 50 50 66 66 66 86 86 86 101 98 89
52711-106 86 58 98 70 6 104 69 6 104 69 6
52712-104 69 6 91 60 6 82 62 34 90 90 90
52713- 62 62 62 38 38 38 22 22 22 14 14 14
52714- 10 10 10 10 10 10 10 10 10 10 10 10
52715- 10 10 10 10 10 10 6 6 6 10 10 10
52716- 10 10 10 10 10 10 10 10 10 14 14 14
52717- 22 22 22 42 42 42 70 70 70 89 81 66
52718- 80 54 7 104 69 6 124 80 6 137 92 6
52719-134 86 6 116 81 8 100 82 52 86 86 86
52720- 58 58 58 30 30 30 14 14 14 6 6 6
52721- 0 0 0 0 0 0 0 0 0 0 0 0
52722- 0 0 0 0 0 0 0 0 0 0 0 0
52723- 0 0 0 0 0 0 0 0 0 0 0 0
52724- 0 0 0 0 0 0 0 0 0 0 0 0
52725- 0 0 0 0 0 0 0 0 0 0 0 0
52726- 0 0 0 0 0 0 0 0 0 0 0 0
52727- 0 0 0 0 0 0 0 0 0 0 0 0
52728- 0 0 0 0 0 0 0 0 0 0 0 0
52729- 0 0 0 6 6 6 10 10 10 14 14 14
52730- 18 18 18 26 26 26 38 38 38 54 54 54
52731- 70 70 70 86 86 86 94 86 76 89 81 66
52732- 89 81 66 86 86 86 74 74 74 50 50 50
52733- 30 30 30 14 14 14 6 6 6 0 0 0
52734- 0 0 0 0 0 0 0 0 0 0 0 0
52735- 0 0 0 0 0 0 0 0 0 0 0 0
52736- 0 0 0 0 0 0 0 0 0 0 0 0
52737- 6 6 6 18 18 18 34 34 34 58 58 58
52738- 82 82 82 89 81 66 89 81 66 89 81 66
52739- 94 86 66 94 86 76 74 74 74 50 50 50
52740- 26 26 26 14 14 14 6 6 6 0 0 0
52741- 0 0 0 0 0 0 0 0 0 0 0 0
52742- 0 0 0 0 0 0 0 0 0 0 0 0
52743- 0 0 0 0 0 0 0 0 0 0 0 0
52744- 0 0 0 0 0 0 0 0 0 0 0 0
52745- 0 0 0 0 0 0 0 0 0 0 0 0
52746- 0 0 0 0 0 0 0 0 0 0 0 0
52747- 0 0 0 0 0 0 0 0 0 0 0 0
52748- 0 0 0 0 0 0 0 0 0 0 0 0
52749- 0 0 0 0 0 0 0 0 0 0 0 0
52750- 6 6 6 6 6 6 14 14 14 18 18 18
52751- 30 30 30 38 38 38 46 46 46 54 54 54
52752- 50 50 50 42 42 42 30 30 30 18 18 18
52753- 10 10 10 0 0 0 0 0 0 0 0 0
52754- 0 0 0 0 0 0 0 0 0 0 0 0
52755- 0 0 0 0 0 0 0 0 0 0 0 0
52756- 0 0 0 0 0 0 0 0 0 0 0 0
52757- 0 0 0 6 6 6 14 14 14 26 26 26
52758- 38 38 38 50 50 50 58 58 58 58 58 58
52759- 54 54 54 42 42 42 30 30 30 18 18 18
52760- 10 10 10 0 0 0 0 0 0 0 0 0
52761- 0 0 0 0 0 0 0 0 0 0 0 0
52762- 0 0 0 0 0 0 0 0 0 0 0 0
52763- 0 0 0 0 0 0 0 0 0 0 0 0
52764- 0 0 0 0 0 0 0 0 0 0 0 0
52765- 0 0 0 0 0 0 0 0 0 0 0 0
52766- 0 0 0 0 0 0 0 0 0 0 0 0
52767- 0 0 0 0 0 0 0 0 0 0 0 0
52768- 0 0 0 0 0 0 0 0 0 0 0 0
52769- 0 0 0 0 0 0 0 0 0 0 0 0
52770- 0 0 0 0 0 0 0 0 0 6 6 6
52771- 6 6 6 10 10 10 14 14 14 18 18 18
52772- 18 18 18 14 14 14 10 10 10 6 6 6
52773- 0 0 0 0 0 0 0 0 0 0 0 0
52774- 0 0 0 0 0 0 0 0 0 0 0 0
52775- 0 0 0 0 0 0 0 0 0 0 0 0
52776- 0 0 0 0 0 0 0 0 0 0 0 0
52777- 0 0 0 0 0 0 0 0 0 6 6 6
52778- 14 14 14 18 18 18 22 22 22 22 22 22
52779- 18 18 18 14 14 14 10 10 10 6 6 6
52780- 0 0 0 0 0 0 0 0 0 0 0 0
52781- 0 0 0 0 0 0 0 0 0 0 0 0
52782- 0 0 0 0 0 0 0 0 0 0 0 0
52783- 0 0 0 0 0 0 0 0 0 0 0 0
52784- 0 0 0 0 0 0 0 0 0 0 0 0
52785+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52786+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52787+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52788+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52789+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52790+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52791+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52792+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52793+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52794+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52795+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52796+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52797+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52798+4 4 4 4 4 4
52799+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52800+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52801+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52802+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52803+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52804+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52805+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52806+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52807+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52808+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52809+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52810+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52811+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52812+4 4 4 4 4 4
52813+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52814+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52815+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52816+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52817+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52818+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52819+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52820+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52821+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52822+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52823+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52824+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52825+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52826+4 4 4 4 4 4
52827+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52828+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52829+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52830+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52831+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52832+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52833+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52834+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52835+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52836+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52837+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52838+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52839+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52840+4 4 4 4 4 4
52841+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52842+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52843+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52844+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52845+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52846+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52847+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52848+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52849+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52850+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52851+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52852+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52853+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52854+4 4 4 4 4 4
52855+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52856+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52857+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52858+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52859+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52860+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52861+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52862+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52863+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52864+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52865+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52866+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52867+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52868+4 4 4 4 4 4
52869+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52870+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52871+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52872+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52873+4 4 4 4 4 4 4 4 4 3 3 3 0 0 0 0 0 0
52874+0 0 0 0 0 0 0 0 0 0 0 0 3 3 3 4 4 4
52875+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52876+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52877+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52878+4 4 4 4 4 4 4 4 4 4 4 4 1 1 1 0 0 0
52879+0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
52880+4 4 4 4 4 4 4 4 4 2 1 0 2 1 0 3 2 2
52881+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52882+4 4 4 4 4 4
52883+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52884+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52885+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52886+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52887+4 4 4 4 4 4 2 2 2 0 0 0 3 4 3 26 28 28
52888+37 38 37 37 38 37 14 17 19 2 2 2 0 0 0 2 2 2
52889+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52890+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52891+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52892+4 4 4 4 4 4 3 3 3 0 0 0 1 1 1 6 6 6
52893+2 2 2 0 0 0 3 3 3 4 4 4 4 4 4 4 4 4
52894+4 4 5 3 3 3 1 0 0 0 0 0 1 0 0 0 0 0
52895+1 1 1 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52896+4 4 4 4 4 4
52897+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52898+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52899+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52900+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52901+2 2 2 0 0 0 0 0 0 14 17 19 60 74 84 137 136 137
52902+153 152 153 137 136 137 125 124 125 60 73 81 6 6 6 3 1 0
52903+0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
52904+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52905+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52906+4 4 4 4 4 4 0 0 0 4 4 4 41 54 63 125 124 125
52907+60 73 81 6 6 6 4 0 0 3 3 3 4 4 4 4 4 4
52908+4 4 4 0 0 0 6 9 11 41 54 63 41 65 82 22 30 35
52909+2 2 2 2 1 0 4 4 4 4 4 4 4 4 4 4 4 4
52910+4 4 4 4 4 4
52911+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52912+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52913+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52914+4 4 4 4 4 4 5 5 5 5 5 5 2 2 2 0 0 0
52915+4 0 0 6 6 6 41 54 63 137 136 137 174 174 174 167 166 167
52916+165 164 165 165 164 165 163 162 163 163 162 163 125 124 125 41 54 63
52917+1 1 1 0 0 0 0 0 0 3 3 3 5 5 5 4 4 4
52918+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52919+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
52920+3 3 3 2 0 0 4 0 0 60 73 81 156 155 156 167 166 167
52921+163 162 163 85 115 134 5 7 8 0 0 0 4 4 4 5 5 5
52922+0 0 0 2 5 5 55 98 126 90 154 193 90 154 193 72 125 159
52923+37 51 59 2 0 0 1 1 1 4 5 5 4 4 4 4 4 4
52924+4 4 4 4 4 4
52925+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52926+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52927+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52928+4 4 4 5 5 5 4 4 4 1 1 1 0 0 0 3 3 3
52929+37 38 37 125 124 125 163 162 163 174 174 174 158 157 158 158 157 158
52930+156 155 156 156 155 156 158 157 158 165 164 165 174 174 174 166 165 166
52931+125 124 125 16 19 21 1 0 0 0 0 0 0 0 0 4 4 4
52932+5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
52933+4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 1 1 1
52934+0 0 0 0 0 0 37 38 37 153 152 153 174 174 174 158 157 158
52935+174 174 174 163 162 163 37 38 37 4 3 3 4 0 0 1 1 1
52936+0 0 0 22 40 52 101 161 196 101 161 196 90 154 193 101 161 196
52937+64 123 161 14 17 19 0 0 0 4 4 4 4 4 4 4 4 4
52938+4 4 4 4 4 4
52939+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52940+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52941+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
52942+5 5 5 2 2 2 0 0 0 4 0 0 24 26 27 85 115 134
52943+156 155 156 174 174 174 167 166 167 156 155 156 154 153 154 157 156 157
52944+156 155 156 156 155 156 155 154 155 153 152 153 158 157 158 167 166 167
52945+174 174 174 156 155 156 60 74 84 16 19 21 0 0 0 0 0 0
52946+1 1 1 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
52947+4 4 4 5 5 5 6 6 6 3 3 3 0 0 0 4 0 0
52948+13 16 17 60 73 81 137 136 137 165 164 165 156 155 156 153 152 153
52949+174 174 174 177 184 187 60 73 81 3 1 0 0 0 0 1 1 2
52950+22 30 35 64 123 161 136 185 209 90 154 193 90 154 193 90 154 193
52951+90 154 193 21 29 34 0 0 0 3 2 2 4 4 5 4 4 4
52952+4 4 4 4 4 4
52953+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52954+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52955+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 3 3 3
52956+0 0 0 0 0 0 10 13 16 60 74 84 157 156 157 174 174 174
52957+174 174 174 158 157 158 153 152 153 154 153 154 156 155 156 155 154 155
52958+156 155 156 155 154 155 154 153 154 157 156 157 154 153 154 153 152 153
52959+163 162 163 174 174 174 177 184 187 137 136 137 60 73 81 13 16 17
52960+4 0 0 0 0 0 3 3 3 5 5 5 4 4 4 4 4 4
52961+5 5 5 4 4 4 1 1 1 0 0 0 3 3 3 41 54 63
52962+131 129 131 174 174 174 174 174 174 174 174 174 167 166 167 174 174 174
52963+190 197 201 137 136 137 24 26 27 4 0 0 16 21 25 50 82 103
52964+90 154 193 136 185 209 90 154 193 101 161 196 101 161 196 101 161 196
52965+31 91 132 3 6 7 0 0 0 4 4 4 4 4 4 4 4 4
52966+4 4 4 4 4 4
52967+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52968+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52969+4 4 4 4 4 4 4 4 4 2 2 2 0 0 0 4 0 0
52970+4 0 0 43 57 68 137 136 137 177 184 187 174 174 174 163 162 163
52971+155 154 155 155 154 155 156 155 156 155 154 155 158 157 158 165 164 165
52972+167 166 167 166 165 166 163 162 163 157 156 157 155 154 155 155 154 155
52973+153 152 153 156 155 156 167 166 167 174 174 174 174 174 174 131 129 131
52974+41 54 63 5 5 5 0 0 0 0 0 0 3 3 3 4 4 4
52975+1 1 1 0 0 0 1 0 0 26 28 28 125 124 125 174 174 174
52976+177 184 187 174 174 174 174 174 174 156 155 156 131 129 131 137 136 137
52977+125 124 125 24 26 27 4 0 0 41 65 82 90 154 193 136 185 209
52978+136 185 209 101 161 196 53 118 160 37 112 160 90 154 193 34 86 122
52979+7 12 15 0 0 0 4 4 4 4 4 4 4 4 4 4 4 4
52980+4 4 4 4 4 4
52981+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52982+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52983+4 4 4 3 3 3 0 0 0 0 0 0 5 5 5 37 38 37
52984+125 124 125 167 166 167 174 174 174 167 166 167 158 157 158 155 154 155
52985+156 155 156 156 155 156 156 155 156 163 162 163 167 166 167 155 154 155
52986+137 136 137 153 152 153 156 155 156 165 164 165 163 162 163 156 155 156
52987+156 155 156 156 155 156 155 154 155 158 157 158 166 165 166 174 174 174
52988+167 166 167 125 124 125 37 38 37 1 0 0 0 0 0 0 0 0
52989+0 0 0 24 26 27 60 74 84 158 157 158 174 174 174 174 174 174
52990+166 165 166 158 157 158 125 124 125 41 54 63 13 16 17 6 6 6
52991+6 6 6 37 38 37 80 127 157 136 185 209 101 161 196 101 161 196
52992+90 154 193 28 67 93 6 10 14 13 20 25 13 20 25 6 10 14
52993+1 1 2 4 3 3 4 4 4 4 4 4 4 4 4 4 4 4
52994+4 4 4 4 4 4
52995+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52996+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52997+1 1 1 1 0 0 4 3 3 37 38 37 60 74 84 153 152 153
52998+167 166 167 167 166 167 158 157 158 154 153 154 155 154 155 156 155 156
52999+157 156 157 158 157 158 167 166 167 167 166 167 131 129 131 43 57 68
53000+26 28 28 37 38 37 60 73 81 131 129 131 165 164 165 166 165 166
53001+158 157 158 155 154 155 156 155 156 156 155 156 156 155 156 158 157 158
53002+165 164 165 174 174 174 163 162 163 60 74 84 16 19 21 13 16 17
53003+60 73 81 131 129 131 174 174 174 174 174 174 167 166 167 165 164 165
53004+137 136 137 60 73 81 24 26 27 4 0 0 4 0 0 16 19 21
53005+52 104 138 101 161 196 136 185 209 136 185 209 90 154 193 27 99 146
53006+13 20 25 4 5 7 2 5 5 4 5 7 1 1 2 0 0 0
53007+4 4 4 4 4 4 3 3 3 2 2 2 2 2 2 4 4 4
53008+4 4 4 4 4 4
53009+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53010+4 4 4 4 4 4 4 4 4 4 4 4 3 3 3 0 0 0
53011+0 0 0 13 16 17 60 73 81 137 136 137 174 174 174 166 165 166
53012+158 157 158 156 155 156 157 156 157 156 155 156 155 154 155 158 157 158
53013+167 166 167 174 174 174 153 152 153 60 73 81 16 19 21 4 0 0
53014+4 0 0 4 0 0 6 6 6 26 28 28 60 74 84 158 157 158
53015+174 174 174 166 165 166 157 156 157 155 154 155 156 155 156 156 155 156
53016+155 154 155 158 157 158 167 166 167 167 166 167 131 129 131 125 124 125
53017+137 136 137 167 166 167 167 166 167 174 174 174 158 157 158 125 124 125
53018+16 19 21 4 0 0 4 0 0 10 13 16 49 76 92 107 159 188
53019+136 185 209 136 185 209 90 154 193 26 108 161 22 40 52 6 10 14
53020+2 3 3 1 1 2 1 1 2 4 4 5 4 4 5 4 4 5
53021+4 4 5 2 2 1 0 0 0 0 0 0 0 0 0 2 2 2
53022+4 4 4 4 4 4
53023+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53024+4 4 4 5 5 5 3 3 3 0 0 0 1 0 0 4 0 0
53025+37 51 59 131 129 131 167 166 167 167 166 167 163 162 163 157 156 157
53026+157 156 157 155 154 155 153 152 153 157 156 157 167 166 167 174 174 174
53027+153 152 153 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
53028+4 3 3 4 3 3 4 0 0 6 6 6 4 0 0 37 38 37
53029+125 124 125 174 174 174 174 174 174 165 164 165 156 155 156 154 153 154
53030+156 155 156 156 155 156 155 154 155 163 162 163 158 157 158 163 162 163
53031+174 174 174 174 174 174 174 174 174 125 124 125 37 38 37 0 0 0
53032+4 0 0 6 9 11 41 54 63 90 154 193 136 185 209 146 190 211
53033+136 185 209 37 112 160 22 40 52 6 10 14 3 6 7 1 1 2
53034+1 1 2 3 3 3 1 1 2 3 3 3 4 4 4 4 4 4
53035+2 2 2 2 0 0 16 19 21 37 38 37 24 26 27 0 0 0
53036+0 0 0 4 4 4
53037+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
53038+4 4 4 0 0 0 0 0 0 0 0 0 26 28 28 120 125 127
53039+158 157 158 174 174 174 165 164 165 157 156 157 155 154 155 156 155 156
53040+153 152 153 153 152 153 167 166 167 174 174 174 174 174 174 125 124 125
53041+37 38 37 4 0 0 0 0 0 4 0 0 4 3 3 4 4 4
53042+4 4 4 4 4 4 5 5 5 4 0 0 4 0 0 4 0 0
53043+4 3 3 43 57 68 137 136 137 174 174 174 174 174 174 165 164 165
53044+154 153 154 153 152 153 153 152 153 153 152 153 163 162 163 174 174 174
53045+174 174 174 153 152 153 60 73 81 6 6 6 4 0 0 4 3 3
53046+32 43 50 80 127 157 136 185 209 146 190 211 146 190 211 90 154 193
53047+28 67 93 28 67 93 40 71 93 3 6 7 1 1 2 2 5 5
53048+50 82 103 79 117 143 26 37 45 0 0 0 3 3 3 1 1 1
53049+0 0 0 41 54 63 137 136 137 174 174 174 153 152 153 60 73 81
53050+2 0 0 0 0 0
53051+4 4 4 4 4 4 4 4 4 4 4 4 6 6 6 2 2 2
53052+0 0 0 2 0 0 24 26 27 60 74 84 153 152 153 174 174 174
53053+174 174 174 157 156 157 154 153 154 156 155 156 154 153 154 153 152 153
53054+165 164 165 174 174 174 177 184 187 137 136 137 43 57 68 6 6 6
53055+4 0 0 2 0 0 3 3 3 5 5 5 5 5 5 4 4 4
53056+4 4 4 4 4 4 4 4 4 5 5 5 6 6 6 4 3 3
53057+4 0 0 4 0 0 24 26 27 60 73 81 153 152 153 174 174 174
53058+174 174 174 158 157 158 158 157 158 174 174 174 174 174 174 158 157 158
53059+60 74 84 24 26 27 4 0 0 4 0 0 17 23 27 59 113 148
53060+136 185 209 191 222 234 146 190 211 136 185 209 31 91 132 7 11 13
53061+22 40 52 101 161 196 90 154 193 6 9 11 3 4 4 43 95 132
53062+136 185 209 172 205 220 55 98 126 0 0 0 0 0 0 2 0 0
53063+26 28 28 153 152 153 177 184 187 167 166 167 177 184 187 165 164 165
53064+37 38 37 0 0 0
53065+4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
53066+13 16 17 60 73 81 137 136 137 174 174 174 174 174 174 165 164 165
53067+153 152 153 153 152 153 155 154 155 154 153 154 158 157 158 174 174 174
53068+177 184 187 163 162 163 60 73 81 16 19 21 4 0 0 4 0 0
53069+4 3 3 4 4 4 5 5 5 5 5 5 4 4 4 5 5 5
53070+5 5 5 5 5 5 5 5 5 4 4 4 4 4 4 5 5 5
53071+6 6 6 4 0 0 4 0 0 4 0 0 24 26 27 60 74 84
53072+166 165 166 174 174 174 177 184 187 165 164 165 125 124 125 24 26 27
53073+4 0 0 4 0 0 5 5 5 50 82 103 136 185 209 172 205 220
53074+146 190 211 136 185 209 26 108 161 22 40 52 7 12 15 44 81 103
53075+71 116 144 28 67 93 37 51 59 41 65 82 100 139 164 101 161 196
53076+90 154 193 90 154 193 28 67 93 0 0 0 0 0 0 26 28 28
53077+125 124 125 167 166 167 163 162 163 153 152 153 163 162 163 174 174 174
53078+85 115 134 4 0 0
53079+4 4 4 5 5 5 4 4 4 1 0 0 4 0 0 34 47 55
53080+125 124 125 174 174 174 174 174 174 167 166 167 157 156 157 153 152 153
53081+155 154 155 155 154 155 158 157 158 166 165 166 167 166 167 154 153 154
53082+125 124 125 26 28 28 4 0 0 4 0 0 4 0 0 5 5 5
53083+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 1 1 1
53084+0 0 0 0 0 0 1 1 1 4 4 4 4 4 4 4 4 4
53085+5 5 5 5 5 5 4 3 3 4 0 0 4 0 0 6 6 6
53086+37 38 37 131 129 131 137 136 137 37 38 37 0 0 0 4 0 0
53087+4 5 5 43 61 72 90 154 193 172 205 220 146 190 211 136 185 209
53088+90 154 193 28 67 93 13 20 25 43 61 72 71 116 144 44 81 103
53089+2 5 5 7 11 13 59 113 148 101 161 196 90 154 193 28 67 93
53090+13 20 25 6 10 14 0 0 0 13 16 17 60 73 81 137 136 137
53091+166 165 166 158 157 158 156 155 156 154 153 154 167 166 167 174 174 174
53092+60 73 81 4 0 0
53093+4 4 4 4 4 4 0 0 0 3 3 3 60 74 84 174 174 174
53094+174 174 174 167 166 167 163 162 163 155 154 155 157 156 157 155 154 155
53095+156 155 156 163 162 163 167 166 167 158 157 158 125 124 125 37 38 37
53096+4 3 3 4 0 0 4 0 0 6 6 6 6 6 6 5 5 5
53097+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 2 3 3
53098+10 13 16 7 11 13 1 0 0 0 0 0 2 2 1 4 4 4
53099+4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 4 0 0
53100+4 0 0 7 11 13 13 16 17 4 0 0 3 3 3 34 47 55
53101+80 127 157 146 190 211 172 205 220 136 185 209 136 185 209 136 185 209
53102+28 67 93 22 40 52 55 98 126 55 98 126 21 29 34 7 11 13
53103+50 82 103 101 161 196 101 161 196 35 83 115 13 20 25 2 2 1
53104+1 1 2 1 1 2 37 51 59 131 129 131 174 174 174 174 174 174
53105+167 166 167 163 162 163 163 162 163 167 166 167 174 174 174 125 124 125
53106+16 19 21 4 0 0
53107+4 4 4 4 0 0 4 0 0 60 74 84 174 174 174 174 174 174
53108+158 157 158 155 154 155 155 154 155 156 155 156 155 154 155 158 157 158
53109+167 166 167 165 164 165 131 129 131 60 73 81 13 16 17 4 0 0
53110+4 0 0 4 3 3 6 6 6 4 3 3 5 5 5 4 4 4
53111+4 4 4 3 2 2 0 0 0 0 0 0 7 11 13 45 69 86
53112+80 127 157 71 116 144 43 61 72 7 11 13 0 0 0 1 1 1
53113+4 3 3 4 4 4 4 4 4 4 4 4 6 6 6 5 5 5
53114+3 2 2 4 0 0 1 0 0 21 29 34 59 113 148 136 185 209
53115+146 190 211 136 185 209 136 185 209 136 185 209 136 185 209 136 185 209
53116+68 124 159 44 81 103 22 40 52 13 16 17 43 61 72 90 154 193
53117+136 185 209 59 113 148 21 29 34 3 4 3 1 1 1 0 0 0
53118+24 26 27 125 124 125 163 162 163 174 174 174 166 165 166 165 164 165
53119+163 162 163 125 124 125 125 124 125 125 124 125 125 124 125 26 28 28
53120+4 0 0 4 3 3
53121+3 3 3 0 0 0 24 26 27 153 152 153 177 184 187 158 157 158
53122+156 155 156 156 155 156 155 154 155 155 154 155 165 164 165 174 174 174
53123+155 154 155 60 74 84 26 28 28 4 0 0 4 0 0 3 1 0
53124+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 3 3
53125+2 0 0 0 0 0 0 0 0 32 43 50 72 125 159 101 161 196
53126+136 185 209 101 161 196 101 161 196 79 117 143 32 43 50 0 0 0
53127+0 0 0 2 2 2 4 4 4 4 4 4 3 3 3 1 0 0
53128+0 0 0 4 5 5 49 76 92 101 161 196 146 190 211 146 190 211
53129+136 185 209 136 185 209 136 185 209 136 185 209 136 185 209 90 154 193
53130+28 67 93 13 16 17 37 51 59 80 127 157 136 185 209 90 154 193
53131+22 40 52 6 9 11 3 4 3 2 2 1 16 19 21 60 73 81
53132+137 136 137 163 162 163 158 157 158 166 165 166 167 166 167 153 152 153
53133+60 74 84 37 38 37 6 6 6 13 16 17 4 0 0 1 0 0
53134+3 2 2 4 4 4
53135+3 2 2 4 0 0 37 38 37 137 136 137 167 166 167 158 157 158
53136+157 156 157 154 153 154 157 156 157 167 166 167 174 174 174 125 124 125
53137+37 38 37 4 0 0 4 0 0 4 0 0 4 3 3 4 4 4
53138+4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
53139+0 0 0 16 21 25 55 98 126 90 154 193 136 185 209 101 161 196
53140+101 161 196 101 161 196 136 185 209 136 185 209 101 161 196 55 98 126
53141+14 17 19 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
53142+22 40 52 90 154 193 146 190 211 146 190 211 136 185 209 136 185 209
53143+136 185 209 136 185 209 136 185 209 101 161 196 35 83 115 7 11 13
53144+17 23 27 59 113 148 136 185 209 101 161 196 34 86 122 7 12 15
53145+2 5 5 3 4 3 6 6 6 60 73 81 131 129 131 163 162 163
53146+166 165 166 174 174 174 174 174 174 163 162 163 125 124 125 41 54 63
53147+13 16 17 4 0 0 4 0 0 4 0 0 1 0 0 2 2 2
53148+4 4 4 4 4 4
53149+1 1 1 2 1 0 43 57 68 137 136 137 153 152 153 153 152 153
53150+163 162 163 156 155 156 165 164 165 167 166 167 60 74 84 6 6 6
53151+4 0 0 4 0 0 5 5 5 4 4 4 4 4 4 4 4 4
53152+4 5 5 6 6 6 4 3 3 0 0 0 0 0 0 11 15 18
53153+40 71 93 100 139 164 101 161 196 101 161 196 101 161 196 101 161 196
53154+101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 136 185 209
53155+101 161 196 45 69 86 6 6 6 0 0 0 17 23 27 55 98 126
53156+136 185 209 146 190 211 136 185 209 136 185 209 136 185 209 136 185 209
53157+136 185 209 136 185 209 90 154 193 22 40 52 7 11 13 50 82 103
53158+136 185 209 136 185 209 53 118 160 22 40 52 7 11 13 2 5 5
53159+3 4 3 37 38 37 125 124 125 157 156 157 166 165 166 167 166 167
53160+174 174 174 174 174 174 137 136 137 60 73 81 4 0 0 4 0 0
53161+4 0 0 4 0 0 5 5 5 3 3 3 3 3 3 4 4 4
53162+4 4 4 4 4 4
53163+4 0 0 4 0 0 41 54 63 137 136 137 125 124 125 131 129 131
53164+155 154 155 167 166 167 174 174 174 60 74 84 6 6 6 4 0 0
53165+4 3 3 6 6 6 4 4 4 4 4 4 4 4 4 5 5 5
53166+4 4 4 1 1 1 0 0 0 3 6 7 41 65 82 72 125 159
53167+101 161 196 101 161 196 101 161 196 90 154 193 90 154 193 101 161 196
53168+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
53169+136 185 209 136 185 209 80 127 157 55 98 126 101 161 196 146 190 211
53170+136 185 209 136 185 209 136 185 209 101 161 196 136 185 209 101 161 196
53171+136 185 209 101 161 196 35 83 115 22 30 35 101 161 196 172 205 220
53172+90 154 193 28 67 93 7 11 13 2 5 5 3 4 3 13 16 17
53173+85 115 134 167 166 167 174 174 174 174 174 174 174 174 174 174 174 174
53174+167 166 167 60 74 84 13 16 17 4 0 0 4 0 0 4 3 3
53175+6 6 6 5 5 5 4 4 4 5 5 5 4 4 4 5 5 5
53176+5 5 5 5 5 5
53177+1 1 1 4 0 0 41 54 63 137 136 137 137 136 137 125 124 125
53178+131 129 131 167 166 167 157 156 157 37 38 37 6 6 6 4 0 0
53179+6 6 6 5 5 5 4 4 4 4 4 4 4 5 5 2 2 1
53180+0 0 0 0 0 0 26 37 45 58 111 146 101 161 196 101 161 196
53181+101 161 196 90 154 193 90 154 193 90 154 193 101 161 196 101 161 196
53182+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
53183+101 161 196 136 185 209 136 185 209 136 185 209 146 190 211 136 185 209
53184+136 185 209 101 161 196 136 185 209 136 185 209 101 161 196 136 185 209
53185+101 161 196 136 185 209 136 185 209 136 185 209 136 185 209 16 89 141
53186+7 11 13 2 5 5 2 5 5 13 16 17 60 73 81 154 154 154
53187+174 174 174 174 174 174 174 174 174 174 174 174 163 162 163 125 124 125
53188+24 26 27 4 0 0 4 0 0 4 0 0 5 5 5 5 5 5
53189+4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
53190+5 5 5 4 4 4
53191+4 0 0 6 6 6 37 38 37 137 136 137 137 136 137 131 129 131
53192+131 129 131 153 152 153 131 129 131 26 28 28 4 0 0 4 3 3
53193+6 6 6 4 4 4 4 4 4 4 4 4 0 0 0 0 0 0
53194+13 20 25 51 88 114 90 154 193 101 161 196 101 161 196 90 154 193
53195+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
53196+101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 101 161 196
53197+101 161 196 136 185 209 101 161 196 136 185 209 136 185 209 101 161 196
53198+136 185 209 101 161 196 136 185 209 101 161 196 101 161 196 101 161 196
53199+136 185 209 136 185 209 136 185 209 37 112 160 21 29 34 5 7 8
53200+2 5 5 13 16 17 43 57 68 131 129 131 174 174 174 174 174 174
53201+174 174 174 167 166 167 157 156 157 125 124 125 37 38 37 4 0 0
53202+4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
53203+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53204+4 4 4 4 4 4
53205+1 1 1 4 0 0 41 54 63 153 152 153 137 136 137 137 136 137
53206+137 136 137 153 152 153 125 124 125 24 26 27 4 0 0 3 2 2
53207+4 4 4 4 4 4 4 3 3 4 0 0 3 6 7 43 61 72
53208+64 123 161 101 161 196 90 154 193 90 154 193 90 154 193 90 154 193
53209+90 154 193 90 154 193 90 154 193 90 154 193 101 161 196 90 154 193
53210+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
53211+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
53212+136 185 209 101 161 196 101 161 196 136 185 209 136 185 209 101 161 196
53213+101 161 196 90 154 193 28 67 93 13 16 17 7 11 13 3 6 7
53214+37 51 59 125 124 125 163 162 163 174 174 174 167 166 167 166 165 166
53215+167 166 167 131 129 131 60 73 81 4 0 0 4 0 0 4 0 0
53216+3 3 3 5 5 5 6 6 6 4 4 4 4 4 4 4 4 4
53217+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53218+4 4 4 4 4 4
53219+4 0 0 4 0 0 41 54 63 137 136 137 153 152 153 137 136 137
53220+153 152 153 157 156 157 125 124 125 24 26 27 0 0 0 2 2 2
53221+4 4 4 4 4 4 2 0 0 0 0 0 28 67 93 90 154 193
53222+90 154 193 90 154 193 90 154 193 90 154 193 64 123 161 90 154 193
53223+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
53224+90 154 193 101 161 196 101 161 196 101 161 196 90 154 193 136 185 209
53225+101 161 196 101 161 196 136 185 209 101 161 196 136 185 209 101 161 196
53226+101 161 196 101 161 196 136 185 209 101 161 196 101 161 196 90 154 193
53227+35 83 115 13 16 17 3 6 7 2 5 5 13 16 17 60 74 84
53228+154 154 154 166 165 166 165 164 165 158 157 158 163 162 163 157 156 157
53229+60 74 84 13 16 17 4 0 0 4 0 0 3 2 2 4 4 4
53230+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53231+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53232+4 4 4 4 4 4
53233+1 1 1 4 0 0 41 54 63 157 156 157 155 154 155 137 136 137
53234+153 152 153 158 157 158 137 136 137 26 28 28 2 0 0 2 2 2
53235+4 4 4 4 4 4 1 0 0 6 10 14 34 86 122 90 154 193
53236+64 123 161 90 154 193 64 123 161 90 154 193 90 154 193 90 154 193
53237+64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
53238+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
53239+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
53240+136 185 209 101 161 196 136 185 209 90 154 193 26 108 161 22 40 52
53241+13 16 17 5 7 8 2 5 5 2 5 5 37 38 37 165 164 165
53242+174 174 174 163 162 163 154 154 154 165 164 165 167 166 167 60 73 81
53243+6 6 6 4 0 0 4 0 0 4 4 4 4 4 4 4 4 4
53244+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53245+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53246+4 4 4 4 4 4
53247+4 0 0 6 6 6 41 54 63 156 155 156 158 157 158 153 152 153
53248+156 155 156 165 164 165 137 136 137 26 28 28 0 0 0 2 2 2
53249+4 4 5 4 4 4 2 0 0 7 12 15 31 96 139 64 123 161
53250+90 154 193 64 123 161 90 154 193 90 154 193 64 123 161 90 154 193
53251+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
53252+90 154 193 90 154 193 90 154 193 101 161 196 101 161 196 101 161 196
53253+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
53254+101 161 196 136 185 209 26 108 161 22 40 52 7 11 13 5 7 8
53255+2 5 5 2 5 5 2 5 5 2 2 1 37 38 37 158 157 158
53256+174 174 174 154 154 154 156 155 156 167 166 167 165 164 165 37 38 37
53257+4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
53258+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53259+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53260+4 4 4 4 4 4
53261+3 1 0 4 0 0 60 73 81 157 156 157 163 162 163 153 152 153
53262+158 157 158 167 166 167 137 136 137 26 28 28 2 0 0 2 2 2
53263+4 5 5 4 4 4 4 0 0 7 12 15 24 86 132 26 108 161
53264+37 112 160 64 123 161 90 154 193 64 123 161 90 154 193 90 154 193
53265+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
53266+90 154 193 101 161 196 90 154 193 101 161 196 101 161 196 101 161 196
53267+101 161 196 101 161 196 101 161 196 136 185 209 101 161 196 136 185 209
53268+90 154 193 35 83 115 13 16 17 13 16 17 7 11 13 3 6 7
53269+5 7 8 6 6 6 3 4 3 2 2 1 30 32 34 154 154 154
53270+167 166 167 154 154 154 154 154 154 174 174 174 165 164 165 37 38 37
53271+6 6 6 4 0 0 6 6 6 4 4 4 4 4 4 4 4 4
53272+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53273+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53274+4 4 4 4 4 4
53275+4 0 0 4 0 0 41 54 63 163 162 163 166 165 166 154 154 154
53276+163 162 163 174 174 174 137 136 137 26 28 28 0 0 0 2 2 2
53277+4 5 5 4 4 5 1 1 2 6 10 14 28 67 93 18 97 151
53278+18 97 151 18 97 151 26 108 161 37 112 160 37 112 160 90 154 193
53279+64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
53280+90 154 193 101 161 196 101 161 196 90 154 193 101 161 196 101 161 196
53281+101 161 196 101 161 196 101 161 196 136 185 209 90 154 193 16 89 141
53282+13 20 25 7 11 13 5 7 8 5 7 8 2 5 5 4 5 5
53283+3 4 3 4 5 5 3 4 3 0 0 0 37 38 37 158 157 158
53284+174 174 174 158 157 158 158 157 158 167 166 167 174 174 174 41 54 63
53285+4 0 0 3 2 2 5 5 5 4 4 4 4 4 4 4 4 4
53286+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53287+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53288+4 4 4 4 4 4
53289+1 1 1 4 0 0 60 73 81 165 164 165 174 174 174 158 157 158
53290+167 166 167 174 174 174 153 152 153 26 28 28 2 0 0 2 2 2
53291+4 5 5 4 4 4 4 0 0 7 12 15 10 87 144 10 87 144
53292+18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
53293+26 108 161 37 112 160 53 118 160 90 154 193 90 154 193 90 154 193
53294+90 154 193 90 154 193 101 161 196 101 161 196 101 161 196 101 161 196
53295+101 161 196 136 185 209 90 154 193 26 108 161 22 40 52 13 16 17
53296+7 11 13 3 6 7 5 7 8 5 7 8 2 5 5 4 5 5
53297+4 5 5 6 6 6 3 4 3 0 0 0 30 32 34 158 157 158
53298+174 174 174 156 155 156 155 154 155 165 164 165 154 153 154 37 38 37
53299+4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
53300+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53301+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53302+4 4 4 4 4 4
53303+4 0 0 4 0 0 60 73 81 167 166 167 174 174 174 163 162 163
53304+174 174 174 174 174 174 153 152 153 26 28 28 0 0 0 3 3 3
53305+5 5 5 4 4 4 1 1 2 7 12 15 28 67 93 18 97 151
53306+18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
53307+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
53308+90 154 193 26 108 161 90 154 193 90 154 193 90 154 193 101 161 196
53309+101 161 196 26 108 161 22 40 52 13 16 17 7 11 13 2 5 5
53310+2 5 5 6 6 6 2 5 5 4 5 5 4 5 5 4 5 5
53311+3 4 3 5 5 5 3 4 3 2 0 0 30 32 34 137 136 137
53312+153 152 153 137 136 137 131 129 131 137 136 137 131 129 131 37 38 37
53313+4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
53314+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53315+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53316+4 4 4 4 4 4
53317+1 1 1 4 0 0 60 73 81 167 166 167 174 174 174 166 165 166
53318+174 174 174 177 184 187 153 152 153 30 32 34 1 0 0 3 3 3
53319+5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
53320+18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
53321+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
53322+26 108 161 26 108 161 26 108 161 90 154 193 90 154 193 26 108 161
53323+35 83 115 13 16 17 7 11 13 5 7 8 3 6 7 5 7 8
53324+2 5 5 6 6 6 4 5 5 4 5 5 3 4 3 4 5 5
53325+3 4 3 6 6 6 3 4 3 0 0 0 26 28 28 125 124 125
53326+131 129 131 125 124 125 125 124 125 131 129 131 131 129 131 37 38 37
53327+4 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
53328+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53329+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53330+4 4 4 4 4 4
53331+3 1 0 4 0 0 60 73 81 174 174 174 177 184 187 167 166 167
53332+174 174 174 177 184 187 153 152 153 30 32 34 0 0 0 3 3 3
53333+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
53334+18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
53335+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
53336+26 108 161 90 154 193 26 108 161 26 108 161 24 86 132 13 20 25
53337+7 11 13 13 20 25 22 40 52 5 7 8 3 4 3 3 4 3
53338+4 5 5 3 4 3 4 5 5 3 4 3 4 5 5 3 4 3
53339+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
53340+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
53341+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
53342+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53343+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53344+4 4 4 4 4 4
53345+1 1 1 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
53346+174 174 174 190 197 201 157 156 157 30 32 34 1 0 0 3 3 3
53347+5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
53348+18 97 151 19 95 150 19 95 150 18 97 151 18 97 151 26 108 161
53349+18 97 151 26 108 161 26 108 161 26 108 161 26 108 161 90 154 193
53350+26 108 161 26 108 161 26 108 161 22 40 52 2 5 5 3 4 3
53351+28 67 93 37 112 160 34 86 122 2 5 5 3 4 3 3 4 3
53352+3 4 3 3 4 3 3 4 3 2 2 1 3 4 3 4 4 4
53353+4 5 5 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
53354+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
53355+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
53356+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53357+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53358+4 4 4 4 4 4
53359+4 0 0 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
53360+174 174 174 190 197 201 158 157 158 30 32 34 0 0 0 2 2 2
53361+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
53362+10 87 144 19 95 150 19 95 150 18 97 151 18 97 151 18 97 151
53363+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
53364+18 97 151 22 40 52 2 5 5 2 2 1 22 40 52 26 108 161
53365+90 154 193 37 112 160 22 40 52 3 4 3 13 20 25 22 30 35
53366+3 6 7 1 1 1 2 2 2 6 9 11 5 5 5 4 3 3
53367+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
53368+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
53369+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
53370+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53371+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53372+4 4 4 4 4 4
53373+1 1 1 4 0 0 60 73 81 177 184 187 193 200 203 174 174 174
53374+177 184 187 193 200 203 163 162 163 30 32 34 4 0 0 2 2 2
53375+5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
53376+10 87 144 10 87 144 19 95 150 19 95 150 19 95 150 18 97 151
53377+26 108 161 26 108 161 26 108 161 90 154 193 26 108 161 28 67 93
53378+6 10 14 2 5 5 13 20 25 24 86 132 37 112 160 90 154 193
53379+10 87 144 7 12 15 2 5 5 28 67 93 37 112 160 28 67 93
53380+2 2 1 7 12 15 35 83 115 28 67 93 3 6 7 1 0 0
53381+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
53382+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
53383+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
53384+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53385+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53386+4 4 4 4 4 4
53387+4 0 0 4 0 0 60 73 81 174 174 174 190 197 201 174 174 174
53388+177 184 187 193 200 203 163 162 163 30 32 34 0 0 0 2 2 2
53389+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
53390+10 87 144 16 89 141 19 95 150 10 87 144 26 108 161 26 108 161
53391+26 108 161 26 108 161 26 108 161 28 67 93 6 10 14 1 1 2
53392+7 12 15 28 67 93 26 108 161 16 89 141 24 86 132 21 29 34
53393+3 4 3 21 29 34 37 112 160 37 112 160 27 99 146 21 29 34
53394+21 29 34 26 108 161 90 154 193 35 83 115 1 1 2 2 0 0
53395+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
53396+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
53397+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
53398+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53399+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53400+4 4 4 4 4 4
53401+3 1 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
53402+190 197 201 193 200 203 165 164 165 37 38 37 4 0 0 2 2 2
53403+5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
53404+10 87 144 10 87 144 16 89 141 18 97 151 18 97 151 10 87 144
53405+24 86 132 24 86 132 13 20 25 4 5 7 4 5 7 22 40 52
53406+18 97 151 37 112 160 26 108 161 7 12 15 1 1 1 0 0 0
53407+28 67 93 37 112 160 26 108 161 28 67 93 22 40 52 28 67 93
53408+26 108 161 90 154 193 26 108 161 10 87 144 0 0 0 2 0 0
53409+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
53410+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
53411+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
53412+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53413+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53414+4 4 4 4 4 4
53415+4 0 0 6 6 6 60 73 81 174 174 174 193 200 203 174 174 174
53416+190 197 201 193 200 203 165 164 165 30 32 34 0 0 0 2 2 2
53417+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
53418+10 87 144 10 87 144 10 87 144 18 97 151 28 67 93 6 10 14
53419+0 0 0 1 1 2 4 5 7 13 20 25 16 89 141 26 108 161
53420+26 108 161 26 108 161 24 86 132 6 9 11 2 3 3 22 40 52
53421+37 112 160 16 89 141 22 40 52 28 67 93 26 108 161 26 108 161
53422+90 154 193 26 108 161 26 108 161 28 67 93 1 1 1 4 0 0
53423+4 4 4 5 5 5 3 3 3 4 0 0 26 28 28 124 126 130
53424+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
53425+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
53426+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53427+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53428+4 4 4 4 4 4
53429+4 0 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
53430+193 200 203 193 200 203 167 166 167 37 38 37 4 0 0 2 2 2
53431+5 5 5 4 4 4 4 0 0 6 10 14 28 67 93 10 87 144
53432+10 87 144 10 87 144 18 97 151 10 87 144 13 20 25 4 5 7
53433+1 1 2 1 1 1 22 40 52 26 108 161 26 108 161 26 108 161
53434+26 108 161 26 108 161 26 108 161 24 86 132 22 40 52 22 40 52
53435+22 40 52 22 40 52 10 87 144 26 108 161 26 108 161 26 108 161
53436+26 108 161 26 108 161 90 154 193 10 87 144 0 0 0 4 0 0
53437+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
53438+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
53439+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
53440+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53441+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53442+4 4 4 4 4 4
53443+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
53444+190 197 201 205 212 215 167 166 167 30 32 34 0 0 0 2 2 2
53445+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
53446+10 87 144 10 87 144 10 87 144 10 87 144 22 40 52 1 1 2
53447+2 0 0 1 1 2 24 86 132 26 108 161 26 108 161 26 108 161
53448+26 108 161 19 95 150 16 89 141 10 87 144 22 40 52 22 40 52
53449+10 87 144 26 108 161 37 112 160 26 108 161 26 108 161 26 108 161
53450+26 108 161 26 108 161 26 108 161 28 67 93 2 0 0 3 1 0
53451+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
53452+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
53453+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
53454+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53455+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53456+4 4 4 4 4 4
53457+4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
53458+193 200 203 193 200 203 174 174 174 37 38 37 4 0 0 2 2 2
53459+5 5 5 4 4 4 3 2 2 1 1 2 13 20 25 10 87 144
53460+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 13 20 25
53461+13 20 25 22 40 52 10 87 144 18 97 151 18 97 151 26 108 161
53462+10 87 144 13 20 25 6 10 14 21 29 34 24 86 132 18 97 151
53463+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
53464+26 108 161 90 154 193 18 97 151 13 20 25 0 0 0 4 3 3
53465+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
53466+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
53467+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
53468+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53469+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53470+4 4 4 4 4 4
53471+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
53472+190 197 201 220 221 221 167 166 167 30 32 34 1 0 0 2 2 2
53473+5 5 5 4 4 4 4 4 5 2 5 5 4 5 7 13 20 25
53474+28 67 93 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
53475+10 87 144 10 87 144 18 97 151 10 87 144 18 97 151 18 97 151
53476+28 67 93 2 3 3 0 0 0 28 67 93 26 108 161 26 108 161
53477+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
53478+26 108 161 10 87 144 13 20 25 1 1 2 3 2 2 4 4 4
53479+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
53480+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
53481+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
53482+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53483+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53484+4 4 4 4 4 4
53485+4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
53486+193 200 203 193 200 203 174 174 174 26 28 28 4 0 0 4 3 3
53487+5 5 5 4 4 4 4 4 4 4 4 5 1 1 2 2 5 5
53488+4 5 7 22 40 52 10 87 144 10 87 144 18 97 151 10 87 144
53489+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 18 97 151
53490+10 87 144 28 67 93 22 40 52 10 87 144 26 108 161 18 97 151
53491+18 97 151 18 97 151 26 108 161 26 108 161 26 108 161 26 108 161
53492+22 40 52 1 1 2 0 0 0 2 3 3 4 4 4 4 4 4
53493+4 4 4 5 5 5 4 4 4 0 0 0 26 28 28 131 129 131
53494+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
53495+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
53496+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53497+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53498+4 4 4 4 4 4
53499+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
53500+190 197 201 220 221 221 190 197 201 41 54 63 4 0 0 2 2 2
53501+6 6 6 4 4 4 4 4 4 4 4 5 4 4 5 3 3 3
53502+1 1 2 1 1 2 6 10 14 22 40 52 10 87 144 18 97 151
53503+18 97 151 10 87 144 10 87 144 10 87 144 18 97 151 10 87 144
53504+10 87 144 18 97 151 26 108 161 18 97 151 18 97 151 10 87 144
53505+26 108 161 26 108 161 26 108 161 10 87 144 28 67 93 6 10 14
53506+1 1 2 1 1 2 4 3 3 4 4 5 4 4 4 4 4 4
53507+5 5 5 5 5 5 1 1 1 4 0 0 37 51 59 137 136 137
53508+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
53509+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
53510+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53511+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53512+4 4 4 4 4 4
53513+4 0 0 4 0 0 60 73 81 220 221 221 193 200 203 174 174 174
53514+193 200 203 193 200 203 220 221 221 137 136 137 13 16 17 4 0 0
53515+2 2 2 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5
53516+4 4 5 4 3 3 1 1 2 4 5 7 13 20 25 28 67 93
53517+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
53518+10 87 144 18 97 151 18 97 151 10 87 144 18 97 151 26 108 161
53519+26 108 161 18 97 151 28 67 93 6 10 14 0 0 0 0 0 0
53520+2 3 3 4 5 5 4 4 5 4 4 4 4 4 4 5 5 5
53521+3 3 3 1 1 1 0 0 0 16 19 21 125 124 125 137 136 137
53522+131 129 131 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
53523+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
53524+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53525+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53526+4 4 4 4 4 4
53527+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
53528+193 200 203 190 197 201 220 221 221 220 221 221 153 152 153 30 32 34
53529+0 0 0 0 0 0 2 2 2 4 4 4 4 4 4 4 4 4
53530+4 4 4 4 5 5 4 5 7 1 1 2 1 1 2 4 5 7
53531+13 20 25 28 67 93 10 87 144 18 97 151 10 87 144 10 87 144
53532+10 87 144 10 87 144 10 87 144 18 97 151 26 108 161 18 97 151
53533+28 67 93 7 12 15 0 0 0 0 0 0 2 2 1 4 4 4
53534+4 5 5 4 5 5 4 4 4 4 4 4 3 3 3 0 0 0
53535+0 0 0 0 0 0 37 38 37 125 124 125 158 157 158 131 129 131
53536+125 124 125 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
53537+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
53538+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53539+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53540+4 4 4 4 4 4
53541+4 3 3 4 0 0 41 54 63 193 200 203 220 221 221 174 174 174
53542+193 200 203 193 200 203 193 200 203 220 221 221 244 246 246 193 200 203
53543+120 125 127 5 5 5 1 0 0 0 0 0 1 1 1 4 4 4
53544+4 4 4 4 4 4 4 5 5 4 5 5 4 4 5 1 1 2
53545+4 5 7 4 5 7 22 40 52 10 87 144 10 87 144 10 87 144
53546+10 87 144 10 87 144 18 97 151 10 87 144 10 87 144 13 20 25
53547+4 5 7 2 3 3 1 1 2 4 4 4 4 5 5 4 4 4
53548+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 1 2
53549+24 26 27 60 74 84 153 152 153 163 162 163 137 136 137 125 124 125
53550+125 124 125 125 124 125 125 124 125 137 136 137 125 124 125 26 28 28
53551+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
53552+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53553+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53554+4 4 4 4 4 4
53555+4 0 0 6 6 6 26 28 28 156 155 156 220 221 221 220 221 221
53556+174 174 174 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
53557+220 221 221 167 166 167 60 73 81 7 11 13 0 0 0 0 0 0
53558+3 3 3 4 4 4 4 4 4 4 4 4 4 4 5 4 4 5
53559+4 4 5 1 1 2 1 1 2 4 5 7 22 40 52 10 87 144
53560+10 87 144 10 87 144 10 87 144 22 40 52 4 5 7 1 1 2
53561+1 1 2 4 4 5 4 4 4 4 4 4 4 4 4 4 4 4
53562+5 5 5 2 2 2 0 0 0 4 0 0 16 19 21 60 73 81
53563+137 136 137 167 166 167 158 157 158 137 136 137 131 129 131 131 129 131
53564+125 124 125 125 124 125 131 129 131 155 154 155 60 74 84 5 7 8
53565+0 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53566+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53567+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53568+4 4 4 4 4 4
53569+5 5 5 4 0 0 4 0 0 60 73 81 193 200 203 220 221 221
53570+193 200 203 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
53571+220 221 221 220 221 221 220 221 221 137 136 137 43 57 68 6 6 6
53572+4 0 0 1 1 1 4 4 4 4 4 4 4 4 4 4 4 4
53573+4 4 5 4 4 5 3 2 2 1 1 2 2 5 5 13 20 25
53574+22 40 52 22 40 52 13 20 25 2 3 3 1 1 2 3 3 3
53575+4 5 7 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53576+1 1 1 0 0 0 2 3 3 41 54 63 131 129 131 166 165 166
53577+166 165 166 155 154 155 153 152 153 137 136 137 137 136 137 125 124 125
53578+125 124 125 137 136 137 137 136 137 125 124 125 37 38 37 4 3 3
53579+4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
53580+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53581+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53582+4 4 4 4 4 4
53583+4 3 3 6 6 6 6 6 6 13 16 17 60 73 81 167 166 167
53584+220 221 221 220 221 221 220 221 221 193 200 203 193 200 203 193 200 203
53585+205 212 215 220 221 221 220 221 221 244 246 246 205 212 215 125 124 125
53586+24 26 27 0 0 0 0 0 0 2 2 2 5 5 5 5 5 5
53587+4 4 4 4 4 4 4 4 4 4 4 5 1 1 2 4 5 7
53588+4 5 7 4 5 7 1 1 2 3 2 2 4 4 5 4 4 4
53589+4 4 4 4 4 4 5 5 5 4 4 4 0 0 0 0 0 0
53590+2 0 0 26 28 28 125 124 125 174 174 174 174 174 174 166 165 166
53591+156 155 156 153 152 153 137 136 137 137 136 137 131 129 131 137 136 137
53592+137 136 137 137 136 137 60 74 84 30 32 34 4 0 0 4 0 0
53593+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53594+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53595+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53596+4 4 4 4 4 4
53597+5 5 5 6 6 6 4 0 0 4 0 0 6 6 6 26 28 28
53598+125 124 125 174 174 174 220 221 221 220 221 221 220 221 221 193 200 203
53599+205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
53600+193 200 203 60 74 84 13 16 17 4 0 0 0 0 0 3 3 3
53601+5 5 5 5 5 5 4 4 4 4 4 4 4 4 5 3 3 3
53602+1 1 2 3 3 3 4 4 5 4 4 5 4 4 4 4 4 4
53603+5 5 5 5 5 5 2 2 2 0 0 0 0 0 0 13 16 17
53604+60 74 84 174 174 174 193 200 203 174 174 174 167 166 167 163 162 163
53605+153 152 153 153 152 153 137 136 137 137 136 137 153 152 153 137 136 137
53606+125 124 125 41 54 63 24 26 27 4 0 0 4 0 0 5 5 5
53607+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53608+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53609+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53610+4 4 4 4 4 4
53611+4 3 3 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
53612+6 6 6 37 38 37 131 129 131 220 221 221 220 221 221 220 221 221
53613+193 200 203 193 200 203 220 221 221 205 212 215 220 221 221 244 246 246
53614+244 246 246 244 246 246 174 174 174 41 54 63 0 0 0 0 0 0
53615+0 0 0 4 4 4 5 5 5 5 5 5 4 4 4 4 4 5
53616+4 4 5 4 4 5 4 4 4 4 4 4 6 6 6 6 6 6
53617+3 3 3 0 0 0 2 0 0 13 16 17 60 73 81 156 155 156
53618+220 221 221 193 200 203 174 174 174 165 164 165 163 162 163 154 153 154
53619+153 152 153 153 152 153 158 157 158 163 162 163 137 136 137 60 73 81
53620+13 16 17 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
53621+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53622+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53623+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53624+4 4 4 4 4 4
53625+5 5 5 4 3 3 4 3 3 6 6 6 6 6 6 6 6 6
53626+6 6 6 6 6 6 6 6 6 37 38 37 167 166 167 244 246 246
53627+244 246 246 220 221 221 205 212 215 205 212 215 220 221 221 193 200 203
53628+220 221 221 244 246 246 244 246 246 244 246 246 137 136 137 37 38 37
53629+3 2 2 0 0 0 1 1 1 5 5 5 5 5 5 4 4 4
53630+4 4 4 4 4 4 4 4 4 5 5 5 4 4 4 1 1 1
53631+0 0 0 5 5 5 43 57 68 153 152 153 193 200 203 220 221 221
53632+177 184 187 174 174 174 167 166 167 166 165 166 158 157 158 157 156 157
53633+158 157 158 166 165 166 156 155 156 85 115 134 13 16 17 4 0 0
53634+4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
53635+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53636+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53637+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53638+4 4 4 4 4 4
53639+5 5 5 4 3 3 6 6 6 6 6 6 4 0 0 6 6 6
53640+6 6 6 6 6 6 6 6 6 6 6 6 13 16 17 60 73 81
53641+177 184 187 220 221 221 220 221 221 220 221 221 205 212 215 220 221 221
53642+220 221 221 205 212 215 220 221 221 244 246 246 244 246 246 205 212 215
53643+125 124 125 30 32 34 0 0 0 0 0 0 2 2 2 5 5 5
53644+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 0 0
53645+37 38 37 131 129 131 205 212 215 220 221 221 193 200 203 174 174 174
53646+174 174 174 174 174 174 167 166 167 165 164 165 166 165 166 167 166 167
53647+158 157 158 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
53648+4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
53649+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53650+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53651+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53652+4 4 4 4 4 4
53653+4 4 4 5 5 5 4 3 3 4 3 3 6 6 6 6 6 6
53654+4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
53655+26 28 28 125 124 125 205 212 215 220 221 221 220 221 221 220 221 221
53656+205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
53657+244 246 246 190 197 201 60 74 84 16 19 21 4 0 0 0 0 0
53658+0 0 0 0 0 0 0 0 0 0 0 0 16 19 21 120 125 127
53659+177 184 187 220 221 221 205 212 215 177 184 187 174 174 174 177 184 187
53660+174 174 174 174 174 174 167 166 167 174 174 174 166 165 166 137 136 137
53661+60 73 81 13 16 17 4 0 0 4 0 0 4 3 3 6 6 6
53662+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53663+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53664+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53665+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53666+4 4 4 4 4 4
53667+5 5 5 4 3 3 5 5 5 4 3 3 6 6 6 4 0 0
53668+6 6 6 6 6 6 4 0 0 6 6 6 4 0 0 6 6 6
53669+6 6 6 6 6 6 37 38 37 137 136 137 193 200 203 220 221 221
53670+220 221 221 205 212 215 220 221 221 205 212 215 205 212 215 220 221 221
53671+220 221 221 220 221 221 244 246 246 166 165 166 43 57 68 2 2 2
53672+0 0 0 4 0 0 16 19 21 60 73 81 157 156 157 202 210 214
53673+220 221 221 193 200 203 177 184 187 177 184 187 177 184 187 174 174 174
53674+174 174 174 174 174 174 174 174 174 157 156 157 60 74 84 24 26 27
53675+4 0 0 4 0 0 4 0 0 6 6 6 4 4 4 4 4 4
53676+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53677+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53678+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53679+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53680+4 4 4 4 4 4
53681+4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
53682+6 6 6 4 0 0 6 6 6 6 6 6 6 6 6 4 0 0
53683+4 0 0 4 0 0 6 6 6 24 26 27 60 73 81 167 166 167
53684+220 221 221 220 221 221 220 221 221 205 212 215 205 212 215 205 212 215
53685+205 212 215 220 221 221 220 221 221 220 221 221 205 212 215 137 136 137
53686+60 74 84 125 124 125 137 136 137 190 197 201 220 221 221 193 200 203
53687+177 184 187 177 184 187 177 184 187 174 174 174 174 174 174 177 184 187
53688+190 197 201 174 174 174 125 124 125 37 38 37 6 6 6 4 0 0
53689+4 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53690+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53691+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53692+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53693+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53694+4 4 4 4 4 4
53695+4 4 4 4 4 4 5 5 5 5 5 5 4 3 3 6 6 6
53696+4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 6 6 6
53697+6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
53698+125 124 125 193 200 203 244 246 246 220 221 221 205 212 215 205 212 215
53699+205 212 215 193 200 203 205 212 215 205 212 215 220 221 221 220 221 221
53700+193 200 203 193 200 203 205 212 215 193 200 203 193 200 203 177 184 187
53701+190 197 201 190 197 201 174 174 174 190 197 201 193 200 203 190 197 201
53702+153 152 153 60 73 81 4 0 0 4 0 0 4 0 0 3 2 2
53703+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53704+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53705+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53706+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53707+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53708+4 4 4 4 4 4
53709+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
53710+6 6 6 4 3 3 4 3 3 4 3 3 6 6 6 6 6 6
53711+4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 4 0 0
53712+4 0 0 26 28 28 131 129 131 220 221 221 244 246 246 220 221 221
53713+205 212 215 193 200 203 205 212 215 193 200 203 193 200 203 205 212 215
53714+220 221 221 193 200 203 193 200 203 193 200 203 190 197 201 174 174 174
53715+174 174 174 190 197 201 193 200 203 193 200 203 167 166 167 125 124 125
53716+6 6 6 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
53717+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53718+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53719+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53720+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53721+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53722+4 4 4 4 4 4
53723+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
53724+5 5 5 4 3 3 5 5 5 6 6 6 4 3 3 5 5 5
53725+6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
53726+4 0 0 4 0 0 6 6 6 41 54 63 158 157 158 220 221 221
53727+220 221 221 220 221 221 193 200 203 193 200 203 193 200 203 190 197 201
53728+190 197 201 190 197 201 190 197 201 190 197 201 174 174 174 193 200 203
53729+193 200 203 220 221 221 174 174 174 125 124 125 37 38 37 4 0 0
53730+4 0 0 4 3 3 6 6 6 4 4 4 4 4 4 4 4 4
53731+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53732+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53733+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53734+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53735+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53736+4 4 4 4 4 4
53737+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53738+4 4 4 5 5 5 4 3 3 4 3 3 4 3 3 5 5 5
53739+4 3 3 6 6 6 5 5 5 4 3 3 6 6 6 6 6 6
53740+6 6 6 6 6 6 4 0 0 4 0 0 13 16 17 60 73 81
53741+174 174 174 220 221 221 220 221 221 205 212 215 190 197 201 174 174 174
53742+193 200 203 174 174 174 190 197 201 174 174 174 193 200 203 220 221 221
53743+193 200 203 131 129 131 37 38 37 6 6 6 4 0 0 4 0 0
53744+6 6 6 6 6 6 4 3 3 5 5 5 4 4 4 4 4 4
53745+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53746+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53747+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53748+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53749+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53750+4 4 4 4 4 4
53751+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53752+4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
53753+5 5 5 4 3 3 4 3 3 5 5 5 4 3 3 4 3 3
53754+5 5 5 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
53755+6 6 6 125 124 125 174 174 174 220 221 221 220 221 221 193 200 203
53756+193 200 203 193 200 203 193 200 203 193 200 203 220 221 221 158 157 158
53757+60 73 81 6 6 6 4 0 0 4 0 0 5 5 5 6 6 6
53758+5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
53759+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53760+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53761+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53762+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53763+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53764+4 4 4 4 4 4
53765+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53766+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53767+4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
53768+5 5 5 5 5 5 6 6 6 6 6 6 4 0 0 4 0 0
53769+4 0 0 4 0 0 26 28 28 125 124 125 174 174 174 193 200 203
53770+193 200 203 174 174 174 193 200 203 167 166 167 125 124 125 6 6 6
53771+6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 5 5 5
53772+4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
53773+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53774+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53775+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53776+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53777+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53778+4 4 4 4 4 4
53779+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53780+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53781+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
53782+4 3 3 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
53783+6 6 6 4 0 0 4 0 0 6 6 6 37 38 37 125 124 125
53784+153 152 153 131 129 131 125 124 125 37 38 37 6 6 6 6 6 6
53785+6 6 6 4 0 0 6 6 6 6 6 6 4 3 3 5 5 5
53786+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53787+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53788+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53789+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53790+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53791+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53792+4 4 4 4 4 4
53793+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53794+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53795+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53796+4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
53797+6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
53798+24 26 27 24 26 27 6 6 6 6 6 6 6 6 6 4 0 0
53799+6 6 6 6 6 6 4 0 0 6 6 6 5 5 5 4 3 3
53800+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53801+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53802+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53803+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53804+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53805+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53806+4 4 4 4 4 4
53807+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53808+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53809+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53810+4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
53811+4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
53812+6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
53813+4 0 0 6 6 6 6 6 6 4 3 3 5 5 5 4 4 4
53814+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53815+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53816+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53817+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53818+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53819+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53820+4 4 4 4 4 4
53821+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53822+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53823+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53824+4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 5 5 5
53825+5 5 5 5 5 5 4 0 0 6 6 6 4 0 0 6 6 6
53826+6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 4 0 0
53827+6 6 6 4 3 3 5 5 5 4 3 3 5 5 5 4 4 4
53828+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53829+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53830+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53831+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53832+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53833+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53834+4 4 4 4 4 4
53835+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53836+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53837+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53838+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
53839+4 3 3 6 6 6 4 3 3 6 6 6 6 6 6 6 6 6
53840+4 0 0 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
53841+6 6 6 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
53842+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53843+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53844+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53845+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53846+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53847+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53848+4 4 4 4 4 4
53849+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53850+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53851+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53852+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53853+4 4 4 5 5 5 4 3 3 5 5 5 4 0 0 6 6 6
53854+6 6 6 4 0 0 6 6 6 6 6 6 4 0 0 6 6 6
53855+4 3 3 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
53856+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53857+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53858+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53859+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53860+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53861+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53862+4 4 4 4 4 4
53863+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53864+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53865+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53866+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53867+4 4 4 5 5 5 4 3 3 5 5 5 6 6 6 4 3 3
53868+4 3 3 6 6 6 6 6 6 4 3 3 6 6 6 4 3 3
53869+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53870+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53871+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53872+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53873+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53874+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53875+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53876+4 4 4 4 4 4
53877+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53878+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53879+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53880+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53881+4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 6 6 6
53882+5 5 5 4 3 3 4 3 3 4 3 3 5 5 5 5 5 5
53883+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53884+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53885+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53886+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53887+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53888+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53889+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53890+4 4 4 4 4 4
53891+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53892+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53893+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53894+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53895+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
53896+5 5 5 4 3 3 5 5 5 5 5 5 4 4 4 4 4 4
53897+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53898+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53899+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53900+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53901+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53902+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53903+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53904+4 4 4 4 4 4
53905diff --git a/drivers/video/matrox/matroxfb_DAC1064.c b/drivers/video/matrox/matroxfb_DAC1064.c
53906index 1717623..25907782 100644
53907--- a/drivers/video/matrox/matroxfb_DAC1064.c
53908+++ b/drivers/video/matrox/matroxfb_DAC1064.c
53909@@ -1088,14 +1088,20 @@ static void MGAG100_restore(struct matrox_fb_info *minfo)
53910
53911 #ifdef CONFIG_FB_MATROX_MYSTIQUE
53912 struct matrox_switch matrox_mystique = {
53913- MGA1064_preinit, MGA1064_reset, MGA1064_init, MGA1064_restore,
53914+ .preinit = MGA1064_preinit,
53915+ .reset = MGA1064_reset,
53916+ .init = MGA1064_init,
53917+ .restore = MGA1064_restore,
53918 };
53919 EXPORT_SYMBOL(matrox_mystique);
53920 #endif
53921
53922 #ifdef CONFIG_FB_MATROX_G
53923 struct matrox_switch matrox_G100 = {
53924- MGAG100_preinit, MGAG100_reset, MGAG100_init, MGAG100_restore,
53925+ .preinit = MGAG100_preinit,
53926+ .reset = MGAG100_reset,
53927+ .init = MGAG100_init,
53928+ .restore = MGAG100_restore,
53929 };
53930 EXPORT_SYMBOL(matrox_G100);
53931 #endif
53932diff --git a/drivers/video/matrox/matroxfb_Ti3026.c b/drivers/video/matrox/matroxfb_Ti3026.c
53933index 9a44cec..07e3b43 100644
53934--- a/drivers/video/matrox/matroxfb_Ti3026.c
53935+++ b/drivers/video/matrox/matroxfb_Ti3026.c
53936@@ -738,7 +738,10 @@ static int Ti3026_preinit(struct matrox_fb_info *minfo)
53937 }
53938
53939 struct matrox_switch matrox_millennium = {
53940- Ti3026_preinit, Ti3026_reset, Ti3026_init, Ti3026_restore
53941+ .preinit = Ti3026_preinit,
53942+ .reset = Ti3026_reset,
53943+ .init = Ti3026_init,
53944+ .restore = Ti3026_restore
53945 };
53946 EXPORT_SYMBOL(matrox_millennium);
53947 #endif
53948diff --git a/drivers/video/mb862xx/mb862xxfb_accel.c b/drivers/video/mb862xx/mb862xxfb_accel.c
53949index fe92eed..106e085 100644
53950--- a/drivers/video/mb862xx/mb862xxfb_accel.c
53951+++ b/drivers/video/mb862xx/mb862xxfb_accel.c
53952@@ -312,14 +312,18 @@ void mb862xxfb_init_accel(struct fb_info *info, int xres)
53953 struct mb862xxfb_par *par = info->par;
53954
53955 if (info->var.bits_per_pixel == 32) {
53956- info->fbops->fb_fillrect = cfb_fillrect;
53957- info->fbops->fb_copyarea = cfb_copyarea;
53958- info->fbops->fb_imageblit = cfb_imageblit;
53959+ pax_open_kernel();
53960+ *(void **)&info->fbops->fb_fillrect = cfb_fillrect;
53961+ *(void **)&info->fbops->fb_copyarea = cfb_copyarea;
53962+ *(void **)&info->fbops->fb_imageblit = cfb_imageblit;
53963+ pax_close_kernel();
53964 } else {
53965 outreg(disp, GC_L0EM, 3);
53966- info->fbops->fb_fillrect = mb86290fb_fillrect;
53967- info->fbops->fb_copyarea = mb86290fb_copyarea;
53968- info->fbops->fb_imageblit = mb86290fb_imageblit;
53969+ pax_open_kernel();
53970+ *(void **)&info->fbops->fb_fillrect = mb86290fb_fillrect;
53971+ *(void **)&info->fbops->fb_copyarea = mb86290fb_copyarea;
53972+ *(void **)&info->fbops->fb_imageblit = mb86290fb_imageblit;
53973+ pax_close_kernel();
53974 }
53975 outreg(draw, GDC_REG_DRAW_BASE, 0);
53976 outreg(draw, GDC_REG_MODE_MISC, 0x8000);
53977diff --git a/drivers/video/nvidia/nvidia.c b/drivers/video/nvidia/nvidia.c
53978index ff22871..b129bed 100644
53979--- a/drivers/video/nvidia/nvidia.c
53980+++ b/drivers/video/nvidia/nvidia.c
53981@@ -669,19 +669,23 @@ static int nvidiafb_set_par(struct fb_info *info)
53982 info->fix.line_length = (info->var.xres_virtual *
53983 info->var.bits_per_pixel) >> 3;
53984 if (info->var.accel_flags) {
53985- info->fbops->fb_imageblit = nvidiafb_imageblit;
53986- info->fbops->fb_fillrect = nvidiafb_fillrect;
53987- info->fbops->fb_copyarea = nvidiafb_copyarea;
53988- info->fbops->fb_sync = nvidiafb_sync;
53989+ pax_open_kernel();
53990+ *(void **)&info->fbops->fb_imageblit = nvidiafb_imageblit;
53991+ *(void **)&info->fbops->fb_fillrect = nvidiafb_fillrect;
53992+ *(void **)&info->fbops->fb_copyarea = nvidiafb_copyarea;
53993+ *(void **)&info->fbops->fb_sync = nvidiafb_sync;
53994+ pax_close_kernel();
53995 info->pixmap.scan_align = 4;
53996 info->flags &= ~FBINFO_HWACCEL_DISABLED;
53997 info->flags |= FBINFO_READS_FAST;
53998 NVResetGraphics(info);
53999 } else {
54000- info->fbops->fb_imageblit = cfb_imageblit;
54001- info->fbops->fb_fillrect = cfb_fillrect;
54002- info->fbops->fb_copyarea = cfb_copyarea;
54003- info->fbops->fb_sync = NULL;
54004+ pax_open_kernel();
54005+ *(void **)&info->fbops->fb_imageblit = cfb_imageblit;
54006+ *(void **)&info->fbops->fb_fillrect = cfb_fillrect;
54007+ *(void **)&info->fbops->fb_copyarea = cfb_copyarea;
54008+ *(void **)&info->fbops->fb_sync = NULL;
54009+ pax_close_kernel();
54010 info->pixmap.scan_align = 1;
54011 info->flags |= FBINFO_HWACCEL_DISABLED;
54012 info->flags &= ~FBINFO_READS_FAST;
54013@@ -1173,8 +1177,11 @@ static int nvidia_set_fbinfo(struct fb_info *info)
54014 info->pixmap.size = 8 * 1024;
54015 info->pixmap.flags = FB_PIXMAP_SYSTEM;
54016
54017- if (!hwcur)
54018- info->fbops->fb_cursor = NULL;
54019+ if (!hwcur) {
54020+ pax_open_kernel();
54021+ *(void **)&info->fbops->fb_cursor = NULL;
54022+ pax_close_kernel();
54023+ }
54024
54025 info->var.accel_flags = (!noaccel);
54026
54027diff --git a/drivers/video/omap2/dss/display.c b/drivers/video/omap2/dss/display.c
54028index fafe7c9..93197b9 100644
54029--- a/drivers/video/omap2/dss/display.c
54030+++ b/drivers/video/omap2/dss/display.c
54031@@ -137,12 +137,14 @@ int omapdss_register_display(struct omap_dss_device *dssdev)
54032 snprintf(dssdev->alias, sizeof(dssdev->alias),
54033 "display%d", disp_num_counter++);
54034
54035+ pax_open_kernel();
54036 if (drv && drv->get_resolution == NULL)
54037- drv->get_resolution = omapdss_default_get_resolution;
54038+ *(void **)&drv->get_resolution = omapdss_default_get_resolution;
54039 if (drv && drv->get_recommended_bpp == NULL)
54040- drv->get_recommended_bpp = omapdss_default_get_recommended_bpp;
54041+ *(void **)&drv->get_recommended_bpp = omapdss_default_get_recommended_bpp;
54042 if (drv && drv->get_timings == NULL)
54043- drv->get_timings = omapdss_default_get_timings;
54044+ *(void **)&drv->get_timings = omapdss_default_get_timings;
54045+ pax_close_kernel();
54046
54047 mutex_lock(&panel_list_mutex);
54048 list_add_tail(&dssdev->panel_list, &panel_list);
54049diff --git a/drivers/video/s1d13xxxfb.c b/drivers/video/s1d13xxxfb.c
54050index 05c2dc3..ea1f391 100644
54051--- a/drivers/video/s1d13xxxfb.c
54052+++ b/drivers/video/s1d13xxxfb.c
54053@@ -881,8 +881,10 @@ static int s1d13xxxfb_probe(struct platform_device *pdev)
54054
54055 switch(prod_id) {
54056 case S1D13506_PROD_ID: /* activate acceleration */
54057- s1d13xxxfb_fbops.fb_fillrect = s1d13xxxfb_bitblt_solidfill;
54058- s1d13xxxfb_fbops.fb_copyarea = s1d13xxxfb_bitblt_copyarea;
54059+ pax_open_kernel();
54060+ *(void **)&s1d13xxxfb_fbops.fb_fillrect = s1d13xxxfb_bitblt_solidfill;
54061+ *(void **)&s1d13xxxfb_fbops.fb_copyarea = s1d13xxxfb_bitblt_copyarea;
54062+ pax_close_kernel();
54063 info->flags = FBINFO_DEFAULT | FBINFO_HWACCEL_YPAN |
54064 FBINFO_HWACCEL_FILLRECT | FBINFO_HWACCEL_COPYAREA;
54065 break;
54066diff --git a/drivers/video/smscufx.c b/drivers/video/smscufx.c
54067index e188ada..aac63c8 100644
54068--- a/drivers/video/smscufx.c
54069+++ b/drivers/video/smscufx.c
54070@@ -1175,7 +1175,9 @@ static int ufx_ops_release(struct fb_info *info, int user)
54071 fb_deferred_io_cleanup(info);
54072 kfree(info->fbdefio);
54073 info->fbdefio = NULL;
54074- info->fbops->fb_mmap = ufx_ops_mmap;
54075+ pax_open_kernel();
54076+ *(void **)&info->fbops->fb_mmap = ufx_ops_mmap;
54077+ pax_close_kernel();
54078 }
54079
54080 pr_debug("released /dev/fb%d user=%d count=%d",
54081diff --git a/drivers/video/udlfb.c b/drivers/video/udlfb.c
54082index d2e5bc3..4cb05d1 100644
54083--- a/drivers/video/udlfb.c
54084+++ b/drivers/video/udlfb.c
54085@@ -623,11 +623,11 @@ static int dlfb_handle_damage(struct dlfb_data *dev, int x, int y,
54086 dlfb_urb_completion(urb);
54087
54088 error:
54089- atomic_add(bytes_sent, &dev->bytes_sent);
54090- atomic_add(bytes_identical, &dev->bytes_identical);
54091- atomic_add(width*height*2, &dev->bytes_rendered);
54092+ atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
54093+ atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
54094+ atomic_add_unchecked(width*height*2, &dev->bytes_rendered);
54095 end_cycles = get_cycles();
54096- atomic_add(((unsigned int) ((end_cycles - start_cycles)
54097+ atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
54098 >> 10)), /* Kcycles */
54099 &dev->cpu_kcycles_used);
54100
54101@@ -748,11 +748,11 @@ static void dlfb_dpy_deferred_io(struct fb_info *info,
54102 dlfb_urb_completion(urb);
54103
54104 error:
54105- atomic_add(bytes_sent, &dev->bytes_sent);
54106- atomic_add(bytes_identical, &dev->bytes_identical);
54107- atomic_add(bytes_rendered, &dev->bytes_rendered);
54108+ atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
54109+ atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
54110+ atomic_add_unchecked(bytes_rendered, &dev->bytes_rendered);
54111 end_cycles = get_cycles();
54112- atomic_add(((unsigned int) ((end_cycles - start_cycles)
54113+ atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
54114 >> 10)), /* Kcycles */
54115 &dev->cpu_kcycles_used);
54116 }
54117@@ -993,7 +993,9 @@ static int dlfb_ops_release(struct fb_info *info, int user)
54118 fb_deferred_io_cleanup(info);
54119 kfree(info->fbdefio);
54120 info->fbdefio = NULL;
54121- info->fbops->fb_mmap = dlfb_ops_mmap;
54122+ pax_open_kernel();
54123+ *(void **)&info->fbops->fb_mmap = dlfb_ops_mmap;
54124+ pax_close_kernel();
54125 }
54126
54127 pr_warn("released /dev/fb%d user=%d count=%d\n",
54128@@ -1376,7 +1378,7 @@ static ssize_t metrics_bytes_rendered_show(struct device *fbdev,
54129 struct fb_info *fb_info = dev_get_drvdata(fbdev);
54130 struct dlfb_data *dev = fb_info->par;
54131 return snprintf(buf, PAGE_SIZE, "%u\n",
54132- atomic_read(&dev->bytes_rendered));
54133+ atomic_read_unchecked(&dev->bytes_rendered));
54134 }
54135
54136 static ssize_t metrics_bytes_identical_show(struct device *fbdev,
54137@@ -1384,7 +1386,7 @@ static ssize_t metrics_bytes_identical_show(struct device *fbdev,
54138 struct fb_info *fb_info = dev_get_drvdata(fbdev);
54139 struct dlfb_data *dev = fb_info->par;
54140 return snprintf(buf, PAGE_SIZE, "%u\n",
54141- atomic_read(&dev->bytes_identical));
54142+ atomic_read_unchecked(&dev->bytes_identical));
54143 }
54144
54145 static ssize_t metrics_bytes_sent_show(struct device *fbdev,
54146@@ -1392,7 +1394,7 @@ static ssize_t metrics_bytes_sent_show(struct device *fbdev,
54147 struct fb_info *fb_info = dev_get_drvdata(fbdev);
54148 struct dlfb_data *dev = fb_info->par;
54149 return snprintf(buf, PAGE_SIZE, "%u\n",
54150- atomic_read(&dev->bytes_sent));
54151+ atomic_read_unchecked(&dev->bytes_sent));
54152 }
54153
54154 static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
54155@@ -1400,7 +1402,7 @@ static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
54156 struct fb_info *fb_info = dev_get_drvdata(fbdev);
54157 struct dlfb_data *dev = fb_info->par;
54158 return snprintf(buf, PAGE_SIZE, "%u\n",
54159- atomic_read(&dev->cpu_kcycles_used));
54160+ atomic_read_unchecked(&dev->cpu_kcycles_used));
54161 }
54162
54163 static ssize_t edid_show(
54164@@ -1460,10 +1462,10 @@ static ssize_t metrics_reset_store(struct device *fbdev,
54165 struct fb_info *fb_info = dev_get_drvdata(fbdev);
54166 struct dlfb_data *dev = fb_info->par;
54167
54168- atomic_set(&dev->bytes_rendered, 0);
54169- atomic_set(&dev->bytes_identical, 0);
54170- atomic_set(&dev->bytes_sent, 0);
54171- atomic_set(&dev->cpu_kcycles_used, 0);
54172+ atomic_set_unchecked(&dev->bytes_rendered, 0);
54173+ atomic_set_unchecked(&dev->bytes_identical, 0);
54174+ atomic_set_unchecked(&dev->bytes_sent, 0);
54175+ atomic_set_unchecked(&dev->cpu_kcycles_used, 0);
54176
54177 return count;
54178 }
54179diff --git a/drivers/video/uvesafb.c b/drivers/video/uvesafb.c
54180index 7aec6f3..e3b2d55 100644
54181--- a/drivers/video/uvesafb.c
54182+++ b/drivers/video/uvesafb.c
54183@@ -19,6 +19,7 @@
54184 #include <linux/io.h>
54185 #include <linux/mutex.h>
54186 #include <linux/slab.h>
54187+#include <linux/moduleloader.h>
54188 #include <video/edid.h>
54189 #include <video/uvesafb.h>
54190 #ifdef CONFIG_X86
54191@@ -566,10 +567,32 @@ static int uvesafb_vbe_getpmi(struct uvesafb_ktask *task,
54192 if ((task->t.regs.eax & 0xffff) != 0x4f || task->t.regs.es < 0xc000) {
54193 par->pmi_setpal = par->ypan = 0;
54194 } else {
54195+
54196+#ifdef CONFIG_PAX_KERNEXEC
54197+#ifdef CONFIG_MODULES
54198+ par->pmi_code = module_alloc_exec((u16)task->t.regs.ecx);
54199+#endif
54200+ if (!par->pmi_code) {
54201+ par->pmi_setpal = par->ypan = 0;
54202+ return 0;
54203+ }
54204+#endif
54205+
54206 par->pmi_base = (u16 *)phys_to_virt(((u32)task->t.regs.es << 4)
54207 + task->t.regs.edi);
54208+
54209+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
54210+ pax_open_kernel();
54211+ memcpy(par->pmi_code, par->pmi_base, (u16)task->t.regs.ecx);
54212+ pax_close_kernel();
54213+
54214+ par->pmi_start = ktva_ktla(par->pmi_code + par->pmi_base[1]);
54215+ par->pmi_pal = ktva_ktla(par->pmi_code + par->pmi_base[2]);
54216+#else
54217 par->pmi_start = (u8 *)par->pmi_base + par->pmi_base[1];
54218 par->pmi_pal = (u8 *)par->pmi_base + par->pmi_base[2];
54219+#endif
54220+
54221 printk(KERN_INFO "uvesafb: protected mode interface info at "
54222 "%04x:%04x\n",
54223 (u16)task->t.regs.es, (u16)task->t.regs.edi);
54224@@ -814,13 +837,14 @@ static int uvesafb_vbe_init(struct fb_info *info)
54225 par->ypan = ypan;
54226
54227 if (par->pmi_setpal || par->ypan) {
54228+#if !defined(CONFIG_MODULES) || !defined(CONFIG_PAX_KERNEXEC)
54229 if (__supported_pte_mask & _PAGE_NX) {
54230 par->pmi_setpal = par->ypan = 0;
54231 printk(KERN_WARNING "uvesafb: NX protection is active, "
54232 "better not use the PMI.\n");
54233- } else {
54234+ } else
54235+#endif
54236 uvesafb_vbe_getpmi(task, par);
54237- }
54238 }
54239 #else
54240 /* The protected mode interface is not available on non-x86. */
54241@@ -1454,8 +1478,11 @@ static void uvesafb_init_info(struct fb_info *info, struct vbe_mode_ib *mode)
54242 info->fix.ywrapstep = (par->ypan > 1) ? 1 : 0;
54243
54244 /* Disable blanking if the user requested so. */
54245- if (!blank)
54246- info->fbops->fb_blank = NULL;
54247+ if (!blank) {
54248+ pax_open_kernel();
54249+ *(void **)&info->fbops->fb_blank = NULL;
54250+ pax_close_kernel();
54251+ }
54252
54253 /*
54254 * Find out how much IO memory is required for the mode with
54255@@ -1531,8 +1558,11 @@ static void uvesafb_init_info(struct fb_info *info, struct vbe_mode_ib *mode)
54256 info->flags = FBINFO_FLAG_DEFAULT |
54257 (par->ypan ? FBINFO_HWACCEL_YPAN : 0);
54258
54259- if (!par->ypan)
54260- info->fbops->fb_pan_display = NULL;
54261+ if (!par->ypan) {
54262+ pax_open_kernel();
54263+ *(void **)&info->fbops->fb_pan_display = NULL;
54264+ pax_close_kernel();
54265+ }
54266 }
54267
54268 static void uvesafb_init_mtrr(struct fb_info *info)
54269@@ -1796,6 +1826,11 @@ out:
54270 if (par->vbe_modes)
54271 kfree(par->vbe_modes);
54272
54273+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
54274+ if (par->pmi_code)
54275+ module_free_exec(NULL, par->pmi_code);
54276+#endif
54277+
54278 framebuffer_release(info);
54279 return err;
54280 }
54281@@ -1823,6 +1858,12 @@ static int uvesafb_remove(struct platform_device *dev)
54282 kfree(par->vbe_state_orig);
54283 if (par->vbe_state_saved)
54284 kfree(par->vbe_state_saved);
54285+
54286+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
54287+ if (par->pmi_code)
54288+ module_free_exec(NULL, par->pmi_code);
54289+#endif
54290+
54291 }
54292
54293 framebuffer_release(info);
54294diff --git a/drivers/video/vesafb.c b/drivers/video/vesafb.c
54295index bd83233..7d8a5aa 100644
54296--- a/drivers/video/vesafb.c
54297+++ b/drivers/video/vesafb.c
54298@@ -9,6 +9,7 @@
54299 */
54300
54301 #include <linux/module.h>
54302+#include <linux/moduleloader.h>
54303 #include <linux/kernel.h>
54304 #include <linux/errno.h>
54305 #include <linux/string.h>
54306@@ -52,8 +53,8 @@ static int vram_remap; /* Set amount of memory to be used */
54307 static int vram_total; /* Set total amount of memory */
54308 static int pmi_setpal __read_mostly = 1; /* pmi for palette changes ??? */
54309 static int ypan __read_mostly; /* 0..nothing, 1..ypan, 2..ywrap */
54310-static void (*pmi_start)(void) __read_mostly;
54311-static void (*pmi_pal) (void) __read_mostly;
54312+static void (*pmi_start)(void) __read_only;
54313+static void (*pmi_pal) (void) __read_only;
54314 static int depth __read_mostly;
54315 static int vga_compat __read_mostly;
54316 /* --------------------------------------------------------------------- */
54317@@ -234,6 +235,7 @@ static int vesafb_probe(struct platform_device *dev)
54318 unsigned int size_remap;
54319 unsigned int size_total;
54320 char *option = NULL;
54321+ void *pmi_code = NULL;
54322
54323 /* ignore error return of fb_get_options */
54324 fb_get_options("vesafb", &option);
54325@@ -280,10 +282,6 @@ static int vesafb_probe(struct platform_device *dev)
54326 size_remap = size_total;
54327 vesafb_fix.smem_len = size_remap;
54328
54329-#ifndef __i386__
54330- screen_info.vesapm_seg = 0;
54331-#endif
54332-
54333 if (!request_mem_region(vesafb_fix.smem_start, size_total, "vesafb")) {
54334 printk(KERN_WARNING
54335 "vesafb: cannot reserve video memory at 0x%lx\n",
54336@@ -312,9 +310,21 @@ static int vesafb_probe(struct platform_device *dev)
54337 printk(KERN_INFO "vesafb: mode is %dx%dx%d, linelength=%d, pages=%d\n",
54338 vesafb_defined.xres, vesafb_defined.yres, vesafb_defined.bits_per_pixel, vesafb_fix.line_length, screen_info.pages);
54339
54340+#ifdef __i386__
54341+
54342+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
54343+ pmi_code = module_alloc_exec(screen_info.vesapm_size);
54344+ if (!pmi_code)
54345+#elif !defined(CONFIG_PAX_KERNEXEC)
54346+ if (0)
54347+#endif
54348+
54349+#endif
54350+ screen_info.vesapm_seg = 0;
54351+
54352 if (screen_info.vesapm_seg) {
54353- printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x\n",
54354- screen_info.vesapm_seg,screen_info.vesapm_off);
54355+ printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x %04x bytes\n",
54356+ screen_info.vesapm_seg,screen_info.vesapm_off,screen_info.vesapm_size);
54357 }
54358
54359 if (screen_info.vesapm_seg < 0xc000)
54360@@ -322,9 +332,25 @@ static int vesafb_probe(struct platform_device *dev)
54361
54362 if (ypan || pmi_setpal) {
54363 unsigned short *pmi_base;
54364+
54365 pmi_base = (unsigned short*)phys_to_virt(((unsigned long)screen_info.vesapm_seg << 4) + screen_info.vesapm_off);
54366- pmi_start = (void*)((char*)pmi_base + pmi_base[1]);
54367- pmi_pal = (void*)((char*)pmi_base + pmi_base[2]);
54368+
54369+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
54370+ pax_open_kernel();
54371+ memcpy(pmi_code, pmi_base, screen_info.vesapm_size);
54372+#else
54373+ pmi_code = pmi_base;
54374+#endif
54375+
54376+ pmi_start = (void*)((char*)pmi_code + pmi_base[1]);
54377+ pmi_pal = (void*)((char*)pmi_code + pmi_base[2]);
54378+
54379+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
54380+ pmi_start = ktva_ktla(pmi_start);
54381+ pmi_pal = ktva_ktla(pmi_pal);
54382+ pax_close_kernel();
54383+#endif
54384+
54385 printk(KERN_INFO "vesafb: pmi: set display start = %p, set palette = %p\n",pmi_start,pmi_pal);
54386 if (pmi_base[3]) {
54387 printk(KERN_INFO "vesafb: pmi: ports = ");
54388@@ -477,8 +503,11 @@ static int vesafb_probe(struct platform_device *dev)
54389 info->flags = FBINFO_FLAG_DEFAULT | FBINFO_MISC_FIRMWARE |
54390 (ypan ? FBINFO_HWACCEL_YPAN : 0);
54391
54392- if (!ypan)
54393- info->fbops->fb_pan_display = NULL;
54394+ if (!ypan) {
54395+ pax_open_kernel();
54396+ *(void **)&info->fbops->fb_pan_display = NULL;
54397+ pax_close_kernel();
54398+ }
54399
54400 if (fb_alloc_cmap(&info->cmap, 256, 0) < 0) {
54401 err = -ENOMEM;
54402@@ -493,6 +522,11 @@ static int vesafb_probe(struct platform_device *dev)
54403 info->node, info->fix.id);
54404 return 0;
54405 err:
54406+
54407+#if defined(__i386__) && defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
54408+ module_free_exec(NULL, pmi_code);
54409+#endif
54410+
54411 if (info->screen_base)
54412 iounmap(info->screen_base);
54413 framebuffer_release(info);
54414diff --git a/drivers/video/via/via_clock.h b/drivers/video/via/via_clock.h
54415index 88714ae..16c2e11 100644
54416--- a/drivers/video/via/via_clock.h
54417+++ b/drivers/video/via/via_clock.h
54418@@ -56,7 +56,7 @@ struct via_clock {
54419
54420 void (*set_engine_pll_state)(u8 state);
54421 void (*set_engine_pll)(struct via_pll_config config);
54422-};
54423+} __no_const;
54424
54425
54426 static inline u32 get_pll_internal_frequency(u32 ref_freq,
54427diff --git a/drivers/xen/xenfs/xenstored.c b/drivers/xen/xenfs/xenstored.c
54428index fef20db..d28b1ab 100644
54429--- a/drivers/xen/xenfs/xenstored.c
54430+++ b/drivers/xen/xenfs/xenstored.c
54431@@ -24,7 +24,12 @@ static int xsd_release(struct inode *inode, struct file *file)
54432 static int xsd_kva_open(struct inode *inode, struct file *file)
54433 {
54434 file->private_data = (void *)kasprintf(GFP_KERNEL, "0x%p",
54435+#ifdef CONFIG_GRKERNSEC_HIDESYM
54436+ NULL);
54437+#else
54438 xen_store_interface);
54439+#endif
54440+
54441 if (!file->private_data)
54442 return -ENOMEM;
54443 return 0;
54444diff --git a/fs/9p/vfs_addr.c b/fs/9p/vfs_addr.c
54445index 9ff073f..05cef23 100644
54446--- a/fs/9p/vfs_addr.c
54447+++ b/fs/9p/vfs_addr.c
54448@@ -187,7 +187,7 @@ static int v9fs_vfs_writepage_locked(struct page *page)
54449
54450 retval = v9fs_file_write_internal(inode,
54451 v9inode->writeback_fid,
54452- (__force const char __user *)buffer,
54453+ (const char __force_user *)buffer,
54454 len, &offset, 0);
54455 if (retval > 0)
54456 retval = 0;
54457diff --git a/fs/9p/vfs_inode.c b/fs/9p/vfs_inode.c
54458index 94de6d1..8d81256 100644
54459--- a/fs/9p/vfs_inode.c
54460+++ b/fs/9p/vfs_inode.c
54461@@ -1312,7 +1312,7 @@ static void *v9fs_vfs_follow_link(struct dentry *dentry, struct nameidata *nd)
54462 void
54463 v9fs_vfs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
54464 {
54465- char *s = nd_get_link(nd);
54466+ const char *s = nd_get_link(nd);
54467
54468 p9_debug(P9_DEBUG_VFS, " %s %s\n",
54469 dentry->d_name.name, IS_ERR(s) ? "<error>" : s);
54470diff --git a/fs/Kconfig.binfmt b/fs/Kconfig.binfmt
54471index 370b24c..ff0be7b 100644
54472--- a/fs/Kconfig.binfmt
54473+++ b/fs/Kconfig.binfmt
54474@@ -103,7 +103,7 @@ config HAVE_AOUT
54475
54476 config BINFMT_AOUT
54477 tristate "Kernel support for a.out and ECOFF binaries"
54478- depends on HAVE_AOUT
54479+ depends on HAVE_AOUT && BROKEN
54480 ---help---
54481 A.out (Assembler.OUTput) is a set of formats for libraries and
54482 executables used in the earliest versions of UNIX. Linux used
54483diff --git a/fs/afs/inode.c b/fs/afs/inode.c
54484index 789bc25..fafaeea 100644
54485--- a/fs/afs/inode.c
54486+++ b/fs/afs/inode.c
54487@@ -141,7 +141,7 @@ struct inode *afs_iget_autocell(struct inode *dir, const char *dev_name,
54488 struct afs_vnode *vnode;
54489 struct super_block *sb;
54490 struct inode *inode;
54491- static atomic_t afs_autocell_ino;
54492+ static atomic_unchecked_t afs_autocell_ino;
54493
54494 _enter("{%x:%u},%*.*s,",
54495 AFS_FS_I(dir)->fid.vid, AFS_FS_I(dir)->fid.vnode,
54496@@ -154,7 +154,7 @@ struct inode *afs_iget_autocell(struct inode *dir, const char *dev_name,
54497 data.fid.unique = 0;
54498 data.fid.vnode = 0;
54499
54500- inode = iget5_locked(sb, atomic_inc_return(&afs_autocell_ino),
54501+ inode = iget5_locked(sb, atomic_inc_return_unchecked(&afs_autocell_ino),
54502 afs_iget5_autocell_test, afs_iget5_set,
54503 &data);
54504 if (!inode) {
54505diff --git a/fs/aio.c b/fs/aio.c
54506index 062a5f6..e5618e0 100644
54507--- a/fs/aio.c
54508+++ b/fs/aio.c
54509@@ -374,7 +374,7 @@ static int aio_setup_ring(struct kioctx *ctx)
54510 size += sizeof(struct io_event) * nr_events;
54511
54512 nr_pages = PFN_UP(size);
54513- if (nr_pages < 0)
54514+ if (nr_pages <= 0)
54515 return -EINVAL;
54516
54517 file = aio_private_file(ctx, nr_pages);
54518diff --git a/fs/attr.c b/fs/attr.c
54519index 1449adb..a2038c2 100644
54520--- a/fs/attr.c
54521+++ b/fs/attr.c
54522@@ -102,6 +102,7 @@ int inode_newsize_ok(const struct inode *inode, loff_t offset)
54523 unsigned long limit;
54524
54525 limit = rlimit(RLIMIT_FSIZE);
54526+ gr_learn_resource(current, RLIMIT_FSIZE, (unsigned long)offset, 1);
54527 if (limit != RLIM_INFINITY && offset > limit)
54528 goto out_sig;
54529 if (offset > inode->i_sb->s_maxbytes)
54530diff --git a/fs/autofs4/waitq.c b/fs/autofs4/waitq.c
54531index 689e40d..515cac5 100644
54532--- a/fs/autofs4/waitq.c
54533+++ b/fs/autofs4/waitq.c
54534@@ -59,7 +59,7 @@ static int autofs4_write(struct autofs_sb_info *sbi,
54535 {
54536 unsigned long sigpipe, flags;
54537 mm_segment_t fs;
54538- const char *data = (const char *)addr;
54539+ const char __user *data = (const char __force_user *)addr;
54540 ssize_t wr = 0;
54541
54542 sigpipe = sigismember(&current->pending.signal, SIGPIPE);
54543@@ -340,6 +340,10 @@ static int validate_request(struct autofs_wait_queue **wait,
54544 return 1;
54545 }
54546
54547+#ifdef CONFIG_GRKERNSEC_HIDESYM
54548+static atomic_unchecked_t autofs_dummy_name_id = ATOMIC_INIT(0);
54549+#endif
54550+
54551 int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
54552 enum autofs_notify notify)
54553 {
54554@@ -373,7 +377,12 @@ int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
54555
54556 /* If this is a direct mount request create a dummy name */
54557 if (IS_ROOT(dentry) && autofs_type_trigger(sbi->type))
54558+#ifdef CONFIG_GRKERNSEC_HIDESYM
54559+ /* this name does get written to userland via autofs4_write() */
54560+ qstr.len = sprintf(name, "%08x", atomic_inc_return_unchecked(&autofs_dummy_name_id));
54561+#else
54562 qstr.len = sprintf(name, "%p", dentry);
54563+#endif
54564 else {
54565 qstr.len = autofs4_getpath(sbi, dentry, &name);
54566 if (!qstr.len) {
54567diff --git a/fs/befs/endian.h b/fs/befs/endian.h
54568index 2722387..56059b5 100644
54569--- a/fs/befs/endian.h
54570+++ b/fs/befs/endian.h
54571@@ -11,7 +11,7 @@
54572
54573 #include <asm/byteorder.h>
54574
54575-static inline u64
54576+static inline u64 __intentional_overflow(-1)
54577 fs64_to_cpu(const struct super_block *sb, fs64 n)
54578 {
54579 if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE)
54580@@ -29,7 +29,7 @@ cpu_to_fs64(const struct super_block *sb, u64 n)
54581 return (__force fs64)cpu_to_be64(n);
54582 }
54583
54584-static inline u32
54585+static inline u32 __intentional_overflow(-1)
54586 fs32_to_cpu(const struct super_block *sb, fs32 n)
54587 {
54588 if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE)
54589@@ -47,7 +47,7 @@ cpu_to_fs32(const struct super_block *sb, u32 n)
54590 return (__force fs32)cpu_to_be32(n);
54591 }
54592
54593-static inline u16
54594+static inline u16 __intentional_overflow(-1)
54595 fs16_to_cpu(const struct super_block *sb, fs16 n)
54596 {
54597 if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE)
54598diff --git a/fs/befs/linuxvfs.c b/fs/befs/linuxvfs.c
54599index e9c75e2..1baece1 100644
54600--- a/fs/befs/linuxvfs.c
54601+++ b/fs/befs/linuxvfs.c
54602@@ -514,7 +514,7 @@ static void befs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
54603 {
54604 befs_inode_info *befs_ino = BEFS_I(dentry->d_inode);
54605 if (befs_ino->i_flags & BEFS_LONG_SYMLINK) {
54606- char *link = nd_get_link(nd);
54607+ const char *link = nd_get_link(nd);
54608 if (!IS_ERR(link))
54609 kfree(link);
54610 }
54611diff --git a/fs/binfmt_aout.c b/fs/binfmt_aout.c
54612index 89dec7f..361b0d75 100644
54613--- a/fs/binfmt_aout.c
54614+++ b/fs/binfmt_aout.c
54615@@ -16,6 +16,7 @@
54616 #include <linux/string.h>
54617 #include <linux/fs.h>
54618 #include <linux/file.h>
54619+#include <linux/security.h>
54620 #include <linux/stat.h>
54621 #include <linux/fcntl.h>
54622 #include <linux/ptrace.h>
54623@@ -59,6 +60,8 @@ static int aout_core_dump(struct coredump_params *cprm)
54624 #endif
54625 # define START_STACK(u) ((void __user *)u.start_stack)
54626
54627+ memset(&dump, 0, sizeof(dump));
54628+
54629 fs = get_fs();
54630 set_fs(KERNEL_DS);
54631 has_dumped = 1;
54632@@ -69,10 +72,12 @@ static int aout_core_dump(struct coredump_params *cprm)
54633
54634 /* If the size of the dump file exceeds the rlimit, then see what would happen
54635 if we wrote the stack, but not the data area. */
54636+ gr_learn_resource(current, RLIMIT_CORE, (dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE, 1);
54637 if ((dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE > cprm->limit)
54638 dump.u_dsize = 0;
54639
54640 /* Make sure we have enough room to write the stack and data areas. */
54641+ gr_learn_resource(current, RLIMIT_CORE, (dump.u_ssize + 1) * PAGE_SIZE, 1);
54642 if ((dump.u_ssize + 1) * PAGE_SIZE > cprm->limit)
54643 dump.u_ssize = 0;
54644
54645@@ -233,6 +238,8 @@ static int load_aout_binary(struct linux_binprm * bprm)
54646 rlim = rlimit(RLIMIT_DATA);
54647 if (rlim >= RLIM_INFINITY)
54648 rlim = ~0;
54649+
54650+ gr_learn_resource(current, RLIMIT_DATA, ex.a_data + ex.a_bss, 1);
54651 if (ex.a_data + ex.a_bss > rlim)
54652 return -ENOMEM;
54653
54654@@ -265,6 +272,27 @@ static int load_aout_binary(struct linux_binprm * bprm)
54655
54656 install_exec_creds(bprm);
54657
54658+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
54659+ current->mm->pax_flags = 0UL;
54660+#endif
54661+
54662+#ifdef CONFIG_PAX_PAGEEXEC
54663+ if (!(N_FLAGS(ex) & F_PAX_PAGEEXEC)) {
54664+ current->mm->pax_flags |= MF_PAX_PAGEEXEC;
54665+
54666+#ifdef CONFIG_PAX_EMUTRAMP
54667+ if (N_FLAGS(ex) & F_PAX_EMUTRAMP)
54668+ current->mm->pax_flags |= MF_PAX_EMUTRAMP;
54669+#endif
54670+
54671+#ifdef CONFIG_PAX_MPROTECT
54672+ if (!(N_FLAGS(ex) & F_PAX_MPROTECT))
54673+ current->mm->pax_flags |= MF_PAX_MPROTECT;
54674+#endif
54675+
54676+ }
54677+#endif
54678+
54679 if (N_MAGIC(ex) == OMAGIC) {
54680 unsigned long text_addr, map_size;
54681 loff_t pos;
54682@@ -322,7 +350,7 @@ static int load_aout_binary(struct linux_binprm * bprm)
54683 }
54684
54685 error = vm_mmap(bprm->file, N_DATADDR(ex), ex.a_data,
54686- PROT_READ | PROT_WRITE | PROT_EXEC,
54687+ PROT_READ | PROT_WRITE,
54688 MAP_FIXED | MAP_PRIVATE | MAP_DENYWRITE | MAP_EXECUTABLE,
54689 fd_offset + ex.a_text);
54690 if (error != N_DATADDR(ex)) {
54691diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c
54692index 4c94a79..9d5fb56 100644
54693--- a/fs/binfmt_elf.c
54694+++ b/fs/binfmt_elf.c
54695@@ -34,6 +34,7 @@
54696 #include <linux/utsname.h>
54697 #include <linux/coredump.h>
54698 #include <linux/sched.h>
54699+#include <linux/xattr.h>
54700 #include <asm/uaccess.h>
54701 #include <asm/param.h>
54702 #include <asm/page.h>
54703@@ -60,6 +61,14 @@ static int elf_core_dump(struct coredump_params *cprm);
54704 #define elf_core_dump NULL
54705 #endif
54706
54707+#ifdef CONFIG_PAX_MPROTECT
54708+static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags);
54709+#endif
54710+
54711+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
54712+static void elf_handle_mmap(struct file *file);
54713+#endif
54714+
54715 #if ELF_EXEC_PAGESIZE > PAGE_SIZE
54716 #define ELF_MIN_ALIGN ELF_EXEC_PAGESIZE
54717 #else
54718@@ -79,6 +88,15 @@ static struct linux_binfmt elf_format = {
54719 .load_binary = load_elf_binary,
54720 .load_shlib = load_elf_library,
54721 .core_dump = elf_core_dump,
54722+
54723+#ifdef CONFIG_PAX_MPROTECT
54724+ .handle_mprotect= elf_handle_mprotect,
54725+#endif
54726+
54727+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
54728+ .handle_mmap = elf_handle_mmap,
54729+#endif
54730+
54731 .min_coredump = ELF_EXEC_PAGESIZE,
54732 };
54733
54734@@ -86,6 +104,8 @@ static struct linux_binfmt elf_format = {
54735
54736 static int set_brk(unsigned long start, unsigned long end)
54737 {
54738+ unsigned long e = end;
54739+
54740 start = ELF_PAGEALIGN(start);
54741 end = ELF_PAGEALIGN(end);
54742 if (end > start) {
54743@@ -94,7 +114,7 @@ static int set_brk(unsigned long start, unsigned long end)
54744 if (BAD_ADDR(addr))
54745 return addr;
54746 }
54747- current->mm->start_brk = current->mm->brk = end;
54748+ current->mm->start_brk = current->mm->brk = e;
54749 return 0;
54750 }
54751
54752@@ -155,12 +175,13 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
54753 elf_addr_t __user *u_rand_bytes;
54754 const char *k_platform = ELF_PLATFORM;
54755 const char *k_base_platform = ELF_BASE_PLATFORM;
54756- unsigned char k_rand_bytes[16];
54757+ u32 k_rand_bytes[4];
54758 int items;
54759 elf_addr_t *elf_info;
54760 int ei_index = 0;
54761 const struct cred *cred = current_cred();
54762 struct vm_area_struct *vma;
54763+ unsigned long saved_auxv[AT_VECTOR_SIZE];
54764
54765 /*
54766 * In some cases (e.g. Hyper-Threading), we want to avoid L1
54767@@ -202,8 +223,12 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
54768 * Generate 16 random bytes for userspace PRNG seeding.
54769 */
54770 get_random_bytes(k_rand_bytes, sizeof(k_rand_bytes));
54771- u_rand_bytes = (elf_addr_t __user *)
54772- STACK_ALLOC(p, sizeof(k_rand_bytes));
54773+ prandom_seed(k_rand_bytes[0] ^ prandom_u32());
54774+ prandom_seed(k_rand_bytes[1] ^ prandom_u32());
54775+ prandom_seed(k_rand_bytes[2] ^ prandom_u32());
54776+ prandom_seed(k_rand_bytes[3] ^ prandom_u32());
54777+ p = STACK_ROUND(p, sizeof(k_rand_bytes));
54778+ u_rand_bytes = (elf_addr_t __user *) p;
54779 if (__copy_to_user(u_rand_bytes, k_rand_bytes, sizeof(k_rand_bytes)))
54780 return -EFAULT;
54781
54782@@ -318,9 +343,11 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
54783 return -EFAULT;
54784 current->mm->env_end = p;
54785
54786+ memcpy(saved_auxv, elf_info, ei_index * sizeof(elf_addr_t));
54787+
54788 /* Put the elf_info on the stack in the right place. */
54789 sp = (elf_addr_t __user *)envp + 1;
54790- if (copy_to_user(sp, elf_info, ei_index * sizeof(elf_addr_t)))
54791+ if (copy_to_user(sp, saved_auxv, ei_index * sizeof(elf_addr_t)))
54792 return -EFAULT;
54793 return 0;
54794 }
54795@@ -388,15 +415,14 @@ static unsigned long total_mapping_size(struct elf_phdr *cmds, int nr)
54796 an ELF header */
54797
54798 static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
54799- struct file *interpreter, unsigned long *interp_map_addr,
54800- unsigned long no_base)
54801+ struct file *interpreter, unsigned long no_base)
54802 {
54803 struct elf_phdr *elf_phdata;
54804 struct elf_phdr *eppnt;
54805- unsigned long load_addr = 0;
54806+ unsigned long load_addr = 0, pax_task_size = TASK_SIZE;
54807 int load_addr_set = 0;
54808 unsigned long last_bss = 0, elf_bss = 0;
54809- unsigned long error = ~0UL;
54810+ unsigned long error = -EINVAL;
54811 unsigned long total_size;
54812 int retval, i, size;
54813
54814@@ -442,6 +468,11 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
54815 goto out_close;
54816 }
54817
54818+#ifdef CONFIG_PAX_SEGMEXEC
54819+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
54820+ pax_task_size = SEGMEXEC_TASK_SIZE;
54821+#endif
54822+
54823 eppnt = elf_phdata;
54824 for (i = 0; i < interp_elf_ex->e_phnum; i++, eppnt++) {
54825 if (eppnt->p_type == PT_LOAD) {
54826@@ -465,8 +496,6 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
54827 map_addr = elf_map(interpreter, load_addr + vaddr,
54828 eppnt, elf_prot, elf_type, total_size);
54829 total_size = 0;
54830- if (!*interp_map_addr)
54831- *interp_map_addr = map_addr;
54832 error = map_addr;
54833 if (BAD_ADDR(map_addr))
54834 goto out_close;
54835@@ -485,8 +514,8 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
54836 k = load_addr + eppnt->p_vaddr;
54837 if (BAD_ADDR(k) ||
54838 eppnt->p_filesz > eppnt->p_memsz ||
54839- eppnt->p_memsz > TASK_SIZE ||
54840- TASK_SIZE - eppnt->p_memsz < k) {
54841+ eppnt->p_memsz > pax_task_size ||
54842+ pax_task_size - eppnt->p_memsz < k) {
54843 error = -ENOMEM;
54844 goto out_close;
54845 }
54846@@ -525,9 +554,11 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
54847 elf_bss = ELF_PAGESTART(elf_bss + ELF_MIN_ALIGN - 1);
54848
54849 /* Map the last of the bss segment */
54850- error = vm_brk(elf_bss, last_bss - elf_bss);
54851- if (BAD_ADDR(error))
54852- goto out_close;
54853+ if (last_bss > elf_bss) {
54854+ error = vm_brk(elf_bss, last_bss - elf_bss);
54855+ if (BAD_ADDR(error))
54856+ goto out_close;
54857+ }
54858 }
54859
54860 error = load_addr;
54861@@ -538,6 +569,336 @@ out:
54862 return error;
54863 }
54864
54865+#ifdef CONFIG_PAX_PT_PAX_FLAGS
54866+#ifdef CONFIG_PAX_SOFTMODE
54867+static unsigned long pax_parse_pt_pax_softmode(const struct elf_phdr * const elf_phdata)
54868+{
54869+ unsigned long pax_flags = 0UL;
54870+
54871+#ifdef CONFIG_PAX_PAGEEXEC
54872+ if (elf_phdata->p_flags & PF_PAGEEXEC)
54873+ pax_flags |= MF_PAX_PAGEEXEC;
54874+#endif
54875+
54876+#ifdef CONFIG_PAX_SEGMEXEC
54877+ if (elf_phdata->p_flags & PF_SEGMEXEC)
54878+ pax_flags |= MF_PAX_SEGMEXEC;
54879+#endif
54880+
54881+#ifdef CONFIG_PAX_EMUTRAMP
54882+ if ((elf_phdata->p_flags & PF_EMUTRAMP) && (pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)))
54883+ pax_flags |= MF_PAX_EMUTRAMP;
54884+#endif
54885+
54886+#ifdef CONFIG_PAX_MPROTECT
54887+ if (elf_phdata->p_flags & PF_MPROTECT)
54888+ pax_flags |= MF_PAX_MPROTECT;
54889+#endif
54890+
54891+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
54892+ if (randomize_va_space && (elf_phdata->p_flags & PF_RANDMMAP))
54893+ pax_flags |= MF_PAX_RANDMMAP;
54894+#endif
54895+
54896+ return pax_flags;
54897+}
54898+#endif
54899+
54900+static unsigned long pax_parse_pt_pax_hardmode(const struct elf_phdr * const elf_phdata)
54901+{
54902+ unsigned long pax_flags = 0UL;
54903+
54904+#ifdef CONFIG_PAX_PAGEEXEC
54905+ if (!(elf_phdata->p_flags & PF_NOPAGEEXEC))
54906+ pax_flags |= MF_PAX_PAGEEXEC;
54907+#endif
54908+
54909+#ifdef CONFIG_PAX_SEGMEXEC
54910+ if (!(elf_phdata->p_flags & PF_NOSEGMEXEC))
54911+ pax_flags |= MF_PAX_SEGMEXEC;
54912+#endif
54913+
54914+#ifdef CONFIG_PAX_EMUTRAMP
54915+ if (!(elf_phdata->p_flags & PF_NOEMUTRAMP))
54916+ pax_flags |= MF_PAX_EMUTRAMP;
54917+#endif
54918+
54919+#ifdef CONFIG_PAX_MPROTECT
54920+ if (!(elf_phdata->p_flags & PF_NOMPROTECT))
54921+ pax_flags |= MF_PAX_MPROTECT;
54922+#endif
54923+
54924+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
54925+ if (randomize_va_space && !(elf_phdata->p_flags & PF_NORANDMMAP))
54926+ pax_flags |= MF_PAX_RANDMMAP;
54927+#endif
54928+
54929+ return pax_flags;
54930+}
54931+#endif
54932+
54933+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
54934+#ifdef CONFIG_PAX_SOFTMODE
54935+static unsigned long pax_parse_xattr_pax_softmode(unsigned long pax_flags_softmode)
54936+{
54937+ unsigned long pax_flags = 0UL;
54938+
54939+#ifdef CONFIG_PAX_PAGEEXEC
54940+ if (pax_flags_softmode & MF_PAX_PAGEEXEC)
54941+ pax_flags |= MF_PAX_PAGEEXEC;
54942+#endif
54943+
54944+#ifdef CONFIG_PAX_SEGMEXEC
54945+ if (pax_flags_softmode & MF_PAX_SEGMEXEC)
54946+ pax_flags |= MF_PAX_SEGMEXEC;
54947+#endif
54948+
54949+#ifdef CONFIG_PAX_EMUTRAMP
54950+ if ((pax_flags_softmode & MF_PAX_EMUTRAMP) && (pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)))
54951+ pax_flags |= MF_PAX_EMUTRAMP;
54952+#endif
54953+
54954+#ifdef CONFIG_PAX_MPROTECT
54955+ if (pax_flags_softmode & MF_PAX_MPROTECT)
54956+ pax_flags |= MF_PAX_MPROTECT;
54957+#endif
54958+
54959+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
54960+ if (randomize_va_space && (pax_flags_softmode & MF_PAX_RANDMMAP))
54961+ pax_flags |= MF_PAX_RANDMMAP;
54962+#endif
54963+
54964+ return pax_flags;
54965+}
54966+#endif
54967+
54968+static unsigned long pax_parse_xattr_pax_hardmode(unsigned long pax_flags_hardmode)
54969+{
54970+ unsigned long pax_flags = 0UL;
54971+
54972+#ifdef CONFIG_PAX_PAGEEXEC
54973+ if (!(pax_flags_hardmode & MF_PAX_PAGEEXEC))
54974+ pax_flags |= MF_PAX_PAGEEXEC;
54975+#endif
54976+
54977+#ifdef CONFIG_PAX_SEGMEXEC
54978+ if (!(pax_flags_hardmode & MF_PAX_SEGMEXEC))
54979+ pax_flags |= MF_PAX_SEGMEXEC;
54980+#endif
54981+
54982+#ifdef CONFIG_PAX_EMUTRAMP
54983+ if (!(pax_flags_hardmode & MF_PAX_EMUTRAMP))
54984+ pax_flags |= MF_PAX_EMUTRAMP;
54985+#endif
54986+
54987+#ifdef CONFIG_PAX_MPROTECT
54988+ if (!(pax_flags_hardmode & MF_PAX_MPROTECT))
54989+ pax_flags |= MF_PAX_MPROTECT;
54990+#endif
54991+
54992+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
54993+ if (randomize_va_space && !(pax_flags_hardmode & MF_PAX_RANDMMAP))
54994+ pax_flags |= MF_PAX_RANDMMAP;
54995+#endif
54996+
54997+ return pax_flags;
54998+}
54999+#endif
55000+
55001+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
55002+static unsigned long pax_parse_defaults(void)
55003+{
55004+ unsigned long pax_flags = 0UL;
55005+
55006+#ifdef CONFIG_PAX_SOFTMODE
55007+ if (pax_softmode)
55008+ return pax_flags;
55009+#endif
55010+
55011+#ifdef CONFIG_PAX_PAGEEXEC
55012+ pax_flags |= MF_PAX_PAGEEXEC;
55013+#endif
55014+
55015+#ifdef CONFIG_PAX_SEGMEXEC
55016+ pax_flags |= MF_PAX_SEGMEXEC;
55017+#endif
55018+
55019+#ifdef CONFIG_PAX_MPROTECT
55020+ pax_flags |= MF_PAX_MPROTECT;
55021+#endif
55022+
55023+#ifdef CONFIG_PAX_RANDMMAP
55024+ if (randomize_va_space)
55025+ pax_flags |= MF_PAX_RANDMMAP;
55026+#endif
55027+
55028+ return pax_flags;
55029+}
55030+
55031+static unsigned long pax_parse_ei_pax(const struct elfhdr * const elf_ex)
55032+{
55033+ unsigned long pax_flags = PAX_PARSE_FLAGS_FALLBACK;
55034+
55035+#ifdef CONFIG_PAX_EI_PAX
55036+
55037+#ifdef CONFIG_PAX_SOFTMODE
55038+ if (pax_softmode)
55039+ return pax_flags;
55040+#endif
55041+
55042+ pax_flags = 0UL;
55043+
55044+#ifdef CONFIG_PAX_PAGEEXEC
55045+ if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_PAGEEXEC))
55046+ pax_flags |= MF_PAX_PAGEEXEC;
55047+#endif
55048+
55049+#ifdef CONFIG_PAX_SEGMEXEC
55050+ if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_SEGMEXEC))
55051+ pax_flags |= MF_PAX_SEGMEXEC;
55052+#endif
55053+
55054+#ifdef CONFIG_PAX_EMUTRAMP
55055+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && (elf_ex->e_ident[EI_PAX] & EF_PAX_EMUTRAMP))
55056+ pax_flags |= MF_PAX_EMUTRAMP;
55057+#endif
55058+
55059+#ifdef CONFIG_PAX_MPROTECT
55060+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && !(elf_ex->e_ident[EI_PAX] & EF_PAX_MPROTECT))
55061+ pax_flags |= MF_PAX_MPROTECT;
55062+#endif
55063+
55064+#ifdef CONFIG_PAX_ASLR
55065+ if (randomize_va_space && !(elf_ex->e_ident[EI_PAX] & EF_PAX_RANDMMAP))
55066+ pax_flags |= MF_PAX_RANDMMAP;
55067+#endif
55068+
55069+#endif
55070+
55071+ return pax_flags;
55072+
55073+}
55074+
55075+static unsigned long pax_parse_pt_pax(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata)
55076+{
55077+
55078+#ifdef CONFIG_PAX_PT_PAX_FLAGS
55079+ unsigned long i;
55080+
55081+ for (i = 0UL; i < elf_ex->e_phnum; i++)
55082+ if (elf_phdata[i].p_type == PT_PAX_FLAGS) {
55083+ if (((elf_phdata[i].p_flags & PF_PAGEEXEC) && (elf_phdata[i].p_flags & PF_NOPAGEEXEC)) ||
55084+ ((elf_phdata[i].p_flags & PF_SEGMEXEC) && (elf_phdata[i].p_flags & PF_NOSEGMEXEC)) ||
55085+ ((elf_phdata[i].p_flags & PF_EMUTRAMP) && (elf_phdata[i].p_flags & PF_NOEMUTRAMP)) ||
55086+ ((elf_phdata[i].p_flags & PF_MPROTECT) && (elf_phdata[i].p_flags & PF_NOMPROTECT)) ||
55087+ ((elf_phdata[i].p_flags & PF_RANDMMAP) && (elf_phdata[i].p_flags & PF_NORANDMMAP)))
55088+ return PAX_PARSE_FLAGS_FALLBACK;
55089+
55090+#ifdef CONFIG_PAX_SOFTMODE
55091+ if (pax_softmode)
55092+ return pax_parse_pt_pax_softmode(&elf_phdata[i]);
55093+ else
55094+#endif
55095+
55096+ return pax_parse_pt_pax_hardmode(&elf_phdata[i]);
55097+ break;
55098+ }
55099+#endif
55100+
55101+ return PAX_PARSE_FLAGS_FALLBACK;
55102+}
55103+
55104+static unsigned long pax_parse_xattr_pax(struct file * const file)
55105+{
55106+
55107+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
55108+ ssize_t xattr_size, i;
55109+ unsigned char xattr_value[sizeof("pemrs") - 1];
55110+ unsigned long pax_flags_hardmode = 0UL, pax_flags_softmode = 0UL;
55111+
55112+ xattr_size = pax_getxattr(file->f_path.dentry, xattr_value, sizeof xattr_value);
55113+ if (xattr_size < 0 || xattr_size > sizeof xattr_value)
55114+ return PAX_PARSE_FLAGS_FALLBACK;
55115+
55116+ for (i = 0; i < xattr_size; i++)
55117+ switch (xattr_value[i]) {
55118+ default:
55119+ return PAX_PARSE_FLAGS_FALLBACK;
55120+
55121+#define parse_flag(option1, option2, flag) \
55122+ case option1: \
55123+ if (pax_flags_hardmode & MF_PAX_##flag) \
55124+ return PAX_PARSE_FLAGS_FALLBACK;\
55125+ pax_flags_hardmode |= MF_PAX_##flag; \
55126+ break; \
55127+ case option2: \
55128+ if (pax_flags_softmode & MF_PAX_##flag) \
55129+ return PAX_PARSE_FLAGS_FALLBACK;\
55130+ pax_flags_softmode |= MF_PAX_##flag; \
55131+ break;
55132+
55133+ parse_flag('p', 'P', PAGEEXEC);
55134+ parse_flag('e', 'E', EMUTRAMP);
55135+ parse_flag('m', 'M', MPROTECT);
55136+ parse_flag('r', 'R', RANDMMAP);
55137+ parse_flag('s', 'S', SEGMEXEC);
55138+
55139+#undef parse_flag
55140+ }
55141+
55142+ if (pax_flags_hardmode & pax_flags_softmode)
55143+ return PAX_PARSE_FLAGS_FALLBACK;
55144+
55145+#ifdef CONFIG_PAX_SOFTMODE
55146+ if (pax_softmode)
55147+ return pax_parse_xattr_pax_softmode(pax_flags_softmode);
55148+ else
55149+#endif
55150+
55151+ return pax_parse_xattr_pax_hardmode(pax_flags_hardmode);
55152+#else
55153+ return PAX_PARSE_FLAGS_FALLBACK;
55154+#endif
55155+
55156+}
55157+
55158+static long pax_parse_pax_flags(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata, struct file * const file)
55159+{
55160+ unsigned long pax_flags, ei_pax_flags, pt_pax_flags, xattr_pax_flags;
55161+
55162+ pax_flags = pax_parse_defaults();
55163+ ei_pax_flags = pax_parse_ei_pax(elf_ex);
55164+ pt_pax_flags = pax_parse_pt_pax(elf_ex, elf_phdata);
55165+ xattr_pax_flags = pax_parse_xattr_pax(file);
55166+
55167+ if (pt_pax_flags != PAX_PARSE_FLAGS_FALLBACK &&
55168+ xattr_pax_flags != PAX_PARSE_FLAGS_FALLBACK &&
55169+ pt_pax_flags != xattr_pax_flags)
55170+ return -EINVAL;
55171+ if (xattr_pax_flags != PAX_PARSE_FLAGS_FALLBACK)
55172+ pax_flags = xattr_pax_flags;
55173+ else if (pt_pax_flags != PAX_PARSE_FLAGS_FALLBACK)
55174+ pax_flags = pt_pax_flags;
55175+ else if (ei_pax_flags != PAX_PARSE_FLAGS_FALLBACK)
55176+ pax_flags = ei_pax_flags;
55177+
55178+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
55179+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
55180+ if ((__supported_pte_mask & _PAGE_NX))
55181+ pax_flags &= ~MF_PAX_SEGMEXEC;
55182+ else
55183+ pax_flags &= ~MF_PAX_PAGEEXEC;
55184+ }
55185+#endif
55186+
55187+ if (0 > pax_check_flags(&pax_flags))
55188+ return -EINVAL;
55189+
55190+ current->mm->pax_flags = pax_flags;
55191+ return 0;
55192+}
55193+#endif
55194+
55195 /*
55196 * These are the functions used to load ELF style executables and shared
55197 * libraries. There is no binary dependent code anywhere else.
55198@@ -554,6 +915,11 @@ static unsigned long randomize_stack_top(unsigned long stack_top)
55199 {
55200 unsigned int random_variable = 0;
55201
55202+#ifdef CONFIG_PAX_RANDUSTACK
55203+ if (current->mm->pax_flags & MF_PAX_RANDMMAP)
55204+ return stack_top - current->mm->delta_stack;
55205+#endif
55206+
55207 if ((current->flags & PF_RANDOMIZE) &&
55208 !(current->personality & ADDR_NO_RANDOMIZE)) {
55209 random_variable = get_random_int() & STACK_RND_MASK;
55210@@ -572,7 +938,7 @@ static int load_elf_binary(struct linux_binprm *bprm)
55211 unsigned long load_addr = 0, load_bias = 0;
55212 int load_addr_set = 0;
55213 char * elf_interpreter = NULL;
55214- unsigned long error;
55215+ unsigned long error = 0;
55216 struct elf_phdr *elf_ppnt, *elf_phdata;
55217 unsigned long elf_bss, elf_brk;
55218 int retval, i;
55219@@ -582,12 +948,12 @@ static int load_elf_binary(struct linux_binprm *bprm)
55220 unsigned long start_code, end_code, start_data, end_data;
55221 unsigned long reloc_func_desc __maybe_unused = 0;
55222 int executable_stack = EXSTACK_DEFAULT;
55223- unsigned long def_flags = 0;
55224 struct pt_regs *regs = current_pt_regs();
55225 struct {
55226 struct elfhdr elf_ex;
55227 struct elfhdr interp_elf_ex;
55228 } *loc;
55229+ unsigned long pax_task_size;
55230
55231 loc = kmalloc(sizeof(*loc), GFP_KERNEL);
55232 if (!loc) {
55233@@ -723,11 +1089,82 @@ static int load_elf_binary(struct linux_binprm *bprm)
55234 goto out_free_dentry;
55235
55236 /* OK, This is the point of no return */
55237- current->mm->def_flags = def_flags;
55238+ current->mm->def_flags = 0;
55239
55240 /* Do this immediately, since STACK_TOP as used in setup_arg_pages
55241 may depend on the personality. */
55242 SET_PERSONALITY(loc->elf_ex);
55243+
55244+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
55245+ current->mm->pax_flags = 0UL;
55246+#endif
55247+
55248+#ifdef CONFIG_PAX_DLRESOLVE
55249+ current->mm->call_dl_resolve = 0UL;
55250+#endif
55251+
55252+#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
55253+ current->mm->call_syscall = 0UL;
55254+#endif
55255+
55256+#ifdef CONFIG_PAX_ASLR
55257+ current->mm->delta_mmap = 0UL;
55258+ current->mm->delta_stack = 0UL;
55259+#endif
55260+
55261+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
55262+ if (0 > pax_parse_pax_flags(&loc->elf_ex, elf_phdata, bprm->file)) {
55263+ send_sig(SIGKILL, current, 0);
55264+ goto out_free_dentry;
55265+ }
55266+#endif
55267+
55268+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
55269+ pax_set_initial_flags(bprm);
55270+#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
55271+ if (pax_set_initial_flags_func)
55272+ (pax_set_initial_flags_func)(bprm);
55273+#endif
55274+
55275+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
55276+ if ((current->mm->pax_flags & MF_PAX_PAGEEXEC) && !(__supported_pte_mask & _PAGE_NX)) {
55277+ current->mm->context.user_cs_limit = PAGE_SIZE;
55278+ current->mm->def_flags |= VM_PAGEEXEC | VM_NOHUGEPAGE;
55279+ }
55280+#endif
55281+
55282+#ifdef CONFIG_PAX_SEGMEXEC
55283+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
55284+ current->mm->context.user_cs_base = SEGMEXEC_TASK_SIZE;
55285+ current->mm->context.user_cs_limit = TASK_SIZE-SEGMEXEC_TASK_SIZE;
55286+ pax_task_size = SEGMEXEC_TASK_SIZE;
55287+ current->mm->def_flags |= VM_NOHUGEPAGE;
55288+ } else
55289+#endif
55290+
55291+ pax_task_size = TASK_SIZE;
55292+
55293+#if defined(CONFIG_ARCH_TRACK_EXEC_LIMIT) || defined(CONFIG_PAX_SEGMEXEC)
55294+ if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
55295+ set_user_cs(current->mm->context.user_cs_base, current->mm->context.user_cs_limit, get_cpu());
55296+ put_cpu();
55297+ }
55298+#endif
55299+
55300+#ifdef CONFIG_PAX_ASLR
55301+ if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
55302+ current->mm->delta_mmap = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN)-1)) << PAGE_SHIFT;
55303+ current->mm->delta_stack = (pax_get_random_long() & ((1UL << PAX_DELTA_STACK_LEN)-1)) << PAGE_SHIFT;
55304+ }
55305+#endif
55306+
55307+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
55308+ if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
55309+ executable_stack = EXSTACK_DISABLE_X;
55310+ current->personality &= ~READ_IMPLIES_EXEC;
55311+ } else
55312+#endif
55313+
55314 if (elf_read_implies_exec(loc->elf_ex, executable_stack))
55315 current->personality |= READ_IMPLIES_EXEC;
55316
55317@@ -817,6 +1254,20 @@ static int load_elf_binary(struct linux_binprm *bprm)
55318 #else
55319 load_bias = ELF_PAGESTART(ELF_ET_DYN_BASE - vaddr);
55320 #endif
55321+
55322+#ifdef CONFIG_PAX_RANDMMAP
55323+ /* PaX: randomize base address at the default exe base if requested */
55324+ if ((current->mm->pax_flags & MF_PAX_RANDMMAP) && elf_interpreter) {
55325+#ifdef CONFIG_SPARC64
55326+ load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << (PAGE_SHIFT+1);
55327+#else
55328+ load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << PAGE_SHIFT;
55329+#endif
55330+ load_bias = ELF_PAGESTART(PAX_ELF_ET_DYN_BASE - vaddr + load_bias);
55331+ elf_flags |= MAP_FIXED;
55332+ }
55333+#endif
55334+
55335 }
55336
55337 error = elf_map(bprm->file, load_bias + vaddr, elf_ppnt,
55338@@ -849,9 +1300,9 @@ static int load_elf_binary(struct linux_binprm *bprm)
55339 * allowed task size. Note that p_filesz must always be
55340 * <= p_memsz so it is only necessary to check p_memsz.
55341 */
55342- if (BAD_ADDR(k) || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
55343- elf_ppnt->p_memsz > TASK_SIZE ||
55344- TASK_SIZE - elf_ppnt->p_memsz < k) {
55345+ if (k >= pax_task_size || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
55346+ elf_ppnt->p_memsz > pax_task_size ||
55347+ pax_task_size - elf_ppnt->p_memsz < k) {
55348 /* set_brk can never work. Avoid overflows. */
55349 send_sig(SIGKILL, current, 0);
55350 retval = -EINVAL;
55351@@ -890,17 +1341,45 @@ static int load_elf_binary(struct linux_binprm *bprm)
55352 goto out_free_dentry;
55353 }
55354 if (likely(elf_bss != elf_brk) && unlikely(padzero(elf_bss))) {
55355- send_sig(SIGSEGV, current, 0);
55356- retval = -EFAULT; /* Nobody gets to see this, but.. */
55357- goto out_free_dentry;
55358+ /*
55359+ * This bss-zeroing can fail if the ELF
55360+ * file specifies odd protections. So
55361+ * we don't check the return value
55362+ */
55363 }
55364
55365+#ifdef CONFIG_PAX_RANDMMAP
55366+ if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
55367+ unsigned long start, size, flags;
55368+ vm_flags_t vm_flags;
55369+
55370+ start = ELF_PAGEALIGN(elf_brk);
55371+ size = PAGE_SIZE + ((pax_get_random_long() & ((1UL << 22) - 1UL)) << 4);
55372+ flags = MAP_FIXED | MAP_PRIVATE;
55373+ vm_flags = VM_DONTEXPAND | VM_DONTDUMP;
55374+
55375+ down_write(&current->mm->mmap_sem);
55376+ start = get_unmapped_area(NULL, start, PAGE_ALIGN(size), 0, flags);
55377+ retval = -ENOMEM;
55378+ if (!IS_ERR_VALUE(start) && !find_vma_intersection(current->mm, start, start + size + PAGE_SIZE)) {
55379+// if (current->personality & ADDR_NO_RANDOMIZE)
55380+// vm_flags |= VM_READ | VM_MAYREAD;
55381+ start = mmap_region(NULL, start, PAGE_ALIGN(size), vm_flags, 0);
55382+ retval = IS_ERR_VALUE(start) ? start : 0;
55383+ }
55384+ up_write(&current->mm->mmap_sem);
55385+ if (retval == 0)
55386+ retval = set_brk(start + size, start + size + PAGE_SIZE);
55387+ if (retval < 0) {
55388+ send_sig(SIGKILL, current, 0);
55389+ goto out_free_dentry;
55390+ }
55391+ }
55392+#endif
55393+
55394 if (elf_interpreter) {
55395- unsigned long interp_map_addr = 0;
55396-
55397 elf_entry = load_elf_interp(&loc->interp_elf_ex,
55398 interpreter,
55399- &interp_map_addr,
55400 load_bias);
55401 if (!IS_ERR((void *)elf_entry)) {
55402 /*
55403@@ -1122,7 +1601,7 @@ static bool always_dump_vma(struct vm_area_struct *vma)
55404 * Decide what to dump of a segment, part, all or none.
55405 */
55406 static unsigned long vma_dump_size(struct vm_area_struct *vma,
55407- unsigned long mm_flags)
55408+ unsigned long mm_flags, long signr)
55409 {
55410 #define FILTER(type) (mm_flags & (1UL << MMF_DUMP_##type))
55411
55412@@ -1160,7 +1639,7 @@ static unsigned long vma_dump_size(struct vm_area_struct *vma,
55413 if (vma->vm_file == NULL)
55414 return 0;
55415
55416- if (FILTER(MAPPED_PRIVATE))
55417+ if (signr == SIGKILL || FILTER(MAPPED_PRIVATE))
55418 goto whole;
55419
55420 /*
55421@@ -1385,9 +1864,9 @@ static void fill_auxv_note(struct memelfnote *note, struct mm_struct *mm)
55422 {
55423 elf_addr_t *auxv = (elf_addr_t *) mm->saved_auxv;
55424 int i = 0;
55425- do
55426+ do {
55427 i += 2;
55428- while (auxv[i - 2] != AT_NULL);
55429+ } while (auxv[i - 2] != AT_NULL);
55430 fill_note(note, "CORE", NT_AUXV, i * sizeof(elf_addr_t), auxv);
55431 }
55432
55433@@ -1396,7 +1875,7 @@ static void fill_siginfo_note(struct memelfnote *note, user_siginfo_t *csigdata,
55434 {
55435 mm_segment_t old_fs = get_fs();
55436 set_fs(KERNEL_DS);
55437- copy_siginfo_to_user((user_siginfo_t __user *) csigdata, siginfo);
55438+ copy_siginfo_to_user((user_siginfo_t __force_user *) csigdata, siginfo);
55439 set_fs(old_fs);
55440 fill_note(note, "CORE", NT_SIGINFO, sizeof(*csigdata), csigdata);
55441 }
55442@@ -2023,14 +2502,14 @@ static void fill_extnum_info(struct elfhdr *elf, struct elf_shdr *shdr4extnum,
55443 }
55444
55445 static size_t elf_core_vma_data_size(struct vm_area_struct *gate_vma,
55446- unsigned long mm_flags)
55447+ struct coredump_params *cprm)
55448 {
55449 struct vm_area_struct *vma;
55450 size_t size = 0;
55451
55452 for (vma = first_vma(current, gate_vma); vma != NULL;
55453 vma = next_vma(vma, gate_vma))
55454- size += vma_dump_size(vma, mm_flags);
55455+ size += vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
55456 return size;
55457 }
55458
55459@@ -2123,7 +2602,7 @@ static int elf_core_dump(struct coredump_params *cprm)
55460
55461 dataoff = offset = roundup(offset, ELF_EXEC_PAGESIZE);
55462
55463- offset += elf_core_vma_data_size(gate_vma, cprm->mm_flags);
55464+ offset += elf_core_vma_data_size(gate_vma, cprm);
55465 offset += elf_core_extra_data_size();
55466 e_shoff = offset;
55467
55468@@ -2137,10 +2616,12 @@ static int elf_core_dump(struct coredump_params *cprm)
55469 offset = dataoff;
55470
55471 size += sizeof(*elf);
55472+ gr_learn_resource(current, RLIMIT_CORE, size, 1);
55473 if (size > cprm->limit || !dump_write(cprm->file, elf, sizeof(*elf)))
55474 goto end_coredump;
55475
55476 size += sizeof(*phdr4note);
55477+ gr_learn_resource(current, RLIMIT_CORE, size, 1);
55478 if (size > cprm->limit
55479 || !dump_write(cprm->file, phdr4note, sizeof(*phdr4note)))
55480 goto end_coredump;
55481@@ -2154,7 +2635,7 @@ static int elf_core_dump(struct coredump_params *cprm)
55482 phdr.p_offset = offset;
55483 phdr.p_vaddr = vma->vm_start;
55484 phdr.p_paddr = 0;
55485- phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags);
55486+ phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
55487 phdr.p_memsz = vma->vm_end - vma->vm_start;
55488 offset += phdr.p_filesz;
55489 phdr.p_flags = vma->vm_flags & VM_READ ? PF_R : 0;
55490@@ -2165,6 +2646,7 @@ static int elf_core_dump(struct coredump_params *cprm)
55491 phdr.p_align = ELF_EXEC_PAGESIZE;
55492
55493 size += sizeof(phdr);
55494+ gr_learn_resource(current, RLIMIT_CORE, size, 1);
55495 if (size > cprm->limit
55496 || !dump_write(cprm->file, &phdr, sizeof(phdr)))
55497 goto end_coredump;
55498@@ -2189,7 +2671,7 @@ static int elf_core_dump(struct coredump_params *cprm)
55499 unsigned long addr;
55500 unsigned long end;
55501
55502- end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags);
55503+ end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
55504
55505 for (addr = vma->vm_start; addr < end; addr += PAGE_SIZE) {
55506 struct page *page;
55507@@ -2198,6 +2680,7 @@ static int elf_core_dump(struct coredump_params *cprm)
55508 page = get_dump_page(addr);
55509 if (page) {
55510 void *kaddr = kmap(page);
55511+ gr_learn_resource(current, RLIMIT_CORE, size + PAGE_SIZE, 1);
55512 stop = ((size += PAGE_SIZE) > cprm->limit) ||
55513 !dump_write(cprm->file, kaddr,
55514 PAGE_SIZE);
55515@@ -2215,6 +2698,7 @@ static int elf_core_dump(struct coredump_params *cprm)
55516
55517 if (e_phnum == PN_XNUM) {
55518 size += sizeof(*shdr4extnum);
55519+ gr_learn_resource(current, RLIMIT_CORE, size, 1);
55520 if (size > cprm->limit
55521 || !dump_write(cprm->file, shdr4extnum,
55522 sizeof(*shdr4extnum)))
55523@@ -2235,6 +2719,167 @@ out:
55524
55525 #endif /* CONFIG_ELF_CORE */
55526
55527+#ifdef CONFIG_PAX_MPROTECT
55528+/* PaX: non-PIC ELF libraries need relocations on their executable segments
55529+ * therefore we'll grant them VM_MAYWRITE once during their life. Similarly
55530+ * we'll remove VM_MAYWRITE for good on RELRO segments.
55531+ *
55532+ * The checks favour ld-linux.so behaviour which operates on a per ELF segment
55533+ * basis because we want to allow the common case and not the special ones.
55534+ */
55535+static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags)
55536+{
55537+ struct elfhdr elf_h;
55538+ struct elf_phdr elf_p;
55539+ unsigned long i;
55540+ unsigned long oldflags;
55541+ bool is_textrel_rw, is_textrel_rx, is_relro;
55542+
55543+ if (!(vma->vm_mm->pax_flags & MF_PAX_MPROTECT) || !vma->vm_file)
55544+ return;
55545+
55546+ oldflags = vma->vm_flags & (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ);
55547+ newflags &= VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ;
55548+
55549+#ifdef CONFIG_PAX_ELFRELOCS
55550+ /* possible TEXTREL */
55551+ is_textrel_rw = !vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYREAD | VM_EXEC | VM_READ) && newflags == (VM_WRITE | VM_READ);
55552+ is_textrel_rx = vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_WRITE | VM_READ) && newflags == (VM_EXEC | VM_READ);
55553+#else
55554+ is_textrel_rw = false;
55555+ is_textrel_rx = false;
55556+#endif
55557+
55558+ /* possible RELRO */
55559+ is_relro = vma->anon_vma && oldflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ) && newflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ);
55560+
55561+ if (!is_textrel_rw && !is_textrel_rx && !is_relro)
55562+ return;
55563+
55564+ if (sizeof(elf_h) != kernel_read(vma->vm_file, 0UL, (char *)&elf_h, sizeof(elf_h)) ||
55565+ memcmp(elf_h.e_ident, ELFMAG, SELFMAG) ||
55566+
55567+#ifdef CONFIG_PAX_ETEXECRELOCS
55568+ ((is_textrel_rw || is_textrel_rx) && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
55569+#else
55570+ ((is_textrel_rw || is_textrel_rx) && elf_h.e_type != ET_DYN) ||
55571+#endif
55572+
55573+ (is_relro && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
55574+ !elf_check_arch(&elf_h) ||
55575+ elf_h.e_phentsize != sizeof(struct elf_phdr) ||
55576+ elf_h.e_phnum > 65536UL / sizeof(struct elf_phdr))
55577+ return;
55578+
55579+ for (i = 0UL; i < elf_h.e_phnum; i++) {
55580+ if (sizeof(elf_p) != kernel_read(vma->vm_file, elf_h.e_phoff + i*sizeof(elf_p), (char *)&elf_p, sizeof(elf_p)))
55581+ return;
55582+ switch (elf_p.p_type) {
55583+ case PT_DYNAMIC:
55584+ if (!is_textrel_rw && !is_textrel_rx)
55585+ continue;
55586+ i = 0UL;
55587+ while ((i+1) * sizeof(elf_dyn) <= elf_p.p_filesz) {
55588+ elf_dyn dyn;
55589+
55590+ if (sizeof(dyn) != kernel_read(vma->vm_file, elf_p.p_offset + i*sizeof(dyn), (char *)&dyn, sizeof(dyn)))
55591+ break;
55592+ if (dyn.d_tag == DT_NULL)
55593+ break;
55594+ if (dyn.d_tag == DT_TEXTREL || (dyn.d_tag == DT_FLAGS && (dyn.d_un.d_val & DF_TEXTREL))) {
55595+ gr_log_textrel(vma);
55596+ if (is_textrel_rw)
55597+ vma->vm_flags |= VM_MAYWRITE;
55598+ else
55599+ /* PaX: disallow write access after relocs are done, hopefully noone else needs it... */
55600+ vma->vm_flags &= ~VM_MAYWRITE;
55601+ break;
55602+ }
55603+ i++;
55604+ }
55605+ is_textrel_rw = false;
55606+ is_textrel_rx = false;
55607+ continue;
55608+
55609+ case PT_GNU_RELRO:
55610+ if (!is_relro)
55611+ continue;
55612+ if ((elf_p.p_offset >> PAGE_SHIFT) == vma->vm_pgoff && ELF_PAGEALIGN(elf_p.p_memsz) == vma->vm_end - vma->vm_start)
55613+ vma->vm_flags &= ~VM_MAYWRITE;
55614+ is_relro = false;
55615+ continue;
55616+
55617+#ifdef CONFIG_PAX_PT_PAX_FLAGS
55618+ case PT_PAX_FLAGS: {
55619+ const char *msg_mprotect = "", *msg_emutramp = "";
55620+ char *buffer_lib, *buffer_exe;
55621+
55622+ if (elf_p.p_flags & PF_NOMPROTECT)
55623+ msg_mprotect = "MPROTECT disabled";
55624+
55625+#ifdef CONFIG_PAX_EMUTRAMP
55626+ if (!(vma->vm_mm->pax_flags & MF_PAX_EMUTRAMP) && !(elf_p.p_flags & PF_NOEMUTRAMP))
55627+ msg_emutramp = "EMUTRAMP enabled";
55628+#endif
55629+
55630+ if (!msg_mprotect[0] && !msg_emutramp[0])
55631+ continue;
55632+
55633+ if (!printk_ratelimit())
55634+ continue;
55635+
55636+ buffer_lib = (char *)__get_free_page(GFP_KERNEL);
55637+ buffer_exe = (char *)__get_free_page(GFP_KERNEL);
55638+ if (buffer_lib && buffer_exe) {
55639+ char *path_lib, *path_exe;
55640+
55641+ path_lib = pax_get_path(&vma->vm_file->f_path, buffer_lib, PAGE_SIZE);
55642+ path_exe = pax_get_path(&vma->vm_mm->exe_file->f_path, buffer_exe, PAGE_SIZE);
55643+
55644+ pr_info("PAX: %s wants %s%s%s on %s\n", path_lib, msg_mprotect,
55645+ (msg_mprotect[0] && msg_emutramp[0] ? " and " : ""), msg_emutramp, path_exe);
55646+
55647+ }
55648+ free_page((unsigned long)buffer_exe);
55649+ free_page((unsigned long)buffer_lib);
55650+ continue;
55651+ }
55652+#endif
55653+
55654+ }
55655+ }
55656+}
55657+#endif
55658+
55659+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
55660+
55661+extern int grsec_enable_log_rwxmaps;
55662+
55663+static void elf_handle_mmap(struct file *file)
55664+{
55665+ struct elfhdr elf_h;
55666+ struct elf_phdr elf_p;
55667+ unsigned long i;
55668+
55669+ if (!grsec_enable_log_rwxmaps)
55670+ return;
55671+
55672+ if (sizeof(elf_h) != kernel_read(file, 0UL, (char *)&elf_h, sizeof(elf_h)) ||
55673+ memcmp(elf_h.e_ident, ELFMAG, SELFMAG) ||
55674+ (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC) || !elf_check_arch(&elf_h) ||
55675+ elf_h.e_phentsize != sizeof(struct elf_phdr) ||
55676+ elf_h.e_phnum > 65536UL / sizeof(struct elf_phdr))
55677+ return;
55678+
55679+ for (i = 0UL; i < elf_h.e_phnum; i++) {
55680+ if (sizeof(elf_p) != kernel_read(file, elf_h.e_phoff + i*sizeof(elf_p), (char *)&elf_p, sizeof(elf_p)))
55681+ return;
55682+ if (elf_p.p_type == PT_GNU_STACK && (elf_p.p_flags & PF_X))
55683+ gr_log_ptgnustack(file);
55684+ }
55685+}
55686+#endif
55687+
55688 static int __init init_elf_binfmt(void)
55689 {
55690 register_binfmt(&elf_format);
55691diff --git a/fs/binfmt_flat.c b/fs/binfmt_flat.c
55692index d50bbe5..af3b649 100644
55693--- a/fs/binfmt_flat.c
55694+++ b/fs/binfmt_flat.c
55695@@ -566,7 +566,9 @@ static int load_flat_file(struct linux_binprm * bprm,
55696 realdatastart = (unsigned long) -ENOMEM;
55697 printk("Unable to allocate RAM for process data, errno %d\n",
55698 (int)-realdatastart);
55699+ down_write(&current->mm->mmap_sem);
55700 vm_munmap(textpos, text_len);
55701+ up_write(&current->mm->mmap_sem);
55702 ret = realdatastart;
55703 goto err;
55704 }
55705@@ -590,8 +592,10 @@ static int load_flat_file(struct linux_binprm * bprm,
55706 }
55707 if (IS_ERR_VALUE(result)) {
55708 printk("Unable to read data+bss, errno %d\n", (int)-result);
55709+ down_write(&current->mm->mmap_sem);
55710 vm_munmap(textpos, text_len);
55711 vm_munmap(realdatastart, len);
55712+ up_write(&current->mm->mmap_sem);
55713 ret = result;
55714 goto err;
55715 }
55716@@ -653,8 +657,10 @@ static int load_flat_file(struct linux_binprm * bprm,
55717 }
55718 if (IS_ERR_VALUE(result)) {
55719 printk("Unable to read code+data+bss, errno %d\n",(int)-result);
55720+ down_write(&current->mm->mmap_sem);
55721 vm_munmap(textpos, text_len + data_len + extra +
55722 MAX_SHARED_LIBS * sizeof(unsigned long));
55723+ up_write(&current->mm->mmap_sem);
55724 ret = result;
55725 goto err;
55726 }
55727diff --git a/fs/bio.c b/fs/bio.c
55728index ea5035d..a2932eb 100644
55729--- a/fs/bio.c
55730+++ b/fs/bio.c
55731@@ -1106,7 +1106,7 @@ struct bio *bio_copy_user_iov(struct request_queue *q,
55732 /*
55733 * Overflow, abort
55734 */
55735- if (end < start)
55736+ if (end < start || end - start > INT_MAX - nr_pages)
55737 return ERR_PTR(-EINVAL);
55738
55739 nr_pages += end - start;
55740@@ -1240,7 +1240,7 @@ static struct bio *__bio_map_user_iov(struct request_queue *q,
55741 /*
55742 * Overflow, abort
55743 */
55744- if (end < start)
55745+ if (end < start || end - start > INT_MAX - nr_pages)
55746 return ERR_PTR(-EINVAL);
55747
55748 nr_pages += end - start;
55749@@ -1502,7 +1502,7 @@ static void bio_copy_kern_endio(struct bio *bio, int err)
55750 const int read = bio_data_dir(bio) == READ;
55751 struct bio_map_data *bmd = bio->bi_private;
55752 int i;
55753- char *p = bmd->sgvecs[0].iov_base;
55754+ char *p = (char __force_kernel *)bmd->sgvecs[0].iov_base;
55755
55756 bio_for_each_segment_all(bvec, bio, i) {
55757 char *addr = page_address(bvec->bv_page);
55758diff --git a/fs/block_dev.c b/fs/block_dev.c
55759index 1e86823..8e34695 100644
55760--- a/fs/block_dev.c
55761+++ b/fs/block_dev.c
55762@@ -637,7 +637,7 @@ static bool bd_may_claim(struct block_device *bdev, struct block_device *whole,
55763 else if (bdev->bd_contains == bdev)
55764 return true; /* is a whole device which isn't held */
55765
55766- else if (whole->bd_holder == bd_may_claim)
55767+ else if (whole->bd_holder == (void *)bd_may_claim)
55768 return true; /* is a partition of a device that is being partitioned */
55769 else if (whole->bd_holder != NULL)
55770 return false; /* is a partition of a held device */
55771diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c
55772index b544a44..f3fb987 100644
55773--- a/fs/btrfs/ctree.c
55774+++ b/fs/btrfs/ctree.c
55775@@ -1028,9 +1028,12 @@ static noinline int __btrfs_cow_block(struct btrfs_trans_handle *trans,
55776 free_extent_buffer(buf);
55777 add_root_to_dirty_list(root);
55778 } else {
55779- if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID)
55780- parent_start = parent->start;
55781- else
55782+ if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID) {
55783+ if (parent)
55784+ parent_start = parent->start;
55785+ else
55786+ parent_start = 0;
55787+ } else
55788 parent_start = 0;
55789
55790 WARN_ON(trans->transid != btrfs_header_generation(parent));
55791diff --git a/fs/btrfs/delayed-inode.c b/fs/btrfs/delayed-inode.c
55792index cbd9523..5cca781 100644
55793--- a/fs/btrfs/delayed-inode.c
55794+++ b/fs/btrfs/delayed-inode.c
55795@@ -459,7 +459,7 @@ static int __btrfs_add_delayed_deletion_item(struct btrfs_delayed_node *node,
55796
55797 static void finish_one_item(struct btrfs_delayed_root *delayed_root)
55798 {
55799- int seq = atomic_inc_return(&delayed_root->items_seq);
55800+ int seq = atomic_inc_return_unchecked(&delayed_root->items_seq);
55801 if ((atomic_dec_return(&delayed_root->items) <
55802 BTRFS_DELAYED_BACKGROUND || seq % BTRFS_DELAYED_BATCH == 0) &&
55803 waitqueue_active(&delayed_root->wait))
55804@@ -1378,7 +1378,7 @@ void btrfs_assert_delayed_root_empty(struct btrfs_root *root)
55805 static int refs_newer(struct btrfs_delayed_root *delayed_root,
55806 int seq, int count)
55807 {
55808- int val = atomic_read(&delayed_root->items_seq);
55809+ int val = atomic_read_unchecked(&delayed_root->items_seq);
55810
55811 if (val < seq || val >= seq + count)
55812 return 1;
55813@@ -1395,7 +1395,7 @@ void btrfs_balance_delayed_items(struct btrfs_root *root)
55814 if (atomic_read(&delayed_root->items) < BTRFS_DELAYED_BACKGROUND)
55815 return;
55816
55817- seq = atomic_read(&delayed_root->items_seq);
55818+ seq = atomic_read_unchecked(&delayed_root->items_seq);
55819
55820 if (atomic_read(&delayed_root->items) >= BTRFS_DELAYED_WRITEBACK) {
55821 int ret;
55822diff --git a/fs/btrfs/delayed-inode.h b/fs/btrfs/delayed-inode.h
55823index a4b38f9..f86a509 100644
55824--- a/fs/btrfs/delayed-inode.h
55825+++ b/fs/btrfs/delayed-inode.h
55826@@ -43,7 +43,7 @@ struct btrfs_delayed_root {
55827 */
55828 struct list_head prepare_list;
55829 atomic_t items; /* for delayed items */
55830- atomic_t items_seq; /* for delayed items */
55831+ atomic_unchecked_t items_seq; /* for delayed items */
55832 int nodes; /* for delayed nodes */
55833 wait_queue_head_t wait;
55834 };
55835@@ -87,7 +87,7 @@ static inline void btrfs_init_delayed_root(
55836 struct btrfs_delayed_root *delayed_root)
55837 {
55838 atomic_set(&delayed_root->items, 0);
55839- atomic_set(&delayed_root->items_seq, 0);
55840+ atomic_set_unchecked(&delayed_root->items_seq, 0);
55841 delayed_root->nodes = 0;
55842 spin_lock_init(&delayed_root->lock);
55843 init_waitqueue_head(&delayed_root->wait);
55844diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
55845index 8747feb..ad1655c 100644
55846--- a/fs/btrfs/ioctl.c
55847+++ b/fs/btrfs/ioctl.c
55848@@ -3465,9 +3465,12 @@ static long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
55849 for (i = 0; i < num_types; i++) {
55850 struct btrfs_space_info *tmp;
55851
55852+ /* Don't copy in more than we allocated */
55853 if (!slot_count)
55854 break;
55855
55856+ slot_count--;
55857+
55858 info = NULL;
55859 rcu_read_lock();
55860 list_for_each_entry_rcu(tmp, &root->fs_info->space_info,
55861@@ -3489,10 +3492,7 @@ static long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
55862 memcpy(dest, &space, sizeof(space));
55863 dest++;
55864 space_args.total_spaces++;
55865- slot_count--;
55866 }
55867- if (!slot_count)
55868- break;
55869 }
55870 up_read(&info->groups_sem);
55871 }
55872diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c
55873index e913328..a34fb36 100644
55874--- a/fs/btrfs/super.c
55875+++ b/fs/btrfs/super.c
55876@@ -266,7 +266,7 @@ void __btrfs_abort_transaction(struct btrfs_trans_handle *trans,
55877 function, line, errstr);
55878 return;
55879 }
55880- ACCESS_ONCE(trans->transaction->aborted) = errno;
55881+ ACCESS_ONCE_RW(trans->transaction->aborted) = errno;
55882 /* Wake up anybody who may be waiting on this transaction */
55883 wake_up(&root->fs_info->transaction_wait);
55884 wake_up(&root->fs_info->transaction_blocked_wait);
55885diff --git a/fs/buffer.c b/fs/buffer.c
55886index 6024877..7bd000a 100644
55887--- a/fs/buffer.c
55888+++ b/fs/buffer.c
55889@@ -3426,7 +3426,7 @@ void __init buffer_init(void)
55890 bh_cachep = kmem_cache_create("buffer_head",
55891 sizeof(struct buffer_head), 0,
55892 (SLAB_RECLAIM_ACCOUNT|SLAB_PANIC|
55893- SLAB_MEM_SPREAD),
55894+ SLAB_MEM_SPREAD|SLAB_NO_SANITIZE),
55895 NULL);
55896
55897 /*
55898diff --git a/fs/cachefiles/bind.c b/fs/cachefiles/bind.c
55899index 622f469..e8d2d55 100644
55900--- a/fs/cachefiles/bind.c
55901+++ b/fs/cachefiles/bind.c
55902@@ -39,13 +39,11 @@ int cachefiles_daemon_bind(struct cachefiles_cache *cache, char *args)
55903 args);
55904
55905 /* start by checking things over */
55906- ASSERT(cache->fstop_percent >= 0 &&
55907- cache->fstop_percent < cache->fcull_percent &&
55908+ ASSERT(cache->fstop_percent < cache->fcull_percent &&
55909 cache->fcull_percent < cache->frun_percent &&
55910 cache->frun_percent < 100);
55911
55912- ASSERT(cache->bstop_percent >= 0 &&
55913- cache->bstop_percent < cache->bcull_percent &&
55914+ ASSERT(cache->bstop_percent < cache->bcull_percent &&
55915 cache->bcull_percent < cache->brun_percent &&
55916 cache->brun_percent < 100);
55917
55918diff --git a/fs/cachefiles/daemon.c b/fs/cachefiles/daemon.c
55919index 0a1467b..6a53245 100644
55920--- a/fs/cachefiles/daemon.c
55921+++ b/fs/cachefiles/daemon.c
55922@@ -196,7 +196,7 @@ static ssize_t cachefiles_daemon_read(struct file *file, char __user *_buffer,
55923 if (n > buflen)
55924 return -EMSGSIZE;
55925
55926- if (copy_to_user(_buffer, buffer, n) != 0)
55927+ if (n > sizeof(buffer) || copy_to_user(_buffer, buffer, n) != 0)
55928 return -EFAULT;
55929
55930 return n;
55931@@ -222,7 +222,7 @@ static ssize_t cachefiles_daemon_write(struct file *file,
55932 if (test_bit(CACHEFILES_DEAD, &cache->flags))
55933 return -EIO;
55934
55935- if (datalen < 0 || datalen > PAGE_SIZE - 1)
55936+ if (datalen > PAGE_SIZE - 1)
55937 return -EOPNOTSUPP;
55938
55939 /* drag the command string into the kernel so we can parse it */
55940@@ -386,7 +386,7 @@ static int cachefiles_daemon_fstop(struct cachefiles_cache *cache, char *args)
55941 if (args[0] != '%' || args[1] != '\0')
55942 return -EINVAL;
55943
55944- if (fstop < 0 || fstop >= cache->fcull_percent)
55945+ if (fstop >= cache->fcull_percent)
55946 return cachefiles_daemon_range_error(cache, args);
55947
55948 cache->fstop_percent = fstop;
55949@@ -458,7 +458,7 @@ static int cachefiles_daemon_bstop(struct cachefiles_cache *cache, char *args)
55950 if (args[0] != '%' || args[1] != '\0')
55951 return -EINVAL;
55952
55953- if (bstop < 0 || bstop >= cache->bcull_percent)
55954+ if (bstop >= cache->bcull_percent)
55955 return cachefiles_daemon_range_error(cache, args);
55956
55957 cache->bstop_percent = bstop;
55958diff --git a/fs/cachefiles/internal.h b/fs/cachefiles/internal.h
55959index 5349473..d6c0b93 100644
55960--- a/fs/cachefiles/internal.h
55961+++ b/fs/cachefiles/internal.h
55962@@ -59,7 +59,7 @@ struct cachefiles_cache {
55963 wait_queue_head_t daemon_pollwq; /* poll waitqueue for daemon */
55964 struct rb_root active_nodes; /* active nodes (can't be culled) */
55965 rwlock_t active_lock; /* lock for active_nodes */
55966- atomic_t gravecounter; /* graveyard uniquifier */
55967+ atomic_unchecked_t gravecounter; /* graveyard uniquifier */
55968 unsigned frun_percent; /* when to stop culling (% files) */
55969 unsigned fcull_percent; /* when to start culling (% files) */
55970 unsigned fstop_percent; /* when to stop allocating (% files) */
55971@@ -171,19 +171,19 @@ extern int cachefiles_check_in_use(struct cachefiles_cache *cache,
55972 * proc.c
55973 */
55974 #ifdef CONFIG_CACHEFILES_HISTOGRAM
55975-extern atomic_t cachefiles_lookup_histogram[HZ];
55976-extern atomic_t cachefiles_mkdir_histogram[HZ];
55977-extern atomic_t cachefiles_create_histogram[HZ];
55978+extern atomic_unchecked_t cachefiles_lookup_histogram[HZ];
55979+extern atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
55980+extern atomic_unchecked_t cachefiles_create_histogram[HZ];
55981
55982 extern int __init cachefiles_proc_init(void);
55983 extern void cachefiles_proc_cleanup(void);
55984 static inline
55985-void cachefiles_hist(atomic_t histogram[], unsigned long start_jif)
55986+void cachefiles_hist(atomic_unchecked_t histogram[], unsigned long start_jif)
55987 {
55988 unsigned long jif = jiffies - start_jif;
55989 if (jif >= HZ)
55990 jif = HZ - 1;
55991- atomic_inc(&histogram[jif]);
55992+ atomic_inc_unchecked(&histogram[jif]);
55993 }
55994
55995 #else
55996diff --git a/fs/cachefiles/namei.c b/fs/cachefiles/namei.c
55997index f4a08d7..5aa4599 100644
55998--- a/fs/cachefiles/namei.c
55999+++ b/fs/cachefiles/namei.c
56000@@ -317,7 +317,7 @@ try_again:
56001 /* first step is to make up a grave dentry in the graveyard */
56002 sprintf(nbuffer, "%08x%08x",
56003 (uint32_t) get_seconds(),
56004- (uint32_t) atomic_inc_return(&cache->gravecounter));
56005+ (uint32_t) atomic_inc_return_unchecked(&cache->gravecounter));
56006
56007 /* do the multiway lock magic */
56008 trap = lock_rename(cache->graveyard, dir);
56009diff --git a/fs/cachefiles/proc.c b/fs/cachefiles/proc.c
56010index eccd339..4c1d995 100644
56011--- a/fs/cachefiles/proc.c
56012+++ b/fs/cachefiles/proc.c
56013@@ -14,9 +14,9 @@
56014 #include <linux/seq_file.h>
56015 #include "internal.h"
56016
56017-atomic_t cachefiles_lookup_histogram[HZ];
56018-atomic_t cachefiles_mkdir_histogram[HZ];
56019-atomic_t cachefiles_create_histogram[HZ];
56020+atomic_unchecked_t cachefiles_lookup_histogram[HZ];
56021+atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
56022+atomic_unchecked_t cachefiles_create_histogram[HZ];
56023
56024 /*
56025 * display the latency histogram
56026@@ -35,9 +35,9 @@ static int cachefiles_histogram_show(struct seq_file *m, void *v)
56027 return 0;
56028 default:
56029 index = (unsigned long) v - 3;
56030- x = atomic_read(&cachefiles_lookup_histogram[index]);
56031- y = atomic_read(&cachefiles_mkdir_histogram[index]);
56032- z = atomic_read(&cachefiles_create_histogram[index]);
56033+ x = atomic_read_unchecked(&cachefiles_lookup_histogram[index]);
56034+ y = atomic_read_unchecked(&cachefiles_mkdir_histogram[index]);
56035+ z = atomic_read_unchecked(&cachefiles_create_histogram[index]);
56036 if (x == 0 && y == 0 && z == 0)
56037 return 0;
56038
56039diff --git a/fs/cachefiles/rdwr.c b/fs/cachefiles/rdwr.c
56040index ebaff36..7e3ea26 100644
56041--- a/fs/cachefiles/rdwr.c
56042+++ b/fs/cachefiles/rdwr.c
56043@@ -950,7 +950,7 @@ int cachefiles_write_page(struct fscache_storage *op, struct page *page)
56044 old_fs = get_fs();
56045 set_fs(KERNEL_DS);
56046 ret = file->f_op->write(
56047- file, (const void __user *) data, len, &pos);
56048+ file, (const void __force_user *) data, len, &pos);
56049 set_fs(old_fs);
56050 kunmap(page);
56051 file_end_write(file);
56052diff --git a/fs/ceph/dir.c b/fs/ceph/dir.c
56053index 868b61d..58835a5 100644
56054--- a/fs/ceph/dir.c
56055+++ b/fs/ceph/dir.c
56056@@ -240,7 +240,7 @@ static int ceph_readdir(struct file *file, struct dir_context *ctx)
56057 struct ceph_fs_client *fsc = ceph_inode_to_client(inode);
56058 struct ceph_mds_client *mdsc = fsc->mdsc;
56059 unsigned frag = fpos_frag(ctx->pos);
56060- int off = fpos_off(ctx->pos);
56061+ unsigned int off = fpos_off(ctx->pos);
56062 int err;
56063 u32 ftype;
56064 struct ceph_mds_reply_info_parsed *rinfo;
56065diff --git a/fs/ceph/super.c b/fs/ceph/super.c
56066index 6a0951e..03fac6d 100644
56067--- a/fs/ceph/super.c
56068+++ b/fs/ceph/super.c
56069@@ -870,7 +870,7 @@ static int ceph_compare_super(struct super_block *sb, void *data)
56070 /*
56071 * construct our own bdi so we can control readahead, etc.
56072 */
56073-static atomic_long_t bdi_seq = ATOMIC_LONG_INIT(0);
56074+static atomic_long_unchecked_t bdi_seq = ATOMIC_LONG_INIT(0);
56075
56076 static int ceph_register_bdi(struct super_block *sb,
56077 struct ceph_fs_client *fsc)
56078@@ -887,7 +887,7 @@ static int ceph_register_bdi(struct super_block *sb,
56079 default_backing_dev_info.ra_pages;
56080
56081 err = bdi_register(&fsc->backing_dev_info, NULL, "ceph-%ld",
56082- atomic_long_inc_return(&bdi_seq));
56083+ atomic_long_inc_return_unchecked(&bdi_seq));
56084 if (!err)
56085 sb->s_bdi = &fsc->backing_dev_info;
56086 return err;
56087diff --git a/fs/cifs/cifs_debug.c b/fs/cifs/cifs_debug.c
56088index f3ac415..3d2420c 100644
56089--- a/fs/cifs/cifs_debug.c
56090+++ b/fs/cifs/cifs_debug.c
56091@@ -286,8 +286,8 @@ static ssize_t cifs_stats_proc_write(struct file *file,
56092
56093 if (c == '1' || c == 'y' || c == 'Y' || c == '0') {
56094 #ifdef CONFIG_CIFS_STATS2
56095- atomic_set(&totBufAllocCount, 0);
56096- atomic_set(&totSmBufAllocCount, 0);
56097+ atomic_set_unchecked(&totBufAllocCount, 0);
56098+ atomic_set_unchecked(&totSmBufAllocCount, 0);
56099 #endif /* CONFIG_CIFS_STATS2 */
56100 spin_lock(&cifs_tcp_ses_lock);
56101 list_for_each(tmp1, &cifs_tcp_ses_list) {
56102@@ -300,7 +300,7 @@ static ssize_t cifs_stats_proc_write(struct file *file,
56103 tcon = list_entry(tmp3,
56104 struct cifs_tcon,
56105 tcon_list);
56106- atomic_set(&tcon->num_smbs_sent, 0);
56107+ atomic_set_unchecked(&tcon->num_smbs_sent, 0);
56108 if (server->ops->clear_stats)
56109 server->ops->clear_stats(tcon);
56110 }
56111@@ -332,8 +332,8 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
56112 smBufAllocCount.counter, cifs_min_small);
56113 #ifdef CONFIG_CIFS_STATS2
56114 seq_printf(m, "Total Large %d Small %d Allocations\n",
56115- atomic_read(&totBufAllocCount),
56116- atomic_read(&totSmBufAllocCount));
56117+ atomic_read_unchecked(&totBufAllocCount),
56118+ atomic_read_unchecked(&totSmBufAllocCount));
56119 #endif /* CONFIG_CIFS_STATS2 */
56120
56121 seq_printf(m, "Operations (MIDs): %d\n", atomic_read(&midCount));
56122@@ -362,7 +362,7 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
56123 if (tcon->need_reconnect)
56124 seq_puts(m, "\tDISCONNECTED ");
56125 seq_printf(m, "\nSMBs: %d",
56126- atomic_read(&tcon->num_smbs_sent));
56127+ atomic_read_unchecked(&tcon->num_smbs_sent));
56128 if (server->ops->print_stats)
56129 server->ops->print_stats(m, tcon);
56130 }
56131diff --git a/fs/cifs/cifsfs.c b/fs/cifs/cifsfs.c
56132index 77fc5e1..e3d13e6 100644
56133--- a/fs/cifs/cifsfs.c
56134+++ b/fs/cifs/cifsfs.c
56135@@ -1056,7 +1056,7 @@ cifs_init_request_bufs(void)
56136 */
56137 cifs_req_cachep = kmem_cache_create("cifs_request",
56138 CIFSMaxBufSize + max_hdr_size, 0,
56139- SLAB_HWCACHE_ALIGN, NULL);
56140+ SLAB_HWCACHE_ALIGN | SLAB_USERCOPY, NULL);
56141 if (cifs_req_cachep == NULL)
56142 return -ENOMEM;
56143
56144@@ -1083,7 +1083,7 @@ cifs_init_request_bufs(void)
56145 efficient to alloc 1 per page off the slab compared to 17K (5page)
56146 alloc of large cifs buffers even when page debugging is on */
56147 cifs_sm_req_cachep = kmem_cache_create("cifs_small_rq",
56148- MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN,
56149+ MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN | SLAB_USERCOPY,
56150 NULL);
56151 if (cifs_sm_req_cachep == NULL) {
56152 mempool_destroy(cifs_req_poolp);
56153@@ -1168,8 +1168,8 @@ init_cifs(void)
56154 atomic_set(&bufAllocCount, 0);
56155 atomic_set(&smBufAllocCount, 0);
56156 #ifdef CONFIG_CIFS_STATS2
56157- atomic_set(&totBufAllocCount, 0);
56158- atomic_set(&totSmBufAllocCount, 0);
56159+ atomic_set_unchecked(&totBufAllocCount, 0);
56160+ atomic_set_unchecked(&totSmBufAllocCount, 0);
56161 #endif /* CONFIG_CIFS_STATS2 */
56162
56163 atomic_set(&midCount, 0);
56164diff --git a/fs/cifs/cifsglob.h b/fs/cifs/cifsglob.h
56165index c8e03f8..75362f6 100644
56166--- a/fs/cifs/cifsglob.h
56167+++ b/fs/cifs/cifsglob.h
56168@@ -758,35 +758,35 @@ struct cifs_tcon {
56169 __u16 Flags; /* optional support bits */
56170 enum statusEnum tidStatus;
56171 #ifdef CONFIG_CIFS_STATS
56172- atomic_t num_smbs_sent;
56173+ atomic_unchecked_t num_smbs_sent;
56174 union {
56175 struct {
56176- atomic_t num_writes;
56177- atomic_t num_reads;
56178- atomic_t num_flushes;
56179- atomic_t num_oplock_brks;
56180- atomic_t num_opens;
56181- atomic_t num_closes;
56182- atomic_t num_deletes;
56183- atomic_t num_mkdirs;
56184- atomic_t num_posixopens;
56185- atomic_t num_posixmkdirs;
56186- atomic_t num_rmdirs;
56187- atomic_t num_renames;
56188- atomic_t num_t2renames;
56189- atomic_t num_ffirst;
56190- atomic_t num_fnext;
56191- atomic_t num_fclose;
56192- atomic_t num_hardlinks;
56193- atomic_t num_symlinks;
56194- atomic_t num_locks;
56195- atomic_t num_acl_get;
56196- atomic_t num_acl_set;
56197+ atomic_unchecked_t num_writes;
56198+ atomic_unchecked_t num_reads;
56199+ atomic_unchecked_t num_flushes;
56200+ atomic_unchecked_t num_oplock_brks;
56201+ atomic_unchecked_t num_opens;
56202+ atomic_unchecked_t num_closes;
56203+ atomic_unchecked_t num_deletes;
56204+ atomic_unchecked_t num_mkdirs;
56205+ atomic_unchecked_t num_posixopens;
56206+ atomic_unchecked_t num_posixmkdirs;
56207+ atomic_unchecked_t num_rmdirs;
56208+ atomic_unchecked_t num_renames;
56209+ atomic_unchecked_t num_t2renames;
56210+ atomic_unchecked_t num_ffirst;
56211+ atomic_unchecked_t num_fnext;
56212+ atomic_unchecked_t num_fclose;
56213+ atomic_unchecked_t num_hardlinks;
56214+ atomic_unchecked_t num_symlinks;
56215+ atomic_unchecked_t num_locks;
56216+ atomic_unchecked_t num_acl_get;
56217+ atomic_unchecked_t num_acl_set;
56218 } cifs_stats;
56219 #ifdef CONFIG_CIFS_SMB2
56220 struct {
56221- atomic_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS];
56222- atomic_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS];
56223+ atomic_unchecked_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS];
56224+ atomic_unchecked_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS];
56225 } smb2_stats;
56226 #endif /* CONFIG_CIFS_SMB2 */
56227 } stats;
56228@@ -1111,7 +1111,7 @@ convert_delimiter(char *path, char delim)
56229 }
56230
56231 #ifdef CONFIG_CIFS_STATS
56232-#define cifs_stats_inc atomic_inc
56233+#define cifs_stats_inc atomic_inc_unchecked
56234
56235 static inline void cifs_stats_bytes_written(struct cifs_tcon *tcon,
56236 unsigned int bytes)
56237@@ -1477,8 +1477,8 @@ GLOBAL_EXTERN atomic_t tconInfoReconnectCount;
56238 /* Various Debug counters */
56239 GLOBAL_EXTERN atomic_t bufAllocCount; /* current number allocated */
56240 #ifdef CONFIG_CIFS_STATS2
56241-GLOBAL_EXTERN atomic_t totBufAllocCount; /* total allocated over all time */
56242-GLOBAL_EXTERN atomic_t totSmBufAllocCount;
56243+GLOBAL_EXTERN atomic_unchecked_t totBufAllocCount; /* total allocated over all time */
56244+GLOBAL_EXTERN atomic_unchecked_t totSmBufAllocCount;
56245 #endif
56246 GLOBAL_EXTERN atomic_t smBufAllocCount;
56247 GLOBAL_EXTERN atomic_t midCount;
56248diff --git a/fs/cifs/file.c b/fs/cifs/file.c
56249index 7ddddf2..2e12dbc 100644
56250--- a/fs/cifs/file.c
56251+++ b/fs/cifs/file.c
56252@@ -1900,10 +1900,14 @@ static int cifs_writepages(struct address_space *mapping,
56253 index = mapping->writeback_index; /* Start from prev offset */
56254 end = -1;
56255 } else {
56256- index = wbc->range_start >> PAGE_CACHE_SHIFT;
56257- end = wbc->range_end >> PAGE_CACHE_SHIFT;
56258- if (wbc->range_start == 0 && wbc->range_end == LLONG_MAX)
56259+ if (wbc->range_start == 0 && wbc->range_end == LLONG_MAX) {
56260 range_whole = true;
56261+ index = 0;
56262+ end = ULONG_MAX;
56263+ } else {
56264+ index = wbc->range_start >> PAGE_CACHE_SHIFT;
56265+ end = wbc->range_end >> PAGE_CACHE_SHIFT;
56266+ }
56267 scanned = true;
56268 }
56269 retry:
56270diff --git a/fs/cifs/link.c b/fs/cifs/link.c
56271index 477e53b..7a32216 100644
56272--- a/fs/cifs/link.c
56273+++ b/fs/cifs/link.c
56274@@ -620,7 +620,7 @@ symlink_exit:
56275
56276 void cifs_put_link(struct dentry *direntry, struct nameidata *nd, void *cookie)
56277 {
56278- char *p = nd_get_link(nd);
56279+ const char *p = nd_get_link(nd);
56280 if (!IS_ERR(p))
56281 kfree(p);
56282 }
56283diff --git a/fs/cifs/misc.c b/fs/cifs/misc.c
56284index 138a011..cf9e13a 100644
56285--- a/fs/cifs/misc.c
56286+++ b/fs/cifs/misc.c
56287@@ -170,7 +170,7 @@ cifs_buf_get(void)
56288 memset(ret_buf, 0, buf_size + 3);
56289 atomic_inc(&bufAllocCount);
56290 #ifdef CONFIG_CIFS_STATS2
56291- atomic_inc(&totBufAllocCount);
56292+ atomic_inc_unchecked(&totBufAllocCount);
56293 #endif /* CONFIG_CIFS_STATS2 */
56294 }
56295
56296@@ -205,7 +205,7 @@ cifs_small_buf_get(void)
56297 /* memset(ret_buf, 0, sizeof(struct smb_hdr) + 27);*/
56298 atomic_inc(&smBufAllocCount);
56299 #ifdef CONFIG_CIFS_STATS2
56300- atomic_inc(&totSmBufAllocCount);
56301+ atomic_inc_unchecked(&totSmBufAllocCount);
56302 #endif /* CONFIG_CIFS_STATS2 */
56303
56304 }
56305diff --git a/fs/cifs/smb1ops.c b/fs/cifs/smb1ops.c
56306index e50554b..c011413 100644
56307--- a/fs/cifs/smb1ops.c
56308+++ b/fs/cifs/smb1ops.c
56309@@ -609,27 +609,27 @@ static void
56310 cifs_clear_stats(struct cifs_tcon *tcon)
56311 {
56312 #ifdef CONFIG_CIFS_STATS
56313- atomic_set(&tcon->stats.cifs_stats.num_writes, 0);
56314- atomic_set(&tcon->stats.cifs_stats.num_reads, 0);
56315- atomic_set(&tcon->stats.cifs_stats.num_flushes, 0);
56316- atomic_set(&tcon->stats.cifs_stats.num_oplock_brks, 0);
56317- atomic_set(&tcon->stats.cifs_stats.num_opens, 0);
56318- atomic_set(&tcon->stats.cifs_stats.num_posixopens, 0);
56319- atomic_set(&tcon->stats.cifs_stats.num_posixmkdirs, 0);
56320- atomic_set(&tcon->stats.cifs_stats.num_closes, 0);
56321- atomic_set(&tcon->stats.cifs_stats.num_deletes, 0);
56322- atomic_set(&tcon->stats.cifs_stats.num_mkdirs, 0);
56323- atomic_set(&tcon->stats.cifs_stats.num_rmdirs, 0);
56324- atomic_set(&tcon->stats.cifs_stats.num_renames, 0);
56325- atomic_set(&tcon->stats.cifs_stats.num_t2renames, 0);
56326- atomic_set(&tcon->stats.cifs_stats.num_ffirst, 0);
56327- atomic_set(&tcon->stats.cifs_stats.num_fnext, 0);
56328- atomic_set(&tcon->stats.cifs_stats.num_fclose, 0);
56329- atomic_set(&tcon->stats.cifs_stats.num_hardlinks, 0);
56330- atomic_set(&tcon->stats.cifs_stats.num_symlinks, 0);
56331- atomic_set(&tcon->stats.cifs_stats.num_locks, 0);
56332- atomic_set(&tcon->stats.cifs_stats.num_acl_get, 0);
56333- atomic_set(&tcon->stats.cifs_stats.num_acl_set, 0);
56334+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_writes, 0);
56335+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_reads, 0);
56336+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_flushes, 0);
56337+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_oplock_brks, 0);
56338+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_opens, 0);
56339+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_posixopens, 0);
56340+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_posixmkdirs, 0);
56341+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_closes, 0);
56342+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_deletes, 0);
56343+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_mkdirs, 0);
56344+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_rmdirs, 0);
56345+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_renames, 0);
56346+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_t2renames, 0);
56347+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_ffirst, 0);
56348+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_fnext, 0);
56349+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_fclose, 0);
56350+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_hardlinks, 0);
56351+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_symlinks, 0);
56352+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_locks, 0);
56353+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_acl_get, 0);
56354+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_acl_set, 0);
56355 #endif
56356 }
56357
56358@@ -638,36 +638,36 @@ cifs_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
56359 {
56360 #ifdef CONFIG_CIFS_STATS
56361 seq_printf(m, " Oplocks breaks: %d",
56362- atomic_read(&tcon->stats.cifs_stats.num_oplock_brks));
56363+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_oplock_brks));
56364 seq_printf(m, "\nReads: %d Bytes: %llu",
56365- atomic_read(&tcon->stats.cifs_stats.num_reads),
56366+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_reads),
56367 (long long)(tcon->bytes_read));
56368 seq_printf(m, "\nWrites: %d Bytes: %llu",
56369- atomic_read(&tcon->stats.cifs_stats.num_writes),
56370+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_writes),
56371 (long long)(tcon->bytes_written));
56372 seq_printf(m, "\nFlushes: %d",
56373- atomic_read(&tcon->stats.cifs_stats.num_flushes));
56374+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_flushes));
56375 seq_printf(m, "\nLocks: %d HardLinks: %d Symlinks: %d",
56376- atomic_read(&tcon->stats.cifs_stats.num_locks),
56377- atomic_read(&tcon->stats.cifs_stats.num_hardlinks),
56378- atomic_read(&tcon->stats.cifs_stats.num_symlinks));
56379+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_locks),
56380+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_hardlinks),
56381+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_symlinks));
56382 seq_printf(m, "\nOpens: %d Closes: %d Deletes: %d",
56383- atomic_read(&tcon->stats.cifs_stats.num_opens),
56384- atomic_read(&tcon->stats.cifs_stats.num_closes),
56385- atomic_read(&tcon->stats.cifs_stats.num_deletes));
56386+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_opens),
56387+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_closes),
56388+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_deletes));
56389 seq_printf(m, "\nPosix Opens: %d Posix Mkdirs: %d",
56390- atomic_read(&tcon->stats.cifs_stats.num_posixopens),
56391- atomic_read(&tcon->stats.cifs_stats.num_posixmkdirs));
56392+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_posixopens),
56393+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_posixmkdirs));
56394 seq_printf(m, "\nMkdirs: %d Rmdirs: %d",
56395- atomic_read(&tcon->stats.cifs_stats.num_mkdirs),
56396- atomic_read(&tcon->stats.cifs_stats.num_rmdirs));
56397+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_mkdirs),
56398+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_rmdirs));
56399 seq_printf(m, "\nRenames: %d T2 Renames %d",
56400- atomic_read(&tcon->stats.cifs_stats.num_renames),
56401- atomic_read(&tcon->stats.cifs_stats.num_t2renames));
56402+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_renames),
56403+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_t2renames));
56404 seq_printf(m, "\nFindFirst: %d FNext %d FClose %d",
56405- atomic_read(&tcon->stats.cifs_stats.num_ffirst),
56406- atomic_read(&tcon->stats.cifs_stats.num_fnext),
56407- atomic_read(&tcon->stats.cifs_stats.num_fclose));
56408+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_ffirst),
56409+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_fnext),
56410+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_fclose));
56411 #endif
56412 }
56413
56414diff --git a/fs/cifs/smb2ops.c b/fs/cifs/smb2ops.c
56415index 861b332..5506392 100644
56416--- a/fs/cifs/smb2ops.c
56417+++ b/fs/cifs/smb2ops.c
56418@@ -282,8 +282,8 @@ smb2_clear_stats(struct cifs_tcon *tcon)
56419 #ifdef CONFIG_CIFS_STATS
56420 int i;
56421 for (i = 0; i < NUMBER_OF_SMB2_COMMANDS; i++) {
56422- atomic_set(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
56423- atomic_set(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
56424+ atomic_set_unchecked(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
56425+ atomic_set_unchecked(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
56426 }
56427 #endif
56428 }
56429@@ -311,65 +311,65 @@ static void
56430 smb2_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
56431 {
56432 #ifdef CONFIG_CIFS_STATS
56433- atomic_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
56434- atomic_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
56435+ atomic_unchecked_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
56436+ atomic_unchecked_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
56437 seq_printf(m, "\nNegotiates: %d sent %d failed",
56438- atomic_read(&sent[SMB2_NEGOTIATE_HE]),
56439- atomic_read(&failed[SMB2_NEGOTIATE_HE]));
56440+ atomic_read_unchecked(&sent[SMB2_NEGOTIATE_HE]),
56441+ atomic_read_unchecked(&failed[SMB2_NEGOTIATE_HE]));
56442 seq_printf(m, "\nSessionSetups: %d sent %d failed",
56443- atomic_read(&sent[SMB2_SESSION_SETUP_HE]),
56444- atomic_read(&failed[SMB2_SESSION_SETUP_HE]));
56445+ atomic_read_unchecked(&sent[SMB2_SESSION_SETUP_HE]),
56446+ atomic_read_unchecked(&failed[SMB2_SESSION_SETUP_HE]));
56447 seq_printf(m, "\nLogoffs: %d sent %d failed",
56448- atomic_read(&sent[SMB2_LOGOFF_HE]),
56449- atomic_read(&failed[SMB2_LOGOFF_HE]));
56450+ atomic_read_unchecked(&sent[SMB2_LOGOFF_HE]),
56451+ atomic_read_unchecked(&failed[SMB2_LOGOFF_HE]));
56452 seq_printf(m, "\nTreeConnects: %d sent %d failed",
56453- atomic_read(&sent[SMB2_TREE_CONNECT_HE]),
56454- atomic_read(&failed[SMB2_TREE_CONNECT_HE]));
56455+ atomic_read_unchecked(&sent[SMB2_TREE_CONNECT_HE]),
56456+ atomic_read_unchecked(&failed[SMB2_TREE_CONNECT_HE]));
56457 seq_printf(m, "\nTreeDisconnects: %d sent %d failed",
56458- atomic_read(&sent[SMB2_TREE_DISCONNECT_HE]),
56459- atomic_read(&failed[SMB2_TREE_DISCONNECT_HE]));
56460+ atomic_read_unchecked(&sent[SMB2_TREE_DISCONNECT_HE]),
56461+ atomic_read_unchecked(&failed[SMB2_TREE_DISCONNECT_HE]));
56462 seq_printf(m, "\nCreates: %d sent %d failed",
56463- atomic_read(&sent[SMB2_CREATE_HE]),
56464- atomic_read(&failed[SMB2_CREATE_HE]));
56465+ atomic_read_unchecked(&sent[SMB2_CREATE_HE]),
56466+ atomic_read_unchecked(&failed[SMB2_CREATE_HE]));
56467 seq_printf(m, "\nCloses: %d sent %d failed",
56468- atomic_read(&sent[SMB2_CLOSE_HE]),
56469- atomic_read(&failed[SMB2_CLOSE_HE]));
56470+ atomic_read_unchecked(&sent[SMB2_CLOSE_HE]),
56471+ atomic_read_unchecked(&failed[SMB2_CLOSE_HE]));
56472 seq_printf(m, "\nFlushes: %d sent %d failed",
56473- atomic_read(&sent[SMB2_FLUSH_HE]),
56474- atomic_read(&failed[SMB2_FLUSH_HE]));
56475+ atomic_read_unchecked(&sent[SMB2_FLUSH_HE]),
56476+ atomic_read_unchecked(&failed[SMB2_FLUSH_HE]));
56477 seq_printf(m, "\nReads: %d sent %d failed",
56478- atomic_read(&sent[SMB2_READ_HE]),
56479- atomic_read(&failed[SMB2_READ_HE]));
56480+ atomic_read_unchecked(&sent[SMB2_READ_HE]),
56481+ atomic_read_unchecked(&failed[SMB2_READ_HE]));
56482 seq_printf(m, "\nWrites: %d sent %d failed",
56483- atomic_read(&sent[SMB2_WRITE_HE]),
56484- atomic_read(&failed[SMB2_WRITE_HE]));
56485+ atomic_read_unchecked(&sent[SMB2_WRITE_HE]),
56486+ atomic_read_unchecked(&failed[SMB2_WRITE_HE]));
56487 seq_printf(m, "\nLocks: %d sent %d failed",
56488- atomic_read(&sent[SMB2_LOCK_HE]),
56489- atomic_read(&failed[SMB2_LOCK_HE]));
56490+ atomic_read_unchecked(&sent[SMB2_LOCK_HE]),
56491+ atomic_read_unchecked(&failed[SMB2_LOCK_HE]));
56492 seq_printf(m, "\nIOCTLs: %d sent %d failed",
56493- atomic_read(&sent[SMB2_IOCTL_HE]),
56494- atomic_read(&failed[SMB2_IOCTL_HE]));
56495+ atomic_read_unchecked(&sent[SMB2_IOCTL_HE]),
56496+ atomic_read_unchecked(&failed[SMB2_IOCTL_HE]));
56497 seq_printf(m, "\nCancels: %d sent %d failed",
56498- atomic_read(&sent[SMB2_CANCEL_HE]),
56499- atomic_read(&failed[SMB2_CANCEL_HE]));
56500+ atomic_read_unchecked(&sent[SMB2_CANCEL_HE]),
56501+ atomic_read_unchecked(&failed[SMB2_CANCEL_HE]));
56502 seq_printf(m, "\nEchos: %d sent %d failed",
56503- atomic_read(&sent[SMB2_ECHO_HE]),
56504- atomic_read(&failed[SMB2_ECHO_HE]));
56505+ atomic_read_unchecked(&sent[SMB2_ECHO_HE]),
56506+ atomic_read_unchecked(&failed[SMB2_ECHO_HE]));
56507 seq_printf(m, "\nQueryDirectories: %d sent %d failed",
56508- atomic_read(&sent[SMB2_QUERY_DIRECTORY_HE]),
56509- atomic_read(&failed[SMB2_QUERY_DIRECTORY_HE]));
56510+ atomic_read_unchecked(&sent[SMB2_QUERY_DIRECTORY_HE]),
56511+ atomic_read_unchecked(&failed[SMB2_QUERY_DIRECTORY_HE]));
56512 seq_printf(m, "\nChangeNotifies: %d sent %d failed",
56513- atomic_read(&sent[SMB2_CHANGE_NOTIFY_HE]),
56514- atomic_read(&failed[SMB2_CHANGE_NOTIFY_HE]));
56515+ atomic_read_unchecked(&sent[SMB2_CHANGE_NOTIFY_HE]),
56516+ atomic_read_unchecked(&failed[SMB2_CHANGE_NOTIFY_HE]));
56517 seq_printf(m, "\nQueryInfos: %d sent %d failed",
56518- atomic_read(&sent[SMB2_QUERY_INFO_HE]),
56519- atomic_read(&failed[SMB2_QUERY_INFO_HE]));
56520+ atomic_read_unchecked(&sent[SMB2_QUERY_INFO_HE]),
56521+ atomic_read_unchecked(&failed[SMB2_QUERY_INFO_HE]));
56522 seq_printf(m, "\nSetInfos: %d sent %d failed",
56523- atomic_read(&sent[SMB2_SET_INFO_HE]),
56524- atomic_read(&failed[SMB2_SET_INFO_HE]));
56525+ atomic_read_unchecked(&sent[SMB2_SET_INFO_HE]),
56526+ atomic_read_unchecked(&failed[SMB2_SET_INFO_HE]));
56527 seq_printf(m, "\nOplockBreaks: %d sent %d failed",
56528- atomic_read(&sent[SMB2_OPLOCK_BREAK_HE]),
56529- atomic_read(&failed[SMB2_OPLOCK_BREAK_HE]));
56530+ atomic_read_unchecked(&sent[SMB2_OPLOCK_BREAK_HE]),
56531+ atomic_read_unchecked(&failed[SMB2_OPLOCK_BREAK_HE]));
56532 #endif
56533 }
56534
56535diff --git a/fs/cifs/smb2pdu.c b/fs/cifs/smb2pdu.c
56536index edccb52..16bc6db 100644
56537--- a/fs/cifs/smb2pdu.c
56538+++ b/fs/cifs/smb2pdu.c
56539@@ -1957,8 +1957,7 @@ SMB2_query_directory(const unsigned int xid, struct cifs_tcon *tcon,
56540 default:
56541 cifs_dbg(VFS, "info level %u isn't supported\n",
56542 srch_inf->info_level);
56543- rc = -EINVAL;
56544- goto qdir_exit;
56545+ return -EINVAL;
56546 }
56547
56548 req->FileIndex = cpu_to_le32(index);
56549diff --git a/fs/coda/cache.c b/fs/coda/cache.c
56550index 1da168c..8bc7ff6 100644
56551--- a/fs/coda/cache.c
56552+++ b/fs/coda/cache.c
56553@@ -24,7 +24,7 @@
56554 #include "coda_linux.h"
56555 #include "coda_cache.h"
56556
56557-static atomic_t permission_epoch = ATOMIC_INIT(0);
56558+static atomic_unchecked_t permission_epoch = ATOMIC_INIT(0);
56559
56560 /* replace or extend an acl cache hit */
56561 void coda_cache_enter(struct inode *inode, int mask)
56562@@ -32,7 +32,7 @@ void coda_cache_enter(struct inode *inode, int mask)
56563 struct coda_inode_info *cii = ITOC(inode);
56564
56565 spin_lock(&cii->c_lock);
56566- cii->c_cached_epoch = atomic_read(&permission_epoch);
56567+ cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch);
56568 if (!uid_eq(cii->c_uid, current_fsuid())) {
56569 cii->c_uid = current_fsuid();
56570 cii->c_cached_perm = mask;
56571@@ -46,14 +46,14 @@ void coda_cache_clear_inode(struct inode *inode)
56572 {
56573 struct coda_inode_info *cii = ITOC(inode);
56574 spin_lock(&cii->c_lock);
56575- cii->c_cached_epoch = atomic_read(&permission_epoch) - 1;
56576+ cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch) - 1;
56577 spin_unlock(&cii->c_lock);
56578 }
56579
56580 /* remove all acl caches */
56581 void coda_cache_clear_all(struct super_block *sb)
56582 {
56583- atomic_inc(&permission_epoch);
56584+ atomic_inc_unchecked(&permission_epoch);
56585 }
56586
56587
56588@@ -66,7 +66,7 @@ int coda_cache_check(struct inode *inode, int mask)
56589 spin_lock(&cii->c_lock);
56590 hit = (mask & cii->c_cached_perm) == mask &&
56591 uid_eq(cii->c_uid, current_fsuid()) &&
56592- cii->c_cached_epoch == atomic_read(&permission_epoch);
56593+ cii->c_cached_epoch == atomic_read_unchecked(&permission_epoch);
56594 spin_unlock(&cii->c_lock);
56595
56596 return hit;
56597diff --git a/fs/compat.c b/fs/compat.c
56598index 6af20de..fec3fbb 100644
56599--- a/fs/compat.c
56600+++ b/fs/compat.c
56601@@ -54,7 +54,7 @@
56602 #include <asm/ioctls.h>
56603 #include "internal.h"
56604
56605-int compat_log = 1;
56606+int compat_log = 0;
56607
56608 int compat_printk(const char *fmt, ...)
56609 {
56610@@ -488,7 +488,7 @@ compat_sys_io_setup(unsigned nr_reqs, u32 __user *ctx32p)
56611
56612 set_fs(KERNEL_DS);
56613 /* The __user pointer cast is valid because of the set_fs() */
56614- ret = sys_io_setup(nr_reqs, (aio_context_t __user *) &ctx64);
56615+ ret = sys_io_setup(nr_reqs, (aio_context_t __force_user *) &ctx64);
56616 set_fs(oldfs);
56617 /* truncating is ok because it's a user address */
56618 if (!ret)
56619@@ -546,7 +546,7 @@ ssize_t compat_rw_copy_check_uvector(int type,
56620 goto out;
56621
56622 ret = -EINVAL;
56623- if (nr_segs > UIO_MAXIOV || nr_segs < 0)
56624+ if (nr_segs > UIO_MAXIOV)
56625 goto out;
56626 if (nr_segs > fast_segs) {
56627 ret = -ENOMEM;
56628@@ -834,6 +834,7 @@ struct compat_old_linux_dirent {
56629 struct compat_readdir_callback {
56630 struct dir_context ctx;
56631 struct compat_old_linux_dirent __user *dirent;
56632+ struct file * file;
56633 int result;
56634 };
56635
56636@@ -851,6 +852,10 @@ static int compat_fillonedir(void *__buf, const char *name, int namlen,
56637 buf->result = -EOVERFLOW;
56638 return -EOVERFLOW;
56639 }
56640+
56641+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
56642+ return 0;
56643+
56644 buf->result++;
56645 dirent = buf->dirent;
56646 if (!access_ok(VERIFY_WRITE, dirent,
56647@@ -882,6 +887,7 @@ asmlinkage long compat_sys_old_readdir(unsigned int fd,
56648 if (!f.file)
56649 return -EBADF;
56650
56651+ buf.file = f.file;
56652 error = iterate_dir(f.file, &buf.ctx);
56653 if (buf.result)
56654 error = buf.result;
56655@@ -901,6 +907,7 @@ struct compat_getdents_callback {
56656 struct dir_context ctx;
56657 struct compat_linux_dirent __user *current_dir;
56658 struct compat_linux_dirent __user *previous;
56659+ struct file * file;
56660 int count;
56661 int error;
56662 };
56663@@ -922,6 +929,10 @@ static int compat_filldir(void *__buf, const char *name, int namlen,
56664 buf->error = -EOVERFLOW;
56665 return -EOVERFLOW;
56666 }
56667+
56668+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
56669+ return 0;
56670+
56671 dirent = buf->previous;
56672 if (dirent) {
56673 if (__put_user(offset, &dirent->d_off))
56674@@ -967,6 +978,7 @@ asmlinkage long compat_sys_getdents(unsigned int fd,
56675 if (!f.file)
56676 return -EBADF;
56677
56678+ buf.file = f.file;
56679 error = iterate_dir(f.file, &buf.ctx);
56680 if (error >= 0)
56681 error = buf.error;
56682@@ -987,6 +999,7 @@ struct compat_getdents_callback64 {
56683 struct dir_context ctx;
56684 struct linux_dirent64 __user *current_dir;
56685 struct linux_dirent64 __user *previous;
56686+ struct file * file;
56687 int count;
56688 int error;
56689 };
56690@@ -1003,6 +1016,10 @@ static int compat_filldir64(void * __buf, const char * name, int namlen, loff_t
56691 buf->error = -EINVAL; /* only used if we fail.. */
56692 if (reclen > buf->count)
56693 return -EINVAL;
56694+
56695+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
56696+ return 0;
56697+
56698 dirent = buf->previous;
56699
56700 if (dirent) {
56701@@ -1052,6 +1069,7 @@ asmlinkage long compat_sys_getdents64(unsigned int fd,
56702 if (!f.file)
56703 return -EBADF;
56704
56705+ buf.file = f.file;
56706 error = iterate_dir(f.file, &buf.ctx);
56707 if (error >= 0)
56708 error = buf.error;
56709diff --git a/fs/compat_binfmt_elf.c b/fs/compat_binfmt_elf.c
56710index a81147e..20bf2b5 100644
56711--- a/fs/compat_binfmt_elf.c
56712+++ b/fs/compat_binfmt_elf.c
56713@@ -30,11 +30,13 @@
56714 #undef elf_phdr
56715 #undef elf_shdr
56716 #undef elf_note
56717+#undef elf_dyn
56718 #undef elf_addr_t
56719 #define elfhdr elf32_hdr
56720 #define elf_phdr elf32_phdr
56721 #define elf_shdr elf32_shdr
56722 #define elf_note elf32_note
56723+#define elf_dyn Elf32_Dyn
56724 #define elf_addr_t Elf32_Addr
56725
56726 /*
56727diff --git a/fs/compat_ioctl.c b/fs/compat_ioctl.c
56728index 5d19acf..9ab093b 100644
56729--- a/fs/compat_ioctl.c
56730+++ b/fs/compat_ioctl.c
56731@@ -621,7 +621,7 @@ static int serial_struct_ioctl(unsigned fd, unsigned cmd,
56732 return -EFAULT;
56733 if (__get_user(udata, &ss32->iomem_base))
56734 return -EFAULT;
56735- ss.iomem_base = compat_ptr(udata);
56736+ ss.iomem_base = (unsigned char __force_kernel *)compat_ptr(udata);
56737 if (__get_user(ss.iomem_reg_shift, &ss32->iomem_reg_shift) ||
56738 __get_user(ss.port_high, &ss32->port_high))
56739 return -EFAULT;
56740@@ -702,8 +702,8 @@ static int do_i2c_rdwr_ioctl(unsigned int fd, unsigned int cmd,
56741 for (i = 0; i < nmsgs; i++) {
56742 if (copy_in_user(&tmsgs[i].addr, &umsgs[i].addr, 3*sizeof(u16)))
56743 return -EFAULT;
56744- if (get_user(datap, &umsgs[i].buf) ||
56745- put_user(compat_ptr(datap), &tmsgs[i].buf))
56746+ if (get_user(datap, (u8 __user * __user *)&umsgs[i].buf) ||
56747+ put_user(compat_ptr(datap), (u8 __user * __user *)&tmsgs[i].buf))
56748 return -EFAULT;
56749 }
56750 return sys_ioctl(fd, cmd, (unsigned long)tdata);
56751@@ -796,7 +796,7 @@ static int compat_ioctl_preallocate(struct file *file,
56752 copy_in_user(&p->l_len, &p32->l_len, sizeof(s64)) ||
56753 copy_in_user(&p->l_sysid, &p32->l_sysid, sizeof(s32)) ||
56754 copy_in_user(&p->l_pid, &p32->l_pid, sizeof(u32)) ||
56755- copy_in_user(&p->l_pad, &p32->l_pad, 4*sizeof(u32)))
56756+ copy_in_user(p->l_pad, &p32->l_pad, 4*sizeof(u32)))
56757 return -EFAULT;
56758
56759 return ioctl_preallocate(file, p);
56760@@ -1616,8 +1616,8 @@ asmlinkage long compat_sys_ioctl(unsigned int fd, unsigned int cmd,
56761 static int __init init_sys32_ioctl_cmp(const void *p, const void *q)
56762 {
56763 unsigned int a, b;
56764- a = *(unsigned int *)p;
56765- b = *(unsigned int *)q;
56766+ a = *(const unsigned int *)p;
56767+ b = *(const unsigned int *)q;
56768 if (a > b)
56769 return 1;
56770 if (a < b)
56771diff --git a/fs/configfs/dir.c b/fs/configfs/dir.c
56772index 511d415..319d0e5 100644
56773--- a/fs/configfs/dir.c
56774+++ b/fs/configfs/dir.c
56775@@ -1558,7 +1558,8 @@ static int configfs_readdir(struct file *file, struct dir_context *ctx)
56776 }
56777 for (p = q->next; p != &parent_sd->s_children; p = p->next) {
56778 struct configfs_dirent *next;
56779- const char *name;
56780+ const unsigned char * name;
56781+ char d_name[sizeof(next->s_dentry->d_iname)];
56782 int len;
56783 struct inode *inode = NULL;
56784
56785@@ -1567,7 +1568,12 @@ static int configfs_readdir(struct file *file, struct dir_context *ctx)
56786 continue;
56787
56788 name = configfs_get_name(next);
56789- len = strlen(name);
56790+ if (next->s_dentry && name == next->s_dentry->d_iname) {
56791+ len = next->s_dentry->d_name.len;
56792+ memcpy(d_name, name, len);
56793+ name = d_name;
56794+ } else
56795+ len = strlen(name);
56796
56797 /*
56798 * We'll have a dentry and an inode for
56799diff --git a/fs/coredump.c b/fs/coredump.c
56800index 9bdeca1..2a9b08d 100644
56801--- a/fs/coredump.c
56802+++ b/fs/coredump.c
56803@@ -438,8 +438,8 @@ static void wait_for_dump_helpers(struct file *file)
56804 struct pipe_inode_info *pipe = file->private_data;
56805
56806 pipe_lock(pipe);
56807- pipe->readers++;
56808- pipe->writers--;
56809+ atomic_inc(&pipe->readers);
56810+ atomic_dec(&pipe->writers);
56811 wake_up_interruptible_sync(&pipe->wait);
56812 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
56813 pipe_unlock(pipe);
56814@@ -448,11 +448,11 @@ static void wait_for_dump_helpers(struct file *file)
56815 * We actually want wait_event_freezable() but then we need
56816 * to clear TIF_SIGPENDING and improve dump_interrupted().
56817 */
56818- wait_event_interruptible(pipe->wait, pipe->readers == 1);
56819+ wait_event_interruptible(pipe->wait, atomic_read(&pipe->readers) == 1);
56820
56821 pipe_lock(pipe);
56822- pipe->readers--;
56823- pipe->writers++;
56824+ atomic_dec(&pipe->readers);
56825+ atomic_inc(&pipe->writers);
56826 pipe_unlock(pipe);
56827 }
56828
56829@@ -499,7 +499,9 @@ void do_coredump(siginfo_t *siginfo)
56830 struct files_struct *displaced;
56831 bool need_nonrelative = false;
56832 bool core_dumped = false;
56833- static atomic_t core_dump_count = ATOMIC_INIT(0);
56834+ static atomic_unchecked_t core_dump_count = ATOMIC_INIT(0);
56835+ long signr = siginfo->si_signo;
56836+ int dumpable;
56837 struct coredump_params cprm = {
56838 .siginfo = siginfo,
56839 .regs = signal_pt_regs(),
56840@@ -512,12 +514,17 @@ void do_coredump(siginfo_t *siginfo)
56841 .mm_flags = mm->flags,
56842 };
56843
56844- audit_core_dumps(siginfo->si_signo);
56845+ audit_core_dumps(signr);
56846+
56847+ dumpable = __get_dumpable(cprm.mm_flags);
56848+
56849+ if (signr == SIGSEGV || signr == SIGBUS || signr == SIGKILL || signr == SIGILL)
56850+ gr_handle_brute_attach(dumpable);
56851
56852 binfmt = mm->binfmt;
56853 if (!binfmt || !binfmt->core_dump)
56854 goto fail;
56855- if (!__get_dumpable(cprm.mm_flags))
56856+ if (!dumpable)
56857 goto fail;
56858
56859 cred = prepare_creds();
56860@@ -536,7 +543,7 @@ void do_coredump(siginfo_t *siginfo)
56861 need_nonrelative = true;
56862 }
56863
56864- retval = coredump_wait(siginfo->si_signo, &core_state);
56865+ retval = coredump_wait(signr, &core_state);
56866 if (retval < 0)
56867 goto fail_creds;
56868
56869@@ -579,7 +586,7 @@ void do_coredump(siginfo_t *siginfo)
56870 }
56871 cprm.limit = RLIM_INFINITY;
56872
56873- dump_count = atomic_inc_return(&core_dump_count);
56874+ dump_count = atomic_inc_return_unchecked(&core_dump_count);
56875 if (core_pipe_limit && (core_pipe_limit < dump_count)) {
56876 printk(KERN_WARNING "Pid %d(%s) over core_pipe_limit\n",
56877 task_tgid_vnr(current), current->comm);
56878@@ -611,6 +618,8 @@ void do_coredump(siginfo_t *siginfo)
56879 } else {
56880 struct inode *inode;
56881
56882+ gr_learn_resource(current, RLIMIT_CORE, binfmt->min_coredump, 1);
56883+
56884 if (cprm.limit < binfmt->min_coredump)
56885 goto fail_unlock;
56886
56887@@ -669,7 +678,7 @@ close_fail:
56888 filp_close(cprm.file, NULL);
56889 fail_dropcount:
56890 if (ispipe)
56891- atomic_dec(&core_dump_count);
56892+ atomic_dec_unchecked(&core_dump_count);
56893 fail_unlock:
56894 kfree(cn.corename);
56895 coredump_finish(mm, core_dumped);
56896@@ -689,7 +698,7 @@ int dump_write(struct file *file, const void *addr, int nr)
56897 {
56898 return !dump_interrupted() &&
56899 access_ok(VERIFY_READ, addr, nr) &&
56900- file->f_op->write(file, addr, nr, &file->f_pos) == nr;
56901+ file->f_op->write(file, (const char __force_user *)addr, nr, &file->f_pos) == nr;
56902 }
56903 EXPORT_SYMBOL(dump_write);
56904
56905diff --git a/fs/dcache.c b/fs/dcache.c
56906index 89f9671..d2dce57 100644
56907--- a/fs/dcache.c
56908+++ b/fs/dcache.c
56909@@ -1570,7 +1570,7 @@ struct dentry *__d_alloc(struct super_block *sb, const struct qstr *name)
56910 */
56911 dentry->d_iname[DNAME_INLINE_LEN-1] = 0;
56912 if (name->len > DNAME_INLINE_LEN-1) {
56913- dname = kmalloc(name->len + 1, GFP_KERNEL);
56914+ dname = kmalloc(round_up(name->len + 1, sizeof(unsigned long)), GFP_KERNEL);
56915 if (!dname) {
56916 kmem_cache_free(dentry_cache, dentry);
56917 return NULL;
56918@@ -2893,6 +2893,7 @@ static int prepend_path(const struct path *path,
56919 restart:
56920 bptr = *buffer;
56921 blen = *buflen;
56922+ error = 0;
56923 dentry = path->dentry;
56924 vfsmnt = path->mnt;
56925 mnt = real_mount(vfsmnt);
56926@@ -3432,7 +3433,8 @@ void __init vfs_caches_init(unsigned long mempages)
56927 mempages -= reserve;
56928
56929 names_cachep = kmem_cache_create("names_cache", PATH_MAX, 0,
56930- SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
56931+ SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_USERCOPY|
56932+ SLAB_NO_SANITIZE, NULL);
56933
56934 dcache_init();
56935 inode_init();
56936diff --git a/fs/debugfs/inode.c b/fs/debugfs/inode.c
56937index c7c83ff..bda9461 100644
56938--- a/fs/debugfs/inode.c
56939+++ b/fs/debugfs/inode.c
56940@@ -415,7 +415,11 @@ EXPORT_SYMBOL_GPL(debugfs_create_file);
56941 */
56942 struct dentry *debugfs_create_dir(const char *name, struct dentry *parent)
56943 {
56944+#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
56945+ return __create_file(name, S_IFDIR | S_IRWXU,
56946+#else
56947 return __create_file(name, S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO,
56948+#endif
56949 parent, NULL, NULL);
56950 }
56951 EXPORT_SYMBOL_GPL(debugfs_create_dir);
56952diff --git a/fs/ecryptfs/inode.c b/fs/ecryptfs/inode.c
56953index 67e9b63..a9adb68 100644
56954--- a/fs/ecryptfs/inode.c
56955+++ b/fs/ecryptfs/inode.c
56956@@ -674,7 +674,7 @@ static int ecryptfs_readlink_lower(struct dentry *dentry, char **buf,
56957 old_fs = get_fs();
56958 set_fs(get_ds());
56959 rc = lower_dentry->d_inode->i_op->readlink(lower_dentry,
56960- (char __user *)lower_buf,
56961+ (char __force_user *)lower_buf,
56962 PATH_MAX);
56963 set_fs(old_fs);
56964 if (rc < 0)
56965@@ -706,7 +706,7 @@ out:
56966 static void
56967 ecryptfs_put_link(struct dentry *dentry, struct nameidata *nd, void *ptr)
56968 {
56969- char *buf = nd_get_link(nd);
56970+ const char *buf = nd_get_link(nd);
56971 if (!IS_ERR(buf)) {
56972 /* Free the char* */
56973 kfree(buf);
56974diff --git a/fs/ecryptfs/miscdev.c b/fs/ecryptfs/miscdev.c
56975index e4141f2..d8263e8 100644
56976--- a/fs/ecryptfs/miscdev.c
56977+++ b/fs/ecryptfs/miscdev.c
56978@@ -304,7 +304,7 @@ check_list:
56979 goto out_unlock_msg_ctx;
56980 i = PKT_TYPE_SIZE + PKT_CTR_SIZE;
56981 if (msg_ctx->msg) {
56982- if (copy_to_user(&buf[i], packet_length, packet_length_size))
56983+ if (packet_length_size > sizeof(packet_length) || copy_to_user(&buf[i], packet_length, packet_length_size))
56984 goto out_unlock_msg_ctx;
56985 i += packet_length_size;
56986 if (copy_to_user(&buf[i], msg_ctx->msg, msg_ctx->msg_size))
56987diff --git a/fs/exec.c b/fs/exec.c
56988index bb8afc1..2f5087e 100644
56989--- a/fs/exec.c
56990+++ b/fs/exec.c
56991@@ -55,8 +55,20 @@
56992 #include <linux/pipe_fs_i.h>
56993 #include <linux/oom.h>
56994 #include <linux/compat.h>
56995+#include <linux/random.h>
56996+#include <linux/seq_file.h>
56997+#include <linux/coredump.h>
56998+#include <linux/mman.h>
56999+
57000+#ifdef CONFIG_PAX_REFCOUNT
57001+#include <linux/kallsyms.h>
57002+#include <linux/kdebug.h>
57003+#endif
57004+
57005+#include <trace/events/fs.h>
57006
57007 #include <asm/uaccess.h>
57008+#include <asm/sections.h>
57009 #include <asm/mmu_context.h>
57010 #include <asm/tlb.h>
57011
57012@@ -66,19 +78,34 @@
57013
57014 #include <trace/events/sched.h>
57015
57016+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
57017+void __weak pax_set_initial_flags(struct linux_binprm *bprm)
57018+{
57019+ pr_warn_once("PAX: PAX_HAVE_ACL_FLAGS was enabled without providing the pax_set_initial_flags callback, this is probably not what you wanted.\n");
57020+}
57021+#endif
57022+
57023+#ifdef CONFIG_PAX_HOOK_ACL_FLAGS
57024+void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
57025+EXPORT_SYMBOL(pax_set_initial_flags_func);
57026+#endif
57027+
57028 int suid_dumpable = 0;
57029
57030 static LIST_HEAD(formats);
57031 static DEFINE_RWLOCK(binfmt_lock);
57032
57033+extern int gr_process_kernel_exec_ban(void);
57034+extern int gr_process_suid_exec_ban(const struct linux_binprm *bprm);
57035+
57036 void __register_binfmt(struct linux_binfmt * fmt, int insert)
57037 {
57038 BUG_ON(!fmt);
57039 if (WARN_ON(!fmt->load_binary))
57040 return;
57041 write_lock(&binfmt_lock);
57042- insert ? list_add(&fmt->lh, &formats) :
57043- list_add_tail(&fmt->lh, &formats);
57044+ insert ? pax_list_add((struct list_head *)&fmt->lh, &formats) :
57045+ pax_list_add_tail((struct list_head *)&fmt->lh, &formats);
57046 write_unlock(&binfmt_lock);
57047 }
57048
57049@@ -87,7 +114,7 @@ EXPORT_SYMBOL(__register_binfmt);
57050 void unregister_binfmt(struct linux_binfmt * fmt)
57051 {
57052 write_lock(&binfmt_lock);
57053- list_del(&fmt->lh);
57054+ pax_list_del((struct list_head *)&fmt->lh);
57055 write_unlock(&binfmt_lock);
57056 }
57057
57058@@ -183,18 +210,10 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
57059 int write)
57060 {
57061 struct page *page;
57062- int ret;
57063
57064-#ifdef CONFIG_STACK_GROWSUP
57065- if (write) {
57066- ret = expand_downwards(bprm->vma, pos);
57067- if (ret < 0)
57068- return NULL;
57069- }
57070-#endif
57071- ret = get_user_pages(current, bprm->mm, pos,
57072- 1, write, 1, &page, NULL);
57073- if (ret <= 0)
57074+ if (0 > expand_downwards(bprm->vma, pos))
57075+ return NULL;
57076+ if (0 >= get_user_pages(current, bprm->mm, pos, 1, write, 1, &page, NULL))
57077 return NULL;
57078
57079 if (write) {
57080@@ -210,6 +229,17 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
57081 if (size <= ARG_MAX)
57082 return page;
57083
57084+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
57085+ // only allow 512KB for argv+env on suid/sgid binaries
57086+ // to prevent easy ASLR exhaustion
57087+ if (((!uid_eq(bprm->cred->euid, current_euid())) ||
57088+ (!gid_eq(bprm->cred->egid, current_egid()))) &&
57089+ (size > (512 * 1024))) {
57090+ put_page(page);
57091+ return NULL;
57092+ }
57093+#endif
57094+
57095 /*
57096 * Limit to 1/4-th the stack size for the argv+env strings.
57097 * This ensures that:
57098@@ -269,6 +299,11 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
57099 vma->vm_end = STACK_TOP_MAX;
57100 vma->vm_start = vma->vm_end - PAGE_SIZE;
57101 vma->vm_flags = VM_SOFTDIRTY | VM_STACK_FLAGS | VM_STACK_INCOMPLETE_SETUP;
57102+
57103+#ifdef CONFIG_PAX_SEGMEXEC
57104+ vma->vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
57105+#endif
57106+
57107 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
57108 INIT_LIST_HEAD(&vma->anon_vma_chain);
57109
57110@@ -279,6 +314,12 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
57111 mm->stack_vm = mm->total_vm = 1;
57112 up_write(&mm->mmap_sem);
57113 bprm->p = vma->vm_end - sizeof(void *);
57114+
57115+#ifdef CONFIG_PAX_RANDUSTACK
57116+ if (randomize_va_space)
57117+ bprm->p ^= prandom_u32() & ~PAGE_MASK;
57118+#endif
57119+
57120 return 0;
57121 err:
57122 up_write(&mm->mmap_sem);
57123@@ -399,7 +440,7 @@ struct user_arg_ptr {
57124 } ptr;
57125 };
57126
57127-static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
57128+const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
57129 {
57130 const char __user *native;
57131
57132@@ -408,14 +449,14 @@ static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
57133 compat_uptr_t compat;
57134
57135 if (get_user(compat, argv.ptr.compat + nr))
57136- return ERR_PTR(-EFAULT);
57137+ return (const char __force_user *)ERR_PTR(-EFAULT);
57138
57139 return compat_ptr(compat);
57140 }
57141 #endif
57142
57143 if (get_user(native, argv.ptr.native + nr))
57144- return ERR_PTR(-EFAULT);
57145+ return (const char __force_user *)ERR_PTR(-EFAULT);
57146
57147 return native;
57148 }
57149@@ -434,7 +475,7 @@ static int count(struct user_arg_ptr argv, int max)
57150 if (!p)
57151 break;
57152
57153- if (IS_ERR(p))
57154+ if (IS_ERR((const char __force_kernel *)p))
57155 return -EFAULT;
57156
57157 if (i >= max)
57158@@ -469,7 +510,7 @@ static int copy_strings(int argc, struct user_arg_ptr argv,
57159
57160 ret = -EFAULT;
57161 str = get_user_arg_ptr(argv, argc);
57162- if (IS_ERR(str))
57163+ if (IS_ERR((const char __force_kernel *)str))
57164 goto out;
57165
57166 len = strnlen_user(str, MAX_ARG_STRLEN);
57167@@ -551,7 +592,7 @@ int copy_strings_kernel(int argc, const char *const *__argv,
57168 int r;
57169 mm_segment_t oldfs = get_fs();
57170 struct user_arg_ptr argv = {
57171- .ptr.native = (const char __user *const __user *)__argv,
57172+ .ptr.native = (const char __force_user * const __force_user *)__argv,
57173 };
57174
57175 set_fs(KERNEL_DS);
57176@@ -586,7 +627,8 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
57177 unsigned long new_end = old_end - shift;
57178 struct mmu_gather tlb;
57179
57180- BUG_ON(new_start > new_end);
57181+ if (new_start >= new_end || new_start < mmap_min_addr)
57182+ return -ENOMEM;
57183
57184 /*
57185 * ensure there are no vmas between where we want to go
57186@@ -595,6 +637,10 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
57187 if (vma != find_vma(mm, new_start))
57188 return -EFAULT;
57189
57190+#ifdef CONFIG_PAX_SEGMEXEC
57191+ BUG_ON(pax_find_mirror_vma(vma));
57192+#endif
57193+
57194 /*
57195 * cover the whole range: [new_start, old_end)
57196 */
57197@@ -675,10 +721,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
57198 stack_top = arch_align_stack(stack_top);
57199 stack_top = PAGE_ALIGN(stack_top);
57200
57201- if (unlikely(stack_top < mmap_min_addr) ||
57202- unlikely(vma->vm_end - vma->vm_start >= stack_top - mmap_min_addr))
57203- return -ENOMEM;
57204-
57205 stack_shift = vma->vm_end - stack_top;
57206
57207 bprm->p -= stack_shift;
57208@@ -690,8 +732,28 @@ int setup_arg_pages(struct linux_binprm *bprm,
57209 bprm->exec -= stack_shift;
57210
57211 down_write(&mm->mmap_sem);
57212+
57213+ /* Move stack pages down in memory. */
57214+ if (stack_shift) {
57215+ ret = shift_arg_pages(vma, stack_shift);
57216+ if (ret)
57217+ goto out_unlock;
57218+ }
57219+
57220 vm_flags = VM_STACK_FLAGS;
57221
57222+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
57223+ if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
57224+ vm_flags &= ~VM_EXEC;
57225+
57226+#ifdef CONFIG_PAX_MPROTECT
57227+ if (mm->pax_flags & MF_PAX_MPROTECT)
57228+ vm_flags &= ~VM_MAYEXEC;
57229+#endif
57230+
57231+ }
57232+#endif
57233+
57234 /*
57235 * Adjust stack execute permissions; explicitly enable for
57236 * EXSTACK_ENABLE_X, disable for EXSTACK_DISABLE_X and leave alone
57237@@ -710,13 +772,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
57238 goto out_unlock;
57239 BUG_ON(prev != vma);
57240
57241- /* Move stack pages down in memory. */
57242- if (stack_shift) {
57243- ret = shift_arg_pages(vma, stack_shift);
57244- if (ret)
57245- goto out_unlock;
57246- }
57247-
57248 /* mprotect_fixup is overkill to remove the temporary stack flags */
57249 vma->vm_flags &= ~VM_STACK_INCOMPLETE_SETUP;
57250
57251@@ -740,6 +795,27 @@ int setup_arg_pages(struct linux_binprm *bprm,
57252 #endif
57253 current->mm->start_stack = bprm->p;
57254 ret = expand_stack(vma, stack_base);
57255+
57256+#if !defined(CONFIG_STACK_GROWSUP) && defined(CONFIG_PAX_RANDMMAP)
57257+ if (!ret && (mm->pax_flags & MF_PAX_RANDMMAP) && STACK_TOP <= 0xFFFFFFFFU && STACK_TOP > vma->vm_end) {
57258+ unsigned long size;
57259+ vm_flags_t vm_flags;
57260+
57261+ size = STACK_TOP - vma->vm_end;
57262+ vm_flags = VM_NONE | VM_DONTEXPAND | VM_DONTDUMP;
57263+
57264+ ret = vma->vm_end != mmap_region(NULL, vma->vm_end, size, vm_flags, 0);
57265+
57266+#ifdef CONFIG_X86
57267+ if (!ret) {
57268+ size = PAGE_SIZE + mmap_min_addr + ((mm->delta_mmap ^ mm->delta_stack) & (0xFFUL << PAGE_SHIFT));
57269+ ret = 0 != mmap_region(NULL, 0, PAGE_ALIGN(size), vm_flags, 0);
57270+ }
57271+#endif
57272+
57273+ }
57274+#endif
57275+
57276 if (ret)
57277 ret = -EFAULT;
57278
57279@@ -776,6 +852,8 @@ struct file *open_exec(const char *name)
57280
57281 fsnotify_open(file);
57282
57283+ trace_open_exec(name);
57284+
57285 err = deny_write_access(file);
57286 if (err)
57287 goto exit;
57288@@ -799,7 +877,7 @@ int kernel_read(struct file *file, loff_t offset,
57289 old_fs = get_fs();
57290 set_fs(get_ds());
57291 /* The cast to a user pointer is valid due to the set_fs() */
57292- result = vfs_read(file, (void __user *)addr, count, &pos);
57293+ result = vfs_read(file, (void __force_user *)addr, count, &pos);
57294 set_fs(old_fs);
57295 return result;
57296 }
57297@@ -1255,7 +1333,7 @@ static int check_unsafe_exec(struct linux_binprm *bprm)
57298 }
57299 rcu_read_unlock();
57300
57301- if (p->fs->users > n_fs) {
57302+ if (atomic_read(&p->fs->users) > n_fs) {
57303 bprm->unsafe |= LSM_UNSAFE_SHARE;
57304 } else {
57305 res = -EAGAIN;
57306@@ -1451,6 +1529,31 @@ static int exec_binprm(struct linux_binprm *bprm)
57307 return ret;
57308 }
57309
57310+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
57311+static DEFINE_PER_CPU(u64, exec_counter);
57312+static int __init init_exec_counters(void)
57313+{
57314+ unsigned int cpu;
57315+
57316+ for_each_possible_cpu(cpu) {
57317+ per_cpu(exec_counter, cpu) = (u64)cpu;
57318+ }
57319+
57320+ return 0;
57321+}
57322+early_initcall(init_exec_counters);
57323+static inline void increment_exec_counter(void)
57324+{
57325+ BUILD_BUG_ON(NR_CPUS > (1 << 16));
57326+ current->exec_id = this_cpu_add_return(exec_counter, 1 << 16);
57327+}
57328+#else
57329+static inline void increment_exec_counter(void) {}
57330+#endif
57331+
57332+extern void gr_handle_exec_args(struct linux_binprm *bprm,
57333+ struct user_arg_ptr argv);
57334+
57335 /*
57336 * sys_execve() executes a new program.
57337 */
57338@@ -1458,12 +1561,19 @@ static int do_execve_common(const char *filename,
57339 struct user_arg_ptr argv,
57340 struct user_arg_ptr envp)
57341 {
57342+#ifdef CONFIG_GRKERNSEC
57343+ struct file *old_exec_file;
57344+ struct acl_subject_label *old_acl;
57345+ struct rlimit old_rlim[RLIM_NLIMITS];
57346+#endif
57347 struct linux_binprm *bprm;
57348 struct file *file;
57349 struct files_struct *displaced;
57350 bool clear_in_exec;
57351 int retval;
57352
57353+ gr_learn_resource(current, RLIMIT_NPROC, atomic_read(&current_user()->processes), 1);
57354+
57355 /*
57356 * We move the actual failure in case of RLIMIT_NPROC excess from
57357 * set*uid() to execve() because too many poorly written programs
57358@@ -1504,12 +1614,22 @@ static int do_execve_common(const char *filename,
57359 if (IS_ERR(file))
57360 goto out_unmark;
57361
57362+ if (gr_ptrace_readexec(file, bprm->unsafe)) {
57363+ retval = -EPERM;
57364+ goto out_file;
57365+ }
57366+
57367 sched_exec();
57368
57369 bprm->file = file;
57370 bprm->filename = filename;
57371 bprm->interp = filename;
57372
57373+ if (!gr_acl_handle_execve(file->f_path.dentry, file->f_path.mnt)) {
57374+ retval = -EACCES;
57375+ goto out_file;
57376+ }
57377+
57378 retval = bprm_mm_init(bprm);
57379 if (retval)
57380 goto out_file;
57381@@ -1526,24 +1646,70 @@ static int do_execve_common(const char *filename,
57382 if (retval < 0)
57383 goto out;
57384
57385+#ifdef CONFIG_GRKERNSEC
57386+ old_acl = current->acl;
57387+ memcpy(old_rlim, current->signal->rlim, sizeof(old_rlim));
57388+ old_exec_file = current->exec_file;
57389+ get_file(file);
57390+ current->exec_file = file;
57391+#endif
57392+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
57393+ /* limit suid stack to 8MB
57394+ * we saved the old limits above and will restore them if this exec fails
57395+ */
57396+ if (((!uid_eq(bprm->cred->euid, current_euid())) || (!gid_eq(bprm->cred->egid, current_egid()))) &&
57397+ (old_rlim[RLIMIT_STACK].rlim_cur > (8 * 1024 * 1024)))
57398+ current->signal->rlim[RLIMIT_STACK].rlim_cur = 8 * 1024 * 1024;
57399+#endif
57400+
57401+ if (gr_process_kernel_exec_ban() || gr_process_suid_exec_ban(bprm)) {
57402+ retval = -EPERM;
57403+ goto out_fail;
57404+ }
57405+
57406+ if (!gr_tpe_allow(file)) {
57407+ retval = -EACCES;
57408+ goto out_fail;
57409+ }
57410+
57411+ if (gr_check_crash_exec(file)) {
57412+ retval = -EACCES;
57413+ goto out_fail;
57414+ }
57415+
57416+ retval = gr_set_proc_label(file->f_path.dentry, file->f_path.mnt,
57417+ bprm->unsafe);
57418+ if (retval < 0)
57419+ goto out_fail;
57420+
57421 retval = copy_strings_kernel(1, &bprm->filename, bprm);
57422 if (retval < 0)
57423- goto out;
57424+ goto out_fail;
57425
57426 bprm->exec = bprm->p;
57427 retval = copy_strings(bprm->envc, envp, bprm);
57428 if (retval < 0)
57429- goto out;
57430+ goto out_fail;
57431
57432 retval = copy_strings(bprm->argc, argv, bprm);
57433 if (retval < 0)
57434- goto out;
57435+ goto out_fail;
57436+
57437+ gr_log_chroot_exec(file->f_path.dentry, file->f_path.mnt);
57438+
57439+ gr_handle_exec_args(bprm, argv);
57440
57441 retval = exec_binprm(bprm);
57442 if (retval < 0)
57443- goto out;
57444+ goto out_fail;
57445+#ifdef CONFIG_GRKERNSEC
57446+ if (old_exec_file)
57447+ fput(old_exec_file);
57448+#endif
57449
57450 /* execve succeeded */
57451+
57452+ increment_exec_counter();
57453 current->fs->in_exec = 0;
57454 current->in_execve = 0;
57455 acct_update_integrals(current);
57456@@ -1552,6 +1718,14 @@ static int do_execve_common(const char *filename,
57457 put_files_struct(displaced);
57458 return retval;
57459
57460+out_fail:
57461+#ifdef CONFIG_GRKERNSEC
57462+ current->acl = old_acl;
57463+ memcpy(current->signal->rlim, old_rlim, sizeof(old_rlim));
57464+ fput(current->exec_file);
57465+ current->exec_file = old_exec_file;
57466+#endif
57467+
57468 out:
57469 if (bprm->mm) {
57470 acct_arg_size(bprm, 0);
57471@@ -1706,3 +1880,295 @@ asmlinkage long compat_sys_execve(const char __user * filename,
57472 return error;
57473 }
57474 #endif
57475+
57476+int pax_check_flags(unsigned long *flags)
57477+{
57478+ int retval = 0;
57479+
57480+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_SEGMEXEC)
57481+ if (*flags & MF_PAX_SEGMEXEC)
57482+ {
57483+ *flags &= ~MF_PAX_SEGMEXEC;
57484+ retval = -EINVAL;
57485+ }
57486+#endif
57487+
57488+ if ((*flags & MF_PAX_PAGEEXEC)
57489+
57490+#ifdef CONFIG_PAX_PAGEEXEC
57491+ && (*flags & MF_PAX_SEGMEXEC)
57492+#endif
57493+
57494+ )
57495+ {
57496+ *flags &= ~MF_PAX_PAGEEXEC;
57497+ retval = -EINVAL;
57498+ }
57499+
57500+ if ((*flags & MF_PAX_MPROTECT)
57501+
57502+#ifdef CONFIG_PAX_MPROTECT
57503+ && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
57504+#endif
57505+
57506+ )
57507+ {
57508+ *flags &= ~MF_PAX_MPROTECT;
57509+ retval = -EINVAL;
57510+ }
57511+
57512+ if ((*flags & MF_PAX_EMUTRAMP)
57513+
57514+#ifdef CONFIG_PAX_EMUTRAMP
57515+ && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
57516+#endif
57517+
57518+ )
57519+ {
57520+ *flags &= ~MF_PAX_EMUTRAMP;
57521+ retval = -EINVAL;
57522+ }
57523+
57524+ return retval;
57525+}
57526+
57527+EXPORT_SYMBOL(pax_check_flags);
57528+
57529+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
57530+char *pax_get_path(const struct path *path, char *buf, int buflen)
57531+{
57532+ char *pathname = d_path(path, buf, buflen);
57533+
57534+ if (IS_ERR(pathname))
57535+ goto toolong;
57536+
57537+ pathname = mangle_path(buf, pathname, "\t\n\\");
57538+ if (!pathname)
57539+ goto toolong;
57540+
57541+ *pathname = 0;
57542+ return buf;
57543+
57544+toolong:
57545+ return "<path too long>";
57546+}
57547+EXPORT_SYMBOL(pax_get_path);
57548+
57549+void pax_report_fault(struct pt_regs *regs, void *pc, void *sp)
57550+{
57551+ struct task_struct *tsk = current;
57552+ struct mm_struct *mm = current->mm;
57553+ char *buffer_exec = (char *)__get_free_page(GFP_KERNEL);
57554+ char *buffer_fault = (char *)__get_free_page(GFP_KERNEL);
57555+ char *path_exec = NULL;
57556+ char *path_fault = NULL;
57557+ unsigned long start = 0UL, end = 0UL, offset = 0UL;
57558+ siginfo_t info = { };
57559+
57560+ if (buffer_exec && buffer_fault) {
57561+ struct vm_area_struct *vma, *vma_exec = NULL, *vma_fault = NULL;
57562+
57563+ down_read(&mm->mmap_sem);
57564+ vma = mm->mmap;
57565+ while (vma && (!vma_exec || !vma_fault)) {
57566+ if (vma->vm_file && mm->exe_file == vma->vm_file && (vma->vm_flags & VM_EXEC))
57567+ vma_exec = vma;
57568+ if (vma->vm_start <= (unsigned long)pc && (unsigned long)pc < vma->vm_end)
57569+ vma_fault = vma;
57570+ vma = vma->vm_next;
57571+ }
57572+ if (vma_exec)
57573+ path_exec = pax_get_path(&vma_exec->vm_file->f_path, buffer_exec, PAGE_SIZE);
57574+ if (vma_fault) {
57575+ start = vma_fault->vm_start;
57576+ end = vma_fault->vm_end;
57577+ offset = vma_fault->vm_pgoff << PAGE_SHIFT;
57578+ if (vma_fault->vm_file)
57579+ path_fault = pax_get_path(&vma_fault->vm_file->f_path, buffer_fault, PAGE_SIZE);
57580+ else if ((unsigned long)pc >= mm->start_brk && (unsigned long)pc < mm->brk)
57581+ path_fault = "<heap>";
57582+ else if (vma_fault->vm_flags & (VM_GROWSDOWN | VM_GROWSUP))
57583+ path_fault = "<stack>";
57584+ else
57585+ path_fault = "<anonymous mapping>";
57586+ }
57587+ up_read(&mm->mmap_sem);
57588+ }
57589+ if (tsk->signal->curr_ip)
57590+ printk(KERN_ERR "PAX: From %pI4: execution attempt in: %s, %08lx-%08lx %08lx\n", &tsk->signal->curr_ip, path_fault, start, end, offset);
57591+ else
57592+ printk(KERN_ERR "PAX: execution attempt in: %s, %08lx-%08lx %08lx\n", path_fault, start, end, offset);
57593+ printk(KERN_ERR "PAX: terminating task: %s(%s):%d, uid/euid: %u/%u, PC: %p, SP: %p\n", path_exec, tsk->comm, task_pid_nr(tsk),
57594+ from_kuid_munged(&init_user_ns, task_uid(tsk)), from_kuid_munged(&init_user_ns, task_euid(tsk)), pc, sp);
57595+ free_page((unsigned long)buffer_exec);
57596+ free_page((unsigned long)buffer_fault);
57597+ pax_report_insns(regs, pc, sp);
57598+ info.si_signo = SIGKILL;
57599+ info.si_errno = 0;
57600+ info.si_code = SI_KERNEL;
57601+ info.si_pid = 0;
57602+ info.si_uid = 0;
57603+ do_coredump(&info);
57604+}
57605+#endif
57606+
57607+#ifdef CONFIG_PAX_REFCOUNT
57608+void pax_report_refcount_overflow(struct pt_regs *regs)
57609+{
57610+ if (current->signal->curr_ip)
57611+ printk(KERN_ERR "PAX: From %pI4: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
57612+ &current->signal->curr_ip, current->comm, task_pid_nr(current),
57613+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
57614+ else
57615+ printk(KERN_ERR "PAX: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n", current->comm, task_pid_nr(current),
57616+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
57617+ print_symbol(KERN_ERR "PAX: refcount overflow occured at: %s\n", instruction_pointer(regs));
57618+ preempt_disable();
57619+ show_regs(regs);
57620+ preempt_enable();
57621+ force_sig_info(SIGKILL, SEND_SIG_FORCED, current);
57622+}
57623+#endif
57624+
57625+#ifdef CONFIG_PAX_USERCOPY
57626+/* 0: not at all, 1: fully, 2: fully inside frame, -1: partially (implies an error) */
57627+static noinline int check_stack_object(const void *obj, unsigned long len)
57628+{
57629+ const void * const stack = task_stack_page(current);
57630+ const void * const stackend = stack + THREAD_SIZE;
57631+
57632+#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
57633+ const void *frame = NULL;
57634+ const void *oldframe;
57635+#endif
57636+
57637+ if (obj + len < obj)
57638+ return -1;
57639+
57640+ if (obj + len <= stack || stackend <= obj)
57641+ return 0;
57642+
57643+ if (obj < stack || stackend < obj + len)
57644+ return -1;
57645+
57646+#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
57647+ oldframe = __builtin_frame_address(1);
57648+ if (oldframe)
57649+ frame = __builtin_frame_address(2);
57650+ /*
57651+ low ----------------------------------------------> high
57652+ [saved bp][saved ip][args][local vars][saved bp][saved ip]
57653+ ^----------------^
57654+ allow copies only within here
57655+ */
57656+ while (stack <= frame && frame < stackend) {
57657+ /* if obj + len extends past the last frame, this
57658+ check won't pass and the next frame will be 0,
57659+ causing us to bail out and correctly report
57660+ the copy as invalid
57661+ */
57662+ if (obj + len <= frame)
57663+ return obj >= oldframe + 2 * sizeof(void *) ? 2 : -1;
57664+ oldframe = frame;
57665+ frame = *(const void * const *)frame;
57666+ }
57667+ return -1;
57668+#else
57669+ return 1;
57670+#endif
57671+}
57672+
57673+static __noreturn void pax_report_usercopy(const void *ptr, unsigned long len, bool to_user, const char *type)
57674+{
57675+ if (current->signal->curr_ip)
57676+ printk(KERN_ERR "PAX: From %pI4: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
57677+ &current->signal->curr_ip, to_user ? "leak" : "overwrite", to_user ? "from" : "to", ptr, type ? : "unknown", len);
57678+ else
57679+ printk(KERN_ERR "PAX: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
57680+ to_user ? "leak" : "overwrite", to_user ? "from" : "to", ptr, type ? : "unknown", len);
57681+ dump_stack();
57682+ gr_handle_kernel_exploit();
57683+ do_group_exit(SIGKILL);
57684+}
57685+#endif
57686+
57687+#ifdef CONFIG_PAX_USERCOPY
57688+static inline bool check_kernel_text_object(unsigned long low, unsigned long high)
57689+{
57690+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
57691+ unsigned long textlow = ktla_ktva((unsigned long)_stext);
57692+#ifdef CONFIG_MODULES
57693+ unsigned long texthigh = (unsigned long)MODULES_EXEC_VADDR;
57694+#else
57695+ unsigned long texthigh = ktla_ktva((unsigned long)_etext);
57696+#endif
57697+
57698+#else
57699+ unsigned long textlow = (unsigned long)_stext;
57700+ unsigned long texthigh = (unsigned long)_etext;
57701+
57702+#ifdef CONFIG_X86_64
57703+ /* check against linear mapping as well */
57704+ if (high > (unsigned long)__va(__pa(textlow)) &&
57705+ low <= (unsigned long)__va(__pa(texthigh)))
57706+ return true;
57707+#endif
57708+
57709+#endif
57710+
57711+ if (high <= textlow || low > texthigh)
57712+ return false;
57713+ else
57714+ return true;
57715+}
57716+#endif
57717+
57718+void __check_object_size(const void *ptr, unsigned long n, bool to_user)
57719+{
57720+
57721+#ifdef CONFIG_PAX_USERCOPY
57722+ const char *type;
57723+
57724+ if (!n)
57725+ return;
57726+
57727+ type = check_heap_object(ptr, n);
57728+ if (!type) {
57729+ int ret = check_stack_object(ptr, n);
57730+ if (ret == 1 || ret == 2)
57731+ return;
57732+ if (ret == 0) {
57733+ if (check_kernel_text_object((unsigned long)ptr, (unsigned long)ptr + n))
57734+ type = "<kernel text>";
57735+ else
57736+ return;
57737+ } else
57738+ type = "<process stack>";
57739+ }
57740+
57741+ pax_report_usercopy(ptr, n, to_user, type);
57742+#endif
57743+
57744+}
57745+EXPORT_SYMBOL(__check_object_size);
57746+
57747+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
57748+void pax_track_stack(void)
57749+{
57750+ unsigned long sp = (unsigned long)&sp;
57751+ if (sp < current_thread_info()->lowest_stack &&
57752+ sp > (unsigned long)task_stack_page(current))
57753+ current_thread_info()->lowest_stack = sp;
57754+}
57755+EXPORT_SYMBOL(pax_track_stack);
57756+#endif
57757+
57758+#ifdef CONFIG_PAX_SIZE_OVERFLOW
57759+void report_size_overflow(const char *file, unsigned int line, const char *func, const char *ssa_name)
57760+{
57761+ printk(KERN_ERR "PAX: size overflow detected in function %s %s:%u %s", func, file, line, ssa_name);
57762+ dump_stack();
57763+ do_group_exit(SIGKILL);
57764+}
57765+EXPORT_SYMBOL(report_size_overflow);
57766+#endif
57767diff --git a/fs/ext2/balloc.c b/fs/ext2/balloc.c
57768index 9f9992b..8b59411 100644
57769--- a/fs/ext2/balloc.c
57770+++ b/fs/ext2/balloc.c
57771@@ -1184,10 +1184,10 @@ static int ext2_has_free_blocks(struct ext2_sb_info *sbi)
57772
57773 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
57774 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
57775- if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
57776+ if (free_blocks < root_blocks + 1 &&
57777 !uid_eq(sbi->s_resuid, current_fsuid()) &&
57778 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
57779- !in_group_p (sbi->s_resgid))) {
57780+ !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
57781 return 0;
57782 }
57783 return 1;
57784diff --git a/fs/ext2/xattr.c b/fs/ext2/xattr.c
57785index 2d7557d..14e38f94 100644
57786--- a/fs/ext2/xattr.c
57787+++ b/fs/ext2/xattr.c
57788@@ -247,7 +247,7 @@ ext2_xattr_list(struct dentry *dentry, char *buffer, size_t buffer_size)
57789 struct buffer_head *bh = NULL;
57790 struct ext2_xattr_entry *entry;
57791 char *end;
57792- size_t rest = buffer_size;
57793+ size_t rest = buffer_size, total_size = 0;
57794 int error;
57795
57796 ea_idebug(inode, "buffer=%p, buffer_size=%ld",
57797@@ -305,9 +305,10 @@ bad_block: ext2_error(inode->i_sb, "ext2_xattr_list",
57798 buffer += size;
57799 }
57800 rest -= size;
57801+ total_size += size;
57802 }
57803 }
57804- error = buffer_size - rest; /* total size */
57805+ error = total_size;
57806
57807 cleanup:
57808 brelse(bh);
57809diff --git a/fs/ext3/balloc.c b/fs/ext3/balloc.c
57810index 22548f5..41521d8 100644
57811--- a/fs/ext3/balloc.c
57812+++ b/fs/ext3/balloc.c
57813@@ -1438,10 +1438,10 @@ static int ext3_has_free_blocks(struct ext3_sb_info *sbi, int use_reservation)
57814
57815 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
57816 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
57817- if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
57818+ if (free_blocks < root_blocks + 1 &&
57819 !use_reservation && !uid_eq(sbi->s_resuid, current_fsuid()) &&
57820 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
57821- !in_group_p (sbi->s_resgid))) {
57822+ !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
57823 return 0;
57824 }
57825 return 1;
57826diff --git a/fs/ext3/xattr.c b/fs/ext3/xattr.c
57827index b1fc963..881228c 100644
57828--- a/fs/ext3/xattr.c
57829+++ b/fs/ext3/xattr.c
57830@@ -330,7 +330,7 @@ static int
57831 ext3_xattr_list_entries(struct dentry *dentry, struct ext3_xattr_entry *entry,
57832 char *buffer, size_t buffer_size)
57833 {
57834- size_t rest = buffer_size;
57835+ size_t rest = buffer_size, total_size = 0;
57836
57837 for (; !IS_LAST_ENTRY(entry); entry = EXT3_XATTR_NEXT(entry)) {
57838 const struct xattr_handler *handler =
57839@@ -347,9 +347,10 @@ ext3_xattr_list_entries(struct dentry *dentry, struct ext3_xattr_entry *entry,
57840 buffer += size;
57841 }
57842 rest -= size;
57843+ total_size += size;
57844 }
57845 }
57846- return buffer_size - rest;
57847+ return total_size;
57848 }
57849
57850 static int
57851diff --git a/fs/ext4/balloc.c b/fs/ext4/balloc.c
57852index dc5d572..4c21f8e 100644
57853--- a/fs/ext4/balloc.c
57854+++ b/fs/ext4/balloc.c
57855@@ -534,8 +534,8 @@ static int ext4_has_free_clusters(struct ext4_sb_info *sbi,
57856 /* Hm, nope. Are (enough) root reserved clusters available? */
57857 if (uid_eq(sbi->s_resuid, current_fsuid()) ||
57858 (!gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) && in_group_p(sbi->s_resgid)) ||
57859- capable(CAP_SYS_RESOURCE) ||
57860- (flags & EXT4_MB_USE_ROOT_BLOCKS)) {
57861+ (flags & EXT4_MB_USE_ROOT_BLOCKS) ||
57862+ capable_nolog(CAP_SYS_RESOURCE)) {
57863
57864 if (free_clusters >= (nclusters + dirty_clusters +
57865 resv_clusters))
57866diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
57867index 745faaa..a072816 100644
57868--- a/fs/ext4/ext4.h
57869+++ b/fs/ext4/ext4.h
57870@@ -1266,19 +1266,19 @@ struct ext4_sb_info {
57871 unsigned long s_mb_last_start;
57872
57873 /* stats for buddy allocator */
57874- atomic_t s_bal_reqs; /* number of reqs with len > 1 */
57875- atomic_t s_bal_success; /* we found long enough chunks */
57876- atomic_t s_bal_allocated; /* in blocks */
57877- atomic_t s_bal_ex_scanned; /* total extents scanned */
57878- atomic_t s_bal_goals; /* goal hits */
57879- atomic_t s_bal_breaks; /* too long searches */
57880- atomic_t s_bal_2orders; /* 2^order hits */
57881+ atomic_unchecked_t s_bal_reqs; /* number of reqs with len > 1 */
57882+ atomic_unchecked_t s_bal_success; /* we found long enough chunks */
57883+ atomic_unchecked_t s_bal_allocated; /* in blocks */
57884+ atomic_unchecked_t s_bal_ex_scanned; /* total extents scanned */
57885+ atomic_unchecked_t s_bal_goals; /* goal hits */
57886+ atomic_unchecked_t s_bal_breaks; /* too long searches */
57887+ atomic_unchecked_t s_bal_2orders; /* 2^order hits */
57888 spinlock_t s_bal_lock;
57889 unsigned long s_mb_buddies_generated;
57890 unsigned long long s_mb_generation_time;
57891- atomic_t s_mb_lost_chunks;
57892- atomic_t s_mb_preallocated;
57893- atomic_t s_mb_discarded;
57894+ atomic_unchecked_t s_mb_lost_chunks;
57895+ atomic_unchecked_t s_mb_preallocated;
57896+ atomic_unchecked_t s_mb_discarded;
57897 atomic_t s_lock_busy;
57898
57899 /* locality groups */
57900diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
57901index 04a5c75..09894fa 100644
57902--- a/fs/ext4/mballoc.c
57903+++ b/fs/ext4/mballoc.c
57904@@ -1880,7 +1880,7 @@ void ext4_mb_simple_scan_group(struct ext4_allocation_context *ac,
57905 BUG_ON(ac->ac_b_ex.fe_len != ac->ac_g_ex.fe_len);
57906
57907 if (EXT4_SB(sb)->s_mb_stats)
57908- atomic_inc(&EXT4_SB(sb)->s_bal_2orders);
57909+ atomic_inc_unchecked(&EXT4_SB(sb)->s_bal_2orders);
57910
57911 break;
57912 }
57913@@ -2189,7 +2189,7 @@ repeat:
57914 ac->ac_status = AC_STATUS_CONTINUE;
57915 ac->ac_flags |= EXT4_MB_HINT_FIRST;
57916 cr = 3;
57917- atomic_inc(&sbi->s_mb_lost_chunks);
57918+ atomic_inc_unchecked(&sbi->s_mb_lost_chunks);
57919 goto repeat;
57920 }
57921 }
57922@@ -2697,25 +2697,25 @@ int ext4_mb_release(struct super_block *sb)
57923 if (sbi->s_mb_stats) {
57924 ext4_msg(sb, KERN_INFO,
57925 "mballoc: %u blocks %u reqs (%u success)",
57926- atomic_read(&sbi->s_bal_allocated),
57927- atomic_read(&sbi->s_bal_reqs),
57928- atomic_read(&sbi->s_bal_success));
57929+ atomic_read_unchecked(&sbi->s_bal_allocated),
57930+ atomic_read_unchecked(&sbi->s_bal_reqs),
57931+ atomic_read_unchecked(&sbi->s_bal_success));
57932 ext4_msg(sb, KERN_INFO,
57933 "mballoc: %u extents scanned, %u goal hits, "
57934 "%u 2^N hits, %u breaks, %u lost",
57935- atomic_read(&sbi->s_bal_ex_scanned),
57936- atomic_read(&sbi->s_bal_goals),
57937- atomic_read(&sbi->s_bal_2orders),
57938- atomic_read(&sbi->s_bal_breaks),
57939- atomic_read(&sbi->s_mb_lost_chunks));
57940+ atomic_read_unchecked(&sbi->s_bal_ex_scanned),
57941+ atomic_read_unchecked(&sbi->s_bal_goals),
57942+ atomic_read_unchecked(&sbi->s_bal_2orders),
57943+ atomic_read_unchecked(&sbi->s_bal_breaks),
57944+ atomic_read_unchecked(&sbi->s_mb_lost_chunks));
57945 ext4_msg(sb, KERN_INFO,
57946 "mballoc: %lu generated and it took %Lu",
57947 sbi->s_mb_buddies_generated,
57948 sbi->s_mb_generation_time);
57949 ext4_msg(sb, KERN_INFO,
57950 "mballoc: %u preallocated, %u discarded",
57951- atomic_read(&sbi->s_mb_preallocated),
57952- atomic_read(&sbi->s_mb_discarded));
57953+ atomic_read_unchecked(&sbi->s_mb_preallocated),
57954+ atomic_read_unchecked(&sbi->s_mb_discarded));
57955 }
57956
57957 free_percpu(sbi->s_locality_groups);
57958@@ -3169,16 +3169,16 @@ static void ext4_mb_collect_stats(struct ext4_allocation_context *ac)
57959 struct ext4_sb_info *sbi = EXT4_SB(ac->ac_sb);
57960
57961 if (sbi->s_mb_stats && ac->ac_g_ex.fe_len > 1) {
57962- atomic_inc(&sbi->s_bal_reqs);
57963- atomic_add(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
57964+ atomic_inc_unchecked(&sbi->s_bal_reqs);
57965+ atomic_add_unchecked(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
57966 if (ac->ac_b_ex.fe_len >= ac->ac_o_ex.fe_len)
57967- atomic_inc(&sbi->s_bal_success);
57968- atomic_add(ac->ac_found, &sbi->s_bal_ex_scanned);
57969+ atomic_inc_unchecked(&sbi->s_bal_success);
57970+ atomic_add_unchecked(ac->ac_found, &sbi->s_bal_ex_scanned);
57971 if (ac->ac_g_ex.fe_start == ac->ac_b_ex.fe_start &&
57972 ac->ac_g_ex.fe_group == ac->ac_b_ex.fe_group)
57973- atomic_inc(&sbi->s_bal_goals);
57974+ atomic_inc_unchecked(&sbi->s_bal_goals);
57975 if (ac->ac_found > sbi->s_mb_max_to_scan)
57976- atomic_inc(&sbi->s_bal_breaks);
57977+ atomic_inc_unchecked(&sbi->s_bal_breaks);
57978 }
57979
57980 if (ac->ac_op == EXT4_MB_HISTORY_ALLOC)
57981@@ -3583,7 +3583,7 @@ ext4_mb_new_inode_pa(struct ext4_allocation_context *ac)
57982 trace_ext4_mb_new_inode_pa(ac, pa);
57983
57984 ext4_mb_use_inode_pa(ac, pa);
57985- atomic_add(pa->pa_free, &sbi->s_mb_preallocated);
57986+ atomic_add_unchecked(pa->pa_free, &sbi->s_mb_preallocated);
57987
57988 ei = EXT4_I(ac->ac_inode);
57989 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
57990@@ -3643,7 +3643,7 @@ ext4_mb_new_group_pa(struct ext4_allocation_context *ac)
57991 trace_ext4_mb_new_group_pa(ac, pa);
57992
57993 ext4_mb_use_group_pa(ac, pa);
57994- atomic_add(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
57995+ atomic_add_unchecked(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
57996
57997 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
57998 lg = ac->ac_lg;
57999@@ -3732,7 +3732,7 @@ ext4_mb_release_inode_pa(struct ext4_buddy *e4b, struct buffer_head *bitmap_bh,
58000 * from the bitmap and continue.
58001 */
58002 }
58003- atomic_add(free, &sbi->s_mb_discarded);
58004+ atomic_add_unchecked(free, &sbi->s_mb_discarded);
58005
58006 return err;
58007 }
58008@@ -3750,7 +3750,7 @@ ext4_mb_release_group_pa(struct ext4_buddy *e4b,
58009 ext4_get_group_no_and_offset(sb, pa->pa_pstart, &group, &bit);
58010 BUG_ON(group != e4b->bd_group && pa->pa_len != 0);
58011 mb_free_blocks(pa->pa_inode, e4b, bit, pa->pa_len);
58012- atomic_add(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
58013+ atomic_add_unchecked(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
58014 trace_ext4_mballoc_discard(sb, NULL, group, bit, pa->pa_len);
58015
58016 return 0;
58017diff --git a/fs/ext4/mmp.c b/fs/ext4/mmp.c
58018index 214461e..3614c89 100644
58019--- a/fs/ext4/mmp.c
58020+++ b/fs/ext4/mmp.c
58021@@ -113,7 +113,7 @@ static int read_mmp_block(struct super_block *sb, struct buffer_head **bh,
58022 void __dump_mmp_msg(struct super_block *sb, struct mmp_struct *mmp,
58023 const char *function, unsigned int line, const char *msg)
58024 {
58025- __ext4_warning(sb, function, line, msg);
58026+ __ext4_warning(sb, function, line, "%s", msg);
58027 __ext4_warning(sb, function, line,
58028 "MMP failure info: last update time: %llu, last update "
58029 "node: %s, last update device: %s\n",
58030diff --git a/fs/ext4/super.c b/fs/ext4/super.c
58031index b947e0a..c102e3b 100644
58032--- a/fs/ext4/super.c
58033+++ b/fs/ext4/super.c
58034@@ -1251,7 +1251,7 @@ static ext4_fsblk_t get_sb_block(void **data)
58035 }
58036
58037 #define DEFAULT_JOURNAL_IOPRIO (IOPRIO_PRIO_VALUE(IOPRIO_CLASS_BE, 3))
58038-static char deprecated_msg[] = "Mount option \"%s\" will be removed by %s\n"
58039+static const char deprecated_msg[] = "Mount option \"%s\" will be removed by %s\n"
58040 "Contact linux-ext4@vger.kernel.org if you think we should keep it.\n";
58041
58042 #ifdef CONFIG_QUOTA
58043@@ -2431,7 +2431,7 @@ struct ext4_attr {
58044 int offset;
58045 int deprecated_val;
58046 } u;
58047-};
58048+} __do_const;
58049
58050 static int parse_strtoull(const char *buf,
58051 unsigned long long max, unsigned long long *value)
58052diff --git a/fs/ext4/xattr.c b/fs/ext4/xattr.c
58053index 1423c48..9c0c6dc 100644
58054--- a/fs/ext4/xattr.c
58055+++ b/fs/ext4/xattr.c
58056@@ -381,7 +381,7 @@ static int
58057 ext4_xattr_list_entries(struct dentry *dentry, struct ext4_xattr_entry *entry,
58058 char *buffer, size_t buffer_size)
58059 {
58060- size_t rest = buffer_size;
58061+ size_t rest = buffer_size, total_size = 0;
58062
58063 for (; !IS_LAST_ENTRY(entry); entry = EXT4_XATTR_NEXT(entry)) {
58064 const struct xattr_handler *handler =
58065@@ -398,9 +398,10 @@ ext4_xattr_list_entries(struct dentry *dentry, struct ext4_xattr_entry *entry,
58066 buffer += size;
58067 }
58068 rest -= size;
58069+ total_size += size;
58070 }
58071 }
58072- return buffer_size - rest;
58073+ return total_size;
58074 }
58075
58076 static int
58077diff --git a/fs/fcntl.c b/fs/fcntl.c
58078index 65343c3..9969dcf 100644
58079--- a/fs/fcntl.c
58080+++ b/fs/fcntl.c
58081@@ -107,6 +107,11 @@ int __f_setown(struct file *filp, struct pid *pid, enum pid_type type,
58082 if (err)
58083 return err;
58084
58085+ if (gr_handle_chroot_fowner(pid, type))
58086+ return -ENOENT;
58087+ if (gr_check_protected_task_fowner(pid, type))
58088+ return -EACCES;
58089+
58090 f_modown(filp, pid, type, force);
58091 return 0;
58092 }
58093diff --git a/fs/fhandle.c b/fs/fhandle.c
58094index 999ff5c..41f4109 100644
58095--- a/fs/fhandle.c
58096+++ b/fs/fhandle.c
58097@@ -67,8 +67,7 @@ static long do_sys_name_to_handle(struct path *path,
58098 } else
58099 retval = 0;
58100 /* copy the mount id */
58101- if (copy_to_user(mnt_id, &real_mount(path->mnt)->mnt_id,
58102- sizeof(*mnt_id)) ||
58103+ if (put_user(real_mount(path->mnt)->mnt_id, mnt_id) ||
58104 copy_to_user(ufh, handle,
58105 sizeof(struct file_handle) + handle_bytes))
58106 retval = -EFAULT;
58107diff --git a/fs/file.c b/fs/file.c
58108index 4a78f98..f9a6d25 100644
58109--- a/fs/file.c
58110+++ b/fs/file.c
58111@@ -16,6 +16,7 @@
58112 #include <linux/slab.h>
58113 #include <linux/vmalloc.h>
58114 #include <linux/file.h>
58115+#include <linux/security.h>
58116 #include <linux/fdtable.h>
58117 #include <linux/bitops.h>
58118 #include <linux/interrupt.h>
58119@@ -141,7 +142,7 @@ out:
58120 * Return <0 error code on error; 1 on successful completion.
58121 * The files->file_lock should be held on entry, and will be held on exit.
58122 */
58123-static int expand_fdtable(struct files_struct *files, int nr)
58124+static int expand_fdtable(struct files_struct *files, unsigned int nr)
58125 __releases(files->file_lock)
58126 __acquires(files->file_lock)
58127 {
58128@@ -186,7 +187,7 @@ static int expand_fdtable(struct files_struct *files, int nr)
58129 * expanded and execution may have blocked.
58130 * The files->file_lock should be held on entry, and will be held on exit.
58131 */
58132-static int expand_files(struct files_struct *files, int nr)
58133+static int expand_files(struct files_struct *files, unsigned int nr)
58134 {
58135 struct fdtable *fdt;
58136
58137@@ -828,6 +829,7 @@ int replace_fd(unsigned fd, struct file *file, unsigned flags)
58138 if (!file)
58139 return __close_fd(files, fd);
58140
58141+ gr_learn_resource(current, RLIMIT_NOFILE, fd, 0);
58142 if (fd >= rlimit(RLIMIT_NOFILE))
58143 return -EBADF;
58144
58145@@ -854,6 +856,7 @@ SYSCALL_DEFINE3(dup3, unsigned int, oldfd, unsigned int, newfd, int, flags)
58146 if (unlikely(oldfd == newfd))
58147 return -EINVAL;
58148
58149+ gr_learn_resource(current, RLIMIT_NOFILE, newfd, 0);
58150 if (newfd >= rlimit(RLIMIT_NOFILE))
58151 return -EBADF;
58152
58153@@ -909,6 +912,7 @@ SYSCALL_DEFINE1(dup, unsigned int, fildes)
58154 int f_dupfd(unsigned int from, struct file *file, unsigned flags)
58155 {
58156 int err;
58157+ gr_learn_resource(current, RLIMIT_NOFILE, from, 0);
58158 if (from >= rlimit(RLIMIT_NOFILE))
58159 return -EINVAL;
58160 err = alloc_fd(from, flags);
58161diff --git a/fs/filesystems.c b/fs/filesystems.c
58162index 92567d9..fcd8cbf 100644
58163--- a/fs/filesystems.c
58164+++ b/fs/filesystems.c
58165@@ -273,7 +273,11 @@ struct file_system_type *get_fs_type(const char *name)
58166 int len = dot ? dot - name : strlen(name);
58167
58168 fs = __get_fs_type(name, len);
58169+#ifdef CONFIG_GRKERNSEC_MODHARDEN
58170+ if (!fs && (___request_module(true, "grsec_modharden_fs", "fs-%.*s", len, name) == 0))
58171+#else
58172 if (!fs && (request_module("fs-%.*s", len, name) == 0))
58173+#endif
58174 fs = __get_fs_type(name, len);
58175
58176 if (dot && fs && !(fs->fs_flags & FS_HAS_SUBTYPE)) {
58177diff --git a/fs/fs_struct.c b/fs/fs_struct.c
58178index d8ac61d..79a36f0 100644
58179--- a/fs/fs_struct.c
58180+++ b/fs/fs_struct.c
58181@@ -4,6 +4,7 @@
58182 #include <linux/path.h>
58183 #include <linux/slab.h>
58184 #include <linux/fs_struct.h>
58185+#include <linux/grsecurity.h>
58186 #include "internal.h"
58187
58188 /*
58189@@ -19,6 +20,7 @@ void set_fs_root(struct fs_struct *fs, const struct path *path)
58190 write_seqcount_begin(&fs->seq);
58191 old_root = fs->root;
58192 fs->root = *path;
58193+ gr_set_chroot_entries(current, path);
58194 write_seqcount_end(&fs->seq);
58195 spin_unlock(&fs->lock);
58196 if (old_root.dentry)
58197@@ -67,6 +69,10 @@ void chroot_fs_refs(const struct path *old_root, const struct path *new_root)
58198 int hits = 0;
58199 spin_lock(&fs->lock);
58200 write_seqcount_begin(&fs->seq);
58201+ /* this root replacement is only done by pivot_root,
58202+ leave grsec's chroot tagging alone for this task
58203+ so that a pivoted root isn't treated as a chroot
58204+ */
58205 hits += replace_path(&fs->root, old_root, new_root);
58206 hits += replace_path(&fs->pwd, old_root, new_root);
58207 write_seqcount_end(&fs->seq);
58208@@ -99,7 +105,8 @@ void exit_fs(struct task_struct *tsk)
58209 task_lock(tsk);
58210 spin_lock(&fs->lock);
58211 tsk->fs = NULL;
58212- kill = !--fs->users;
58213+ gr_clear_chroot_entries(tsk);
58214+ kill = !atomic_dec_return(&fs->users);
58215 spin_unlock(&fs->lock);
58216 task_unlock(tsk);
58217 if (kill)
58218@@ -112,7 +119,7 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
58219 struct fs_struct *fs = kmem_cache_alloc(fs_cachep, GFP_KERNEL);
58220 /* We don't need to lock fs - think why ;-) */
58221 if (fs) {
58222- fs->users = 1;
58223+ atomic_set(&fs->users, 1);
58224 fs->in_exec = 0;
58225 spin_lock_init(&fs->lock);
58226 seqcount_init(&fs->seq);
58227@@ -121,6 +128,9 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
58228 spin_lock(&old->lock);
58229 fs->root = old->root;
58230 path_get(&fs->root);
58231+ /* instead of calling gr_set_chroot_entries here,
58232+ we call it from every caller of this function
58233+ */
58234 fs->pwd = old->pwd;
58235 path_get(&fs->pwd);
58236 spin_unlock(&old->lock);
58237@@ -139,8 +149,9 @@ int unshare_fs_struct(void)
58238
58239 task_lock(current);
58240 spin_lock(&fs->lock);
58241- kill = !--fs->users;
58242+ kill = !atomic_dec_return(&fs->users);
58243 current->fs = new_fs;
58244+ gr_set_chroot_entries(current, &new_fs->root);
58245 spin_unlock(&fs->lock);
58246 task_unlock(current);
58247
58248@@ -153,13 +164,13 @@ EXPORT_SYMBOL_GPL(unshare_fs_struct);
58249
58250 int current_umask(void)
58251 {
58252- return current->fs->umask;
58253+ return current->fs->umask | gr_acl_umask();
58254 }
58255 EXPORT_SYMBOL(current_umask);
58256
58257 /* to be mentioned only in INIT_TASK */
58258 struct fs_struct init_fs = {
58259- .users = 1,
58260+ .users = ATOMIC_INIT(1),
58261 .lock = __SPIN_LOCK_UNLOCKED(init_fs.lock),
58262 .seq = SEQCNT_ZERO,
58263 .umask = 0022,
58264diff --git a/fs/fscache/cookie.c b/fs/fscache/cookie.c
58265index b2a86e3..37f425a 100644
58266--- a/fs/fscache/cookie.c
58267+++ b/fs/fscache/cookie.c
58268@@ -19,7 +19,7 @@
58269
58270 struct kmem_cache *fscache_cookie_jar;
58271
58272-static atomic_t fscache_object_debug_id = ATOMIC_INIT(0);
58273+static atomic_unchecked_t fscache_object_debug_id = ATOMIC_INIT(0);
58274
58275 static int fscache_acquire_non_index_cookie(struct fscache_cookie *cookie);
58276 static int fscache_alloc_object(struct fscache_cache *cache,
58277@@ -68,11 +68,11 @@ struct fscache_cookie *__fscache_acquire_cookie(
58278 parent ? (char *) parent->def->name : "<no-parent>",
58279 def->name, netfs_data);
58280
58281- fscache_stat(&fscache_n_acquires);
58282+ fscache_stat_unchecked(&fscache_n_acquires);
58283
58284 /* if there's no parent cookie, then we don't create one here either */
58285 if (!parent) {
58286- fscache_stat(&fscache_n_acquires_null);
58287+ fscache_stat_unchecked(&fscache_n_acquires_null);
58288 _leave(" [no parent]");
58289 return NULL;
58290 }
58291@@ -87,7 +87,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
58292 /* allocate and initialise a cookie */
58293 cookie = kmem_cache_alloc(fscache_cookie_jar, GFP_KERNEL);
58294 if (!cookie) {
58295- fscache_stat(&fscache_n_acquires_oom);
58296+ fscache_stat_unchecked(&fscache_n_acquires_oom);
58297 _leave(" [ENOMEM]");
58298 return NULL;
58299 }
58300@@ -114,13 +114,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
58301
58302 switch (cookie->def->type) {
58303 case FSCACHE_COOKIE_TYPE_INDEX:
58304- fscache_stat(&fscache_n_cookie_index);
58305+ fscache_stat_unchecked(&fscache_n_cookie_index);
58306 break;
58307 case FSCACHE_COOKIE_TYPE_DATAFILE:
58308- fscache_stat(&fscache_n_cookie_data);
58309+ fscache_stat_unchecked(&fscache_n_cookie_data);
58310 break;
58311 default:
58312- fscache_stat(&fscache_n_cookie_special);
58313+ fscache_stat_unchecked(&fscache_n_cookie_special);
58314 break;
58315 }
58316
58317@@ -131,13 +131,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
58318 if (fscache_acquire_non_index_cookie(cookie) < 0) {
58319 atomic_dec(&parent->n_children);
58320 __fscache_cookie_put(cookie);
58321- fscache_stat(&fscache_n_acquires_nobufs);
58322+ fscache_stat_unchecked(&fscache_n_acquires_nobufs);
58323 _leave(" = NULL");
58324 return NULL;
58325 }
58326 }
58327
58328- fscache_stat(&fscache_n_acquires_ok);
58329+ fscache_stat_unchecked(&fscache_n_acquires_ok);
58330 _leave(" = %p", cookie);
58331 return cookie;
58332 }
58333@@ -173,7 +173,7 @@ static int fscache_acquire_non_index_cookie(struct fscache_cookie *cookie)
58334 cache = fscache_select_cache_for_object(cookie->parent);
58335 if (!cache) {
58336 up_read(&fscache_addremove_sem);
58337- fscache_stat(&fscache_n_acquires_no_cache);
58338+ fscache_stat_unchecked(&fscache_n_acquires_no_cache);
58339 _leave(" = -ENOMEDIUM [no cache]");
58340 return -ENOMEDIUM;
58341 }
58342@@ -259,14 +259,14 @@ static int fscache_alloc_object(struct fscache_cache *cache,
58343 object = cache->ops->alloc_object(cache, cookie);
58344 fscache_stat_d(&fscache_n_cop_alloc_object);
58345 if (IS_ERR(object)) {
58346- fscache_stat(&fscache_n_object_no_alloc);
58347+ fscache_stat_unchecked(&fscache_n_object_no_alloc);
58348 ret = PTR_ERR(object);
58349 goto error;
58350 }
58351
58352- fscache_stat(&fscache_n_object_alloc);
58353+ fscache_stat_unchecked(&fscache_n_object_alloc);
58354
58355- object->debug_id = atomic_inc_return(&fscache_object_debug_id);
58356+ object->debug_id = atomic_inc_return_unchecked(&fscache_object_debug_id);
58357
58358 _debug("ALLOC OBJ%x: %s {%lx}",
58359 object->debug_id, cookie->def->name, object->events);
58360@@ -380,7 +380,7 @@ void __fscache_invalidate(struct fscache_cookie *cookie)
58361
58362 _enter("{%s}", cookie->def->name);
58363
58364- fscache_stat(&fscache_n_invalidates);
58365+ fscache_stat_unchecked(&fscache_n_invalidates);
58366
58367 /* Only permit invalidation of data files. Invalidating an index will
58368 * require the caller to release all its attachments to the tree rooted
58369@@ -438,10 +438,10 @@ void __fscache_update_cookie(struct fscache_cookie *cookie)
58370 {
58371 struct fscache_object *object;
58372
58373- fscache_stat(&fscache_n_updates);
58374+ fscache_stat_unchecked(&fscache_n_updates);
58375
58376 if (!cookie) {
58377- fscache_stat(&fscache_n_updates_null);
58378+ fscache_stat_unchecked(&fscache_n_updates_null);
58379 _leave(" [no cookie]");
58380 return;
58381 }
58382@@ -473,12 +473,12 @@ void __fscache_relinquish_cookie(struct fscache_cookie *cookie, int retire)
58383 {
58384 struct fscache_object *object;
58385
58386- fscache_stat(&fscache_n_relinquishes);
58387+ fscache_stat_unchecked(&fscache_n_relinquishes);
58388 if (retire)
58389- fscache_stat(&fscache_n_relinquishes_retire);
58390+ fscache_stat_unchecked(&fscache_n_relinquishes_retire);
58391
58392 if (!cookie) {
58393- fscache_stat(&fscache_n_relinquishes_null);
58394+ fscache_stat_unchecked(&fscache_n_relinquishes_null);
58395 _leave(" [no cookie]");
58396 return;
58397 }
58398@@ -598,7 +598,7 @@ int __fscache_check_consistency(struct fscache_cookie *cookie)
58399 if (test_bit(FSCACHE_IOERROR, &object->cache->flags))
58400 goto inconsistent;
58401
58402- op->debug_id = atomic_inc_return(&fscache_op_debug_id);
58403+ op->debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
58404
58405 atomic_inc(&cookie->n_active);
58406 if (fscache_submit_op(object, op) < 0)
58407diff --git a/fs/fscache/internal.h b/fs/fscache/internal.h
58408index 4226f66..0fb3f45 100644
58409--- a/fs/fscache/internal.h
58410+++ b/fs/fscache/internal.h
58411@@ -133,8 +133,8 @@ extern void fscache_operation_gc(struct work_struct *);
58412 extern int fscache_wait_for_deferred_lookup(struct fscache_cookie *);
58413 extern int fscache_wait_for_operation_activation(struct fscache_object *,
58414 struct fscache_operation *,
58415- atomic_t *,
58416- atomic_t *,
58417+ atomic_unchecked_t *,
58418+ atomic_unchecked_t *,
58419 void (*)(struct fscache_operation *));
58420 extern void fscache_invalidate_writes(struct fscache_cookie *);
58421
58422@@ -153,101 +153,101 @@ extern void fscache_proc_cleanup(void);
58423 * stats.c
58424 */
58425 #ifdef CONFIG_FSCACHE_STATS
58426-extern atomic_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
58427-extern atomic_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
58428+extern atomic_unchecked_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
58429+extern atomic_unchecked_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
58430
58431-extern atomic_t fscache_n_op_pend;
58432-extern atomic_t fscache_n_op_run;
58433-extern atomic_t fscache_n_op_enqueue;
58434-extern atomic_t fscache_n_op_deferred_release;
58435-extern atomic_t fscache_n_op_release;
58436-extern atomic_t fscache_n_op_gc;
58437-extern atomic_t fscache_n_op_cancelled;
58438-extern atomic_t fscache_n_op_rejected;
58439+extern atomic_unchecked_t fscache_n_op_pend;
58440+extern atomic_unchecked_t fscache_n_op_run;
58441+extern atomic_unchecked_t fscache_n_op_enqueue;
58442+extern atomic_unchecked_t fscache_n_op_deferred_release;
58443+extern atomic_unchecked_t fscache_n_op_release;
58444+extern atomic_unchecked_t fscache_n_op_gc;
58445+extern atomic_unchecked_t fscache_n_op_cancelled;
58446+extern atomic_unchecked_t fscache_n_op_rejected;
58447
58448-extern atomic_t fscache_n_attr_changed;
58449-extern atomic_t fscache_n_attr_changed_ok;
58450-extern atomic_t fscache_n_attr_changed_nobufs;
58451-extern atomic_t fscache_n_attr_changed_nomem;
58452-extern atomic_t fscache_n_attr_changed_calls;
58453+extern atomic_unchecked_t fscache_n_attr_changed;
58454+extern atomic_unchecked_t fscache_n_attr_changed_ok;
58455+extern atomic_unchecked_t fscache_n_attr_changed_nobufs;
58456+extern atomic_unchecked_t fscache_n_attr_changed_nomem;
58457+extern atomic_unchecked_t fscache_n_attr_changed_calls;
58458
58459-extern atomic_t fscache_n_allocs;
58460-extern atomic_t fscache_n_allocs_ok;
58461-extern atomic_t fscache_n_allocs_wait;
58462-extern atomic_t fscache_n_allocs_nobufs;
58463-extern atomic_t fscache_n_allocs_intr;
58464-extern atomic_t fscache_n_allocs_object_dead;
58465-extern atomic_t fscache_n_alloc_ops;
58466-extern atomic_t fscache_n_alloc_op_waits;
58467+extern atomic_unchecked_t fscache_n_allocs;
58468+extern atomic_unchecked_t fscache_n_allocs_ok;
58469+extern atomic_unchecked_t fscache_n_allocs_wait;
58470+extern atomic_unchecked_t fscache_n_allocs_nobufs;
58471+extern atomic_unchecked_t fscache_n_allocs_intr;
58472+extern atomic_unchecked_t fscache_n_allocs_object_dead;
58473+extern atomic_unchecked_t fscache_n_alloc_ops;
58474+extern atomic_unchecked_t fscache_n_alloc_op_waits;
58475
58476-extern atomic_t fscache_n_retrievals;
58477-extern atomic_t fscache_n_retrievals_ok;
58478-extern atomic_t fscache_n_retrievals_wait;
58479-extern atomic_t fscache_n_retrievals_nodata;
58480-extern atomic_t fscache_n_retrievals_nobufs;
58481-extern atomic_t fscache_n_retrievals_intr;
58482-extern atomic_t fscache_n_retrievals_nomem;
58483-extern atomic_t fscache_n_retrievals_object_dead;
58484-extern atomic_t fscache_n_retrieval_ops;
58485-extern atomic_t fscache_n_retrieval_op_waits;
58486+extern atomic_unchecked_t fscache_n_retrievals;
58487+extern atomic_unchecked_t fscache_n_retrievals_ok;
58488+extern atomic_unchecked_t fscache_n_retrievals_wait;
58489+extern atomic_unchecked_t fscache_n_retrievals_nodata;
58490+extern atomic_unchecked_t fscache_n_retrievals_nobufs;
58491+extern atomic_unchecked_t fscache_n_retrievals_intr;
58492+extern atomic_unchecked_t fscache_n_retrievals_nomem;
58493+extern atomic_unchecked_t fscache_n_retrievals_object_dead;
58494+extern atomic_unchecked_t fscache_n_retrieval_ops;
58495+extern atomic_unchecked_t fscache_n_retrieval_op_waits;
58496
58497-extern atomic_t fscache_n_stores;
58498-extern atomic_t fscache_n_stores_ok;
58499-extern atomic_t fscache_n_stores_again;
58500-extern atomic_t fscache_n_stores_nobufs;
58501-extern atomic_t fscache_n_stores_oom;
58502-extern atomic_t fscache_n_store_ops;
58503-extern atomic_t fscache_n_store_calls;
58504-extern atomic_t fscache_n_store_pages;
58505-extern atomic_t fscache_n_store_radix_deletes;
58506-extern atomic_t fscache_n_store_pages_over_limit;
58507+extern atomic_unchecked_t fscache_n_stores;
58508+extern atomic_unchecked_t fscache_n_stores_ok;
58509+extern atomic_unchecked_t fscache_n_stores_again;
58510+extern atomic_unchecked_t fscache_n_stores_nobufs;
58511+extern atomic_unchecked_t fscache_n_stores_oom;
58512+extern atomic_unchecked_t fscache_n_store_ops;
58513+extern atomic_unchecked_t fscache_n_store_calls;
58514+extern atomic_unchecked_t fscache_n_store_pages;
58515+extern atomic_unchecked_t fscache_n_store_radix_deletes;
58516+extern atomic_unchecked_t fscache_n_store_pages_over_limit;
58517
58518-extern atomic_t fscache_n_store_vmscan_not_storing;
58519-extern atomic_t fscache_n_store_vmscan_gone;
58520-extern atomic_t fscache_n_store_vmscan_busy;
58521-extern atomic_t fscache_n_store_vmscan_cancelled;
58522-extern atomic_t fscache_n_store_vmscan_wait;
58523+extern atomic_unchecked_t fscache_n_store_vmscan_not_storing;
58524+extern atomic_unchecked_t fscache_n_store_vmscan_gone;
58525+extern atomic_unchecked_t fscache_n_store_vmscan_busy;
58526+extern atomic_unchecked_t fscache_n_store_vmscan_cancelled;
58527+extern atomic_unchecked_t fscache_n_store_vmscan_wait;
58528
58529-extern atomic_t fscache_n_marks;
58530-extern atomic_t fscache_n_uncaches;
58531+extern atomic_unchecked_t fscache_n_marks;
58532+extern atomic_unchecked_t fscache_n_uncaches;
58533
58534-extern atomic_t fscache_n_acquires;
58535-extern atomic_t fscache_n_acquires_null;
58536-extern atomic_t fscache_n_acquires_no_cache;
58537-extern atomic_t fscache_n_acquires_ok;
58538-extern atomic_t fscache_n_acquires_nobufs;
58539-extern atomic_t fscache_n_acquires_oom;
58540+extern atomic_unchecked_t fscache_n_acquires;
58541+extern atomic_unchecked_t fscache_n_acquires_null;
58542+extern atomic_unchecked_t fscache_n_acquires_no_cache;
58543+extern atomic_unchecked_t fscache_n_acquires_ok;
58544+extern atomic_unchecked_t fscache_n_acquires_nobufs;
58545+extern atomic_unchecked_t fscache_n_acquires_oom;
58546
58547-extern atomic_t fscache_n_invalidates;
58548-extern atomic_t fscache_n_invalidates_run;
58549+extern atomic_unchecked_t fscache_n_invalidates;
58550+extern atomic_unchecked_t fscache_n_invalidates_run;
58551
58552-extern atomic_t fscache_n_updates;
58553-extern atomic_t fscache_n_updates_null;
58554-extern atomic_t fscache_n_updates_run;
58555+extern atomic_unchecked_t fscache_n_updates;
58556+extern atomic_unchecked_t fscache_n_updates_null;
58557+extern atomic_unchecked_t fscache_n_updates_run;
58558
58559-extern atomic_t fscache_n_relinquishes;
58560-extern atomic_t fscache_n_relinquishes_null;
58561-extern atomic_t fscache_n_relinquishes_waitcrt;
58562-extern atomic_t fscache_n_relinquishes_retire;
58563+extern atomic_unchecked_t fscache_n_relinquishes;
58564+extern atomic_unchecked_t fscache_n_relinquishes_null;
58565+extern atomic_unchecked_t fscache_n_relinquishes_waitcrt;
58566+extern atomic_unchecked_t fscache_n_relinquishes_retire;
58567
58568-extern atomic_t fscache_n_cookie_index;
58569-extern atomic_t fscache_n_cookie_data;
58570-extern atomic_t fscache_n_cookie_special;
58571+extern atomic_unchecked_t fscache_n_cookie_index;
58572+extern atomic_unchecked_t fscache_n_cookie_data;
58573+extern atomic_unchecked_t fscache_n_cookie_special;
58574
58575-extern atomic_t fscache_n_object_alloc;
58576-extern atomic_t fscache_n_object_no_alloc;
58577-extern atomic_t fscache_n_object_lookups;
58578-extern atomic_t fscache_n_object_lookups_negative;
58579-extern atomic_t fscache_n_object_lookups_positive;
58580-extern atomic_t fscache_n_object_lookups_timed_out;
58581-extern atomic_t fscache_n_object_created;
58582-extern atomic_t fscache_n_object_avail;
58583-extern atomic_t fscache_n_object_dead;
58584+extern atomic_unchecked_t fscache_n_object_alloc;
58585+extern atomic_unchecked_t fscache_n_object_no_alloc;
58586+extern atomic_unchecked_t fscache_n_object_lookups;
58587+extern atomic_unchecked_t fscache_n_object_lookups_negative;
58588+extern atomic_unchecked_t fscache_n_object_lookups_positive;
58589+extern atomic_unchecked_t fscache_n_object_lookups_timed_out;
58590+extern atomic_unchecked_t fscache_n_object_created;
58591+extern atomic_unchecked_t fscache_n_object_avail;
58592+extern atomic_unchecked_t fscache_n_object_dead;
58593
58594-extern atomic_t fscache_n_checkaux_none;
58595-extern atomic_t fscache_n_checkaux_okay;
58596-extern atomic_t fscache_n_checkaux_update;
58597-extern atomic_t fscache_n_checkaux_obsolete;
58598+extern atomic_unchecked_t fscache_n_checkaux_none;
58599+extern atomic_unchecked_t fscache_n_checkaux_okay;
58600+extern atomic_unchecked_t fscache_n_checkaux_update;
58601+extern atomic_unchecked_t fscache_n_checkaux_obsolete;
58602
58603 extern atomic_t fscache_n_cop_alloc_object;
58604 extern atomic_t fscache_n_cop_lookup_object;
58605@@ -272,6 +272,11 @@ static inline void fscache_stat(atomic_t *stat)
58606 atomic_inc(stat);
58607 }
58608
58609+static inline void fscache_stat_unchecked(atomic_unchecked_t *stat)
58610+{
58611+ atomic_inc_unchecked(stat);
58612+}
58613+
58614 static inline void fscache_stat_d(atomic_t *stat)
58615 {
58616 atomic_dec(stat);
58617@@ -284,6 +289,7 @@ extern const struct file_operations fscache_stats_fops;
58618
58619 #define __fscache_stat(stat) (NULL)
58620 #define fscache_stat(stat) do {} while (0)
58621+#define fscache_stat_unchecked(stat) do {} while (0)
58622 #define fscache_stat_d(stat) do {} while (0)
58623 #endif
58624
58625diff --git a/fs/fscache/object.c b/fs/fscache/object.c
58626index 86d75a6..5f3d7a0 100644
58627--- a/fs/fscache/object.c
58628+++ b/fs/fscache/object.c
58629@@ -451,7 +451,7 @@ static const struct fscache_state *fscache_look_up_object(struct fscache_object
58630 _debug("LOOKUP \"%s\" in \"%s\"",
58631 cookie->def->name, object->cache->tag->name);
58632
58633- fscache_stat(&fscache_n_object_lookups);
58634+ fscache_stat_unchecked(&fscache_n_object_lookups);
58635 fscache_stat(&fscache_n_cop_lookup_object);
58636 ret = object->cache->ops->lookup_object(object);
58637 fscache_stat_d(&fscache_n_cop_lookup_object);
58638@@ -461,7 +461,7 @@ static const struct fscache_state *fscache_look_up_object(struct fscache_object
58639 if (ret == -ETIMEDOUT) {
58640 /* probably stuck behind another object, so move this one to
58641 * the back of the queue */
58642- fscache_stat(&fscache_n_object_lookups_timed_out);
58643+ fscache_stat_unchecked(&fscache_n_object_lookups_timed_out);
58644 _leave(" [timeout]");
58645 return NO_TRANSIT;
58646 }
58647@@ -489,7 +489,7 @@ void fscache_object_lookup_negative(struct fscache_object *object)
58648 _enter("{OBJ%x,%s}", object->debug_id, object->state->name);
58649
58650 if (!test_and_set_bit(FSCACHE_OBJECT_IS_LOOKED_UP, &object->flags)) {
58651- fscache_stat(&fscache_n_object_lookups_negative);
58652+ fscache_stat_unchecked(&fscache_n_object_lookups_negative);
58653
58654 /* Allow write requests to begin stacking up and read requests to begin
58655 * returning ENODATA.
58656@@ -523,7 +523,7 @@ void fscache_obtained_object(struct fscache_object *object)
58657 /* if we were still looking up, then we must have a positive lookup
58658 * result, in which case there may be data available */
58659 if (!test_and_set_bit(FSCACHE_OBJECT_IS_LOOKED_UP, &object->flags)) {
58660- fscache_stat(&fscache_n_object_lookups_positive);
58661+ fscache_stat_unchecked(&fscache_n_object_lookups_positive);
58662
58663 /* We do (presumably) have data */
58664 clear_bit_unlock(FSCACHE_COOKIE_NO_DATA_YET, &cookie->flags);
58665@@ -534,7 +534,7 @@ void fscache_obtained_object(struct fscache_object *object)
58666 clear_bit_unlock(FSCACHE_COOKIE_LOOKING_UP, &cookie->flags);
58667 wake_up_bit(&cookie->flags, FSCACHE_COOKIE_LOOKING_UP);
58668 } else {
58669- fscache_stat(&fscache_n_object_created);
58670+ fscache_stat_unchecked(&fscache_n_object_created);
58671 }
58672
58673 set_bit(FSCACHE_OBJECT_IS_AVAILABLE, &object->flags);
58674@@ -570,7 +570,7 @@ static const struct fscache_state *fscache_object_available(struct fscache_objec
58675 fscache_stat_d(&fscache_n_cop_lookup_complete);
58676
58677 fscache_hist(fscache_obj_instantiate_histogram, object->lookup_jif);
58678- fscache_stat(&fscache_n_object_avail);
58679+ fscache_stat_unchecked(&fscache_n_object_avail);
58680
58681 _leave("");
58682 return transit_to(JUMPSTART_DEPS);
58683@@ -716,7 +716,7 @@ static const struct fscache_state *fscache_drop_object(struct fscache_object *ob
58684
58685 /* this just shifts the object release to the work processor */
58686 fscache_put_object(object);
58687- fscache_stat(&fscache_n_object_dead);
58688+ fscache_stat_unchecked(&fscache_n_object_dead);
58689
58690 _leave("");
58691 return transit_to(OBJECT_DEAD);
58692@@ -881,7 +881,7 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
58693 enum fscache_checkaux result;
58694
58695 if (!object->cookie->def->check_aux) {
58696- fscache_stat(&fscache_n_checkaux_none);
58697+ fscache_stat_unchecked(&fscache_n_checkaux_none);
58698 return FSCACHE_CHECKAUX_OKAY;
58699 }
58700
58701@@ -890,17 +890,17 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
58702 switch (result) {
58703 /* entry okay as is */
58704 case FSCACHE_CHECKAUX_OKAY:
58705- fscache_stat(&fscache_n_checkaux_okay);
58706+ fscache_stat_unchecked(&fscache_n_checkaux_okay);
58707 break;
58708
58709 /* entry requires update */
58710 case FSCACHE_CHECKAUX_NEEDS_UPDATE:
58711- fscache_stat(&fscache_n_checkaux_update);
58712+ fscache_stat_unchecked(&fscache_n_checkaux_update);
58713 break;
58714
58715 /* entry requires deletion */
58716 case FSCACHE_CHECKAUX_OBSOLETE:
58717- fscache_stat(&fscache_n_checkaux_obsolete);
58718+ fscache_stat_unchecked(&fscache_n_checkaux_obsolete);
58719 break;
58720
58721 default:
58722@@ -986,7 +986,7 @@ static const struct fscache_state *fscache_invalidate_object(struct fscache_obje
58723 {
58724 const struct fscache_state *s;
58725
58726- fscache_stat(&fscache_n_invalidates_run);
58727+ fscache_stat_unchecked(&fscache_n_invalidates_run);
58728 fscache_stat(&fscache_n_cop_invalidate_object);
58729 s = _fscache_invalidate_object(object, event);
58730 fscache_stat_d(&fscache_n_cop_invalidate_object);
58731@@ -1001,7 +1001,7 @@ static const struct fscache_state *fscache_update_object(struct fscache_object *
58732 {
58733 _enter("{OBJ%x},%d", object->debug_id, event);
58734
58735- fscache_stat(&fscache_n_updates_run);
58736+ fscache_stat_unchecked(&fscache_n_updates_run);
58737 fscache_stat(&fscache_n_cop_update_object);
58738 object->cache->ops->update_object(object);
58739 fscache_stat_d(&fscache_n_cop_update_object);
58740diff --git a/fs/fscache/operation.c b/fs/fscache/operation.c
58741index 318071a..379938b 100644
58742--- a/fs/fscache/operation.c
58743+++ b/fs/fscache/operation.c
58744@@ -17,7 +17,7 @@
58745 #include <linux/slab.h>
58746 #include "internal.h"
58747
58748-atomic_t fscache_op_debug_id;
58749+atomic_unchecked_t fscache_op_debug_id;
58750 EXPORT_SYMBOL(fscache_op_debug_id);
58751
58752 /**
58753@@ -39,7 +39,7 @@ void fscache_enqueue_operation(struct fscache_operation *op)
58754 ASSERTCMP(atomic_read(&op->usage), >, 0);
58755 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_IN_PROGRESS);
58756
58757- fscache_stat(&fscache_n_op_enqueue);
58758+ fscache_stat_unchecked(&fscache_n_op_enqueue);
58759 switch (op->flags & FSCACHE_OP_TYPE) {
58760 case FSCACHE_OP_ASYNC:
58761 _debug("queue async");
58762@@ -73,7 +73,7 @@ static void fscache_run_op(struct fscache_object *object,
58763 wake_up_bit(&op->flags, FSCACHE_OP_WAITING);
58764 if (op->processor)
58765 fscache_enqueue_operation(op);
58766- fscache_stat(&fscache_n_op_run);
58767+ fscache_stat_unchecked(&fscache_n_op_run);
58768 }
58769
58770 /*
58771@@ -105,11 +105,11 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
58772 if (object->n_in_progress > 0) {
58773 atomic_inc(&op->usage);
58774 list_add_tail(&op->pend_link, &object->pending_ops);
58775- fscache_stat(&fscache_n_op_pend);
58776+ fscache_stat_unchecked(&fscache_n_op_pend);
58777 } else if (!list_empty(&object->pending_ops)) {
58778 atomic_inc(&op->usage);
58779 list_add_tail(&op->pend_link, &object->pending_ops);
58780- fscache_stat(&fscache_n_op_pend);
58781+ fscache_stat_unchecked(&fscache_n_op_pend);
58782 fscache_start_operations(object);
58783 } else {
58784 ASSERTCMP(object->n_in_progress, ==, 0);
58785@@ -125,7 +125,7 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
58786 object->n_exclusive++; /* reads and writes must wait */
58787 atomic_inc(&op->usage);
58788 list_add_tail(&op->pend_link, &object->pending_ops);
58789- fscache_stat(&fscache_n_op_pend);
58790+ fscache_stat_unchecked(&fscache_n_op_pend);
58791 ret = 0;
58792 } else {
58793 /* If we're in any other state, there must have been an I/O
58794@@ -212,11 +212,11 @@ int fscache_submit_op(struct fscache_object *object,
58795 if (object->n_exclusive > 0) {
58796 atomic_inc(&op->usage);
58797 list_add_tail(&op->pend_link, &object->pending_ops);
58798- fscache_stat(&fscache_n_op_pend);
58799+ fscache_stat_unchecked(&fscache_n_op_pend);
58800 } else if (!list_empty(&object->pending_ops)) {
58801 atomic_inc(&op->usage);
58802 list_add_tail(&op->pend_link, &object->pending_ops);
58803- fscache_stat(&fscache_n_op_pend);
58804+ fscache_stat_unchecked(&fscache_n_op_pend);
58805 fscache_start_operations(object);
58806 } else {
58807 ASSERTCMP(object->n_exclusive, ==, 0);
58808@@ -228,10 +228,10 @@ int fscache_submit_op(struct fscache_object *object,
58809 object->n_ops++;
58810 atomic_inc(&op->usage);
58811 list_add_tail(&op->pend_link, &object->pending_ops);
58812- fscache_stat(&fscache_n_op_pend);
58813+ fscache_stat_unchecked(&fscache_n_op_pend);
58814 ret = 0;
58815 } else if (fscache_object_is_dying(object)) {
58816- fscache_stat(&fscache_n_op_rejected);
58817+ fscache_stat_unchecked(&fscache_n_op_rejected);
58818 op->state = FSCACHE_OP_ST_CANCELLED;
58819 ret = -ENOBUFS;
58820 } else if (!test_bit(FSCACHE_IOERROR, &object->cache->flags)) {
58821@@ -310,7 +310,7 @@ int fscache_cancel_op(struct fscache_operation *op,
58822 ret = -EBUSY;
58823 if (op->state == FSCACHE_OP_ST_PENDING) {
58824 ASSERT(!list_empty(&op->pend_link));
58825- fscache_stat(&fscache_n_op_cancelled);
58826+ fscache_stat_unchecked(&fscache_n_op_cancelled);
58827 list_del_init(&op->pend_link);
58828 if (do_cancel)
58829 do_cancel(op);
58830@@ -342,7 +342,7 @@ void fscache_cancel_all_ops(struct fscache_object *object)
58831 while (!list_empty(&object->pending_ops)) {
58832 op = list_entry(object->pending_ops.next,
58833 struct fscache_operation, pend_link);
58834- fscache_stat(&fscache_n_op_cancelled);
58835+ fscache_stat_unchecked(&fscache_n_op_cancelled);
58836 list_del_init(&op->pend_link);
58837
58838 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_PENDING);
58839@@ -414,7 +414,7 @@ void fscache_put_operation(struct fscache_operation *op)
58840 op->state, ==, FSCACHE_OP_ST_CANCELLED);
58841 op->state = FSCACHE_OP_ST_DEAD;
58842
58843- fscache_stat(&fscache_n_op_release);
58844+ fscache_stat_unchecked(&fscache_n_op_release);
58845
58846 if (op->release) {
58847 op->release(op);
58848@@ -433,7 +433,7 @@ void fscache_put_operation(struct fscache_operation *op)
58849 * lock, and defer it otherwise */
58850 if (!spin_trylock(&object->lock)) {
58851 _debug("defer put");
58852- fscache_stat(&fscache_n_op_deferred_release);
58853+ fscache_stat_unchecked(&fscache_n_op_deferred_release);
58854
58855 cache = object->cache;
58856 spin_lock(&cache->op_gc_list_lock);
58857@@ -486,7 +486,7 @@ void fscache_operation_gc(struct work_struct *work)
58858
58859 _debug("GC DEFERRED REL OBJ%x OP%x",
58860 object->debug_id, op->debug_id);
58861- fscache_stat(&fscache_n_op_gc);
58862+ fscache_stat_unchecked(&fscache_n_op_gc);
58863
58864 ASSERTCMP(atomic_read(&op->usage), ==, 0);
58865 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_DEAD);
58866diff --git a/fs/fscache/page.c b/fs/fscache/page.c
58867index 73899c1..ae40c58 100644
58868--- a/fs/fscache/page.c
58869+++ b/fs/fscache/page.c
58870@@ -61,7 +61,7 @@ try_again:
58871 val = radix_tree_lookup(&cookie->stores, page->index);
58872 if (!val) {
58873 rcu_read_unlock();
58874- fscache_stat(&fscache_n_store_vmscan_not_storing);
58875+ fscache_stat_unchecked(&fscache_n_store_vmscan_not_storing);
58876 __fscache_uncache_page(cookie, page);
58877 return true;
58878 }
58879@@ -91,11 +91,11 @@ try_again:
58880 spin_unlock(&cookie->stores_lock);
58881
58882 if (xpage) {
58883- fscache_stat(&fscache_n_store_vmscan_cancelled);
58884- fscache_stat(&fscache_n_store_radix_deletes);
58885+ fscache_stat_unchecked(&fscache_n_store_vmscan_cancelled);
58886+ fscache_stat_unchecked(&fscache_n_store_radix_deletes);
58887 ASSERTCMP(xpage, ==, page);
58888 } else {
58889- fscache_stat(&fscache_n_store_vmscan_gone);
58890+ fscache_stat_unchecked(&fscache_n_store_vmscan_gone);
58891 }
58892
58893 wake_up_bit(&cookie->flags, 0);
58894@@ -110,11 +110,11 @@ page_busy:
58895 * sleeping on memory allocation, so we may need to impose a timeout
58896 * too. */
58897 if (!(gfp & __GFP_WAIT) || !(gfp & __GFP_FS)) {
58898- fscache_stat(&fscache_n_store_vmscan_busy);
58899+ fscache_stat_unchecked(&fscache_n_store_vmscan_busy);
58900 return false;
58901 }
58902
58903- fscache_stat(&fscache_n_store_vmscan_wait);
58904+ fscache_stat_unchecked(&fscache_n_store_vmscan_wait);
58905 __fscache_wait_on_page_write(cookie, page);
58906 gfp &= ~__GFP_WAIT;
58907 goto try_again;
58908@@ -140,7 +140,7 @@ static void fscache_end_page_write(struct fscache_object *object,
58909 FSCACHE_COOKIE_STORING_TAG);
58910 if (!radix_tree_tag_get(&cookie->stores, page->index,
58911 FSCACHE_COOKIE_PENDING_TAG)) {
58912- fscache_stat(&fscache_n_store_radix_deletes);
58913+ fscache_stat_unchecked(&fscache_n_store_radix_deletes);
58914 xpage = radix_tree_delete(&cookie->stores, page->index);
58915 }
58916 spin_unlock(&cookie->stores_lock);
58917@@ -161,7 +161,7 @@ static void fscache_attr_changed_op(struct fscache_operation *op)
58918
58919 _enter("{OBJ%x OP%x}", object->debug_id, op->debug_id);
58920
58921- fscache_stat(&fscache_n_attr_changed_calls);
58922+ fscache_stat_unchecked(&fscache_n_attr_changed_calls);
58923
58924 if (fscache_object_is_active(object) &&
58925 fscache_use_cookie(object)) {
58926@@ -189,11 +189,11 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
58927
58928 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
58929
58930- fscache_stat(&fscache_n_attr_changed);
58931+ fscache_stat_unchecked(&fscache_n_attr_changed);
58932
58933 op = kzalloc(sizeof(*op), GFP_KERNEL);
58934 if (!op) {
58935- fscache_stat(&fscache_n_attr_changed_nomem);
58936+ fscache_stat_unchecked(&fscache_n_attr_changed_nomem);
58937 _leave(" = -ENOMEM");
58938 return -ENOMEM;
58939 }
58940@@ -211,7 +211,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
58941 if (fscache_submit_exclusive_op(object, op) < 0)
58942 goto nobufs;
58943 spin_unlock(&cookie->lock);
58944- fscache_stat(&fscache_n_attr_changed_ok);
58945+ fscache_stat_unchecked(&fscache_n_attr_changed_ok);
58946 fscache_put_operation(op);
58947 _leave(" = 0");
58948 return 0;
58949@@ -219,7 +219,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
58950 nobufs:
58951 spin_unlock(&cookie->lock);
58952 kfree(op);
58953- fscache_stat(&fscache_n_attr_changed_nobufs);
58954+ fscache_stat_unchecked(&fscache_n_attr_changed_nobufs);
58955 _leave(" = %d", -ENOBUFS);
58956 return -ENOBUFS;
58957 }
58958@@ -258,7 +258,7 @@ static struct fscache_retrieval *fscache_alloc_retrieval(
58959 /* allocate a retrieval operation and attempt to submit it */
58960 op = kzalloc(sizeof(*op), GFP_NOIO);
58961 if (!op) {
58962- fscache_stat(&fscache_n_retrievals_nomem);
58963+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
58964 return NULL;
58965 }
58966
58967@@ -289,13 +289,13 @@ int fscache_wait_for_deferred_lookup(struct fscache_cookie *cookie)
58968 return 0;
58969 }
58970
58971- fscache_stat(&fscache_n_retrievals_wait);
58972+ fscache_stat_unchecked(&fscache_n_retrievals_wait);
58973
58974 jif = jiffies;
58975 if (wait_on_bit(&cookie->flags, FSCACHE_COOKIE_LOOKING_UP,
58976 fscache_wait_bit_interruptible,
58977 TASK_INTERRUPTIBLE) != 0) {
58978- fscache_stat(&fscache_n_retrievals_intr);
58979+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
58980 _leave(" = -ERESTARTSYS");
58981 return -ERESTARTSYS;
58982 }
58983@@ -324,8 +324,8 @@ static void fscache_do_cancel_retrieval(struct fscache_operation *_op)
58984 */
58985 int fscache_wait_for_operation_activation(struct fscache_object *object,
58986 struct fscache_operation *op,
58987- atomic_t *stat_op_waits,
58988- atomic_t *stat_object_dead,
58989+ atomic_unchecked_t *stat_op_waits,
58990+ atomic_unchecked_t *stat_object_dead,
58991 void (*do_cancel)(struct fscache_operation *))
58992 {
58993 int ret;
58994@@ -335,7 +335,7 @@ int fscache_wait_for_operation_activation(struct fscache_object *object,
58995
58996 _debug(">>> WT");
58997 if (stat_op_waits)
58998- fscache_stat(stat_op_waits);
58999+ fscache_stat_unchecked(stat_op_waits);
59000 if (wait_on_bit(&op->flags, FSCACHE_OP_WAITING,
59001 fscache_wait_bit_interruptible,
59002 TASK_INTERRUPTIBLE) != 0) {
59003@@ -353,7 +353,7 @@ int fscache_wait_for_operation_activation(struct fscache_object *object,
59004 check_if_dead:
59005 if (op->state == FSCACHE_OP_ST_CANCELLED) {
59006 if (stat_object_dead)
59007- fscache_stat(stat_object_dead);
59008+ fscache_stat_unchecked(stat_object_dead);
59009 _leave(" = -ENOBUFS [cancelled]");
59010 return -ENOBUFS;
59011 }
59012@@ -361,7 +361,7 @@ check_if_dead:
59013 pr_err("%s() = -ENOBUFS [obj dead %d]\n", __func__, op->state);
59014 fscache_cancel_op(op, do_cancel);
59015 if (stat_object_dead)
59016- fscache_stat(stat_object_dead);
59017+ fscache_stat_unchecked(stat_object_dead);
59018 return -ENOBUFS;
59019 }
59020 return 0;
59021@@ -388,7 +388,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
59022
59023 _enter("%p,%p,,,", cookie, page);
59024
59025- fscache_stat(&fscache_n_retrievals);
59026+ fscache_stat_unchecked(&fscache_n_retrievals);
59027
59028 if (hlist_empty(&cookie->backing_objects))
59029 goto nobufs;
59030@@ -428,7 +428,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
59031 goto nobufs_unlock_dec;
59032 spin_unlock(&cookie->lock);
59033
59034- fscache_stat(&fscache_n_retrieval_ops);
59035+ fscache_stat_unchecked(&fscache_n_retrieval_ops);
59036
59037 /* pin the netfs read context in case we need to do the actual netfs
59038 * read because we've encountered a cache read failure */
59039@@ -459,15 +459,15 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
59040
59041 error:
59042 if (ret == -ENOMEM)
59043- fscache_stat(&fscache_n_retrievals_nomem);
59044+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
59045 else if (ret == -ERESTARTSYS)
59046- fscache_stat(&fscache_n_retrievals_intr);
59047+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
59048 else if (ret == -ENODATA)
59049- fscache_stat(&fscache_n_retrievals_nodata);
59050+ fscache_stat_unchecked(&fscache_n_retrievals_nodata);
59051 else if (ret < 0)
59052- fscache_stat(&fscache_n_retrievals_nobufs);
59053+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
59054 else
59055- fscache_stat(&fscache_n_retrievals_ok);
59056+ fscache_stat_unchecked(&fscache_n_retrievals_ok);
59057
59058 fscache_put_retrieval(op);
59059 _leave(" = %d", ret);
59060@@ -480,7 +480,7 @@ nobufs_unlock:
59061 atomic_dec(&cookie->n_active);
59062 kfree(op);
59063 nobufs:
59064- fscache_stat(&fscache_n_retrievals_nobufs);
59065+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
59066 _leave(" = -ENOBUFS");
59067 return -ENOBUFS;
59068 }
59069@@ -518,7 +518,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
59070
59071 _enter("%p,,%d,,,", cookie, *nr_pages);
59072
59073- fscache_stat(&fscache_n_retrievals);
59074+ fscache_stat_unchecked(&fscache_n_retrievals);
59075
59076 if (hlist_empty(&cookie->backing_objects))
59077 goto nobufs;
59078@@ -554,7 +554,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
59079 goto nobufs_unlock_dec;
59080 spin_unlock(&cookie->lock);
59081
59082- fscache_stat(&fscache_n_retrieval_ops);
59083+ fscache_stat_unchecked(&fscache_n_retrieval_ops);
59084
59085 /* pin the netfs read context in case we need to do the actual netfs
59086 * read because we've encountered a cache read failure */
59087@@ -585,15 +585,15 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
59088
59089 error:
59090 if (ret == -ENOMEM)
59091- fscache_stat(&fscache_n_retrievals_nomem);
59092+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
59093 else if (ret == -ERESTARTSYS)
59094- fscache_stat(&fscache_n_retrievals_intr);
59095+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
59096 else if (ret == -ENODATA)
59097- fscache_stat(&fscache_n_retrievals_nodata);
59098+ fscache_stat_unchecked(&fscache_n_retrievals_nodata);
59099 else if (ret < 0)
59100- fscache_stat(&fscache_n_retrievals_nobufs);
59101+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
59102 else
59103- fscache_stat(&fscache_n_retrievals_ok);
59104+ fscache_stat_unchecked(&fscache_n_retrievals_ok);
59105
59106 fscache_put_retrieval(op);
59107 _leave(" = %d", ret);
59108@@ -606,7 +606,7 @@ nobufs_unlock:
59109 atomic_dec(&cookie->n_active);
59110 kfree(op);
59111 nobufs:
59112- fscache_stat(&fscache_n_retrievals_nobufs);
59113+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
59114 _leave(" = -ENOBUFS");
59115 return -ENOBUFS;
59116 }
59117@@ -630,7 +630,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
59118
59119 _enter("%p,%p,,,", cookie, page);
59120
59121- fscache_stat(&fscache_n_allocs);
59122+ fscache_stat_unchecked(&fscache_n_allocs);
59123
59124 if (hlist_empty(&cookie->backing_objects))
59125 goto nobufs;
59126@@ -662,7 +662,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
59127 goto nobufs_unlock;
59128 spin_unlock(&cookie->lock);
59129
59130- fscache_stat(&fscache_n_alloc_ops);
59131+ fscache_stat_unchecked(&fscache_n_alloc_ops);
59132
59133 ret = fscache_wait_for_operation_activation(
59134 object, &op->op,
59135@@ -679,11 +679,11 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
59136
59137 error:
59138 if (ret == -ERESTARTSYS)
59139- fscache_stat(&fscache_n_allocs_intr);
59140+ fscache_stat_unchecked(&fscache_n_allocs_intr);
59141 else if (ret < 0)
59142- fscache_stat(&fscache_n_allocs_nobufs);
59143+ fscache_stat_unchecked(&fscache_n_allocs_nobufs);
59144 else
59145- fscache_stat(&fscache_n_allocs_ok);
59146+ fscache_stat_unchecked(&fscache_n_allocs_ok);
59147
59148 fscache_put_retrieval(op);
59149 _leave(" = %d", ret);
59150@@ -694,7 +694,7 @@ nobufs_unlock:
59151 atomic_dec(&cookie->n_active);
59152 kfree(op);
59153 nobufs:
59154- fscache_stat(&fscache_n_allocs_nobufs);
59155+ fscache_stat_unchecked(&fscache_n_allocs_nobufs);
59156 _leave(" = -ENOBUFS");
59157 return -ENOBUFS;
59158 }
59159@@ -770,7 +770,7 @@ static void fscache_write_op(struct fscache_operation *_op)
59160
59161 spin_lock(&cookie->stores_lock);
59162
59163- fscache_stat(&fscache_n_store_calls);
59164+ fscache_stat_unchecked(&fscache_n_store_calls);
59165
59166 /* find a page to store */
59167 page = NULL;
59168@@ -781,7 +781,7 @@ static void fscache_write_op(struct fscache_operation *_op)
59169 page = results[0];
59170 _debug("gang %d [%lx]", n, page->index);
59171 if (page->index > op->store_limit) {
59172- fscache_stat(&fscache_n_store_pages_over_limit);
59173+ fscache_stat_unchecked(&fscache_n_store_pages_over_limit);
59174 goto superseded;
59175 }
59176
59177@@ -793,7 +793,7 @@ static void fscache_write_op(struct fscache_operation *_op)
59178 spin_unlock(&cookie->stores_lock);
59179 spin_unlock(&object->lock);
59180
59181- fscache_stat(&fscache_n_store_pages);
59182+ fscache_stat_unchecked(&fscache_n_store_pages);
59183 fscache_stat(&fscache_n_cop_write_page);
59184 ret = object->cache->ops->write_page(op, page);
59185 fscache_stat_d(&fscache_n_cop_write_page);
59186@@ -896,7 +896,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
59187 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
59188 ASSERT(PageFsCache(page));
59189
59190- fscache_stat(&fscache_n_stores);
59191+ fscache_stat_unchecked(&fscache_n_stores);
59192
59193 if (test_bit(FSCACHE_COOKIE_INVALIDATING, &cookie->flags)) {
59194 _leave(" = -ENOBUFS [invalidating]");
59195@@ -954,7 +954,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
59196 spin_unlock(&cookie->stores_lock);
59197 spin_unlock(&object->lock);
59198
59199- op->op.debug_id = atomic_inc_return(&fscache_op_debug_id);
59200+ op->op.debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
59201 op->store_limit = object->store_limit;
59202
59203 atomic_inc(&cookie->n_active);
59204@@ -963,8 +963,8 @@ int __fscache_write_page(struct fscache_cookie *cookie,
59205
59206 spin_unlock(&cookie->lock);
59207 radix_tree_preload_end();
59208- fscache_stat(&fscache_n_store_ops);
59209- fscache_stat(&fscache_n_stores_ok);
59210+ fscache_stat_unchecked(&fscache_n_store_ops);
59211+ fscache_stat_unchecked(&fscache_n_stores_ok);
59212
59213 /* the work queue now carries its own ref on the object */
59214 fscache_put_operation(&op->op);
59215@@ -972,14 +972,14 @@ int __fscache_write_page(struct fscache_cookie *cookie,
59216 return 0;
59217
59218 already_queued:
59219- fscache_stat(&fscache_n_stores_again);
59220+ fscache_stat_unchecked(&fscache_n_stores_again);
59221 already_pending:
59222 spin_unlock(&cookie->stores_lock);
59223 spin_unlock(&object->lock);
59224 spin_unlock(&cookie->lock);
59225 radix_tree_preload_end();
59226 kfree(op);
59227- fscache_stat(&fscache_n_stores_ok);
59228+ fscache_stat_unchecked(&fscache_n_stores_ok);
59229 _leave(" = 0");
59230 return 0;
59231
59232@@ -999,14 +999,14 @@ nobufs:
59233 spin_unlock(&cookie->lock);
59234 radix_tree_preload_end();
59235 kfree(op);
59236- fscache_stat(&fscache_n_stores_nobufs);
59237+ fscache_stat_unchecked(&fscache_n_stores_nobufs);
59238 _leave(" = -ENOBUFS");
59239 return -ENOBUFS;
59240
59241 nomem_free:
59242 kfree(op);
59243 nomem:
59244- fscache_stat(&fscache_n_stores_oom);
59245+ fscache_stat_unchecked(&fscache_n_stores_oom);
59246 _leave(" = -ENOMEM");
59247 return -ENOMEM;
59248 }
59249@@ -1024,7 +1024,7 @@ void __fscache_uncache_page(struct fscache_cookie *cookie, struct page *page)
59250 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
59251 ASSERTCMP(page, !=, NULL);
59252
59253- fscache_stat(&fscache_n_uncaches);
59254+ fscache_stat_unchecked(&fscache_n_uncaches);
59255
59256 /* cache withdrawal may beat us to it */
59257 if (!PageFsCache(page))
59258@@ -1075,7 +1075,7 @@ void fscache_mark_page_cached(struct fscache_retrieval *op, struct page *page)
59259 struct fscache_cookie *cookie = op->op.object->cookie;
59260
59261 #ifdef CONFIG_FSCACHE_STATS
59262- atomic_inc(&fscache_n_marks);
59263+ atomic_inc_unchecked(&fscache_n_marks);
59264 #endif
59265
59266 _debug("- mark %p{%lx}", page, page->index);
59267diff --git a/fs/fscache/stats.c b/fs/fscache/stats.c
59268index 40d13c7..ddf52b9 100644
59269--- a/fs/fscache/stats.c
59270+++ b/fs/fscache/stats.c
59271@@ -18,99 +18,99 @@
59272 /*
59273 * operation counters
59274 */
59275-atomic_t fscache_n_op_pend;
59276-atomic_t fscache_n_op_run;
59277-atomic_t fscache_n_op_enqueue;
59278-atomic_t fscache_n_op_requeue;
59279-atomic_t fscache_n_op_deferred_release;
59280-atomic_t fscache_n_op_release;
59281-atomic_t fscache_n_op_gc;
59282-atomic_t fscache_n_op_cancelled;
59283-atomic_t fscache_n_op_rejected;
59284+atomic_unchecked_t fscache_n_op_pend;
59285+atomic_unchecked_t fscache_n_op_run;
59286+atomic_unchecked_t fscache_n_op_enqueue;
59287+atomic_unchecked_t fscache_n_op_requeue;
59288+atomic_unchecked_t fscache_n_op_deferred_release;
59289+atomic_unchecked_t fscache_n_op_release;
59290+atomic_unchecked_t fscache_n_op_gc;
59291+atomic_unchecked_t fscache_n_op_cancelled;
59292+atomic_unchecked_t fscache_n_op_rejected;
59293
59294-atomic_t fscache_n_attr_changed;
59295-atomic_t fscache_n_attr_changed_ok;
59296-atomic_t fscache_n_attr_changed_nobufs;
59297-atomic_t fscache_n_attr_changed_nomem;
59298-atomic_t fscache_n_attr_changed_calls;
59299+atomic_unchecked_t fscache_n_attr_changed;
59300+atomic_unchecked_t fscache_n_attr_changed_ok;
59301+atomic_unchecked_t fscache_n_attr_changed_nobufs;
59302+atomic_unchecked_t fscache_n_attr_changed_nomem;
59303+atomic_unchecked_t fscache_n_attr_changed_calls;
59304
59305-atomic_t fscache_n_allocs;
59306-atomic_t fscache_n_allocs_ok;
59307-atomic_t fscache_n_allocs_wait;
59308-atomic_t fscache_n_allocs_nobufs;
59309-atomic_t fscache_n_allocs_intr;
59310-atomic_t fscache_n_allocs_object_dead;
59311-atomic_t fscache_n_alloc_ops;
59312-atomic_t fscache_n_alloc_op_waits;
59313+atomic_unchecked_t fscache_n_allocs;
59314+atomic_unchecked_t fscache_n_allocs_ok;
59315+atomic_unchecked_t fscache_n_allocs_wait;
59316+atomic_unchecked_t fscache_n_allocs_nobufs;
59317+atomic_unchecked_t fscache_n_allocs_intr;
59318+atomic_unchecked_t fscache_n_allocs_object_dead;
59319+atomic_unchecked_t fscache_n_alloc_ops;
59320+atomic_unchecked_t fscache_n_alloc_op_waits;
59321
59322-atomic_t fscache_n_retrievals;
59323-atomic_t fscache_n_retrievals_ok;
59324-atomic_t fscache_n_retrievals_wait;
59325-atomic_t fscache_n_retrievals_nodata;
59326-atomic_t fscache_n_retrievals_nobufs;
59327-atomic_t fscache_n_retrievals_intr;
59328-atomic_t fscache_n_retrievals_nomem;
59329-atomic_t fscache_n_retrievals_object_dead;
59330-atomic_t fscache_n_retrieval_ops;
59331-atomic_t fscache_n_retrieval_op_waits;
59332+atomic_unchecked_t fscache_n_retrievals;
59333+atomic_unchecked_t fscache_n_retrievals_ok;
59334+atomic_unchecked_t fscache_n_retrievals_wait;
59335+atomic_unchecked_t fscache_n_retrievals_nodata;
59336+atomic_unchecked_t fscache_n_retrievals_nobufs;
59337+atomic_unchecked_t fscache_n_retrievals_intr;
59338+atomic_unchecked_t fscache_n_retrievals_nomem;
59339+atomic_unchecked_t fscache_n_retrievals_object_dead;
59340+atomic_unchecked_t fscache_n_retrieval_ops;
59341+atomic_unchecked_t fscache_n_retrieval_op_waits;
59342
59343-atomic_t fscache_n_stores;
59344-atomic_t fscache_n_stores_ok;
59345-atomic_t fscache_n_stores_again;
59346-atomic_t fscache_n_stores_nobufs;
59347-atomic_t fscache_n_stores_oom;
59348-atomic_t fscache_n_store_ops;
59349-atomic_t fscache_n_store_calls;
59350-atomic_t fscache_n_store_pages;
59351-atomic_t fscache_n_store_radix_deletes;
59352-atomic_t fscache_n_store_pages_over_limit;
59353+atomic_unchecked_t fscache_n_stores;
59354+atomic_unchecked_t fscache_n_stores_ok;
59355+atomic_unchecked_t fscache_n_stores_again;
59356+atomic_unchecked_t fscache_n_stores_nobufs;
59357+atomic_unchecked_t fscache_n_stores_oom;
59358+atomic_unchecked_t fscache_n_store_ops;
59359+atomic_unchecked_t fscache_n_store_calls;
59360+atomic_unchecked_t fscache_n_store_pages;
59361+atomic_unchecked_t fscache_n_store_radix_deletes;
59362+atomic_unchecked_t fscache_n_store_pages_over_limit;
59363
59364-atomic_t fscache_n_store_vmscan_not_storing;
59365-atomic_t fscache_n_store_vmscan_gone;
59366-atomic_t fscache_n_store_vmscan_busy;
59367-atomic_t fscache_n_store_vmscan_cancelled;
59368-atomic_t fscache_n_store_vmscan_wait;
59369+atomic_unchecked_t fscache_n_store_vmscan_not_storing;
59370+atomic_unchecked_t fscache_n_store_vmscan_gone;
59371+atomic_unchecked_t fscache_n_store_vmscan_busy;
59372+atomic_unchecked_t fscache_n_store_vmscan_cancelled;
59373+atomic_unchecked_t fscache_n_store_vmscan_wait;
59374
59375-atomic_t fscache_n_marks;
59376-atomic_t fscache_n_uncaches;
59377+atomic_unchecked_t fscache_n_marks;
59378+atomic_unchecked_t fscache_n_uncaches;
59379
59380-atomic_t fscache_n_acquires;
59381-atomic_t fscache_n_acquires_null;
59382-atomic_t fscache_n_acquires_no_cache;
59383-atomic_t fscache_n_acquires_ok;
59384-atomic_t fscache_n_acquires_nobufs;
59385-atomic_t fscache_n_acquires_oom;
59386+atomic_unchecked_t fscache_n_acquires;
59387+atomic_unchecked_t fscache_n_acquires_null;
59388+atomic_unchecked_t fscache_n_acquires_no_cache;
59389+atomic_unchecked_t fscache_n_acquires_ok;
59390+atomic_unchecked_t fscache_n_acquires_nobufs;
59391+atomic_unchecked_t fscache_n_acquires_oom;
59392
59393-atomic_t fscache_n_invalidates;
59394-atomic_t fscache_n_invalidates_run;
59395+atomic_unchecked_t fscache_n_invalidates;
59396+atomic_unchecked_t fscache_n_invalidates_run;
59397
59398-atomic_t fscache_n_updates;
59399-atomic_t fscache_n_updates_null;
59400-atomic_t fscache_n_updates_run;
59401+atomic_unchecked_t fscache_n_updates;
59402+atomic_unchecked_t fscache_n_updates_null;
59403+atomic_unchecked_t fscache_n_updates_run;
59404
59405-atomic_t fscache_n_relinquishes;
59406-atomic_t fscache_n_relinquishes_null;
59407-atomic_t fscache_n_relinquishes_waitcrt;
59408-atomic_t fscache_n_relinquishes_retire;
59409+atomic_unchecked_t fscache_n_relinquishes;
59410+atomic_unchecked_t fscache_n_relinquishes_null;
59411+atomic_unchecked_t fscache_n_relinquishes_waitcrt;
59412+atomic_unchecked_t fscache_n_relinquishes_retire;
59413
59414-atomic_t fscache_n_cookie_index;
59415-atomic_t fscache_n_cookie_data;
59416-atomic_t fscache_n_cookie_special;
59417+atomic_unchecked_t fscache_n_cookie_index;
59418+atomic_unchecked_t fscache_n_cookie_data;
59419+atomic_unchecked_t fscache_n_cookie_special;
59420
59421-atomic_t fscache_n_object_alloc;
59422-atomic_t fscache_n_object_no_alloc;
59423-atomic_t fscache_n_object_lookups;
59424-atomic_t fscache_n_object_lookups_negative;
59425-atomic_t fscache_n_object_lookups_positive;
59426-atomic_t fscache_n_object_lookups_timed_out;
59427-atomic_t fscache_n_object_created;
59428-atomic_t fscache_n_object_avail;
59429-atomic_t fscache_n_object_dead;
59430+atomic_unchecked_t fscache_n_object_alloc;
59431+atomic_unchecked_t fscache_n_object_no_alloc;
59432+atomic_unchecked_t fscache_n_object_lookups;
59433+atomic_unchecked_t fscache_n_object_lookups_negative;
59434+atomic_unchecked_t fscache_n_object_lookups_positive;
59435+atomic_unchecked_t fscache_n_object_lookups_timed_out;
59436+atomic_unchecked_t fscache_n_object_created;
59437+atomic_unchecked_t fscache_n_object_avail;
59438+atomic_unchecked_t fscache_n_object_dead;
59439
59440-atomic_t fscache_n_checkaux_none;
59441-atomic_t fscache_n_checkaux_okay;
59442-atomic_t fscache_n_checkaux_update;
59443-atomic_t fscache_n_checkaux_obsolete;
59444+atomic_unchecked_t fscache_n_checkaux_none;
59445+atomic_unchecked_t fscache_n_checkaux_okay;
59446+atomic_unchecked_t fscache_n_checkaux_update;
59447+atomic_unchecked_t fscache_n_checkaux_obsolete;
59448
59449 atomic_t fscache_n_cop_alloc_object;
59450 atomic_t fscache_n_cop_lookup_object;
59451@@ -138,118 +138,118 @@ static int fscache_stats_show(struct seq_file *m, void *v)
59452 seq_puts(m, "FS-Cache statistics\n");
59453
59454 seq_printf(m, "Cookies: idx=%u dat=%u spc=%u\n",
59455- atomic_read(&fscache_n_cookie_index),
59456- atomic_read(&fscache_n_cookie_data),
59457- atomic_read(&fscache_n_cookie_special));
59458+ atomic_read_unchecked(&fscache_n_cookie_index),
59459+ atomic_read_unchecked(&fscache_n_cookie_data),
59460+ atomic_read_unchecked(&fscache_n_cookie_special));
59461
59462 seq_printf(m, "Objects: alc=%u nal=%u avl=%u ded=%u\n",
59463- atomic_read(&fscache_n_object_alloc),
59464- atomic_read(&fscache_n_object_no_alloc),
59465- atomic_read(&fscache_n_object_avail),
59466- atomic_read(&fscache_n_object_dead));
59467+ atomic_read_unchecked(&fscache_n_object_alloc),
59468+ atomic_read_unchecked(&fscache_n_object_no_alloc),
59469+ atomic_read_unchecked(&fscache_n_object_avail),
59470+ atomic_read_unchecked(&fscache_n_object_dead));
59471 seq_printf(m, "ChkAux : non=%u ok=%u upd=%u obs=%u\n",
59472- atomic_read(&fscache_n_checkaux_none),
59473- atomic_read(&fscache_n_checkaux_okay),
59474- atomic_read(&fscache_n_checkaux_update),
59475- atomic_read(&fscache_n_checkaux_obsolete));
59476+ atomic_read_unchecked(&fscache_n_checkaux_none),
59477+ atomic_read_unchecked(&fscache_n_checkaux_okay),
59478+ atomic_read_unchecked(&fscache_n_checkaux_update),
59479+ atomic_read_unchecked(&fscache_n_checkaux_obsolete));
59480
59481 seq_printf(m, "Pages : mrk=%u unc=%u\n",
59482- atomic_read(&fscache_n_marks),
59483- atomic_read(&fscache_n_uncaches));
59484+ atomic_read_unchecked(&fscache_n_marks),
59485+ atomic_read_unchecked(&fscache_n_uncaches));
59486
59487 seq_printf(m, "Acquire: n=%u nul=%u noc=%u ok=%u nbf=%u"
59488 " oom=%u\n",
59489- atomic_read(&fscache_n_acquires),
59490- atomic_read(&fscache_n_acquires_null),
59491- atomic_read(&fscache_n_acquires_no_cache),
59492- atomic_read(&fscache_n_acquires_ok),
59493- atomic_read(&fscache_n_acquires_nobufs),
59494- atomic_read(&fscache_n_acquires_oom));
59495+ atomic_read_unchecked(&fscache_n_acquires),
59496+ atomic_read_unchecked(&fscache_n_acquires_null),
59497+ atomic_read_unchecked(&fscache_n_acquires_no_cache),
59498+ atomic_read_unchecked(&fscache_n_acquires_ok),
59499+ atomic_read_unchecked(&fscache_n_acquires_nobufs),
59500+ atomic_read_unchecked(&fscache_n_acquires_oom));
59501
59502 seq_printf(m, "Lookups: n=%u neg=%u pos=%u crt=%u tmo=%u\n",
59503- atomic_read(&fscache_n_object_lookups),
59504- atomic_read(&fscache_n_object_lookups_negative),
59505- atomic_read(&fscache_n_object_lookups_positive),
59506- atomic_read(&fscache_n_object_created),
59507- atomic_read(&fscache_n_object_lookups_timed_out));
59508+ atomic_read_unchecked(&fscache_n_object_lookups),
59509+ atomic_read_unchecked(&fscache_n_object_lookups_negative),
59510+ atomic_read_unchecked(&fscache_n_object_lookups_positive),
59511+ atomic_read_unchecked(&fscache_n_object_created),
59512+ atomic_read_unchecked(&fscache_n_object_lookups_timed_out));
59513
59514 seq_printf(m, "Invals : n=%u run=%u\n",
59515- atomic_read(&fscache_n_invalidates),
59516- atomic_read(&fscache_n_invalidates_run));
59517+ atomic_read_unchecked(&fscache_n_invalidates),
59518+ atomic_read_unchecked(&fscache_n_invalidates_run));
59519
59520 seq_printf(m, "Updates: n=%u nul=%u run=%u\n",
59521- atomic_read(&fscache_n_updates),
59522- atomic_read(&fscache_n_updates_null),
59523- atomic_read(&fscache_n_updates_run));
59524+ atomic_read_unchecked(&fscache_n_updates),
59525+ atomic_read_unchecked(&fscache_n_updates_null),
59526+ atomic_read_unchecked(&fscache_n_updates_run));
59527
59528 seq_printf(m, "Relinqs: n=%u nul=%u wcr=%u rtr=%u\n",
59529- atomic_read(&fscache_n_relinquishes),
59530- atomic_read(&fscache_n_relinquishes_null),
59531- atomic_read(&fscache_n_relinquishes_waitcrt),
59532- atomic_read(&fscache_n_relinquishes_retire));
59533+ atomic_read_unchecked(&fscache_n_relinquishes),
59534+ atomic_read_unchecked(&fscache_n_relinquishes_null),
59535+ atomic_read_unchecked(&fscache_n_relinquishes_waitcrt),
59536+ atomic_read_unchecked(&fscache_n_relinquishes_retire));
59537
59538 seq_printf(m, "AttrChg: n=%u ok=%u nbf=%u oom=%u run=%u\n",
59539- atomic_read(&fscache_n_attr_changed),
59540- atomic_read(&fscache_n_attr_changed_ok),
59541- atomic_read(&fscache_n_attr_changed_nobufs),
59542- atomic_read(&fscache_n_attr_changed_nomem),
59543- atomic_read(&fscache_n_attr_changed_calls));
59544+ atomic_read_unchecked(&fscache_n_attr_changed),
59545+ atomic_read_unchecked(&fscache_n_attr_changed_ok),
59546+ atomic_read_unchecked(&fscache_n_attr_changed_nobufs),
59547+ atomic_read_unchecked(&fscache_n_attr_changed_nomem),
59548+ atomic_read_unchecked(&fscache_n_attr_changed_calls));
59549
59550 seq_printf(m, "Allocs : n=%u ok=%u wt=%u nbf=%u int=%u\n",
59551- atomic_read(&fscache_n_allocs),
59552- atomic_read(&fscache_n_allocs_ok),
59553- atomic_read(&fscache_n_allocs_wait),
59554- atomic_read(&fscache_n_allocs_nobufs),
59555- atomic_read(&fscache_n_allocs_intr));
59556+ atomic_read_unchecked(&fscache_n_allocs),
59557+ atomic_read_unchecked(&fscache_n_allocs_ok),
59558+ atomic_read_unchecked(&fscache_n_allocs_wait),
59559+ atomic_read_unchecked(&fscache_n_allocs_nobufs),
59560+ atomic_read_unchecked(&fscache_n_allocs_intr));
59561 seq_printf(m, "Allocs : ops=%u owt=%u abt=%u\n",
59562- atomic_read(&fscache_n_alloc_ops),
59563- atomic_read(&fscache_n_alloc_op_waits),
59564- atomic_read(&fscache_n_allocs_object_dead));
59565+ atomic_read_unchecked(&fscache_n_alloc_ops),
59566+ atomic_read_unchecked(&fscache_n_alloc_op_waits),
59567+ atomic_read_unchecked(&fscache_n_allocs_object_dead));
59568
59569 seq_printf(m, "Retrvls: n=%u ok=%u wt=%u nod=%u nbf=%u"
59570 " int=%u oom=%u\n",
59571- atomic_read(&fscache_n_retrievals),
59572- atomic_read(&fscache_n_retrievals_ok),
59573- atomic_read(&fscache_n_retrievals_wait),
59574- atomic_read(&fscache_n_retrievals_nodata),
59575- atomic_read(&fscache_n_retrievals_nobufs),
59576- atomic_read(&fscache_n_retrievals_intr),
59577- atomic_read(&fscache_n_retrievals_nomem));
59578+ atomic_read_unchecked(&fscache_n_retrievals),
59579+ atomic_read_unchecked(&fscache_n_retrievals_ok),
59580+ atomic_read_unchecked(&fscache_n_retrievals_wait),
59581+ atomic_read_unchecked(&fscache_n_retrievals_nodata),
59582+ atomic_read_unchecked(&fscache_n_retrievals_nobufs),
59583+ atomic_read_unchecked(&fscache_n_retrievals_intr),
59584+ atomic_read_unchecked(&fscache_n_retrievals_nomem));
59585 seq_printf(m, "Retrvls: ops=%u owt=%u abt=%u\n",
59586- atomic_read(&fscache_n_retrieval_ops),
59587- atomic_read(&fscache_n_retrieval_op_waits),
59588- atomic_read(&fscache_n_retrievals_object_dead));
59589+ atomic_read_unchecked(&fscache_n_retrieval_ops),
59590+ atomic_read_unchecked(&fscache_n_retrieval_op_waits),
59591+ atomic_read_unchecked(&fscache_n_retrievals_object_dead));
59592
59593 seq_printf(m, "Stores : n=%u ok=%u agn=%u nbf=%u oom=%u\n",
59594- atomic_read(&fscache_n_stores),
59595- atomic_read(&fscache_n_stores_ok),
59596- atomic_read(&fscache_n_stores_again),
59597- atomic_read(&fscache_n_stores_nobufs),
59598- atomic_read(&fscache_n_stores_oom));
59599+ atomic_read_unchecked(&fscache_n_stores),
59600+ atomic_read_unchecked(&fscache_n_stores_ok),
59601+ atomic_read_unchecked(&fscache_n_stores_again),
59602+ atomic_read_unchecked(&fscache_n_stores_nobufs),
59603+ atomic_read_unchecked(&fscache_n_stores_oom));
59604 seq_printf(m, "Stores : ops=%u run=%u pgs=%u rxd=%u olm=%u\n",
59605- atomic_read(&fscache_n_store_ops),
59606- atomic_read(&fscache_n_store_calls),
59607- atomic_read(&fscache_n_store_pages),
59608- atomic_read(&fscache_n_store_radix_deletes),
59609- atomic_read(&fscache_n_store_pages_over_limit));
59610+ atomic_read_unchecked(&fscache_n_store_ops),
59611+ atomic_read_unchecked(&fscache_n_store_calls),
59612+ atomic_read_unchecked(&fscache_n_store_pages),
59613+ atomic_read_unchecked(&fscache_n_store_radix_deletes),
59614+ atomic_read_unchecked(&fscache_n_store_pages_over_limit));
59615
59616 seq_printf(m, "VmScan : nos=%u gon=%u bsy=%u can=%u wt=%u\n",
59617- atomic_read(&fscache_n_store_vmscan_not_storing),
59618- atomic_read(&fscache_n_store_vmscan_gone),
59619- atomic_read(&fscache_n_store_vmscan_busy),
59620- atomic_read(&fscache_n_store_vmscan_cancelled),
59621- atomic_read(&fscache_n_store_vmscan_wait));
59622+ atomic_read_unchecked(&fscache_n_store_vmscan_not_storing),
59623+ atomic_read_unchecked(&fscache_n_store_vmscan_gone),
59624+ atomic_read_unchecked(&fscache_n_store_vmscan_busy),
59625+ atomic_read_unchecked(&fscache_n_store_vmscan_cancelled),
59626+ atomic_read_unchecked(&fscache_n_store_vmscan_wait));
59627
59628 seq_printf(m, "Ops : pend=%u run=%u enq=%u can=%u rej=%u\n",
59629- atomic_read(&fscache_n_op_pend),
59630- atomic_read(&fscache_n_op_run),
59631- atomic_read(&fscache_n_op_enqueue),
59632- atomic_read(&fscache_n_op_cancelled),
59633- atomic_read(&fscache_n_op_rejected));
59634+ atomic_read_unchecked(&fscache_n_op_pend),
59635+ atomic_read_unchecked(&fscache_n_op_run),
59636+ atomic_read_unchecked(&fscache_n_op_enqueue),
59637+ atomic_read_unchecked(&fscache_n_op_cancelled),
59638+ atomic_read_unchecked(&fscache_n_op_rejected));
59639 seq_printf(m, "Ops : dfr=%u rel=%u gc=%u\n",
59640- atomic_read(&fscache_n_op_deferred_release),
59641- atomic_read(&fscache_n_op_release),
59642- atomic_read(&fscache_n_op_gc));
59643+ atomic_read_unchecked(&fscache_n_op_deferred_release),
59644+ atomic_read_unchecked(&fscache_n_op_release),
59645+ atomic_read_unchecked(&fscache_n_op_gc));
59646
59647 seq_printf(m, "CacheOp: alo=%d luo=%d luc=%d gro=%d\n",
59648 atomic_read(&fscache_n_cop_alloc_object),
59649diff --git a/fs/fuse/cuse.c b/fs/fuse/cuse.c
59650index adbfd66..4b25822 100644
59651--- a/fs/fuse/cuse.c
59652+++ b/fs/fuse/cuse.c
59653@@ -603,10 +603,12 @@ static int __init cuse_init(void)
59654 INIT_LIST_HEAD(&cuse_conntbl[i]);
59655
59656 /* inherit and extend fuse_dev_operations */
59657- cuse_channel_fops = fuse_dev_operations;
59658- cuse_channel_fops.owner = THIS_MODULE;
59659- cuse_channel_fops.open = cuse_channel_open;
59660- cuse_channel_fops.release = cuse_channel_release;
59661+ pax_open_kernel();
59662+ memcpy((void *)&cuse_channel_fops, &fuse_dev_operations, sizeof(fuse_dev_operations));
59663+ *(void **)&cuse_channel_fops.owner = THIS_MODULE;
59664+ *(void **)&cuse_channel_fops.open = cuse_channel_open;
59665+ *(void **)&cuse_channel_fops.release = cuse_channel_release;
59666+ pax_close_kernel();
59667
59668 cuse_class = class_create(THIS_MODULE, "cuse");
59669 if (IS_ERR(cuse_class))
59670diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c
59671index ef74ad5..c9ac759e 100644
59672--- a/fs/fuse/dev.c
59673+++ b/fs/fuse/dev.c
59674@@ -1339,7 +1339,7 @@ static ssize_t fuse_dev_splice_read(struct file *in, loff_t *ppos,
59675 ret = 0;
59676 pipe_lock(pipe);
59677
59678- if (!pipe->readers) {
59679+ if (!atomic_read(&pipe->readers)) {
59680 send_sig(SIGPIPE, current, 0);
59681 if (!ret)
59682 ret = -EPIPE;
59683@@ -1364,7 +1364,7 @@ static ssize_t fuse_dev_splice_read(struct file *in, loff_t *ppos,
59684 page_nr++;
59685 ret += buf->len;
59686
59687- if (pipe->files)
59688+ if (atomic_read(&pipe->files))
59689 do_wakeup = 1;
59690 }
59691
59692diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c
59693index b7989f2..1f72ec4 100644
59694--- a/fs/fuse/dir.c
59695+++ b/fs/fuse/dir.c
59696@@ -1438,7 +1438,7 @@ static char *read_link(struct dentry *dentry)
59697 return link;
59698 }
59699
59700-static void free_link(char *link)
59701+static void free_link(const char *link)
59702 {
59703 if (!IS_ERR(link))
59704 free_page((unsigned long) link);
59705diff --git a/fs/gfs2/inode.c b/fs/gfs2/inode.c
59706index 1298766..c964c60 100644
59707--- a/fs/gfs2/inode.c
59708+++ b/fs/gfs2/inode.c
59709@@ -1515,7 +1515,7 @@ out:
59710
59711 static void gfs2_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
59712 {
59713- char *s = nd_get_link(nd);
59714+ const char *s = nd_get_link(nd);
59715 if (!IS_ERR(s))
59716 kfree(s);
59717 }
59718diff --git a/fs/hostfs/hostfs_kern.c b/fs/hostfs/hostfs_kern.c
59719index 2543728..14d7bd4 100644
59720--- a/fs/hostfs/hostfs_kern.c
59721+++ b/fs/hostfs/hostfs_kern.c
59722@@ -904,7 +904,7 @@ static void *hostfs_follow_link(struct dentry *dentry, struct nameidata *nd)
59723
59724 static void hostfs_put_link(struct dentry *dentry, struct nameidata *nd, void *cookie)
59725 {
59726- char *s = nd_get_link(nd);
59727+ const char *s = nd_get_link(nd);
59728 if (!IS_ERR(s))
59729 __putname(s);
59730 }
59731diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c
59732index d19b30a..ef89c36 100644
59733--- a/fs/hugetlbfs/inode.c
59734+++ b/fs/hugetlbfs/inode.c
59735@@ -152,6 +152,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
59736 struct mm_struct *mm = current->mm;
59737 struct vm_area_struct *vma;
59738 struct hstate *h = hstate_file(file);
59739+ unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
59740 struct vm_unmapped_area_info info;
59741
59742 if (len & ~huge_page_mask(h))
59743@@ -165,17 +166,26 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
59744 return addr;
59745 }
59746
59747+#ifdef CONFIG_PAX_RANDMMAP
59748+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
59749+#endif
59750+
59751 if (addr) {
59752 addr = ALIGN(addr, huge_page_size(h));
59753 vma = find_vma(mm, addr);
59754- if (TASK_SIZE - len >= addr &&
59755- (!vma || addr + len <= vma->vm_start))
59756+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
59757 return addr;
59758 }
59759
59760 info.flags = 0;
59761 info.length = len;
59762 info.low_limit = TASK_UNMAPPED_BASE;
59763+
59764+#ifdef CONFIG_PAX_RANDMMAP
59765+ if (mm->pax_flags & MF_PAX_RANDMMAP)
59766+ info.low_limit += mm->delta_mmap;
59767+#endif
59768+
59769 info.high_limit = TASK_SIZE;
59770 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
59771 info.align_offset = 0;
59772@@ -908,7 +918,7 @@ static struct file_system_type hugetlbfs_fs_type = {
59773 };
59774 MODULE_ALIAS_FS("hugetlbfs");
59775
59776-static struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
59777+struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
59778
59779 static int can_do_hugetlb_shm(void)
59780 {
59781diff --git a/fs/inode.c b/fs/inode.c
59782index b33ba8e..3c79a47 100644
59783--- a/fs/inode.c
59784+++ b/fs/inode.c
59785@@ -849,8 +849,8 @@ unsigned int get_next_ino(void)
59786
59787 #ifdef CONFIG_SMP
59788 if (unlikely((res & (LAST_INO_BATCH-1)) == 0)) {
59789- static atomic_t shared_last_ino;
59790- int next = atomic_add_return(LAST_INO_BATCH, &shared_last_ino);
59791+ static atomic_unchecked_t shared_last_ino;
59792+ int next = atomic_add_return_unchecked(LAST_INO_BATCH, &shared_last_ino);
59793
59794 res = next - LAST_INO_BATCH;
59795 }
59796diff --git a/fs/jffs2/erase.c b/fs/jffs2/erase.c
59797index 4a6cf28..d3a29d3 100644
59798--- a/fs/jffs2/erase.c
59799+++ b/fs/jffs2/erase.c
59800@@ -452,7 +452,8 @@ static void jffs2_mark_erased_block(struct jffs2_sb_info *c, struct jffs2_eraseb
59801 struct jffs2_unknown_node marker = {
59802 .magic = cpu_to_je16(JFFS2_MAGIC_BITMASK),
59803 .nodetype = cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
59804- .totlen = cpu_to_je32(c->cleanmarker_size)
59805+ .totlen = cpu_to_je32(c->cleanmarker_size),
59806+ .hdr_crc = cpu_to_je32(0)
59807 };
59808
59809 jffs2_prealloc_raw_node_refs(c, jeb, 1);
59810diff --git a/fs/jffs2/wbuf.c b/fs/jffs2/wbuf.c
59811index a6597d6..41b30ec 100644
59812--- a/fs/jffs2/wbuf.c
59813+++ b/fs/jffs2/wbuf.c
59814@@ -1023,7 +1023,8 @@ static const struct jffs2_unknown_node oob_cleanmarker =
59815 {
59816 .magic = constant_cpu_to_je16(JFFS2_MAGIC_BITMASK),
59817 .nodetype = constant_cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
59818- .totlen = constant_cpu_to_je32(8)
59819+ .totlen = constant_cpu_to_je32(8),
59820+ .hdr_crc = constant_cpu_to_je32(0)
59821 };
59822
59823 /*
59824diff --git a/fs/jfs/super.c b/fs/jfs/super.c
59825index 6669aa2..36b033d 100644
59826--- a/fs/jfs/super.c
59827+++ b/fs/jfs/super.c
59828@@ -882,7 +882,7 @@ static int __init init_jfs_fs(void)
59829
59830 jfs_inode_cachep =
59831 kmem_cache_create("jfs_ip", sizeof(struct jfs_inode_info), 0,
59832- SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD,
59833+ SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD|SLAB_USERCOPY,
59834 init_once);
59835 if (jfs_inode_cachep == NULL)
59836 return -ENOMEM;
59837diff --git a/fs/libfs.c b/fs/libfs.c
59838index 193e0c2..7404665 100644
59839--- a/fs/libfs.c
59840+++ b/fs/libfs.c
59841@@ -150,6 +150,9 @@ int dcache_readdir(struct file *file, struct dir_context *ctx)
59842
59843 for (p = q->next; p != &dentry->d_subdirs; p = p->next) {
59844 struct dentry *next = list_entry(p, struct dentry, d_u.d_child);
59845+ char d_name[sizeof(next->d_iname)];
59846+ const unsigned char *name;
59847+
59848 spin_lock_nested(&next->d_lock, DENTRY_D_LOCK_NESTED);
59849 if (!simple_positive(next)) {
59850 spin_unlock(&next->d_lock);
59851@@ -158,7 +161,12 @@ int dcache_readdir(struct file *file, struct dir_context *ctx)
59852
59853 spin_unlock(&next->d_lock);
59854 spin_unlock(&dentry->d_lock);
59855- if (!dir_emit(ctx, next->d_name.name, next->d_name.len,
59856+ name = next->d_name.name;
59857+ if (name == next->d_iname) {
59858+ memcpy(d_name, name, next->d_name.len);
59859+ name = d_name;
59860+ }
59861+ if (!dir_emit(ctx, name, next->d_name.len,
59862 next->d_inode->i_ino, dt_type(next->d_inode)))
59863 return 0;
59864 spin_lock(&dentry->d_lock);
59865diff --git a/fs/lockd/clntproc.c b/fs/lockd/clntproc.c
59866index acd3947..1f896e2 100644
59867--- a/fs/lockd/clntproc.c
59868+++ b/fs/lockd/clntproc.c
59869@@ -36,11 +36,11 @@ static const struct rpc_call_ops nlmclnt_cancel_ops;
59870 /*
59871 * Cookie counter for NLM requests
59872 */
59873-static atomic_t nlm_cookie = ATOMIC_INIT(0x1234);
59874+static atomic_unchecked_t nlm_cookie = ATOMIC_INIT(0x1234);
59875
59876 void nlmclnt_next_cookie(struct nlm_cookie *c)
59877 {
59878- u32 cookie = atomic_inc_return(&nlm_cookie);
59879+ u32 cookie = atomic_inc_return_unchecked(&nlm_cookie);
59880
59881 memcpy(c->data, &cookie, 4);
59882 c->len=4;
59883diff --git a/fs/locks.c b/fs/locks.c
59884index b27a300..4156d0b 100644
59885--- a/fs/locks.c
59886+++ b/fs/locks.c
59887@@ -2183,16 +2183,16 @@ void locks_remove_flock(struct file *filp)
59888 return;
59889
59890 if (filp->f_op && filp->f_op->flock) {
59891- struct file_lock fl = {
59892+ struct file_lock flock = {
59893 .fl_pid = current->tgid,
59894 .fl_file = filp,
59895 .fl_flags = FL_FLOCK,
59896 .fl_type = F_UNLCK,
59897 .fl_end = OFFSET_MAX,
59898 };
59899- filp->f_op->flock(filp, F_SETLKW, &fl);
59900- if (fl.fl_ops && fl.fl_ops->fl_release_private)
59901- fl.fl_ops->fl_release_private(&fl);
59902+ filp->f_op->flock(filp, F_SETLKW, &flock);
59903+ if (flock.fl_ops && flock.fl_ops->fl_release_private)
59904+ flock.fl_ops->fl_release_private(&flock);
59905 }
59906
59907 spin_lock(&inode->i_lock);
59908diff --git a/fs/mount.h b/fs/mount.h
59909index 64a8581..fe9c11d 100644
59910--- a/fs/mount.h
59911+++ b/fs/mount.h
59912@@ -11,7 +11,7 @@ struct mnt_namespace {
59913 u64 seq; /* Sequence number to prevent loops */
59914 wait_queue_head_t poll;
59915 int event;
59916-};
59917+} __randomize_layout;
59918
59919 struct mnt_pcp {
59920 int mnt_count;
59921@@ -56,7 +56,7 @@ struct mount {
59922 int mnt_expiry_mark; /* true if marked for expiry */
59923 int mnt_pinned;
59924 int mnt_ghosts;
59925-};
59926+} __randomize_layout;
59927
59928 #define MNT_NS_INTERNAL ERR_PTR(-EINVAL) /* distinct from any mnt_namespace */
59929
59930diff --git a/fs/namei.c b/fs/namei.c
59931index 23ac50f..c6757a5 100644
59932--- a/fs/namei.c
59933+++ b/fs/namei.c
59934@@ -319,16 +319,32 @@ int generic_permission(struct inode *inode, int mask)
59935 if (ret != -EACCES)
59936 return ret;
59937
59938+#ifdef CONFIG_GRKERNSEC
59939+ /* we'll block if we have to log due to a denied capability use */
59940+ if (mask & MAY_NOT_BLOCK)
59941+ return -ECHILD;
59942+#endif
59943+
59944 if (S_ISDIR(inode->i_mode)) {
59945 /* DACs are overridable for directories */
59946- if (inode_capable(inode, CAP_DAC_OVERRIDE))
59947- return 0;
59948 if (!(mask & MAY_WRITE))
59949- if (inode_capable(inode, CAP_DAC_READ_SEARCH))
59950+ if (inode_capable_nolog(inode, CAP_DAC_OVERRIDE) ||
59951+ inode_capable(inode, CAP_DAC_READ_SEARCH))
59952 return 0;
59953+ if (inode_capable(inode, CAP_DAC_OVERRIDE))
59954+ return 0;
59955 return -EACCES;
59956 }
59957 /*
59958+ * Searching includes executable on directories, else just read.
59959+ */
59960+ mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
59961+ if (mask == MAY_READ)
59962+ if (inode_capable_nolog(inode, CAP_DAC_OVERRIDE) ||
59963+ inode_capable(inode, CAP_DAC_READ_SEARCH))
59964+ return 0;
59965+
59966+ /*
59967 * Read/write DACs are always overridable.
59968 * Executable DACs are overridable when there is
59969 * at least one exec bit set.
59970@@ -337,14 +353,6 @@ int generic_permission(struct inode *inode, int mask)
59971 if (inode_capable(inode, CAP_DAC_OVERRIDE))
59972 return 0;
59973
59974- /*
59975- * Searching includes executable on directories, else just read.
59976- */
59977- mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
59978- if (mask == MAY_READ)
59979- if (inode_capable(inode, CAP_DAC_READ_SEARCH))
59980- return 0;
59981-
59982 return -EACCES;
59983 }
59984
59985@@ -821,7 +829,7 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
59986 {
59987 struct dentry *dentry = link->dentry;
59988 int error;
59989- char *s;
59990+ const char *s;
59991
59992 BUG_ON(nd->flags & LOOKUP_RCU);
59993
59994@@ -842,6 +850,12 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
59995 if (error)
59996 goto out_put_nd_path;
59997
59998+ if (gr_handle_follow_link(dentry->d_parent->d_inode,
59999+ dentry->d_inode, dentry, nd->path.mnt)) {
60000+ error = -EACCES;
60001+ goto out_put_nd_path;
60002+ }
60003+
60004 nd->last_type = LAST_BIND;
60005 *p = dentry->d_inode->i_op->follow_link(dentry, nd);
60006 error = PTR_ERR(*p);
60007@@ -1602,6 +1616,8 @@ static inline int nested_symlink(struct path *path, struct nameidata *nd)
60008 if (res)
60009 break;
60010 res = walk_component(nd, path, LOOKUP_FOLLOW);
60011+ if (res >= 0 && gr_handle_symlink_owner(&link, nd->inode))
60012+ res = -EACCES;
60013 put_link(nd, &link, cookie);
60014 } while (res > 0);
60015
60016@@ -1700,7 +1716,7 @@ EXPORT_SYMBOL(full_name_hash);
60017 static inline unsigned long hash_name(const char *name, unsigned int *hashp)
60018 {
60019 unsigned long a, b, adata, bdata, mask, hash, len;
60020- const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
60021+ static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
60022
60023 hash = a = 0;
60024 len = -sizeof(unsigned long);
60025@@ -1981,6 +1997,8 @@ static int path_lookupat(int dfd, const char *name,
60026 if (err)
60027 break;
60028 err = lookup_last(nd, &path);
60029+ if (!err && gr_handle_symlink_owner(&link, nd->inode))
60030+ err = -EACCES;
60031 put_link(nd, &link, cookie);
60032 }
60033 }
60034@@ -1988,6 +2006,13 @@ static int path_lookupat(int dfd, const char *name,
60035 if (!err)
60036 err = complete_walk(nd);
60037
60038+ if (!err && !(nd->flags & LOOKUP_PARENT)) {
60039+ if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
60040+ path_put(&nd->path);
60041+ err = -ENOENT;
60042+ }
60043+ }
60044+
60045 if (!err && nd->flags & LOOKUP_DIRECTORY) {
60046 if (!can_lookup(nd->inode)) {
60047 path_put(&nd->path);
60048@@ -2015,8 +2040,15 @@ static int filename_lookup(int dfd, struct filename *name,
60049 retval = path_lookupat(dfd, name->name,
60050 flags | LOOKUP_REVAL, nd);
60051
60052- if (likely(!retval))
60053+ if (likely(!retval)) {
60054 audit_inode(name, nd->path.dentry, flags & LOOKUP_PARENT);
60055+ if (name->name[0] != '/' && nd->path.dentry && nd->inode) {
60056+ if (!gr_chroot_fchdir(nd->path.dentry, nd->path.mnt)) {
60057+ path_put(&nd->path);
60058+ return -ENOENT;
60059+ }
60060+ }
60061+ }
60062 return retval;
60063 }
60064
60065@@ -2587,6 +2619,13 @@ static int may_open(struct path *path, int acc_mode, int flag)
60066 if (flag & O_NOATIME && !inode_owner_or_capable(inode))
60067 return -EPERM;
60068
60069+ if (gr_handle_rofs_blockwrite(dentry, path->mnt, acc_mode))
60070+ return -EPERM;
60071+ if (gr_handle_rawio(inode))
60072+ return -EPERM;
60073+ if (!gr_acl_handle_open(dentry, path->mnt, acc_mode))
60074+ return -EACCES;
60075+
60076 return 0;
60077 }
60078
60079@@ -2818,7 +2857,7 @@ looked_up:
60080 * cleared otherwise prior to returning.
60081 */
60082 static int lookup_open(struct nameidata *nd, struct path *path,
60083- struct file *file,
60084+ struct path *link, struct file *file,
60085 const struct open_flags *op,
60086 bool got_write, int *opened)
60087 {
60088@@ -2853,6 +2892,17 @@ static int lookup_open(struct nameidata *nd, struct path *path,
60089 /* Negative dentry, just create the file */
60090 if (!dentry->d_inode && (op->open_flag & O_CREAT)) {
60091 umode_t mode = op->mode;
60092+
60093+ if (link && gr_handle_symlink_owner(link, dir->d_inode)) {
60094+ error = -EACCES;
60095+ goto out_dput;
60096+ }
60097+
60098+ if (!gr_acl_handle_creat(dentry, dir, nd->path.mnt, op->open_flag, op->acc_mode, mode)) {
60099+ error = -EACCES;
60100+ goto out_dput;
60101+ }
60102+
60103 if (!IS_POSIXACL(dir->d_inode))
60104 mode &= ~current_umask();
60105 /*
60106@@ -2874,6 +2924,8 @@ static int lookup_open(struct nameidata *nd, struct path *path,
60107 nd->flags & LOOKUP_EXCL);
60108 if (error)
60109 goto out_dput;
60110+ else
60111+ gr_handle_create(dentry, nd->path.mnt);
60112 }
60113 out_no_open:
60114 path->dentry = dentry;
60115@@ -2888,7 +2940,7 @@ out_dput:
60116 /*
60117 * Handle the last step of open()
60118 */
60119-static int do_last(struct nameidata *nd, struct path *path,
60120+static int do_last(struct nameidata *nd, struct path *path, struct path *link,
60121 struct file *file, const struct open_flags *op,
60122 int *opened, struct filename *name)
60123 {
60124@@ -2938,6 +2990,15 @@ static int do_last(struct nameidata *nd, struct path *path,
60125 if (error)
60126 return error;
60127
60128+ if (!gr_acl_handle_hidden_file(dir, nd->path.mnt)) {
60129+ error = -ENOENT;
60130+ goto out;
60131+ }
60132+ if (link && gr_handle_symlink_owner(link, nd->inode)) {
60133+ error = -EACCES;
60134+ goto out;
60135+ }
60136+
60137 audit_inode(name, dir, LOOKUP_PARENT);
60138 error = -EISDIR;
60139 /* trailing slashes? */
60140@@ -2957,7 +3018,7 @@ retry_lookup:
60141 */
60142 }
60143 mutex_lock(&dir->d_inode->i_mutex);
60144- error = lookup_open(nd, path, file, op, got_write, opened);
60145+ error = lookup_open(nd, path, link, file, op, got_write, opened);
60146 mutex_unlock(&dir->d_inode->i_mutex);
60147
60148 if (error <= 0) {
60149@@ -2981,11 +3042,28 @@ retry_lookup:
60150 goto finish_open_created;
60151 }
60152
60153+ if (!gr_acl_handle_hidden_file(path->dentry, nd->path.mnt)) {
60154+ error = -ENOENT;
60155+ goto exit_dput;
60156+ }
60157+ if (link && gr_handle_symlink_owner(link, path->dentry->d_inode)) {
60158+ error = -EACCES;
60159+ goto exit_dput;
60160+ }
60161+
60162 /*
60163 * create/update audit record if it already exists.
60164 */
60165- if (path->dentry->d_inode)
60166+ if (path->dentry->d_inode) {
60167+ /* only check if O_CREAT is specified, all other checks need to go
60168+ into may_open */
60169+ if (gr_handle_fifo(path->dentry, path->mnt, dir, open_flag, acc_mode)) {
60170+ error = -EACCES;
60171+ goto exit_dput;
60172+ }
60173+
60174 audit_inode(name, path->dentry, 0);
60175+ }
60176
60177 /*
60178 * If atomic_open() acquired write access it is dropped now due to
60179@@ -3026,6 +3104,11 @@ finish_lookup:
60180 }
60181 }
60182 BUG_ON(inode != path->dentry->d_inode);
60183+ /* if we're resolving a symlink to another symlink */
60184+ if (link && gr_handle_symlink_owner(link, inode)) {
60185+ error = -EACCES;
60186+ goto out;
60187+ }
60188 return 1;
60189 }
60190
60191@@ -3035,7 +3118,6 @@ finish_lookup:
60192 save_parent.dentry = nd->path.dentry;
60193 save_parent.mnt = mntget(path->mnt);
60194 nd->path.dentry = path->dentry;
60195-
60196 }
60197 nd->inode = inode;
60198 /* Why this, you ask? _Now_ we might have grown LOOKUP_JUMPED... */
60199@@ -3045,7 +3127,18 @@ finish_open:
60200 path_put(&save_parent);
60201 return error;
60202 }
60203+
60204+ if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
60205+ error = -ENOENT;
60206+ goto out;
60207+ }
60208+ if (link && gr_handle_symlink_owner(link, nd->inode)) {
60209+ error = -EACCES;
60210+ goto out;
60211+ }
60212+
60213 audit_inode(name, nd->path.dentry, 0);
60214+
60215 error = -EISDIR;
60216 if ((open_flag & O_CREAT) && S_ISDIR(nd->inode->i_mode))
60217 goto out;
60218@@ -3208,7 +3301,7 @@ static struct file *path_openat(int dfd, struct filename *pathname,
60219 if (unlikely(error))
60220 goto out;
60221
60222- error = do_last(nd, &path, file, op, &opened, pathname);
60223+ error = do_last(nd, &path, NULL, file, op, &opened, pathname);
60224 while (unlikely(error > 0)) { /* trailing symlink */
60225 struct path link = path;
60226 void *cookie;
60227@@ -3226,7 +3319,7 @@ static struct file *path_openat(int dfd, struct filename *pathname,
60228 error = follow_link(&link, nd, &cookie);
60229 if (unlikely(error))
60230 break;
60231- error = do_last(nd, &path, file, op, &opened, pathname);
60232+ error = do_last(nd, &path, &link, file, op, &opened, pathname);
60233 put_link(nd, &link, cookie);
60234 }
60235 out:
60236@@ -3326,8 +3419,12 @@ struct dentry *kern_path_create(int dfd, const char *pathname,
60237 goto unlock;
60238
60239 error = -EEXIST;
60240- if (dentry->d_inode)
60241+ if (dentry->d_inode) {
60242+ if (!gr_acl_handle_hidden_file(dentry, nd.path.mnt)) {
60243+ error = -ENOENT;
60244+ }
60245 goto fail;
60246+ }
60247 /*
60248 * Special case - lookup gave negative, but... we had foo/bar/
60249 * From the vfs_mknod() POV we just have a negative dentry -
60250@@ -3379,6 +3476,20 @@ struct dentry *user_path_create(int dfd, const char __user *pathname,
60251 }
60252 EXPORT_SYMBOL(user_path_create);
60253
60254+static struct dentry *user_path_create_with_name(int dfd, const char __user *pathname, struct path *path, struct filename **to, unsigned int lookup_flags)
60255+{
60256+ struct filename *tmp = getname(pathname);
60257+ struct dentry *res;
60258+ if (IS_ERR(tmp))
60259+ return ERR_CAST(tmp);
60260+ res = kern_path_create(dfd, tmp->name, path, lookup_flags);
60261+ if (IS_ERR(res))
60262+ putname(tmp);
60263+ else
60264+ *to = tmp;
60265+ return res;
60266+}
60267+
60268 int vfs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode, dev_t dev)
60269 {
60270 int error = may_create(dir, dentry);
60271@@ -3441,6 +3552,17 @@ retry:
60272
60273 if (!IS_POSIXACL(path.dentry->d_inode))
60274 mode &= ~current_umask();
60275+
60276+ if (gr_handle_chroot_mknod(dentry, path.mnt, mode)) {
60277+ error = -EPERM;
60278+ goto out;
60279+ }
60280+
60281+ if (!gr_acl_handle_mknod(dentry, path.dentry, path.mnt, mode)) {
60282+ error = -EACCES;
60283+ goto out;
60284+ }
60285+
60286 error = security_path_mknod(&path, dentry, mode, dev);
60287 if (error)
60288 goto out;
60289@@ -3457,6 +3579,8 @@ retry:
60290 break;
60291 }
60292 out:
60293+ if (!error)
60294+ gr_handle_create(dentry, path.mnt);
60295 done_path_create(&path, dentry);
60296 if (retry_estale(error, lookup_flags)) {
60297 lookup_flags |= LOOKUP_REVAL;
60298@@ -3509,9 +3633,16 @@ retry:
60299
60300 if (!IS_POSIXACL(path.dentry->d_inode))
60301 mode &= ~current_umask();
60302+ if (!gr_acl_handle_mkdir(dentry, path.dentry, path.mnt)) {
60303+ error = -EACCES;
60304+ goto out;
60305+ }
60306 error = security_path_mkdir(&path, dentry, mode);
60307 if (!error)
60308 error = vfs_mkdir(path.dentry->d_inode, dentry, mode);
60309+ if (!error)
60310+ gr_handle_create(dentry, path.mnt);
60311+out:
60312 done_path_create(&path, dentry);
60313 if (retry_estale(error, lookup_flags)) {
60314 lookup_flags |= LOOKUP_REVAL;
60315@@ -3592,6 +3723,8 @@ static long do_rmdir(int dfd, const char __user *pathname)
60316 struct filename *name;
60317 struct dentry *dentry;
60318 struct nameidata nd;
60319+ ino_t saved_ino = 0;
60320+ dev_t saved_dev = 0;
60321 unsigned int lookup_flags = 0;
60322 retry:
60323 name = user_path_parent(dfd, pathname, &nd, lookup_flags);
60324@@ -3624,10 +3757,21 @@ retry:
60325 error = -ENOENT;
60326 goto exit3;
60327 }
60328+
60329+ saved_ino = dentry->d_inode->i_ino;
60330+ saved_dev = gr_get_dev_from_dentry(dentry);
60331+
60332+ if (!gr_acl_handle_rmdir(dentry, nd.path.mnt)) {
60333+ error = -EACCES;
60334+ goto exit3;
60335+ }
60336+
60337 error = security_path_rmdir(&nd.path, dentry);
60338 if (error)
60339 goto exit3;
60340 error = vfs_rmdir(nd.path.dentry->d_inode, dentry);
60341+ if (!error && (saved_dev || saved_ino))
60342+ gr_handle_delete(saved_ino, saved_dev);
60343 exit3:
60344 dput(dentry);
60345 exit2:
60346@@ -3693,6 +3837,8 @@ static long do_unlinkat(int dfd, const char __user *pathname)
60347 struct dentry *dentry;
60348 struct nameidata nd;
60349 struct inode *inode = NULL;
60350+ ino_t saved_ino = 0;
60351+ dev_t saved_dev = 0;
60352 unsigned int lookup_flags = 0;
60353 retry:
60354 name = user_path_parent(dfd, pathname, &nd, lookup_flags);
60355@@ -3719,10 +3865,22 @@ retry:
60356 if (!inode)
60357 goto slashes;
60358 ihold(inode);
60359+
60360+ if (inode->i_nlink <= 1) {
60361+ saved_ino = inode->i_ino;
60362+ saved_dev = gr_get_dev_from_dentry(dentry);
60363+ }
60364+ if (!gr_acl_handle_unlink(dentry, nd.path.mnt)) {
60365+ error = -EACCES;
60366+ goto exit2;
60367+ }
60368+
60369 error = security_path_unlink(&nd.path, dentry);
60370 if (error)
60371 goto exit2;
60372 error = vfs_unlink(nd.path.dentry->d_inode, dentry);
60373+ if (!error && (saved_ino || saved_dev))
60374+ gr_handle_delete(saved_ino, saved_dev);
60375 exit2:
60376 dput(dentry);
60377 }
60378@@ -3800,9 +3958,17 @@ retry:
60379 if (IS_ERR(dentry))
60380 goto out_putname;
60381
60382+ if (!gr_acl_handle_symlink(dentry, path.dentry, path.mnt, from)) {
60383+ error = -EACCES;
60384+ goto out;
60385+ }
60386+
60387 error = security_path_symlink(&path, dentry, from->name);
60388 if (!error)
60389 error = vfs_symlink(path.dentry->d_inode, dentry, from->name);
60390+ if (!error)
60391+ gr_handle_create(dentry, path.mnt);
60392+out:
60393 done_path_create(&path, dentry);
60394 if (retry_estale(error, lookup_flags)) {
60395 lookup_flags |= LOOKUP_REVAL;
60396@@ -3882,6 +4048,7 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
60397 {
60398 struct dentry *new_dentry;
60399 struct path old_path, new_path;
60400+ struct filename *to = NULL;
60401 int how = 0;
60402 int error;
60403
60404@@ -3905,7 +4072,7 @@ retry:
60405 if (error)
60406 return error;
60407
60408- new_dentry = user_path_create(newdfd, newname, &new_path,
60409+ new_dentry = user_path_create_with_name(newdfd, newname, &new_path, &to,
60410 (how & LOOKUP_REVAL));
60411 error = PTR_ERR(new_dentry);
60412 if (IS_ERR(new_dentry))
60413@@ -3917,11 +4084,28 @@ retry:
60414 error = may_linkat(&old_path);
60415 if (unlikely(error))
60416 goto out_dput;
60417+
60418+ if (gr_handle_hardlink(old_path.dentry, old_path.mnt,
60419+ old_path.dentry->d_inode,
60420+ old_path.dentry->d_inode->i_mode, to)) {
60421+ error = -EACCES;
60422+ goto out_dput;
60423+ }
60424+
60425+ if (!gr_acl_handle_link(new_dentry, new_path.dentry, new_path.mnt,
60426+ old_path.dentry, old_path.mnt, to)) {
60427+ error = -EACCES;
60428+ goto out_dput;
60429+ }
60430+
60431 error = security_path_link(old_path.dentry, &new_path, new_dentry);
60432 if (error)
60433 goto out_dput;
60434 error = vfs_link(old_path.dentry, new_path.dentry->d_inode, new_dentry);
60435+ if (!error)
60436+ gr_handle_create(new_dentry, new_path.mnt);
60437 out_dput:
60438+ putname(to);
60439 done_path_create(&new_path, new_dentry);
60440 if (retry_estale(error, how)) {
60441 how |= LOOKUP_REVAL;
60442@@ -4167,12 +4351,21 @@ retry:
60443 if (new_dentry == trap)
60444 goto exit5;
60445
60446+ error = gr_acl_handle_rename(new_dentry, new_dir, newnd.path.mnt,
60447+ old_dentry, old_dir->d_inode, oldnd.path.mnt,
60448+ to);
60449+ if (error)
60450+ goto exit5;
60451+
60452 error = security_path_rename(&oldnd.path, old_dentry,
60453 &newnd.path, new_dentry);
60454 if (error)
60455 goto exit5;
60456 error = vfs_rename(old_dir->d_inode, old_dentry,
60457 new_dir->d_inode, new_dentry);
60458+ if (!error)
60459+ gr_handle_rename(old_dir->d_inode, new_dir->d_inode, old_dentry,
60460+ new_dentry, oldnd.path.mnt, new_dentry->d_inode ? 1 : 0);
60461 exit5:
60462 dput(new_dentry);
60463 exit4:
60464@@ -4204,6 +4397,8 @@ SYSCALL_DEFINE2(rename, const char __user *, oldname, const char __user *, newna
60465
60466 int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const char *link)
60467 {
60468+ char tmpbuf[64];
60469+ const char *newlink;
60470 int len;
60471
60472 len = PTR_ERR(link);
60473@@ -4213,7 +4408,14 @@ int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const c
60474 len = strlen(link);
60475 if (len > (unsigned) buflen)
60476 len = buflen;
60477- if (copy_to_user(buffer, link, len))
60478+
60479+ if (len < sizeof(tmpbuf)) {
60480+ memcpy(tmpbuf, link, len);
60481+ newlink = tmpbuf;
60482+ } else
60483+ newlink = link;
60484+
60485+ if (copy_to_user(buffer, newlink, len))
60486 len = -EFAULT;
60487 out:
60488 return len;
60489diff --git a/fs/namespace.c b/fs/namespace.c
60490index da5c494..a755a54 100644
60491--- a/fs/namespace.c
60492+++ b/fs/namespace.c
60493@@ -1268,6 +1268,9 @@ static int do_umount(struct mount *mnt, int flags)
60494 if (!(sb->s_flags & MS_RDONLY))
60495 retval = do_remount_sb(sb, MS_RDONLY, NULL, 0);
60496 up_write(&sb->s_umount);
60497+
60498+ gr_log_remount(mnt->mnt_devname, retval);
60499+
60500 return retval;
60501 }
60502
60503@@ -1286,6 +1289,9 @@ static int do_umount(struct mount *mnt, int flags)
60504 }
60505 br_write_unlock(&vfsmount_lock);
60506 namespace_unlock();
60507+
60508+ gr_log_unmount(mnt->mnt_devname, retval);
60509+
60510 return retval;
60511 }
60512
60513@@ -1305,7 +1311,7 @@ static inline bool may_mount(void)
60514 * unixes. Our API is identical to OSF/1 to avoid making a mess of AMD
60515 */
60516
60517-SYSCALL_DEFINE2(umount, char __user *, name, int, flags)
60518+SYSCALL_DEFINE2(umount, const char __user *, name, int, flags)
60519 {
60520 struct path path;
60521 struct mount *mnt;
60522@@ -1347,7 +1353,7 @@ out:
60523 /*
60524 * The 2.0 compatible umount. No flags.
60525 */
60526-SYSCALL_DEFINE1(oldumount, char __user *, name)
60527+SYSCALL_DEFINE1(oldumount, const char __user *, name)
60528 {
60529 return sys_umount(name, 0);
60530 }
60531@@ -2358,6 +2364,16 @@ long do_mount(const char *dev_name, const char *dir_name,
60532 MS_NOATIME | MS_NODIRATIME | MS_RELATIME| MS_KERNMOUNT |
60533 MS_STRICTATIME);
60534
60535+ if (gr_handle_rofs_mount(path.dentry, path.mnt, mnt_flags)) {
60536+ retval = -EPERM;
60537+ goto dput_out;
60538+ }
60539+
60540+ if (gr_handle_chroot_mount(path.dentry, path.mnt, dev_name)) {
60541+ retval = -EPERM;
60542+ goto dput_out;
60543+ }
60544+
60545 if (flags & MS_REMOUNT)
60546 retval = do_remount(&path, flags & ~MS_REMOUNT, mnt_flags,
60547 data_page);
60548@@ -2372,6 +2388,9 @@ long do_mount(const char *dev_name, const char *dir_name,
60549 dev_name, data_page);
60550 dput_out:
60551 path_put(&path);
60552+
60553+ gr_log_mount(dev_name, dir_name, retval);
60554+
60555 return retval;
60556 }
60557
60558@@ -2389,7 +2408,7 @@ static void free_mnt_ns(struct mnt_namespace *ns)
60559 * number incrementing at 10Ghz will take 12,427 years to wrap which
60560 * is effectively never, so we can ignore the possibility.
60561 */
60562-static atomic64_t mnt_ns_seq = ATOMIC64_INIT(1);
60563+static atomic64_unchecked_t mnt_ns_seq = ATOMIC64_INIT(1);
60564
60565 static struct mnt_namespace *alloc_mnt_ns(struct user_namespace *user_ns)
60566 {
60567@@ -2404,7 +2423,7 @@ static struct mnt_namespace *alloc_mnt_ns(struct user_namespace *user_ns)
60568 kfree(new_ns);
60569 return ERR_PTR(ret);
60570 }
60571- new_ns->seq = atomic64_add_return(1, &mnt_ns_seq);
60572+ new_ns->seq = atomic64_inc_return_unchecked(&mnt_ns_seq);
60573 atomic_set(&new_ns->count, 1);
60574 new_ns->root = NULL;
60575 INIT_LIST_HEAD(&new_ns->list);
60576@@ -2418,7 +2437,7 @@ static struct mnt_namespace *alloc_mnt_ns(struct user_namespace *user_ns)
60577 * Allocate a new namespace structure and populate it with contents
60578 * copied from the namespace of the passed in task structure.
60579 */
60580-static struct mnt_namespace *dup_mnt_ns(struct mnt_namespace *mnt_ns,
60581+static __latent_entropy struct mnt_namespace *dup_mnt_ns(struct mnt_namespace *mnt_ns,
60582 struct user_namespace *user_ns, struct fs_struct *fs)
60583 {
60584 struct mnt_namespace *new_ns;
60585@@ -2549,8 +2568,8 @@ struct dentry *mount_subtree(struct vfsmount *mnt, const char *name)
60586 }
60587 EXPORT_SYMBOL(mount_subtree);
60588
60589-SYSCALL_DEFINE5(mount, char __user *, dev_name, char __user *, dir_name,
60590- char __user *, type, unsigned long, flags, void __user *, data)
60591+SYSCALL_DEFINE5(mount, const char __user *, dev_name, const char __user *, dir_name,
60592+ const char __user *, type, unsigned long, flags, void __user *, data)
60593 {
60594 int ret;
60595 char *kernel_type;
60596@@ -2663,6 +2682,11 @@ SYSCALL_DEFINE2(pivot_root, const char __user *, new_root,
60597 if (error)
60598 goto out2;
60599
60600+ if (gr_handle_chroot_pivot()) {
60601+ error = -EPERM;
60602+ goto out2;
60603+ }
60604+
60605 get_fs_root(current->fs, &root);
60606 old_mp = lock_mount(&old);
60607 error = PTR_ERR(old_mp);
60608@@ -2932,7 +2956,7 @@ static int mntns_install(struct nsproxy *nsproxy, void *ns)
60609 !ns_capable(current_user_ns(), CAP_SYS_ADMIN))
60610 return -EPERM;
60611
60612- if (fs->users != 1)
60613+ if (atomic_read(&fs->users) != 1)
60614 return -EINVAL;
60615
60616 get_mnt_ns(mnt_ns);
60617diff --git a/fs/nfs/callback_xdr.c b/fs/nfs/callback_xdr.c
60618index f4ccfe6..a5cf064 100644
60619--- a/fs/nfs/callback_xdr.c
60620+++ b/fs/nfs/callback_xdr.c
60621@@ -51,7 +51,7 @@ struct callback_op {
60622 callback_decode_arg_t decode_args;
60623 callback_encode_res_t encode_res;
60624 long res_maxsize;
60625-};
60626+} __do_const;
60627
60628 static struct callback_op callback_ops[];
60629
60630diff --git a/fs/nfs/inode.c b/fs/nfs/inode.c
60631index eda8879..bfc6837 100644
60632--- a/fs/nfs/inode.c
60633+++ b/fs/nfs/inode.c
60634@@ -1150,16 +1150,16 @@ static int nfs_size_need_update(const struct inode *inode, const struct nfs_fatt
60635 return nfs_size_to_loff_t(fattr->size) > i_size_read(inode);
60636 }
60637
60638-static atomic_long_t nfs_attr_generation_counter;
60639+static atomic_long_unchecked_t nfs_attr_generation_counter;
60640
60641 static unsigned long nfs_read_attr_generation_counter(void)
60642 {
60643- return atomic_long_read(&nfs_attr_generation_counter);
60644+ return atomic_long_read_unchecked(&nfs_attr_generation_counter);
60645 }
60646
60647 unsigned long nfs_inc_attr_generation_counter(void)
60648 {
60649- return atomic_long_inc_return(&nfs_attr_generation_counter);
60650+ return atomic_long_inc_return_unchecked(&nfs_attr_generation_counter);
60651 }
60652
60653 void nfs_fattr_init(struct nfs_fattr *fattr)
60654diff --git a/fs/nfsd/nfs4proc.c b/fs/nfsd/nfs4proc.c
60655index 419572f..5414a23 100644
60656--- a/fs/nfsd/nfs4proc.c
60657+++ b/fs/nfsd/nfs4proc.c
60658@@ -1168,7 +1168,7 @@ struct nfsd4_operation {
60659 nfsd4op_rsize op_rsize_bop;
60660 stateid_getter op_get_currentstateid;
60661 stateid_setter op_set_currentstateid;
60662-};
60663+} __do_const;
60664
60665 static struct nfsd4_operation nfsd4_ops[];
60666
60667diff --git a/fs/nfsd/nfs4xdr.c b/fs/nfsd/nfs4xdr.c
60668index ecc735e..79b2d31 100644
60669--- a/fs/nfsd/nfs4xdr.c
60670+++ b/fs/nfsd/nfs4xdr.c
60671@@ -1500,7 +1500,7 @@ nfsd4_decode_notsupp(struct nfsd4_compoundargs *argp, void *p)
60672
60673 typedef __be32(*nfsd4_dec)(struct nfsd4_compoundargs *argp, void *);
60674
60675-static nfsd4_dec nfsd4_dec_ops[] = {
60676+static const nfsd4_dec nfsd4_dec_ops[] = {
60677 [OP_ACCESS] = (nfsd4_dec)nfsd4_decode_access,
60678 [OP_CLOSE] = (nfsd4_dec)nfsd4_decode_close,
60679 [OP_COMMIT] = (nfsd4_dec)nfsd4_decode_commit,
60680@@ -1540,7 +1540,7 @@ static nfsd4_dec nfsd4_dec_ops[] = {
60681 [OP_RELEASE_LOCKOWNER] = (nfsd4_dec)nfsd4_decode_release_lockowner,
60682 };
60683
60684-static nfsd4_dec nfsd41_dec_ops[] = {
60685+static const nfsd4_dec nfsd41_dec_ops[] = {
60686 [OP_ACCESS] = (nfsd4_dec)nfsd4_decode_access,
60687 [OP_CLOSE] = (nfsd4_dec)nfsd4_decode_close,
60688 [OP_COMMIT] = (nfsd4_dec)nfsd4_decode_commit,
60689@@ -1602,7 +1602,7 @@ static nfsd4_dec nfsd41_dec_ops[] = {
60690 };
60691
60692 struct nfsd4_minorversion_ops {
60693- nfsd4_dec *decoders;
60694+ const nfsd4_dec *decoders;
60695 int nops;
60696 };
60697
60698diff --git a/fs/nfsd/nfscache.c b/fs/nfsd/nfscache.c
60699index b6af150..f6ec5e3 100644
60700--- a/fs/nfsd/nfscache.c
60701+++ b/fs/nfsd/nfscache.c
60702@@ -547,14 +547,17 @@ nfsd_cache_update(struct svc_rqst *rqstp, int cachetype, __be32 *statp)
60703 {
60704 struct svc_cacherep *rp = rqstp->rq_cacherep;
60705 struct kvec *resv = &rqstp->rq_res.head[0], *cachv;
60706- int len;
60707+ long len;
60708 size_t bufsize = 0;
60709
60710 if (!rp)
60711 return;
60712
60713- len = resv->iov_len - ((char*)statp - (char*)resv->iov_base);
60714- len >>= 2;
60715+ if (statp) {
60716+ len = (char*)statp - (char*)resv->iov_base;
60717+ len = resv->iov_len - len;
60718+ len >>= 2;
60719+ }
60720
60721 /* Don't cache excessive amounts of data and XDR failures */
60722 if (!statp || len > (256 >> 2)) {
60723diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c
60724index 72cb28e..5b5f87d 100644
60725--- a/fs/nfsd/vfs.c
60726+++ b/fs/nfsd/vfs.c
60727@@ -993,7 +993,7 @@ nfsd_vfs_read(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
60728 } else {
60729 oldfs = get_fs();
60730 set_fs(KERNEL_DS);
60731- host_err = vfs_readv(file, (struct iovec __user *)vec, vlen, &offset);
60732+ host_err = vfs_readv(file, (struct iovec __force_user *)vec, vlen, &offset);
60733 set_fs(oldfs);
60734 }
60735
60736@@ -1080,7 +1080,7 @@ nfsd_vfs_write(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
60737
60738 /* Write the data. */
60739 oldfs = get_fs(); set_fs(KERNEL_DS);
60740- host_err = vfs_writev(file, (struct iovec __user *)vec, vlen, &pos);
60741+ host_err = vfs_writev(file, (struct iovec __force_user *)vec, vlen, &pos);
60742 set_fs(oldfs);
60743 if (host_err < 0)
60744 goto out_nfserr;
60745@@ -1626,7 +1626,7 @@ nfsd_readlink(struct svc_rqst *rqstp, struct svc_fh *fhp, char *buf, int *lenp)
60746 */
60747
60748 oldfs = get_fs(); set_fs(KERNEL_DS);
60749- host_err = inode->i_op->readlink(path.dentry, (char __user *)buf, *lenp);
60750+ host_err = inode->i_op->readlink(path.dentry, (char __force_user *)buf, *lenp);
60751 set_fs(oldfs);
60752
60753 if (host_err < 0)
60754diff --git a/fs/nilfs2/segment.c b/fs/nilfs2/segment.c
60755index 9f6b486..a1a19163 100644
60756--- a/fs/nilfs2/segment.c
60757+++ b/fs/nilfs2/segment.c
60758@@ -1440,17 +1440,19 @@ static int nilfs_segctor_collect(struct nilfs_sc_info *sci,
60759
60760 nilfs_clear_logs(&sci->sc_segbufs);
60761
60762- err = nilfs_segctor_extend_segments(sci, nilfs, nadd);
60763- if (unlikely(err))
60764- return err;
60765-
60766 if (sci->sc_stage.flags & NILFS_CF_SUFREED) {
60767 err = nilfs_sufile_cancel_freev(nilfs->ns_sufile,
60768 sci->sc_freesegs,
60769 sci->sc_nfreesegs,
60770 NULL);
60771 WARN_ON(err); /* do not happen */
60772+ sci->sc_stage.flags &= ~NILFS_CF_SUFREED;
60773 }
60774+
60775+ err = nilfs_segctor_extend_segments(sci, nilfs, nadd);
60776+ if (unlikely(err))
60777+ return err;
60778+
60779 nadd = min_t(int, nadd << 1, SC_MAX_SEGDELTA);
60780 sci->sc_stage = prev_stage;
60781 }
60782diff --git a/fs/nls/nls_base.c b/fs/nls/nls_base.c
60783index fea6bd5..8ee9d81 100644
60784--- a/fs/nls/nls_base.c
60785+++ b/fs/nls/nls_base.c
60786@@ -234,20 +234,22 @@ EXPORT_SYMBOL(utf16s_to_utf8s);
60787
60788 int register_nls(struct nls_table * nls)
60789 {
60790- struct nls_table ** tmp = &tables;
60791+ struct nls_table *tmp = tables;
60792
60793 if (nls->next)
60794 return -EBUSY;
60795
60796 spin_lock(&nls_lock);
60797- while (*tmp) {
60798- if (nls == *tmp) {
60799+ while (tmp) {
60800+ if (nls == tmp) {
60801 spin_unlock(&nls_lock);
60802 return -EBUSY;
60803 }
60804- tmp = &(*tmp)->next;
60805+ tmp = tmp->next;
60806 }
60807- nls->next = tables;
60808+ pax_open_kernel();
60809+ *(struct nls_table **)&nls->next = tables;
60810+ pax_close_kernel();
60811 tables = nls;
60812 spin_unlock(&nls_lock);
60813 return 0;
60814@@ -255,12 +257,14 @@ int register_nls(struct nls_table * nls)
60815
60816 int unregister_nls(struct nls_table * nls)
60817 {
60818- struct nls_table ** tmp = &tables;
60819+ struct nls_table * const * tmp = &tables;
60820
60821 spin_lock(&nls_lock);
60822 while (*tmp) {
60823 if (nls == *tmp) {
60824- *tmp = nls->next;
60825+ pax_open_kernel();
60826+ *(struct nls_table **)tmp = nls->next;
60827+ pax_close_kernel();
60828 spin_unlock(&nls_lock);
60829 return 0;
60830 }
60831diff --git a/fs/nls/nls_euc-jp.c b/fs/nls/nls_euc-jp.c
60832index 7424929..35f6be5 100644
60833--- a/fs/nls/nls_euc-jp.c
60834+++ b/fs/nls/nls_euc-jp.c
60835@@ -561,8 +561,10 @@ static int __init init_nls_euc_jp(void)
60836 p_nls = load_nls("cp932");
60837
60838 if (p_nls) {
60839- table.charset2upper = p_nls->charset2upper;
60840- table.charset2lower = p_nls->charset2lower;
60841+ pax_open_kernel();
60842+ *(const unsigned char **)&table.charset2upper = p_nls->charset2upper;
60843+ *(const unsigned char **)&table.charset2lower = p_nls->charset2lower;
60844+ pax_close_kernel();
60845 return register_nls(&table);
60846 }
60847
60848diff --git a/fs/nls/nls_koi8-ru.c b/fs/nls/nls_koi8-ru.c
60849index e7bc1d7..06bd4bb 100644
60850--- a/fs/nls/nls_koi8-ru.c
60851+++ b/fs/nls/nls_koi8-ru.c
60852@@ -63,8 +63,10 @@ static int __init init_nls_koi8_ru(void)
60853 p_nls = load_nls("koi8-u");
60854
60855 if (p_nls) {
60856- table.charset2upper = p_nls->charset2upper;
60857- table.charset2lower = p_nls->charset2lower;
60858+ pax_open_kernel();
60859+ *(const unsigned char **)&table.charset2upper = p_nls->charset2upper;
60860+ *(const unsigned char **)&table.charset2lower = p_nls->charset2lower;
60861+ pax_close_kernel();
60862 return register_nls(&table);
60863 }
60864
60865diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c
60866index e44cb64..4807084 100644
60867--- a/fs/notify/fanotify/fanotify_user.c
60868+++ b/fs/notify/fanotify/fanotify_user.c
60869@@ -253,8 +253,8 @@ static ssize_t copy_event_to_user(struct fsnotify_group *group,
60870
60871 fd = fanotify_event_metadata.fd;
60872 ret = -EFAULT;
60873- if (copy_to_user(buf, &fanotify_event_metadata,
60874- fanotify_event_metadata.event_len))
60875+ if (fanotify_event_metadata.event_len > sizeof fanotify_event_metadata ||
60876+ copy_to_user(buf, &fanotify_event_metadata, fanotify_event_metadata.event_len))
60877 goto out_close_fd;
60878
60879 ret = prepare_for_access_response(group, event, fd);
60880diff --git a/fs/notify/notification.c b/fs/notify/notification.c
60881index 7b51b05..5ea5ef6 100644
60882--- a/fs/notify/notification.c
60883+++ b/fs/notify/notification.c
60884@@ -57,7 +57,7 @@ static struct kmem_cache *fsnotify_event_holder_cachep;
60885 * get set to 0 so it will never get 'freed'
60886 */
60887 static struct fsnotify_event *q_overflow_event;
60888-static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
60889+static atomic_unchecked_t fsnotify_sync_cookie = ATOMIC_INIT(0);
60890
60891 /**
60892 * fsnotify_get_cookie - return a unique cookie for use in synchronizing events.
60893@@ -65,7 +65,7 @@ static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
60894 */
60895 u32 fsnotify_get_cookie(void)
60896 {
60897- return atomic_inc_return(&fsnotify_sync_cookie);
60898+ return atomic_inc_return_unchecked(&fsnotify_sync_cookie);
60899 }
60900 EXPORT_SYMBOL_GPL(fsnotify_get_cookie);
60901
60902diff --git a/fs/ntfs/dir.c b/fs/ntfs/dir.c
60903index 9e38daf..5727cae 100644
60904--- a/fs/ntfs/dir.c
60905+++ b/fs/ntfs/dir.c
60906@@ -1310,7 +1310,7 @@ find_next_index_buffer:
60907 ia = (INDEX_ALLOCATION*)(kaddr + (ia_pos & ~PAGE_CACHE_MASK &
60908 ~(s64)(ndir->itype.index.block_size - 1)));
60909 /* Bounds checks. */
60910- if (unlikely((u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
60911+ if (unlikely(!kaddr || (u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
60912 ntfs_error(sb, "Out of bounds check failed. Corrupt directory "
60913 "inode 0x%lx or driver bug.", vdir->i_ino);
60914 goto err_out;
60915diff --git a/fs/ntfs/file.c b/fs/ntfs/file.c
60916index ea4ba9d..1e13d34 100644
60917--- a/fs/ntfs/file.c
60918+++ b/fs/ntfs/file.c
60919@@ -1282,7 +1282,7 @@ static inline size_t ntfs_copy_from_user(struct page **pages,
60920 char *addr;
60921 size_t total = 0;
60922 unsigned len;
60923- int left;
60924+ unsigned left;
60925
60926 do {
60927 len = PAGE_CACHE_SIZE - ofs;
60928diff --git a/fs/ntfs/super.c b/fs/ntfs/super.c
60929index 82650d5..db37dcf 100644
60930--- a/fs/ntfs/super.c
60931+++ b/fs/ntfs/super.c
60932@@ -685,7 +685,7 @@ static struct buffer_head *read_ntfs_boot_sector(struct super_block *sb,
60933 if (!silent)
60934 ntfs_error(sb, "Primary boot sector is invalid.");
60935 } else if (!silent)
60936- ntfs_error(sb, read_err_str, "primary");
60937+ ntfs_error(sb, read_err_str, "%s", "primary");
60938 if (!(NTFS_SB(sb)->on_errors & ON_ERRORS_RECOVER)) {
60939 if (bh_primary)
60940 brelse(bh_primary);
60941@@ -701,7 +701,7 @@ static struct buffer_head *read_ntfs_boot_sector(struct super_block *sb,
60942 goto hotfix_primary_boot_sector;
60943 brelse(bh_backup);
60944 } else if (!silent)
60945- ntfs_error(sb, read_err_str, "backup");
60946+ ntfs_error(sb, read_err_str, "%s", "backup");
60947 /* Try to read NT3.51- backup boot sector. */
60948 if ((bh_backup = sb_bread(sb, nr_blocks >> 1))) {
60949 if (is_boot_sector_ntfs(sb, (NTFS_BOOT_SECTOR*)
60950@@ -712,7 +712,7 @@ static struct buffer_head *read_ntfs_boot_sector(struct super_block *sb,
60951 "sector.");
60952 brelse(bh_backup);
60953 } else if (!silent)
60954- ntfs_error(sb, read_err_str, "backup");
60955+ ntfs_error(sb, read_err_str, "%s", "backup");
60956 /* We failed. Cleanup and return. */
60957 if (bh_primary)
60958 brelse(bh_primary);
60959diff --git a/fs/ocfs2/localalloc.c b/fs/ocfs2/localalloc.c
60960index cd5496b..26a1055 100644
60961--- a/fs/ocfs2/localalloc.c
60962+++ b/fs/ocfs2/localalloc.c
60963@@ -1278,7 +1278,7 @@ static int ocfs2_local_alloc_slide_window(struct ocfs2_super *osb,
60964 goto bail;
60965 }
60966
60967- atomic_inc(&osb->alloc_stats.moves);
60968+ atomic_inc_unchecked(&osb->alloc_stats.moves);
60969
60970 bail:
60971 if (handle)
60972diff --git a/fs/ocfs2/ocfs2.h b/fs/ocfs2/ocfs2.h
60973index 3a90347..c40bef8 100644
60974--- a/fs/ocfs2/ocfs2.h
60975+++ b/fs/ocfs2/ocfs2.h
60976@@ -235,11 +235,11 @@ enum ocfs2_vol_state
60977
60978 struct ocfs2_alloc_stats
60979 {
60980- atomic_t moves;
60981- atomic_t local_data;
60982- atomic_t bitmap_data;
60983- atomic_t bg_allocs;
60984- atomic_t bg_extends;
60985+ atomic_unchecked_t moves;
60986+ atomic_unchecked_t local_data;
60987+ atomic_unchecked_t bitmap_data;
60988+ atomic_unchecked_t bg_allocs;
60989+ atomic_unchecked_t bg_extends;
60990 };
60991
60992 enum ocfs2_local_alloc_state
60993diff --git a/fs/ocfs2/suballoc.c b/fs/ocfs2/suballoc.c
60994index 5397c07..54afc55 100644
60995--- a/fs/ocfs2/suballoc.c
60996+++ b/fs/ocfs2/suballoc.c
60997@@ -872,7 +872,7 @@ static int ocfs2_reserve_suballoc_bits(struct ocfs2_super *osb,
60998 mlog_errno(status);
60999 goto bail;
61000 }
61001- atomic_inc(&osb->alloc_stats.bg_extends);
61002+ atomic_inc_unchecked(&osb->alloc_stats.bg_extends);
61003
61004 /* You should never ask for this much metadata */
61005 BUG_ON(bits_wanted >
61006@@ -2000,7 +2000,7 @@ int ocfs2_claim_metadata(handle_t *handle,
61007 mlog_errno(status);
61008 goto bail;
61009 }
61010- atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
61011+ atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
61012
61013 *suballoc_loc = res.sr_bg_blkno;
61014 *suballoc_bit_start = res.sr_bit_offset;
61015@@ -2164,7 +2164,7 @@ int ocfs2_claim_new_inode_at_loc(handle_t *handle,
61016 trace_ocfs2_claim_new_inode_at_loc((unsigned long long)di_blkno,
61017 res->sr_bits);
61018
61019- atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
61020+ atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
61021
61022 BUG_ON(res->sr_bits != 1);
61023
61024@@ -2206,7 +2206,7 @@ int ocfs2_claim_new_inode(handle_t *handle,
61025 mlog_errno(status);
61026 goto bail;
61027 }
61028- atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
61029+ atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
61030
61031 BUG_ON(res.sr_bits != 1);
61032
61033@@ -2310,7 +2310,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
61034 cluster_start,
61035 num_clusters);
61036 if (!status)
61037- atomic_inc(&osb->alloc_stats.local_data);
61038+ atomic_inc_unchecked(&osb->alloc_stats.local_data);
61039 } else {
61040 if (min_clusters > (osb->bitmap_cpg - 1)) {
61041 /* The only paths asking for contiguousness
61042@@ -2336,7 +2336,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
61043 ocfs2_desc_bitmap_to_cluster_off(ac->ac_inode,
61044 res.sr_bg_blkno,
61045 res.sr_bit_offset);
61046- atomic_inc(&osb->alloc_stats.bitmap_data);
61047+ atomic_inc_unchecked(&osb->alloc_stats.bitmap_data);
61048 *num_clusters = res.sr_bits;
61049 }
61050 }
61051diff --git a/fs/ocfs2/super.c b/fs/ocfs2/super.c
61052index d4e81e4..ad89f5f 100644
61053--- a/fs/ocfs2/super.c
61054+++ b/fs/ocfs2/super.c
61055@@ -300,11 +300,11 @@ static int ocfs2_osb_dump(struct ocfs2_super *osb, char *buf, int len)
61056 "%10s => GlobalAllocs: %d LocalAllocs: %d "
61057 "SubAllocs: %d LAWinMoves: %d SAExtends: %d\n",
61058 "Stats",
61059- atomic_read(&osb->alloc_stats.bitmap_data),
61060- atomic_read(&osb->alloc_stats.local_data),
61061- atomic_read(&osb->alloc_stats.bg_allocs),
61062- atomic_read(&osb->alloc_stats.moves),
61063- atomic_read(&osb->alloc_stats.bg_extends));
61064+ atomic_read_unchecked(&osb->alloc_stats.bitmap_data),
61065+ atomic_read_unchecked(&osb->alloc_stats.local_data),
61066+ atomic_read_unchecked(&osb->alloc_stats.bg_allocs),
61067+ atomic_read_unchecked(&osb->alloc_stats.moves),
61068+ atomic_read_unchecked(&osb->alloc_stats.bg_extends));
61069
61070 out += snprintf(buf + out, len - out,
61071 "%10s => State: %u Descriptor: %llu Size: %u bits "
61072@@ -2121,11 +2121,11 @@ static int ocfs2_initialize_super(struct super_block *sb,
61073 spin_lock_init(&osb->osb_xattr_lock);
61074 ocfs2_init_steal_slots(osb);
61075
61076- atomic_set(&osb->alloc_stats.moves, 0);
61077- atomic_set(&osb->alloc_stats.local_data, 0);
61078- atomic_set(&osb->alloc_stats.bitmap_data, 0);
61079- atomic_set(&osb->alloc_stats.bg_allocs, 0);
61080- atomic_set(&osb->alloc_stats.bg_extends, 0);
61081+ atomic_set_unchecked(&osb->alloc_stats.moves, 0);
61082+ atomic_set_unchecked(&osb->alloc_stats.local_data, 0);
61083+ atomic_set_unchecked(&osb->alloc_stats.bitmap_data, 0);
61084+ atomic_set_unchecked(&osb->alloc_stats.bg_allocs, 0);
61085+ atomic_set_unchecked(&osb->alloc_stats.bg_extends, 0);
61086
61087 /* Copy the blockcheck stats from the superblock probe */
61088 osb->osb_ecc_stats = *stats;
61089diff --git a/fs/open.c b/fs/open.c
61090index d420331..2dbb3fd 100644
61091--- a/fs/open.c
61092+++ b/fs/open.c
61093@@ -32,6 +32,8 @@
61094 #include <linux/dnotify.h>
61095 #include <linux/compat.h>
61096
61097+#define CREATE_TRACE_POINTS
61098+#include <trace/events/fs.h>
61099 #include "internal.h"
61100
61101 int do_truncate(struct dentry *dentry, loff_t length, unsigned int time_attrs,
61102@@ -102,6 +104,8 @@ long vfs_truncate(struct path *path, loff_t length)
61103 error = locks_verify_truncate(inode, NULL, length);
61104 if (!error)
61105 error = security_path_truncate(path);
61106+ if (!error && !gr_acl_handle_truncate(path->dentry, path->mnt))
61107+ error = -EACCES;
61108 if (!error)
61109 error = do_truncate(path->dentry, length, 0, NULL);
61110
61111@@ -186,6 +190,8 @@ static long do_sys_ftruncate(unsigned int fd, loff_t length, int small)
61112 error = locks_verify_truncate(inode, f.file, length);
61113 if (!error)
61114 error = security_path_truncate(&f.file->f_path);
61115+ if (!error && !gr_acl_handle_truncate(f.file->f_path.dentry, f.file->f_path.mnt))
61116+ error = -EACCES;
61117 if (!error)
61118 error = do_truncate(dentry, length, ATTR_MTIME|ATTR_CTIME, f.file);
61119 sb_end_write(inode->i_sb);
61120@@ -360,6 +366,9 @@ retry:
61121 if (__mnt_is_readonly(path.mnt))
61122 res = -EROFS;
61123
61124+ if (!res && !gr_acl_handle_access(path.dentry, path.mnt, mode))
61125+ res = -EACCES;
61126+
61127 out_path_release:
61128 path_put(&path);
61129 if (retry_estale(res, lookup_flags)) {
61130@@ -391,6 +400,8 @@ retry:
61131 if (error)
61132 goto dput_and_out;
61133
61134+ gr_log_chdir(path.dentry, path.mnt);
61135+
61136 set_fs_pwd(current->fs, &path);
61137
61138 dput_and_out:
61139@@ -420,6 +431,13 @@ SYSCALL_DEFINE1(fchdir, unsigned int, fd)
61140 goto out_putf;
61141
61142 error = inode_permission(inode, MAY_EXEC | MAY_CHDIR);
61143+
61144+ if (!error && !gr_chroot_fchdir(f.file->f_path.dentry, f.file->f_path.mnt))
61145+ error = -EPERM;
61146+
61147+ if (!error)
61148+ gr_log_chdir(f.file->f_path.dentry, f.file->f_path.mnt);
61149+
61150 if (!error)
61151 set_fs_pwd(current->fs, &f.file->f_path);
61152 out_putf:
61153@@ -449,7 +467,13 @@ retry:
61154 if (error)
61155 goto dput_and_out;
61156
61157+ if (gr_handle_chroot_chroot(path.dentry, path.mnt))
61158+ goto dput_and_out;
61159+
61160 set_fs_root(current->fs, &path);
61161+
61162+ gr_handle_chroot_chdir(&path);
61163+
61164 error = 0;
61165 dput_and_out:
61166 path_put(&path);
61167@@ -471,6 +495,16 @@ static int chmod_common(struct path *path, umode_t mode)
61168 if (error)
61169 return error;
61170 mutex_lock(&inode->i_mutex);
61171+
61172+ if (!gr_acl_handle_chmod(path->dentry, path->mnt, &mode)) {
61173+ error = -EACCES;
61174+ goto out_unlock;
61175+ }
61176+ if (gr_handle_chroot_chmod(path->dentry, path->mnt, mode)) {
61177+ error = -EACCES;
61178+ goto out_unlock;
61179+ }
61180+
61181 error = security_path_chmod(path, mode);
61182 if (error)
61183 goto out_unlock;
61184@@ -530,6 +564,9 @@ static int chown_common(struct path *path, uid_t user, gid_t group)
61185 uid = make_kuid(current_user_ns(), user);
61186 gid = make_kgid(current_user_ns(), group);
61187
61188+ if (!gr_acl_handle_chown(path->dentry, path->mnt))
61189+ return -EACCES;
61190+
61191 newattrs.ia_valid = ATTR_CTIME;
61192 if (user != (uid_t) -1) {
61193 if (!uid_valid(uid))
61194@@ -974,6 +1011,7 @@ long do_sys_open(int dfd, const char __user *filename, int flags, umode_t mode)
61195 } else {
61196 fsnotify_open(f);
61197 fd_install(fd, f);
61198+ trace_do_sys_open(tmp->name, flags, mode);
61199 }
61200 }
61201 putname(tmp);
61202diff --git a/fs/pipe.c b/fs/pipe.c
61203index 0e0752e..7cfdd50 100644
61204--- a/fs/pipe.c
61205+++ b/fs/pipe.c
61206@@ -56,7 +56,7 @@ unsigned int pipe_min_size = PAGE_SIZE;
61207
61208 static void pipe_lock_nested(struct pipe_inode_info *pipe, int subclass)
61209 {
61210- if (pipe->files)
61211+ if (atomic_read(&pipe->files))
61212 mutex_lock_nested(&pipe->mutex, subclass);
61213 }
61214
61215@@ -71,7 +71,7 @@ EXPORT_SYMBOL(pipe_lock);
61216
61217 void pipe_unlock(struct pipe_inode_info *pipe)
61218 {
61219- if (pipe->files)
61220+ if (atomic_read(&pipe->files))
61221 mutex_unlock(&pipe->mutex);
61222 }
61223 EXPORT_SYMBOL(pipe_unlock);
61224@@ -449,9 +449,9 @@ redo:
61225 }
61226 if (bufs) /* More to do? */
61227 continue;
61228- if (!pipe->writers)
61229+ if (!atomic_read(&pipe->writers))
61230 break;
61231- if (!pipe->waiting_writers) {
61232+ if (!atomic_read(&pipe->waiting_writers)) {
61233 /* syscall merging: Usually we must not sleep
61234 * if O_NONBLOCK is set, or if we got some data.
61235 * But if a writer sleeps in kernel space, then
61236@@ -513,7 +513,7 @@ pipe_write(struct kiocb *iocb, const struct iovec *_iov,
61237 ret = 0;
61238 __pipe_lock(pipe);
61239
61240- if (!pipe->readers) {
61241+ if (!atomic_read(&pipe->readers)) {
61242 send_sig(SIGPIPE, current, 0);
61243 ret = -EPIPE;
61244 goto out;
61245@@ -562,7 +562,7 @@ redo1:
61246 for (;;) {
61247 int bufs;
61248
61249- if (!pipe->readers) {
61250+ if (!atomic_read(&pipe->readers)) {
61251 send_sig(SIGPIPE, current, 0);
61252 if (!ret)
61253 ret = -EPIPE;
61254@@ -653,9 +653,9 @@ redo2:
61255 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
61256 do_wakeup = 0;
61257 }
61258- pipe->waiting_writers++;
61259+ atomic_inc(&pipe->waiting_writers);
61260 pipe_wait(pipe);
61261- pipe->waiting_writers--;
61262+ atomic_dec(&pipe->waiting_writers);
61263 }
61264 out:
61265 __pipe_unlock(pipe);
61266@@ -709,7 +709,7 @@ pipe_poll(struct file *filp, poll_table *wait)
61267 mask = 0;
61268 if (filp->f_mode & FMODE_READ) {
61269 mask = (nrbufs > 0) ? POLLIN | POLLRDNORM : 0;
61270- if (!pipe->writers && filp->f_version != pipe->w_counter)
61271+ if (!atomic_read(&pipe->writers) && filp->f_version != pipe->w_counter)
61272 mask |= POLLHUP;
61273 }
61274
61275@@ -719,7 +719,7 @@ pipe_poll(struct file *filp, poll_table *wait)
61276 * Most Unices do not set POLLERR for FIFOs but on Linux they
61277 * behave exactly like pipes for poll().
61278 */
61279- if (!pipe->readers)
61280+ if (!atomic_read(&pipe->readers))
61281 mask |= POLLERR;
61282 }
61283
61284@@ -731,7 +731,7 @@ static void put_pipe_info(struct inode *inode, struct pipe_inode_info *pipe)
61285 int kill = 0;
61286
61287 spin_lock(&inode->i_lock);
61288- if (!--pipe->files) {
61289+ if (atomic_dec_and_test(&pipe->files)) {
61290 inode->i_pipe = NULL;
61291 kill = 1;
61292 }
61293@@ -748,11 +748,11 @@ pipe_release(struct inode *inode, struct file *file)
61294
61295 __pipe_lock(pipe);
61296 if (file->f_mode & FMODE_READ)
61297- pipe->readers--;
61298+ atomic_dec(&pipe->readers);
61299 if (file->f_mode & FMODE_WRITE)
61300- pipe->writers--;
61301+ atomic_dec(&pipe->writers);
61302
61303- if (pipe->readers || pipe->writers) {
61304+ if (atomic_read(&pipe->readers) || atomic_read(&pipe->writers)) {
61305 wake_up_interruptible_sync_poll(&pipe->wait, POLLIN | POLLOUT | POLLRDNORM | POLLWRNORM | POLLERR | POLLHUP);
61306 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
61307 kill_fasync(&pipe->fasync_writers, SIGIO, POLL_OUT);
61308@@ -817,7 +817,7 @@ void free_pipe_info(struct pipe_inode_info *pipe)
61309 kfree(pipe);
61310 }
61311
61312-static struct vfsmount *pipe_mnt __read_mostly;
61313+struct vfsmount *pipe_mnt __read_mostly;
61314
61315 /*
61316 * pipefs_dname() is called from d_path().
61317@@ -847,8 +847,9 @@ static struct inode * get_pipe_inode(void)
61318 goto fail_iput;
61319
61320 inode->i_pipe = pipe;
61321- pipe->files = 2;
61322- pipe->readers = pipe->writers = 1;
61323+ atomic_set(&pipe->files, 2);
61324+ atomic_set(&pipe->readers, 1);
61325+ atomic_set(&pipe->writers, 1);
61326 inode->i_fop = &pipefifo_fops;
61327
61328 /*
61329@@ -1027,17 +1028,17 @@ static int fifo_open(struct inode *inode, struct file *filp)
61330 spin_lock(&inode->i_lock);
61331 if (inode->i_pipe) {
61332 pipe = inode->i_pipe;
61333- pipe->files++;
61334+ atomic_inc(&pipe->files);
61335 spin_unlock(&inode->i_lock);
61336 } else {
61337 spin_unlock(&inode->i_lock);
61338 pipe = alloc_pipe_info();
61339 if (!pipe)
61340 return -ENOMEM;
61341- pipe->files = 1;
61342+ atomic_set(&pipe->files, 1);
61343 spin_lock(&inode->i_lock);
61344 if (unlikely(inode->i_pipe)) {
61345- inode->i_pipe->files++;
61346+ atomic_inc(&inode->i_pipe->files);
61347 spin_unlock(&inode->i_lock);
61348 free_pipe_info(pipe);
61349 pipe = inode->i_pipe;
61350@@ -1062,10 +1063,10 @@ static int fifo_open(struct inode *inode, struct file *filp)
61351 * opened, even when there is no process writing the FIFO.
61352 */
61353 pipe->r_counter++;
61354- if (pipe->readers++ == 0)
61355+ if (atomic_inc_return(&pipe->readers) == 1)
61356 wake_up_partner(pipe);
61357
61358- if (!is_pipe && !pipe->writers) {
61359+ if (!is_pipe && !atomic_read(&pipe->writers)) {
61360 if ((filp->f_flags & O_NONBLOCK)) {
61361 /* suppress POLLHUP until we have
61362 * seen a writer */
61363@@ -1084,14 +1085,14 @@ static int fifo_open(struct inode *inode, struct file *filp)
61364 * errno=ENXIO when there is no process reading the FIFO.
61365 */
61366 ret = -ENXIO;
61367- if (!is_pipe && (filp->f_flags & O_NONBLOCK) && !pipe->readers)
61368+ if (!is_pipe && (filp->f_flags & O_NONBLOCK) && !atomic_read(&pipe->readers))
61369 goto err;
61370
61371 pipe->w_counter++;
61372- if (!pipe->writers++)
61373+ if (atomic_inc_return(&pipe->writers) == 1)
61374 wake_up_partner(pipe);
61375
61376- if (!is_pipe && !pipe->readers) {
61377+ if (!is_pipe && !atomic_read(&pipe->readers)) {
61378 if (wait_for_partner(pipe, &pipe->r_counter))
61379 goto err_wr;
61380 }
61381@@ -1105,11 +1106,11 @@ static int fifo_open(struct inode *inode, struct file *filp)
61382 * the process can at least talk to itself.
61383 */
61384
61385- pipe->readers++;
61386- pipe->writers++;
61387+ atomic_inc(&pipe->readers);
61388+ atomic_inc(&pipe->writers);
61389 pipe->r_counter++;
61390 pipe->w_counter++;
61391- if (pipe->readers == 1 || pipe->writers == 1)
61392+ if (atomic_read(&pipe->readers) == 1 || atomic_read(&pipe->writers) == 1)
61393 wake_up_partner(pipe);
61394 break;
61395
61396@@ -1123,13 +1124,13 @@ static int fifo_open(struct inode *inode, struct file *filp)
61397 return 0;
61398
61399 err_rd:
61400- if (!--pipe->readers)
61401+ if (atomic_dec_and_test(&pipe->readers))
61402 wake_up_interruptible(&pipe->wait);
61403 ret = -ERESTARTSYS;
61404 goto err;
61405
61406 err_wr:
61407- if (!--pipe->writers)
61408+ if (atomic_dec_and_test(&pipe->writers))
61409 wake_up_interruptible(&pipe->wait);
61410 ret = -ERESTARTSYS;
61411 goto err;
61412diff --git a/fs/proc/Kconfig b/fs/proc/Kconfig
61413index 15af622..0e9f4467 100644
61414--- a/fs/proc/Kconfig
61415+++ b/fs/proc/Kconfig
61416@@ -30,12 +30,12 @@ config PROC_FS
61417
61418 config PROC_KCORE
61419 bool "/proc/kcore support" if !ARM
61420- depends on PROC_FS && MMU
61421+ depends on PROC_FS && MMU && !GRKERNSEC_PROC_ADD
61422
61423 config PROC_VMCORE
61424 bool "/proc/vmcore support"
61425- depends on PROC_FS && CRASH_DUMP
61426- default y
61427+ depends on PROC_FS && CRASH_DUMP && !GRKERNSEC
61428+ default n
61429 help
61430 Exports the dump image of crashed kernel in ELF format.
61431
61432@@ -59,8 +59,8 @@ config PROC_SYSCTL
61433 limited in memory.
61434
61435 config PROC_PAGE_MONITOR
61436- default y
61437- depends on PROC_FS && MMU
61438+ default n
61439+ depends on PROC_FS && MMU && !GRKERNSEC
61440 bool "Enable /proc page monitoring" if EXPERT
61441 help
61442 Various /proc files exist to monitor process memory utilization:
61443diff --git a/fs/proc/array.c b/fs/proc/array.c
61444index cbd0f1b..adec3f0 100644
61445--- a/fs/proc/array.c
61446+++ b/fs/proc/array.c
61447@@ -60,6 +60,7 @@
61448 #include <linux/tty.h>
61449 #include <linux/string.h>
61450 #include <linux/mman.h>
61451+#include <linux/grsecurity.h>
61452 #include <linux/proc_fs.h>
61453 #include <linux/ioport.h>
61454 #include <linux/uaccess.h>
61455@@ -363,6 +364,21 @@ static void task_cpus_allowed(struct seq_file *m, struct task_struct *task)
61456 seq_putc(m, '\n');
61457 }
61458
61459+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
61460+static inline void task_pax(struct seq_file *m, struct task_struct *p)
61461+{
61462+ if (p->mm)
61463+ seq_printf(m, "PaX:\t%c%c%c%c%c\n",
61464+ p->mm->pax_flags & MF_PAX_PAGEEXEC ? 'P' : 'p',
61465+ p->mm->pax_flags & MF_PAX_EMUTRAMP ? 'E' : 'e',
61466+ p->mm->pax_flags & MF_PAX_MPROTECT ? 'M' : 'm',
61467+ p->mm->pax_flags & MF_PAX_RANDMMAP ? 'R' : 'r',
61468+ p->mm->pax_flags & MF_PAX_SEGMEXEC ? 'S' : 's');
61469+ else
61470+ seq_printf(m, "PaX:\t-----\n");
61471+}
61472+#endif
61473+
61474 int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
61475 struct pid *pid, struct task_struct *task)
61476 {
61477@@ -381,9 +397,24 @@ int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
61478 task_cpus_allowed(m, task);
61479 cpuset_task_status_allowed(m, task);
61480 task_context_switch_counts(m, task);
61481+
61482+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
61483+ task_pax(m, task);
61484+#endif
61485+
61486+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
61487+ task_grsec_rbac(m, task);
61488+#endif
61489+
61490 return 0;
61491 }
61492
61493+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
61494+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
61495+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
61496+ _mm->pax_flags & MF_PAX_SEGMEXEC))
61497+#endif
61498+
61499 static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
61500 struct pid *pid, struct task_struct *task, int whole)
61501 {
61502@@ -405,6 +436,13 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
61503 char tcomm[sizeof(task->comm)];
61504 unsigned long flags;
61505
61506+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
61507+ if (current->exec_id != m->exec_id) {
61508+ gr_log_badprocpid("stat");
61509+ return 0;
61510+ }
61511+#endif
61512+
61513 state = *get_task_state(task);
61514 vsize = eip = esp = 0;
61515 permitted = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
61516@@ -476,6 +514,19 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
61517 gtime = task_gtime(task);
61518 }
61519
61520+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
61521+ if (PAX_RAND_FLAGS(mm)) {
61522+ eip = 0;
61523+ esp = 0;
61524+ wchan = 0;
61525+ }
61526+#endif
61527+#ifdef CONFIG_GRKERNSEC_HIDESYM
61528+ wchan = 0;
61529+ eip =0;
61530+ esp =0;
61531+#endif
61532+
61533 /* scale priority and nice values from timeslices to -20..20 */
61534 /* to make it look like a "normal" Unix priority/nice value */
61535 priority = task_prio(task);
61536@@ -512,9 +563,15 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
61537 seq_put_decimal_ull(m, ' ', vsize);
61538 seq_put_decimal_ull(m, ' ', mm ? get_mm_rss(mm) : 0);
61539 seq_put_decimal_ull(m, ' ', rsslim);
61540+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
61541+ seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->start_code : 1) : 0));
61542+ seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->end_code : 1) : 0));
61543+ seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 0 : ((permitted && mm) ? mm->start_stack : 0));
61544+#else
61545 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->start_code : 1) : 0);
61546 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->end_code : 1) : 0);
61547 seq_put_decimal_ull(m, ' ', (permitted && mm) ? mm->start_stack : 0);
61548+#endif
61549 seq_put_decimal_ull(m, ' ', esp);
61550 seq_put_decimal_ull(m, ' ', eip);
61551 /* The signal information here is obsolete.
61552@@ -536,7 +593,11 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
61553 seq_put_decimal_ull(m, ' ', cputime_to_clock_t(gtime));
61554 seq_put_decimal_ll(m, ' ', cputime_to_clock_t(cgtime));
61555
61556- if (mm && permitted) {
61557+ if (mm && permitted
61558+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
61559+ && !PAX_RAND_FLAGS(mm)
61560+#endif
61561+ ) {
61562 seq_put_decimal_ull(m, ' ', mm->start_data);
61563 seq_put_decimal_ull(m, ' ', mm->end_data);
61564 seq_put_decimal_ull(m, ' ', mm->start_brk);
61565@@ -574,8 +635,15 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
61566 struct pid *pid, struct task_struct *task)
61567 {
61568 unsigned long size = 0, resident = 0, shared = 0, text = 0, data = 0;
61569- struct mm_struct *mm = get_task_mm(task);
61570+ struct mm_struct *mm;
61571
61572+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
61573+ if (current->exec_id != m->exec_id) {
61574+ gr_log_badprocpid("statm");
61575+ return 0;
61576+ }
61577+#endif
61578+ mm = get_task_mm(task);
61579 if (mm) {
61580 size = task_statm(mm, &shared, &text, &data, &resident);
61581 mmput(mm);
61582@@ -598,6 +666,13 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
61583 return 0;
61584 }
61585
61586+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
61587+int proc_pid_ipaddr(struct task_struct *task, char *buffer)
61588+{
61589+ return sprintf(buffer, "%pI4\n", &task->signal->curr_ip);
61590+}
61591+#endif
61592+
61593 #ifdef CONFIG_CHECKPOINT_RESTORE
61594 static struct pid *
61595 get_children_pid(struct inode *inode, struct pid *pid_prev, loff_t pos)
61596diff --git a/fs/proc/base.c b/fs/proc/base.c
61597index 1485e38..8ad4236 100644
61598--- a/fs/proc/base.c
61599+++ b/fs/proc/base.c
61600@@ -113,6 +113,14 @@ struct pid_entry {
61601 union proc_op op;
61602 };
61603
61604+struct getdents_callback {
61605+ struct linux_dirent __user * current_dir;
61606+ struct linux_dirent __user * previous;
61607+ struct file * file;
61608+ int count;
61609+ int error;
61610+};
61611+
61612 #define NOD(NAME, MODE, IOP, FOP, OP) { \
61613 .name = (NAME), \
61614 .len = sizeof(NAME) - 1, \
61615@@ -210,6 +218,9 @@ static int proc_pid_cmdline(struct task_struct *task, char * buffer)
61616 if (!mm->arg_end)
61617 goto out_mm; /* Shh! No looking before we're done */
61618
61619+ if (gr_acl_handle_procpidmem(task))
61620+ goto out_mm;
61621+
61622 len = mm->arg_end - mm->arg_start;
61623
61624 if (len > PAGE_SIZE)
61625@@ -237,12 +248,28 @@ out:
61626 return res;
61627 }
61628
61629+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
61630+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
61631+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
61632+ _mm->pax_flags & MF_PAX_SEGMEXEC))
61633+#endif
61634+
61635 static int proc_pid_auxv(struct task_struct *task, char *buffer)
61636 {
61637 struct mm_struct *mm = mm_access(task, PTRACE_MODE_READ);
61638 int res = PTR_ERR(mm);
61639 if (mm && !IS_ERR(mm)) {
61640 unsigned int nwords = 0;
61641+
61642+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
61643+ /* allow if we're currently ptracing this task */
61644+ if (PAX_RAND_FLAGS(mm) &&
61645+ (!(task->ptrace & PT_PTRACED) || (task->parent != current))) {
61646+ mmput(mm);
61647+ return 0;
61648+ }
61649+#endif
61650+
61651 do {
61652 nwords += 2;
61653 } while (mm->saved_auxv[nwords - 2] != 0); /* AT_NULL */
61654@@ -256,7 +283,7 @@ static int proc_pid_auxv(struct task_struct *task, char *buffer)
61655 }
61656
61657
61658-#ifdef CONFIG_KALLSYMS
61659+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
61660 /*
61661 * Provides a wchan file via kallsyms in a proper one-value-per-file format.
61662 * Returns the resolved symbol. If that fails, simply return the address.
61663@@ -295,7 +322,7 @@ static void unlock_trace(struct task_struct *task)
61664 mutex_unlock(&task->signal->cred_guard_mutex);
61665 }
61666
61667-#ifdef CONFIG_STACKTRACE
61668+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
61669
61670 #define MAX_STACK_TRACE_DEPTH 64
61671
61672@@ -518,7 +545,7 @@ static int proc_pid_limits(struct task_struct *task, char *buffer)
61673 return count;
61674 }
61675
61676-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
61677+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
61678 static int proc_pid_syscall(struct task_struct *task, char *buffer)
61679 {
61680 long nr;
61681@@ -547,7 +574,7 @@ static int proc_pid_syscall(struct task_struct *task, char *buffer)
61682 /************************************************************************/
61683
61684 /* permission checks */
61685-static int proc_fd_access_allowed(struct inode *inode)
61686+static int proc_fd_access_allowed(struct inode *inode, unsigned int log)
61687 {
61688 struct task_struct *task;
61689 int allowed = 0;
61690@@ -557,7 +584,10 @@ static int proc_fd_access_allowed(struct inode *inode)
61691 */
61692 task = get_proc_task(inode);
61693 if (task) {
61694- allowed = ptrace_may_access(task, PTRACE_MODE_READ);
61695+ if (log)
61696+ allowed = ptrace_may_access(task, PTRACE_MODE_READ);
61697+ else
61698+ allowed = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
61699 put_task_struct(task);
61700 }
61701 return allowed;
61702@@ -588,10 +618,35 @@ static bool has_pid_permissions(struct pid_namespace *pid,
61703 struct task_struct *task,
61704 int hide_pid_min)
61705 {
61706+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
61707+ return false;
61708+
61709+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
61710+ rcu_read_lock();
61711+ {
61712+ const struct cred *tmpcred = current_cred();
61713+ const struct cred *cred = __task_cred(task);
61714+
61715+ if (uid_eq(tmpcred->uid, GLOBAL_ROOT_UID) || uid_eq(tmpcred->uid, cred->uid)
61716+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
61717+ || in_group_p(grsec_proc_gid)
61718+#endif
61719+ ) {
61720+ rcu_read_unlock();
61721+ return true;
61722+ }
61723+ }
61724+ rcu_read_unlock();
61725+
61726+ if (!pid->hide_pid)
61727+ return false;
61728+#endif
61729+
61730 if (pid->hide_pid < hide_pid_min)
61731 return true;
61732 if (in_group_p(pid->pid_gid))
61733 return true;
61734+
61735 return ptrace_may_access(task, PTRACE_MODE_READ);
61736 }
61737
61738@@ -609,7 +664,11 @@ static int proc_pid_permission(struct inode *inode, int mask)
61739 put_task_struct(task);
61740
61741 if (!has_perms) {
61742+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
61743+ {
61744+#else
61745 if (pid->hide_pid == 2) {
61746+#endif
61747 /*
61748 * Let's make getdents(), stat(), and open()
61749 * consistent with each other. If a process
61750@@ -707,6 +766,11 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
61751 if (!task)
61752 return -ESRCH;
61753
61754+ if (gr_acl_handle_procpidmem(task)) {
61755+ put_task_struct(task);
61756+ return -EPERM;
61757+ }
61758+
61759 mm = mm_access(task, mode);
61760 put_task_struct(task);
61761
61762@@ -722,6 +786,10 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
61763
61764 file->private_data = mm;
61765
61766+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
61767+ file->f_version = current->exec_id;
61768+#endif
61769+
61770 return 0;
61771 }
61772
61773@@ -743,6 +811,17 @@ static ssize_t mem_rw(struct file *file, char __user *buf,
61774 ssize_t copied;
61775 char *page;
61776
61777+#ifdef CONFIG_GRKERNSEC
61778+ if (write)
61779+ return -EPERM;
61780+#endif
61781+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
61782+ if (file->f_version != current->exec_id) {
61783+ gr_log_badprocpid("mem");
61784+ return 0;
61785+ }
61786+#endif
61787+
61788 if (!mm)
61789 return 0;
61790
61791@@ -755,7 +834,7 @@ static ssize_t mem_rw(struct file *file, char __user *buf,
61792 goto free;
61793
61794 while (count > 0) {
61795- int this_len = min_t(int, count, PAGE_SIZE);
61796+ ssize_t this_len = min_t(ssize_t, count, PAGE_SIZE);
61797
61798 if (write && copy_from_user(page, buf, this_len)) {
61799 copied = -EFAULT;
61800@@ -847,6 +926,13 @@ static ssize_t environ_read(struct file *file, char __user *buf,
61801 if (!mm)
61802 return 0;
61803
61804+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
61805+ if (file->f_version != current->exec_id) {
61806+ gr_log_badprocpid("environ");
61807+ return 0;
61808+ }
61809+#endif
61810+
61811 page = (char *)__get_free_page(GFP_TEMPORARY);
61812 if (!page)
61813 return -ENOMEM;
61814@@ -856,7 +942,7 @@ static ssize_t environ_read(struct file *file, char __user *buf,
61815 goto free;
61816 while (count > 0) {
61817 size_t this_len, max_len;
61818- int retval;
61819+ ssize_t retval;
61820
61821 if (src >= (mm->env_end - mm->env_start))
61822 break;
61823@@ -1461,7 +1547,7 @@ static void *proc_pid_follow_link(struct dentry *dentry, struct nameidata *nd)
61824 int error = -EACCES;
61825
61826 /* Are we allowed to snoop on the tasks file descriptors? */
61827- if (!proc_fd_access_allowed(inode))
61828+ if (!proc_fd_access_allowed(inode, 0))
61829 goto out;
61830
61831 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
61832@@ -1505,8 +1591,18 @@ static int proc_pid_readlink(struct dentry * dentry, char __user * buffer, int b
61833 struct path path;
61834
61835 /* Are we allowed to snoop on the tasks file descriptors? */
61836- if (!proc_fd_access_allowed(inode))
61837- goto out;
61838+ /* logging this is needed for learning on chromium to work properly,
61839+ but we don't want to flood the logs from 'ps' which does a readlink
61840+ on /proc/fd/2 of tasks in the listing, nor do we want 'ps' to learn
61841+ CAP_SYS_PTRACE as it's not necessary for its basic functionality
61842+ */
61843+ if (dentry->d_name.name[0] == '2' && dentry->d_name.name[1] == '\0') {
61844+ if (!proc_fd_access_allowed(inode,0))
61845+ goto out;
61846+ } else {
61847+ if (!proc_fd_access_allowed(inode,1))
61848+ goto out;
61849+ }
61850
61851 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
61852 if (error)
61853@@ -1556,7 +1652,11 @@ struct inode *proc_pid_make_inode(struct super_block * sb, struct task_struct *t
61854 rcu_read_lock();
61855 cred = __task_cred(task);
61856 inode->i_uid = cred->euid;
61857+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
61858+ inode->i_gid = grsec_proc_gid;
61859+#else
61860 inode->i_gid = cred->egid;
61861+#endif
61862 rcu_read_unlock();
61863 }
61864 security_task_to_inode(task, inode);
61865@@ -1592,10 +1692,19 @@ int pid_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
61866 return -ENOENT;
61867 }
61868 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
61869+#ifdef CONFIG_GRKERNSEC_PROC_USER
61870+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
61871+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
61872+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
61873+#endif
61874 task_dumpable(task)) {
61875 cred = __task_cred(task);
61876 stat->uid = cred->euid;
61877+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
61878+ stat->gid = grsec_proc_gid;
61879+#else
61880 stat->gid = cred->egid;
61881+#endif
61882 }
61883 }
61884 rcu_read_unlock();
61885@@ -1633,11 +1742,20 @@ int pid_revalidate(struct dentry *dentry, unsigned int flags)
61886
61887 if (task) {
61888 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
61889+#ifdef CONFIG_GRKERNSEC_PROC_USER
61890+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
61891+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
61892+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
61893+#endif
61894 task_dumpable(task)) {
61895 rcu_read_lock();
61896 cred = __task_cred(task);
61897 inode->i_uid = cred->euid;
61898+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
61899+ inode->i_gid = grsec_proc_gid;
61900+#else
61901 inode->i_gid = cred->egid;
61902+#endif
61903 rcu_read_unlock();
61904 } else {
61905 inode->i_uid = GLOBAL_ROOT_UID;
61906@@ -2166,6 +2284,9 @@ static struct dentry *proc_pident_lookup(struct inode *dir,
61907 if (!task)
61908 goto out_no_task;
61909
61910+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
61911+ goto out;
61912+
61913 /*
61914 * Yes, it does not scale. And it should not. Don't add
61915 * new entries into /proc/<tgid>/ without very good reasons.
61916@@ -2196,6 +2317,9 @@ static int proc_pident_readdir(struct file *file, struct dir_context *ctx,
61917 if (!task)
61918 return -ENOENT;
61919
61920+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
61921+ goto out;
61922+
61923 if (!dir_emit_dots(file, ctx))
61924 goto out;
61925
61926@@ -2585,7 +2709,7 @@ static const struct pid_entry tgid_base_stuff[] = {
61927 REG("autogroup", S_IRUGO|S_IWUSR, proc_pid_sched_autogroup_operations),
61928 #endif
61929 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
61930-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
61931+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
61932 INF("syscall", S_IRUGO, proc_pid_syscall),
61933 #endif
61934 INF("cmdline", S_IRUGO, proc_pid_cmdline),
61935@@ -2610,10 +2734,10 @@ static const struct pid_entry tgid_base_stuff[] = {
61936 #ifdef CONFIG_SECURITY
61937 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
61938 #endif
61939-#ifdef CONFIG_KALLSYMS
61940+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
61941 INF("wchan", S_IRUGO, proc_pid_wchan),
61942 #endif
61943-#ifdef CONFIG_STACKTRACE
61944+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
61945 ONE("stack", S_IRUGO, proc_pid_stack),
61946 #endif
61947 #ifdef CONFIG_SCHEDSTATS
61948@@ -2647,6 +2771,9 @@ static const struct pid_entry tgid_base_stuff[] = {
61949 #ifdef CONFIG_HARDWALL
61950 INF("hardwall", S_IRUGO, proc_pid_hardwall),
61951 #endif
61952+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
61953+ INF("ipaddr", S_IRUSR, proc_pid_ipaddr),
61954+#endif
61955 #ifdef CONFIG_USER_NS
61956 REG("uid_map", S_IRUGO|S_IWUSR, proc_uid_map_operations),
61957 REG("gid_map", S_IRUGO|S_IWUSR, proc_gid_map_operations),
61958@@ -2777,7 +2904,14 @@ static int proc_pid_instantiate(struct inode *dir,
61959 if (!inode)
61960 goto out;
61961
61962+#ifdef CONFIG_GRKERNSEC_PROC_USER
61963+ inode->i_mode = S_IFDIR|S_IRUSR|S_IXUSR;
61964+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
61965+ inode->i_gid = grsec_proc_gid;
61966+ inode->i_mode = S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP;
61967+#else
61968 inode->i_mode = S_IFDIR|S_IRUGO|S_IXUGO;
61969+#endif
61970 inode->i_op = &proc_tgid_base_inode_operations;
61971 inode->i_fop = &proc_tgid_base_operations;
61972 inode->i_flags|=S_IMMUTABLE;
61973@@ -2815,7 +2949,11 @@ struct dentry *proc_pid_lookup(struct inode *dir, struct dentry * dentry, unsign
61974 if (!task)
61975 goto out;
61976
61977+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
61978+ goto out_put_task;
61979+
61980 result = proc_pid_instantiate(dir, dentry, task, NULL);
61981+out_put_task:
61982 put_task_struct(task);
61983 out:
61984 return ERR_PTR(result);
61985@@ -2921,7 +3059,7 @@ static const struct pid_entry tid_base_stuff[] = {
61986 REG("sched", S_IRUGO|S_IWUSR, proc_pid_sched_operations),
61987 #endif
61988 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
61989-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
61990+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
61991 INF("syscall", S_IRUGO, proc_pid_syscall),
61992 #endif
61993 INF("cmdline", S_IRUGO, proc_pid_cmdline),
61994@@ -2948,10 +3086,10 @@ static const struct pid_entry tid_base_stuff[] = {
61995 #ifdef CONFIG_SECURITY
61996 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
61997 #endif
61998-#ifdef CONFIG_KALLSYMS
61999+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
62000 INF("wchan", S_IRUGO, proc_pid_wchan),
62001 #endif
62002-#ifdef CONFIG_STACKTRACE
62003+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
62004 ONE("stack", S_IRUGO, proc_pid_stack),
62005 #endif
62006 #ifdef CONFIG_SCHEDSTATS
62007diff --git a/fs/proc/cmdline.c b/fs/proc/cmdline.c
62008index 82676e3..5f8518a 100644
62009--- a/fs/proc/cmdline.c
62010+++ b/fs/proc/cmdline.c
62011@@ -23,7 +23,11 @@ static const struct file_operations cmdline_proc_fops = {
62012
62013 static int __init proc_cmdline_init(void)
62014 {
62015+#ifdef CONFIG_GRKERNSEC_PROC_ADD
62016+ proc_create_grsec("cmdline", 0, NULL, &cmdline_proc_fops);
62017+#else
62018 proc_create("cmdline", 0, NULL, &cmdline_proc_fops);
62019+#endif
62020 return 0;
62021 }
62022 module_init(proc_cmdline_init);
62023diff --git a/fs/proc/devices.c b/fs/proc/devices.c
62024index b143471..bb105e5 100644
62025--- a/fs/proc/devices.c
62026+++ b/fs/proc/devices.c
62027@@ -64,7 +64,11 @@ static const struct file_operations proc_devinfo_operations = {
62028
62029 static int __init proc_devices_init(void)
62030 {
62031+#ifdef CONFIG_GRKERNSEC_PROC_ADD
62032+ proc_create_grsec("devices", 0, NULL, &proc_devinfo_operations);
62033+#else
62034 proc_create("devices", 0, NULL, &proc_devinfo_operations);
62035+#endif
62036 return 0;
62037 }
62038 module_init(proc_devices_init);
62039diff --git a/fs/proc/fd.c b/fs/proc/fd.c
62040index 985ea88..d118a0a 100644
62041--- a/fs/proc/fd.c
62042+++ b/fs/proc/fd.c
62043@@ -25,7 +25,8 @@ static int seq_show(struct seq_file *m, void *v)
62044 if (!task)
62045 return -ENOENT;
62046
62047- files = get_files_struct(task);
62048+ if (!gr_acl_handle_procpidmem(task))
62049+ files = get_files_struct(task);
62050 put_task_struct(task);
62051
62052 if (files) {
62053@@ -283,11 +284,21 @@ static struct dentry *proc_lookupfd(struct inode *dir, struct dentry *dentry,
62054 */
62055 int proc_fd_permission(struct inode *inode, int mask)
62056 {
62057+ struct task_struct *task;
62058 int rv = generic_permission(inode, mask);
62059- if (rv == 0)
62060- return 0;
62061+
62062 if (task_tgid(current) == proc_pid(inode))
62063 rv = 0;
62064+
62065+ task = get_proc_task(inode);
62066+ if (task == NULL)
62067+ return rv;
62068+
62069+ if (gr_acl_handle_procpidmem(task))
62070+ rv = -EACCES;
62071+
62072+ put_task_struct(task);
62073+
62074 return rv;
62075 }
62076
62077diff --git a/fs/proc/inode.c b/fs/proc/inode.c
62078index 8eaa1ba..cc6ff42 100644
62079--- a/fs/proc/inode.c
62080+++ b/fs/proc/inode.c
62081@@ -23,11 +23,17 @@
62082 #include <linux/slab.h>
62083 #include <linux/mount.h>
62084 #include <linux/magic.h>
62085+#include <linux/grsecurity.h>
62086
62087 #include <asm/uaccess.h>
62088
62089 #include "internal.h"
62090
62091+#ifdef CONFIG_PROC_SYSCTL
62092+extern const struct inode_operations proc_sys_inode_operations;
62093+extern const struct inode_operations proc_sys_dir_operations;
62094+#endif
62095+
62096 static void proc_evict_inode(struct inode *inode)
62097 {
62098 struct proc_dir_entry *de;
62099@@ -55,6 +61,13 @@ static void proc_evict_inode(struct inode *inode)
62100 ns = PROC_I(inode)->ns.ns;
62101 if (ns_ops && ns)
62102 ns_ops->put(ns);
62103+
62104+#ifdef CONFIG_PROC_SYSCTL
62105+ if (inode->i_op == &proc_sys_inode_operations ||
62106+ inode->i_op == &proc_sys_dir_operations)
62107+ gr_handle_delete(inode->i_ino, inode->i_sb->s_dev);
62108+#endif
62109+
62110 }
62111
62112 static struct kmem_cache * proc_inode_cachep;
62113@@ -405,7 +418,11 @@ struct inode *proc_get_inode(struct super_block *sb, struct proc_dir_entry *de)
62114 if (de->mode) {
62115 inode->i_mode = de->mode;
62116 inode->i_uid = de->uid;
62117+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
62118+ inode->i_gid = grsec_proc_gid;
62119+#else
62120 inode->i_gid = de->gid;
62121+#endif
62122 }
62123 if (de->size)
62124 inode->i_size = de->size;
62125diff --git a/fs/proc/internal.h b/fs/proc/internal.h
62126index 651d09a..3d7f0bf 100644
62127--- a/fs/proc/internal.h
62128+++ b/fs/proc/internal.h
62129@@ -48,7 +48,7 @@ struct proc_dir_entry {
62130 spinlock_t pde_unload_lock; /* proc_fops checks and pde_users bumps */
62131 u8 namelen;
62132 char name[];
62133-};
62134+} __randomize_layout;
62135
62136 union proc_op {
62137 int (*proc_get_link)(struct dentry *, struct path *);
62138@@ -67,7 +67,7 @@ struct proc_inode {
62139 struct ctl_table *sysctl_entry;
62140 struct proc_ns ns;
62141 struct inode vfs_inode;
62142-};
62143+} __randomize_layout;
62144
62145 /*
62146 * General functions
62147@@ -155,6 +155,9 @@ extern int proc_pid_status(struct seq_file *, struct pid_namespace *,
62148 struct pid *, struct task_struct *);
62149 extern int proc_pid_statm(struct seq_file *, struct pid_namespace *,
62150 struct pid *, struct task_struct *);
62151+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
62152+extern int proc_pid_ipaddr(struct task_struct *task, char *buffer);
62153+#endif
62154
62155 /*
62156 * base.c
62157diff --git a/fs/proc/interrupts.c b/fs/proc/interrupts.c
62158index 05029c0..7ea1987 100644
62159--- a/fs/proc/interrupts.c
62160+++ b/fs/proc/interrupts.c
62161@@ -47,7 +47,11 @@ static const struct file_operations proc_interrupts_operations = {
62162
62163 static int __init proc_interrupts_init(void)
62164 {
62165+#ifdef CONFIG_GRKERNSEC_PROC_ADD
62166+ proc_create_grsec("interrupts", 0, NULL, &proc_interrupts_operations);
62167+#else
62168 proc_create("interrupts", 0, NULL, &proc_interrupts_operations);
62169+#endif
62170 return 0;
62171 }
62172 module_init(proc_interrupts_init);
62173diff --git a/fs/proc/kcore.c b/fs/proc/kcore.c
62174index 06ea155..9a798c7 100644
62175--- a/fs/proc/kcore.c
62176+++ b/fs/proc/kcore.c
62177@@ -484,9 +484,10 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
62178 * the addresses in the elf_phdr on our list.
62179 */
62180 start = kc_offset_to_vaddr(*fpos - elf_buflen);
62181- if ((tsz = (PAGE_SIZE - (start & ~PAGE_MASK))) > buflen)
62182+ tsz = PAGE_SIZE - (start & ~PAGE_MASK);
62183+ if (tsz > buflen)
62184 tsz = buflen;
62185-
62186+
62187 while (buflen) {
62188 struct kcore_list *m;
62189
62190@@ -515,20 +516,23 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
62191 kfree(elf_buf);
62192 } else {
62193 if (kern_addr_valid(start)) {
62194- unsigned long n;
62195+ char *elf_buf;
62196+ mm_segment_t oldfs;
62197
62198- n = copy_to_user(buffer, (char *)start, tsz);
62199- /*
62200- * We cannot distinguish between fault on source
62201- * and fault on destination. When this happens
62202- * we clear too and hope it will trigger the
62203- * EFAULT again.
62204- */
62205- if (n) {
62206- if (clear_user(buffer + tsz - n,
62207- n))
62208+ elf_buf = kmalloc(tsz, GFP_KERNEL);
62209+ if (!elf_buf)
62210+ return -ENOMEM;
62211+ oldfs = get_fs();
62212+ set_fs(KERNEL_DS);
62213+ if (!__copy_from_user(elf_buf, (const void __user *)start, tsz)) {
62214+ set_fs(oldfs);
62215+ if (copy_to_user(buffer, elf_buf, tsz)) {
62216+ kfree(elf_buf);
62217 return -EFAULT;
62218+ }
62219 }
62220+ set_fs(oldfs);
62221+ kfree(elf_buf);
62222 } else {
62223 if (clear_user(buffer, tsz))
62224 return -EFAULT;
62225@@ -548,6 +552,9 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
62226
62227 static int open_kcore(struct inode *inode, struct file *filp)
62228 {
62229+#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
62230+ return -EPERM;
62231+#endif
62232 if (!capable(CAP_SYS_RAWIO))
62233 return -EPERM;
62234 if (kcore_need_update)
62235diff --git a/fs/proc/meminfo.c b/fs/proc/meminfo.c
62236index 59d85d6..ac6fc05 100644
62237--- a/fs/proc/meminfo.c
62238+++ b/fs/proc/meminfo.c
62239@@ -153,7 +153,7 @@ static int meminfo_proc_show(struct seq_file *m, void *v)
62240 vmi.used >> 10,
62241 vmi.largest_chunk >> 10
62242 #ifdef CONFIG_MEMORY_FAILURE
62243- ,atomic_long_read(&num_poisoned_pages) << (PAGE_SHIFT - 10)
62244+ ,atomic_long_read_unchecked(&num_poisoned_pages) << (PAGE_SHIFT - 10)
62245 #endif
62246 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
62247 ,K(global_page_state(NR_ANON_TRANSPARENT_HUGEPAGES) *
62248diff --git a/fs/proc/nommu.c b/fs/proc/nommu.c
62249index ccfd99b..1b7e255 100644
62250--- a/fs/proc/nommu.c
62251+++ b/fs/proc/nommu.c
62252@@ -66,7 +66,7 @@ static int nommu_region_show(struct seq_file *m, struct vm_region *region)
62253 if (len < 1)
62254 len = 1;
62255 seq_printf(m, "%*c", len, ' ');
62256- seq_path(m, &file->f_path, "");
62257+ seq_path(m, &file->f_path, "\n\\");
62258 }
62259
62260 seq_putc(m, '\n');
62261diff --git a/fs/proc/proc_net.c b/fs/proc/proc_net.c
62262index 4677bb7..408e936 100644
62263--- a/fs/proc/proc_net.c
62264+++ b/fs/proc/proc_net.c
62265@@ -23,6 +23,7 @@
62266 #include <linux/nsproxy.h>
62267 #include <net/net_namespace.h>
62268 #include <linux/seq_file.h>
62269+#include <linux/grsecurity.h>
62270
62271 #include "internal.h"
62272
62273@@ -109,6 +110,17 @@ static struct net *get_proc_task_net(struct inode *dir)
62274 struct task_struct *task;
62275 struct nsproxy *ns;
62276 struct net *net = NULL;
62277+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
62278+ const struct cred *cred = current_cred();
62279+#endif
62280+
62281+#ifdef CONFIG_GRKERNSEC_PROC_USER
62282+ if (!uid_eq(cred->fsuid, GLOBAL_ROOT_UID))
62283+ return net;
62284+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
62285+ if (!uid_eq(cred->fsuid, GLOBAL_ROOT_UID) && !in_group_p(grsec_proc_gid))
62286+ return net;
62287+#endif
62288
62289 rcu_read_lock();
62290 task = pid_task(proc_pid(dir), PIDTYPE_PID);
62291diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c
62292index 7129046..6914844 100644
62293--- a/fs/proc/proc_sysctl.c
62294+++ b/fs/proc/proc_sysctl.c
62295@@ -11,13 +11,21 @@
62296 #include <linux/namei.h>
62297 #include <linux/mm.h>
62298 #include <linux/module.h>
62299+#include <linux/nsproxy.h>
62300+#ifdef CONFIG_GRKERNSEC
62301+#include <net/net_namespace.h>
62302+#endif
62303 #include "internal.h"
62304
62305+extern int gr_handle_chroot_sysctl(const int op);
62306+extern int gr_handle_sysctl_mod(const char *dirname, const char *name,
62307+ const int op);
62308+
62309 static const struct dentry_operations proc_sys_dentry_operations;
62310 static const struct file_operations proc_sys_file_operations;
62311-static const struct inode_operations proc_sys_inode_operations;
62312+const struct inode_operations proc_sys_inode_operations;
62313 static const struct file_operations proc_sys_dir_file_operations;
62314-static const struct inode_operations proc_sys_dir_operations;
62315+const struct inode_operations proc_sys_dir_operations;
62316
62317 void proc_sys_poll_notify(struct ctl_table_poll *poll)
62318 {
62319@@ -467,6 +475,9 @@ static struct dentry *proc_sys_lookup(struct inode *dir, struct dentry *dentry,
62320
62321 err = NULL;
62322 d_set_d_op(dentry, &proc_sys_dentry_operations);
62323+
62324+ gr_handle_proc_create(dentry, inode);
62325+
62326 d_add(dentry, inode);
62327
62328 out:
62329@@ -482,6 +493,7 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
62330 struct inode *inode = file_inode(filp);
62331 struct ctl_table_header *head = grab_header(inode);
62332 struct ctl_table *table = PROC_I(inode)->sysctl_entry;
62333+ int op = write ? MAY_WRITE : MAY_READ;
62334 ssize_t error;
62335 size_t res;
62336
62337@@ -493,7 +505,7 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
62338 * and won't be until we finish.
62339 */
62340 error = -EPERM;
62341- if (sysctl_perm(head, table, write ? MAY_WRITE : MAY_READ))
62342+ if (sysctl_perm(head, table, op))
62343 goto out;
62344
62345 /* if that can happen at all, it should be -EINVAL, not -EISDIR */
62346@@ -501,6 +513,27 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
62347 if (!table->proc_handler)
62348 goto out;
62349
62350+#ifdef CONFIG_GRKERNSEC
62351+ error = -EPERM;
62352+ if (gr_handle_chroot_sysctl(op))
62353+ goto out;
62354+ dget(filp->f_path.dentry);
62355+ if (gr_handle_sysctl_mod(filp->f_path.dentry->d_parent->d_name.name, table->procname, op)) {
62356+ dput(filp->f_path.dentry);
62357+ goto out;
62358+ }
62359+ dput(filp->f_path.dentry);
62360+ if (!gr_acl_handle_open(filp->f_path.dentry, filp->f_path.mnt, op))
62361+ goto out;
62362+ if (write) {
62363+ if (current->nsproxy->net_ns != table->extra2) {
62364+ if (!capable(CAP_SYS_ADMIN))
62365+ goto out;
62366+ } else if (!ns_capable(current->nsproxy->net_ns->user_ns, CAP_NET_ADMIN))
62367+ goto out;
62368+ }
62369+#endif
62370+
62371 /* careful: calling conventions are nasty here */
62372 res = count;
62373 error = table->proc_handler(table, write, buf, &res, ppos);
62374@@ -598,6 +631,9 @@ static bool proc_sys_fill_cache(struct file *file,
62375 return false;
62376 } else {
62377 d_set_d_op(child, &proc_sys_dentry_operations);
62378+
62379+ gr_handle_proc_create(child, inode);
62380+
62381 d_add(child, inode);
62382 }
62383 } else {
62384@@ -641,6 +677,9 @@ static int scan(struct ctl_table_header *head, ctl_table *table,
62385 if ((*pos)++ < ctx->pos)
62386 return true;
62387
62388+ if (!gr_acl_handle_hidden_file(file->f_path.dentry, file->f_path.mnt))
62389+ return 0;
62390+
62391 if (unlikely(S_ISLNK(table->mode)))
62392 res = proc_sys_link_fill_cache(file, ctx, head, table);
62393 else
62394@@ -734,6 +773,9 @@ static int proc_sys_getattr(struct vfsmount *mnt, struct dentry *dentry, struct
62395 if (IS_ERR(head))
62396 return PTR_ERR(head);
62397
62398+ if (table && !gr_acl_handle_hidden_file(dentry, mnt))
62399+ return -ENOENT;
62400+
62401 generic_fillattr(inode, stat);
62402 if (table)
62403 stat->mode = (stat->mode & S_IFMT) | table->mode;
62404@@ -756,13 +798,13 @@ static const struct file_operations proc_sys_dir_file_operations = {
62405 .llseek = generic_file_llseek,
62406 };
62407
62408-static const struct inode_operations proc_sys_inode_operations = {
62409+const struct inode_operations proc_sys_inode_operations = {
62410 .permission = proc_sys_permission,
62411 .setattr = proc_sys_setattr,
62412 .getattr = proc_sys_getattr,
62413 };
62414
62415-static const struct inode_operations proc_sys_dir_operations = {
62416+const struct inode_operations proc_sys_dir_operations = {
62417 .lookup = proc_sys_lookup,
62418 .permission = proc_sys_permission,
62419 .setattr = proc_sys_setattr,
62420@@ -839,7 +881,7 @@ static struct ctl_dir *find_subdir(struct ctl_dir *dir,
62421 static struct ctl_dir *new_dir(struct ctl_table_set *set,
62422 const char *name, int namelen)
62423 {
62424- struct ctl_table *table;
62425+ ctl_table_no_const *table;
62426 struct ctl_dir *new;
62427 struct ctl_node *node;
62428 char *new_name;
62429@@ -851,7 +893,7 @@ static struct ctl_dir *new_dir(struct ctl_table_set *set,
62430 return NULL;
62431
62432 node = (struct ctl_node *)(new + 1);
62433- table = (struct ctl_table *)(node + 1);
62434+ table = (ctl_table_no_const *)(node + 1);
62435 new_name = (char *)(table + 2);
62436 memcpy(new_name, name, namelen);
62437 new_name[namelen] = '\0';
62438@@ -1020,7 +1062,8 @@ static int sysctl_check_table(const char *path, struct ctl_table *table)
62439 static struct ctl_table_header *new_links(struct ctl_dir *dir, struct ctl_table *table,
62440 struct ctl_table_root *link_root)
62441 {
62442- struct ctl_table *link_table, *entry, *link;
62443+ ctl_table_no_const *link_table, *link;
62444+ struct ctl_table *entry;
62445 struct ctl_table_header *links;
62446 struct ctl_node *node;
62447 char *link_name;
62448@@ -1043,7 +1086,7 @@ static struct ctl_table_header *new_links(struct ctl_dir *dir, struct ctl_table
62449 return NULL;
62450
62451 node = (struct ctl_node *)(links + 1);
62452- link_table = (struct ctl_table *)(node + nr_entries);
62453+ link_table = (ctl_table_no_const *)(node + nr_entries);
62454 link_name = (char *)&link_table[nr_entries + 1];
62455
62456 for (link = link_table, entry = table; entry->procname; link++, entry++) {
62457@@ -1291,8 +1334,8 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
62458 struct ctl_table_header ***subheader, struct ctl_table_set *set,
62459 struct ctl_table *table)
62460 {
62461- struct ctl_table *ctl_table_arg = NULL;
62462- struct ctl_table *entry, *files;
62463+ ctl_table_no_const *ctl_table_arg = NULL, *files = NULL;
62464+ struct ctl_table *entry;
62465 int nr_files = 0;
62466 int nr_dirs = 0;
62467 int err = -ENOMEM;
62468@@ -1304,10 +1347,9 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
62469 nr_files++;
62470 }
62471
62472- files = table;
62473 /* If there are mixed files and directories we need a new table */
62474 if (nr_dirs && nr_files) {
62475- struct ctl_table *new;
62476+ ctl_table_no_const *new;
62477 files = kzalloc(sizeof(struct ctl_table) * (nr_files + 1),
62478 GFP_KERNEL);
62479 if (!files)
62480@@ -1325,7 +1367,7 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
62481 /* Register everything except a directory full of subdirectories */
62482 if (nr_files || !nr_dirs) {
62483 struct ctl_table_header *header;
62484- header = __register_sysctl_table(set, path, files);
62485+ header = __register_sysctl_table(set, path, files ? files : table);
62486 if (!header) {
62487 kfree(ctl_table_arg);
62488 goto out;
62489diff --git a/fs/proc/root.c b/fs/proc/root.c
62490index 87dbcbe..55e1b4d 100644
62491--- a/fs/proc/root.c
62492+++ b/fs/proc/root.c
62493@@ -186,7 +186,15 @@ void __init proc_root_init(void)
62494 #ifdef CONFIG_PROC_DEVICETREE
62495 proc_device_tree_init();
62496 #endif
62497+#ifdef CONFIG_GRKERNSEC_PROC_ADD
62498+#ifdef CONFIG_GRKERNSEC_PROC_USER
62499+ proc_mkdir_mode("bus", S_IRUSR | S_IXUSR, NULL);
62500+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
62501+ proc_mkdir_mode("bus", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
62502+#endif
62503+#else
62504 proc_mkdir("bus", NULL);
62505+#endif
62506 proc_sys_init();
62507 }
62508
62509diff --git a/fs/proc/self.c b/fs/proc/self.c
62510index 6b6a993..807cccc 100644
62511--- a/fs/proc/self.c
62512+++ b/fs/proc/self.c
62513@@ -39,7 +39,7 @@ static void *proc_self_follow_link(struct dentry *dentry, struct nameidata *nd)
62514 static void proc_self_put_link(struct dentry *dentry, struct nameidata *nd,
62515 void *cookie)
62516 {
62517- char *s = nd_get_link(nd);
62518+ const char *s = nd_get_link(nd);
62519 if (!IS_ERR(s))
62520 kfree(s);
62521 }
62522diff --git a/fs/proc/stat.c b/fs/proc/stat.c
62523index 1cf86c0..0ee1ca5 100644
62524--- a/fs/proc/stat.c
62525+++ b/fs/proc/stat.c
62526@@ -11,6 +11,7 @@
62527 #include <linux/irqnr.h>
62528 #include <asm/cputime.h>
62529 #include <linux/tick.h>
62530+#include <linux/grsecurity.h>
62531
62532 #ifndef arch_irq_stat_cpu
62533 #define arch_irq_stat_cpu(cpu) 0
62534@@ -87,6 +88,18 @@ static int show_stat(struct seq_file *p, void *v)
62535 u64 sum_softirq = 0;
62536 unsigned int per_softirq_sums[NR_SOFTIRQS] = {0};
62537 struct timespec boottime;
62538+ int unrestricted = 1;
62539+
62540+#ifdef CONFIG_GRKERNSEC_PROC_ADD
62541+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
62542+ if (!uid_eq(current_uid(), GLOBAL_ROOT_UID)
62543+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
62544+ && !in_group_p(grsec_proc_gid)
62545+#endif
62546+ )
62547+ unrestricted = 0;
62548+#endif
62549+#endif
62550
62551 user = nice = system = idle = iowait =
62552 irq = softirq = steal = 0;
62553@@ -94,6 +107,7 @@ static int show_stat(struct seq_file *p, void *v)
62554 getboottime(&boottime);
62555 jif = boottime.tv_sec;
62556
62557+ if (unrestricted) {
62558 for_each_possible_cpu(i) {
62559 user += kcpustat_cpu(i).cpustat[CPUTIME_USER];
62560 nice += kcpustat_cpu(i).cpustat[CPUTIME_NICE];
62561@@ -116,6 +130,7 @@ static int show_stat(struct seq_file *p, void *v)
62562 }
62563 }
62564 sum += arch_irq_stat();
62565+ }
62566
62567 seq_puts(p, "cpu ");
62568 seq_put_decimal_ull(p, ' ', cputime64_to_clock_t(user));
62569@@ -131,6 +146,7 @@ static int show_stat(struct seq_file *p, void *v)
62570 seq_putc(p, '\n');
62571
62572 for_each_online_cpu(i) {
62573+ if (unrestricted) {
62574 /* Copy values here to work around gcc-2.95.3, gcc-2.96 */
62575 user = kcpustat_cpu(i).cpustat[CPUTIME_USER];
62576 nice = kcpustat_cpu(i).cpustat[CPUTIME_NICE];
62577@@ -142,6 +158,7 @@ static int show_stat(struct seq_file *p, void *v)
62578 steal = kcpustat_cpu(i).cpustat[CPUTIME_STEAL];
62579 guest = kcpustat_cpu(i).cpustat[CPUTIME_GUEST];
62580 guest_nice = kcpustat_cpu(i).cpustat[CPUTIME_GUEST_NICE];
62581+ }
62582 seq_printf(p, "cpu%d", i);
62583 seq_put_decimal_ull(p, ' ', cputime64_to_clock_t(user));
62584 seq_put_decimal_ull(p, ' ', cputime64_to_clock_t(nice));
62585@@ -159,7 +176,7 @@ static int show_stat(struct seq_file *p, void *v)
62586
62587 /* sum again ? it could be updated? */
62588 for_each_irq_nr(j)
62589- seq_put_decimal_ull(p, ' ', kstat_irqs(j));
62590+ seq_put_decimal_ull(p, ' ', unrestricted ? kstat_irqs(j) : 0ULL);
62591
62592 seq_printf(p,
62593 "\nctxt %llu\n"
62594@@ -167,11 +184,11 @@ static int show_stat(struct seq_file *p, void *v)
62595 "processes %lu\n"
62596 "procs_running %lu\n"
62597 "procs_blocked %lu\n",
62598- nr_context_switches(),
62599+ unrestricted ? nr_context_switches() : 0ULL,
62600 (unsigned long)jif,
62601- total_forks,
62602- nr_running(),
62603- nr_iowait());
62604+ unrestricted ? total_forks : 0UL,
62605+ unrestricted ? nr_running() : 0UL,
62606+ unrestricted ? nr_iowait() : 0UL);
62607
62608 seq_printf(p, "softirq %llu", (unsigned long long)sum_softirq);
62609
62610diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
62611index 390bdab..83c1e8a 100644
62612--- a/fs/proc/task_mmu.c
62613+++ b/fs/proc/task_mmu.c
62614@@ -12,12 +12,19 @@
62615 #include <linux/swap.h>
62616 #include <linux/swapops.h>
62617 #include <linux/mmu_notifier.h>
62618+#include <linux/grsecurity.h>
62619
62620 #include <asm/elf.h>
62621 #include <asm/uaccess.h>
62622 #include <asm/tlbflush.h>
62623 #include "internal.h"
62624
62625+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
62626+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
62627+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
62628+ _mm->pax_flags & MF_PAX_SEGMEXEC))
62629+#endif
62630+
62631 void task_mem(struct seq_file *m, struct mm_struct *mm)
62632 {
62633 unsigned long data, text, lib, swap;
62634@@ -53,8 +60,13 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
62635 "VmExe:\t%8lu kB\n"
62636 "VmLib:\t%8lu kB\n"
62637 "VmPTE:\t%8lu kB\n"
62638- "VmSwap:\t%8lu kB\n",
62639- hiwater_vm << (PAGE_SHIFT-10),
62640+ "VmSwap:\t%8lu kB\n"
62641+
62642+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
62643+ "CsBase:\t%8lx\nCsLim:\t%8lx\n"
62644+#endif
62645+
62646+ ,hiwater_vm << (PAGE_SHIFT-10),
62647 total_vm << (PAGE_SHIFT-10),
62648 mm->locked_vm << (PAGE_SHIFT-10),
62649 mm->pinned_vm << (PAGE_SHIFT-10),
62650@@ -63,7 +75,19 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
62651 data << (PAGE_SHIFT-10),
62652 mm->stack_vm << (PAGE_SHIFT-10), text, lib,
62653 (PTRS_PER_PTE*sizeof(pte_t)*mm->nr_ptes) >> 10,
62654- swap << (PAGE_SHIFT-10));
62655+ swap << (PAGE_SHIFT-10)
62656+
62657+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
62658+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
62659+ , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_base
62660+ , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_limit
62661+#else
62662+ , mm->context.user_cs_base
62663+ , mm->context.user_cs_limit
62664+#endif
62665+#endif
62666+
62667+ );
62668 }
62669
62670 unsigned long task_vsize(struct mm_struct *mm)
62671@@ -278,13 +302,13 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
62672 pgoff = ((loff_t)vma->vm_pgoff) << PAGE_SHIFT;
62673 }
62674
62675- /* We don't show the stack guard page in /proc/maps */
62676+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
62677+ start = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_start;
62678+ end = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_end;
62679+#else
62680 start = vma->vm_start;
62681- if (stack_guard_page_start(vma, start))
62682- start += PAGE_SIZE;
62683 end = vma->vm_end;
62684- if (stack_guard_page_end(vma, end))
62685- end -= PAGE_SIZE;
62686+#endif
62687
62688 seq_printf(m, "%08lx-%08lx %c%c%c%c %08llx %02x:%02x %lu %n",
62689 start,
62690@@ -293,7 +317,11 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
62691 flags & VM_WRITE ? 'w' : '-',
62692 flags & VM_EXEC ? 'x' : '-',
62693 flags & VM_MAYSHARE ? 's' : 'p',
62694+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
62695+ PAX_RAND_FLAGS(mm) ? 0UL : pgoff,
62696+#else
62697 pgoff,
62698+#endif
62699 MAJOR(dev), MINOR(dev), ino, &len);
62700
62701 /*
62702@@ -302,7 +330,7 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
62703 */
62704 if (file) {
62705 pad_len_spaces(m, len);
62706- seq_path(m, &file->f_path, "\n");
62707+ seq_path(m, &file->f_path, "\n\\");
62708 goto done;
62709 }
62710
62711@@ -328,8 +356,9 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
62712 * Thread stack in /proc/PID/task/TID/maps or
62713 * the main process stack.
62714 */
62715- if (!is_pid || (vma->vm_start <= mm->start_stack &&
62716- vma->vm_end >= mm->start_stack)) {
62717+ if (!is_pid || (vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP)) ||
62718+ (vma->vm_start <= mm->start_stack &&
62719+ vma->vm_end >= mm->start_stack)) {
62720 name = "[stack]";
62721 } else {
62722 /* Thread stack in /proc/PID/maps */
62723@@ -353,6 +382,13 @@ static int show_map(struct seq_file *m, void *v, int is_pid)
62724 struct proc_maps_private *priv = m->private;
62725 struct task_struct *task = priv->task;
62726
62727+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
62728+ if (current->exec_id != m->exec_id) {
62729+ gr_log_badprocpid("maps");
62730+ return 0;
62731+ }
62732+#endif
62733+
62734 show_map_vma(m, vma, is_pid);
62735
62736 if (m->count < m->size) /* vma is copied successfully */
62737@@ -590,12 +626,23 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
62738 .private = &mss,
62739 };
62740
62741+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
62742+ if (current->exec_id != m->exec_id) {
62743+ gr_log_badprocpid("smaps");
62744+ return 0;
62745+ }
62746+#endif
62747 memset(&mss, 0, sizeof mss);
62748- mss.vma = vma;
62749- /* mmap_sem is held in m_start */
62750- if (vma->vm_mm && !is_vm_hugetlb_page(vma))
62751- walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
62752-
62753+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
62754+ if (!PAX_RAND_FLAGS(vma->vm_mm)) {
62755+#endif
62756+ mss.vma = vma;
62757+ /* mmap_sem is held in m_start */
62758+ if (vma->vm_mm && !is_vm_hugetlb_page(vma))
62759+ walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
62760+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
62761+ }
62762+#endif
62763 show_map_vma(m, vma, is_pid);
62764
62765 seq_printf(m,
62766@@ -613,7 +660,11 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
62767 "KernelPageSize: %8lu kB\n"
62768 "MMUPageSize: %8lu kB\n"
62769 "Locked: %8lu kB\n",
62770+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
62771+ PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : (vma->vm_end - vma->vm_start) >> 10,
62772+#else
62773 (vma->vm_end - vma->vm_start) >> 10,
62774+#endif
62775 mss.resident >> 10,
62776 (unsigned long)(mss.pss >> (10 + PSS_SHIFT)),
62777 mss.shared_clean >> 10,
62778@@ -1390,6 +1441,13 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
62779 int n;
62780 char buffer[50];
62781
62782+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
62783+ if (current->exec_id != m->exec_id) {
62784+ gr_log_badprocpid("numa_maps");
62785+ return 0;
62786+ }
62787+#endif
62788+
62789 if (!mm)
62790 return 0;
62791
62792@@ -1409,11 +1467,15 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
62793 if (n < 0)
62794 return n;
62795
62796+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
62797+ seq_printf(m, "%08lx %s", PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : vma->vm_start, buffer);
62798+#else
62799 seq_printf(m, "%08lx %s", vma->vm_start, buffer);
62800+#endif
62801
62802 if (file) {
62803 seq_printf(m, " file=");
62804- seq_path(m, &file->f_path, "\n\t= ");
62805+ seq_path(m, &file->f_path, "\n\t\\= ");
62806 } else if (vma->vm_start <= mm->brk && vma->vm_end >= mm->start_brk) {
62807 seq_printf(m, " heap");
62808 } else {
62809diff --git a/fs/proc/task_nommu.c b/fs/proc/task_nommu.c
62810index 56123a6..5a2f6ec 100644
62811--- a/fs/proc/task_nommu.c
62812+++ b/fs/proc/task_nommu.c
62813@@ -51,7 +51,7 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
62814 else
62815 bytes += kobjsize(mm);
62816
62817- if (current->fs && current->fs->users > 1)
62818+ if (current->fs && atomic_read(&current->fs->users) > 1)
62819 sbytes += kobjsize(current->fs);
62820 else
62821 bytes += kobjsize(current->fs);
62822@@ -168,7 +168,7 @@ static int nommu_vma_show(struct seq_file *m, struct vm_area_struct *vma,
62823
62824 if (file) {
62825 pad_len_spaces(m, len);
62826- seq_path(m, &file->f_path, "");
62827+ seq_path(m, &file->f_path, "\n\\");
62828 } else if (mm) {
62829 pid_t tid = vm_is_stack(priv->task, vma, is_pid);
62830
62831diff --git a/fs/proc/vmcore.c b/fs/proc/vmcore.c
62832index 9100d69..f1f9fc9 100644
62833--- a/fs/proc/vmcore.c
62834+++ b/fs/proc/vmcore.c
62835@@ -105,9 +105,13 @@ static ssize_t read_from_oldmem(char *buf, size_t count,
62836 nr_bytes = count;
62837
62838 /* If pfn is not ram, return zeros for sparse dump files */
62839- if (pfn_is_ram(pfn) == 0)
62840- memset(buf, 0, nr_bytes);
62841- else {
62842+ if (pfn_is_ram(pfn) == 0) {
62843+ if (userbuf) {
62844+ if (clear_user((char __force_user *)buf, nr_bytes))
62845+ return -EFAULT;
62846+ } else
62847+ memset(buf, 0, nr_bytes);
62848+ } else {
62849 tmp = copy_oldmem_page(pfn, buf, nr_bytes,
62850 offset, userbuf);
62851 if (tmp < 0)
62852@@ -233,7 +237,7 @@ static ssize_t __read_vmcore(char *buffer, size_t buflen, loff_t *fpos,
62853 if (*fpos < m->offset + m->size) {
62854 tsz = min_t(size_t, m->offset + m->size - *fpos, buflen);
62855 start = m->paddr + *fpos - m->offset;
62856- tmp = read_from_oldmem(buffer, tsz, &start, userbuf);
62857+ tmp = read_from_oldmem((char __force_kernel *)buffer, tsz, &start, userbuf);
62858 if (tmp < 0)
62859 return tmp;
62860 buflen -= tsz;
62861diff --git a/fs/qnx6/qnx6.h b/fs/qnx6/qnx6.h
62862index b00fcc9..e0c6381 100644
62863--- a/fs/qnx6/qnx6.h
62864+++ b/fs/qnx6/qnx6.h
62865@@ -74,7 +74,7 @@ enum {
62866 BYTESEX_BE,
62867 };
62868
62869-static inline __u64 fs64_to_cpu(struct qnx6_sb_info *sbi, __fs64 n)
62870+static inline __u64 __intentional_overflow(-1) fs64_to_cpu(struct qnx6_sb_info *sbi, __fs64 n)
62871 {
62872 if (sbi->s_bytesex == BYTESEX_LE)
62873 return le64_to_cpu((__force __le64)n);
62874@@ -90,7 +90,7 @@ static inline __fs64 cpu_to_fs64(struct qnx6_sb_info *sbi, __u64 n)
62875 return (__force __fs64)cpu_to_be64(n);
62876 }
62877
62878-static inline __u32 fs32_to_cpu(struct qnx6_sb_info *sbi, __fs32 n)
62879+static inline __u32 __intentional_overflow(-1) fs32_to_cpu(struct qnx6_sb_info *sbi, __fs32 n)
62880 {
62881 if (sbi->s_bytesex == BYTESEX_LE)
62882 return le32_to_cpu((__force __le32)n);
62883diff --git a/fs/quota/netlink.c b/fs/quota/netlink.c
62884index 16e8abb..2dcf914 100644
62885--- a/fs/quota/netlink.c
62886+++ b/fs/quota/netlink.c
62887@@ -33,7 +33,7 @@ static struct genl_family quota_genl_family = {
62888 void quota_send_warning(struct kqid qid, dev_t dev,
62889 const char warntype)
62890 {
62891- static atomic_t seq;
62892+ static atomic_unchecked_t seq;
62893 struct sk_buff *skb;
62894 void *msg_head;
62895 int ret;
62896@@ -49,7 +49,7 @@ void quota_send_warning(struct kqid qid, dev_t dev,
62897 "VFS: Not enough memory to send quota warning.\n");
62898 return;
62899 }
62900- msg_head = genlmsg_put(skb, 0, atomic_add_return(1, &seq),
62901+ msg_head = genlmsg_put(skb, 0, atomic_add_return_unchecked(1, &seq),
62902 &quota_genl_family, 0, QUOTA_NL_C_WARNING);
62903 if (!msg_head) {
62904 printk(KERN_ERR
62905diff --git a/fs/read_write.c b/fs/read_write.c
62906index e3cd280..a378473 100644
62907--- a/fs/read_write.c
62908+++ b/fs/read_write.c
62909@@ -438,7 +438,7 @@ ssize_t __kernel_write(struct file *file, const char *buf, size_t count, loff_t
62910
62911 old_fs = get_fs();
62912 set_fs(get_ds());
62913- p = (__force const char __user *)buf;
62914+ p = (const char __force_user *)buf;
62915 if (count > MAX_RW_COUNT)
62916 count = MAX_RW_COUNT;
62917 if (file->f_op->write)
62918diff --git a/fs/readdir.c b/fs/readdir.c
62919index 93d71e5..6a14be8 100644
62920--- a/fs/readdir.c
62921+++ b/fs/readdir.c
62922@@ -17,6 +17,7 @@
62923 #include <linux/security.h>
62924 #include <linux/syscalls.h>
62925 #include <linux/unistd.h>
62926+#include <linux/namei.h>
62927
62928 #include <asm/uaccess.h>
62929
62930@@ -69,6 +70,7 @@ struct old_linux_dirent {
62931 struct readdir_callback {
62932 struct dir_context ctx;
62933 struct old_linux_dirent __user * dirent;
62934+ struct file * file;
62935 int result;
62936 };
62937
62938@@ -86,6 +88,10 @@ static int fillonedir(void * __buf, const char * name, int namlen, loff_t offset
62939 buf->result = -EOVERFLOW;
62940 return -EOVERFLOW;
62941 }
62942+
62943+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
62944+ return 0;
62945+
62946 buf->result++;
62947 dirent = buf->dirent;
62948 if (!access_ok(VERIFY_WRITE, dirent,
62949@@ -117,6 +123,7 @@ SYSCALL_DEFINE3(old_readdir, unsigned int, fd,
62950 if (!f.file)
62951 return -EBADF;
62952
62953+ buf.file = f.file;
62954 error = iterate_dir(f.file, &buf.ctx);
62955 if (buf.result)
62956 error = buf.result;
62957@@ -142,6 +149,7 @@ struct getdents_callback {
62958 struct dir_context ctx;
62959 struct linux_dirent __user * current_dir;
62960 struct linux_dirent __user * previous;
62961+ struct file * file;
62962 int count;
62963 int error;
62964 };
62965@@ -163,6 +171,10 @@ static int filldir(void * __buf, const char * name, int namlen, loff_t offset,
62966 buf->error = -EOVERFLOW;
62967 return -EOVERFLOW;
62968 }
62969+
62970+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
62971+ return 0;
62972+
62973 dirent = buf->previous;
62974 if (dirent) {
62975 if (__put_user(offset, &dirent->d_off))
62976@@ -208,6 +220,7 @@ SYSCALL_DEFINE3(getdents, unsigned int, fd,
62977 if (!f.file)
62978 return -EBADF;
62979
62980+ buf.file = f.file;
62981 error = iterate_dir(f.file, &buf.ctx);
62982 if (error >= 0)
62983 error = buf.error;
62984@@ -226,6 +239,7 @@ struct getdents_callback64 {
62985 struct dir_context ctx;
62986 struct linux_dirent64 __user * current_dir;
62987 struct linux_dirent64 __user * previous;
62988+ struct file *file;
62989 int count;
62990 int error;
62991 };
62992@@ -241,6 +255,10 @@ static int filldir64(void * __buf, const char * name, int namlen, loff_t offset,
62993 buf->error = -EINVAL; /* only used if we fail.. */
62994 if (reclen > buf->count)
62995 return -EINVAL;
62996+
62997+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
62998+ return 0;
62999+
63000 dirent = buf->previous;
63001 if (dirent) {
63002 if (__put_user(offset, &dirent->d_off))
63003@@ -288,6 +306,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
63004 if (!f.file)
63005 return -EBADF;
63006
63007+ buf.file = f.file;
63008 error = iterate_dir(f.file, &buf.ctx);
63009 if (error >= 0)
63010 error = buf.error;
63011diff --git a/fs/reiserfs/do_balan.c b/fs/reiserfs/do_balan.c
63012index 2b7882b..1c5ef48 100644
63013--- a/fs/reiserfs/do_balan.c
63014+++ b/fs/reiserfs/do_balan.c
63015@@ -2051,7 +2051,7 @@ void do_balance(struct tree_balance *tb, /* tree_balance structure */
63016 return;
63017 }
63018
63019- atomic_inc(&(fs_generation(tb->tb_sb)));
63020+ atomic_inc_unchecked(&(fs_generation(tb->tb_sb)));
63021 do_balance_starts(tb);
63022
63023 /* balance leaf returns 0 except if combining L R and S into
63024diff --git a/fs/reiserfs/item_ops.c b/fs/reiserfs/item_ops.c
63025index ee382ef..f4eb6eb5 100644
63026--- a/fs/reiserfs/item_ops.c
63027+++ b/fs/reiserfs/item_ops.c
63028@@ -725,18 +725,18 @@ static void errcatch_print_vi(struct virtual_item *vi)
63029 }
63030
63031 static struct item_operations errcatch_ops = {
63032- errcatch_bytes_number,
63033- errcatch_decrement_key,
63034- errcatch_is_left_mergeable,
63035- errcatch_print_item,
63036- errcatch_check_item,
63037+ .bytes_number = errcatch_bytes_number,
63038+ .decrement_key = errcatch_decrement_key,
63039+ .is_left_mergeable = errcatch_is_left_mergeable,
63040+ .print_item = errcatch_print_item,
63041+ .check_item = errcatch_check_item,
63042
63043- errcatch_create_vi,
63044- errcatch_check_left,
63045- errcatch_check_right,
63046- errcatch_part_size,
63047- errcatch_unit_num,
63048- errcatch_print_vi
63049+ .create_vi = errcatch_create_vi,
63050+ .check_left = errcatch_check_left,
63051+ .check_right = errcatch_check_right,
63052+ .part_size = errcatch_part_size,
63053+ .unit_num = errcatch_unit_num,
63054+ .print_vi = errcatch_print_vi
63055 };
63056
63057 //////////////////////////////////////////////////////////////////////////////
63058diff --git a/fs/reiserfs/procfs.c b/fs/reiserfs/procfs.c
63059index a958444..42b2323 100644
63060--- a/fs/reiserfs/procfs.c
63061+++ b/fs/reiserfs/procfs.c
63062@@ -114,7 +114,7 @@ static int show_super(struct seq_file *m, void *unused)
63063 "SMALL_TAILS " : "NO_TAILS ",
63064 replay_only(sb) ? "REPLAY_ONLY " : "",
63065 convert_reiserfs(sb) ? "CONV " : "",
63066- atomic_read(&r->s_generation_counter),
63067+ atomic_read_unchecked(&r->s_generation_counter),
63068 SF(s_disk_reads), SF(s_disk_writes), SF(s_fix_nodes),
63069 SF(s_do_balance), SF(s_unneeded_left_neighbor),
63070 SF(s_good_search_by_key_reada), SF(s_bmaps),
63071diff --git a/fs/reiserfs/reiserfs.h b/fs/reiserfs/reiserfs.h
63072index f8adaee..0eeeeca 100644
63073--- a/fs/reiserfs/reiserfs.h
63074+++ b/fs/reiserfs/reiserfs.h
63075@@ -453,7 +453,7 @@ struct reiserfs_sb_info {
63076 /* Comment? -Hans */
63077 wait_queue_head_t s_wait;
63078 /* To be obsoleted soon by per buffer seals.. -Hans */
63079- atomic_t s_generation_counter; // increased by one every time the
63080+ atomic_unchecked_t s_generation_counter; // increased by one every time the
63081 // tree gets re-balanced
63082 unsigned long s_properties; /* File system properties. Currently holds
63083 on-disk FS format */
63084@@ -1982,7 +1982,7 @@ static inline loff_t max_reiserfs_offset(struct inode *inode)
63085 #define REISERFS_USER_MEM 1 /* reiserfs user memory mode */
63086
63087 #define fs_generation(s) (REISERFS_SB(s)->s_generation_counter)
63088-#define get_generation(s) atomic_read (&fs_generation(s))
63089+#define get_generation(s) atomic_read_unchecked (&fs_generation(s))
63090 #define FILESYSTEM_CHANGED_TB(tb) (get_generation((tb)->tb_sb) != (tb)->fs_gen)
63091 #define __fs_changed(gen,s) (gen != get_generation (s))
63092 #define fs_changed(gen,s) \
63093diff --git a/fs/select.c b/fs/select.c
63094index dfd5cb1..1754d57 100644
63095--- a/fs/select.c
63096+++ b/fs/select.c
63097@@ -20,6 +20,7 @@
63098 #include <linux/export.h>
63099 #include <linux/slab.h>
63100 #include <linux/poll.h>
63101+#include <linux/security.h>
63102 #include <linux/personality.h> /* for STICKY_TIMEOUTS */
63103 #include <linux/file.h>
63104 #include <linux/fdtable.h>
63105@@ -880,6 +881,7 @@ int do_sys_poll(struct pollfd __user *ufds, unsigned int nfds,
63106 struct poll_list *walk = head;
63107 unsigned long todo = nfds;
63108
63109+ gr_learn_resource(current, RLIMIT_NOFILE, nfds, 1);
63110 if (nfds > rlimit(RLIMIT_NOFILE))
63111 return -EINVAL;
63112
63113diff --git a/fs/seq_file.c b/fs/seq_file.c
63114index a290157..ec3211a 100644
63115--- a/fs/seq_file.c
63116+++ b/fs/seq_file.c
63117@@ -10,6 +10,7 @@
63118 #include <linux/seq_file.h>
63119 #include <linux/slab.h>
63120 #include <linux/cred.h>
63121+#include <linux/sched.h>
63122
63123 #include <asm/uaccess.h>
63124 #include <asm/page.h>
63125@@ -60,6 +61,9 @@ int seq_open(struct file *file, const struct seq_operations *op)
63126 #ifdef CONFIG_USER_NS
63127 p->user_ns = file->f_cred->user_ns;
63128 #endif
63129+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63130+ p->exec_id = current->exec_id;
63131+#endif
63132
63133 /*
63134 * Wrappers around seq_open(e.g. swaps_open) need to be
63135@@ -96,7 +100,7 @@ static int traverse(struct seq_file *m, loff_t offset)
63136 return 0;
63137 }
63138 if (!m->buf) {
63139- m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
63140+ m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL | GFP_USERCOPY);
63141 if (!m->buf)
63142 return -ENOMEM;
63143 }
63144@@ -136,7 +140,7 @@ static int traverse(struct seq_file *m, loff_t offset)
63145 Eoverflow:
63146 m->op->stop(m, p);
63147 kfree(m->buf);
63148- m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
63149+ m->buf = kmalloc(m->size <<= 1, GFP_KERNEL | GFP_USERCOPY);
63150 return !m->buf ? -ENOMEM : -EAGAIN;
63151 }
63152
63153@@ -152,7 +156,7 @@ Eoverflow:
63154 ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
63155 {
63156 struct seq_file *m = file->private_data;
63157- size_t copied = 0;
63158+ ssize_t copied = 0;
63159 loff_t pos;
63160 size_t n;
63161 void *p;
63162@@ -191,7 +195,7 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
63163
63164 /* grab buffer if we didn't have one */
63165 if (!m->buf) {
63166- m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
63167+ m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL | GFP_USERCOPY);
63168 if (!m->buf)
63169 goto Enomem;
63170 }
63171@@ -232,7 +236,7 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
63172 goto Fill;
63173 m->op->stop(m, p);
63174 kfree(m->buf);
63175- m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
63176+ m->buf = kmalloc(m->size <<= 1, GFP_KERNEL | GFP_USERCOPY);
63177 if (!m->buf)
63178 goto Enomem;
63179 m->count = 0;
63180@@ -583,7 +587,7 @@ static void single_stop(struct seq_file *p, void *v)
63181 int single_open(struct file *file, int (*show)(struct seq_file *, void *),
63182 void *data)
63183 {
63184- struct seq_operations *op = kmalloc(sizeof(*op), GFP_KERNEL);
63185+ seq_operations_no_const *op = kzalloc(sizeof(*op), GFP_KERNEL);
63186 int res = -ENOMEM;
63187
63188 if (op) {
63189diff --git a/fs/splice.c b/fs/splice.c
63190index 3b7ee65..87fc2e4 100644
63191--- a/fs/splice.c
63192+++ b/fs/splice.c
63193@@ -196,7 +196,7 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
63194 pipe_lock(pipe);
63195
63196 for (;;) {
63197- if (!pipe->readers) {
63198+ if (!atomic_read(&pipe->readers)) {
63199 send_sig(SIGPIPE, current, 0);
63200 if (!ret)
63201 ret = -EPIPE;
63202@@ -219,7 +219,7 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
63203 page_nr++;
63204 ret += buf->len;
63205
63206- if (pipe->files)
63207+ if (atomic_read(&pipe->files))
63208 do_wakeup = 1;
63209
63210 if (!--spd->nr_pages)
63211@@ -250,9 +250,9 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
63212 do_wakeup = 0;
63213 }
63214
63215- pipe->waiting_writers++;
63216+ atomic_inc(&pipe->waiting_writers);
63217 pipe_wait(pipe);
63218- pipe->waiting_writers--;
63219+ atomic_dec(&pipe->waiting_writers);
63220 }
63221
63222 pipe_unlock(pipe);
63223@@ -565,7 +565,7 @@ static ssize_t kernel_readv(struct file *file, const struct iovec *vec,
63224 old_fs = get_fs();
63225 set_fs(get_ds());
63226 /* The cast to a user pointer is valid due to the set_fs() */
63227- res = vfs_readv(file, (const struct iovec __user *)vec, vlen, &pos);
63228+ res = vfs_readv(file, (const struct iovec __force_user *)vec, vlen, &pos);
63229 set_fs(old_fs);
63230
63231 return res;
63232@@ -580,7 +580,7 @@ ssize_t kernel_write(struct file *file, const char *buf, size_t count,
63233 old_fs = get_fs();
63234 set_fs(get_ds());
63235 /* The cast to a user pointer is valid due to the set_fs() */
63236- res = vfs_write(file, (__force const char __user *)buf, count, &pos);
63237+ res = vfs_write(file, (const char __force_user *)buf, count, &pos);
63238 set_fs(old_fs);
63239
63240 return res;
63241@@ -633,7 +633,7 @@ ssize_t default_file_splice_read(struct file *in, loff_t *ppos,
63242 goto err;
63243
63244 this_len = min_t(size_t, len, PAGE_CACHE_SIZE - offset);
63245- vec[i].iov_base = (void __user *) page_address(page);
63246+ vec[i].iov_base = (void __force_user *) page_address(page);
63247 vec[i].iov_len = this_len;
63248 spd.pages[i] = page;
63249 spd.nr_pages++;
63250@@ -829,7 +829,7 @@ int splice_from_pipe_feed(struct pipe_inode_info *pipe, struct splice_desc *sd,
63251 ops->release(pipe, buf);
63252 pipe->curbuf = (pipe->curbuf + 1) & (pipe->buffers - 1);
63253 pipe->nrbufs--;
63254- if (pipe->files)
63255+ if (atomic_read(&pipe->files))
63256 sd->need_wakeup = true;
63257 }
63258
63259@@ -854,10 +854,10 @@ EXPORT_SYMBOL(splice_from_pipe_feed);
63260 int splice_from_pipe_next(struct pipe_inode_info *pipe, struct splice_desc *sd)
63261 {
63262 while (!pipe->nrbufs) {
63263- if (!pipe->writers)
63264+ if (!atomic_read(&pipe->writers))
63265 return 0;
63266
63267- if (!pipe->waiting_writers && sd->num_spliced)
63268+ if (!atomic_read(&pipe->waiting_writers) && sd->num_spliced)
63269 return 0;
63270
63271 if (sd->flags & SPLICE_F_NONBLOCK)
63272@@ -1179,7 +1179,7 @@ ssize_t splice_direct_to_actor(struct file *in, struct splice_desc *sd,
63273 * out of the pipe right after the splice_to_pipe(). So set
63274 * PIPE_READERS appropriately.
63275 */
63276- pipe->readers = 1;
63277+ atomic_set(&pipe->readers, 1);
63278
63279 current->splice_pipe = pipe;
63280 }
63281@@ -1475,6 +1475,7 @@ static int get_iovec_page_array(const struct iovec __user *iov,
63282
63283 partial[buffers].offset = off;
63284 partial[buffers].len = plen;
63285+ partial[buffers].private = 0;
63286
63287 off = 0;
63288 len -= plen;
63289@@ -1777,9 +1778,9 @@ static int ipipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
63290 ret = -ERESTARTSYS;
63291 break;
63292 }
63293- if (!pipe->writers)
63294+ if (!atomic_read(&pipe->writers))
63295 break;
63296- if (!pipe->waiting_writers) {
63297+ if (!atomic_read(&pipe->waiting_writers)) {
63298 if (flags & SPLICE_F_NONBLOCK) {
63299 ret = -EAGAIN;
63300 break;
63301@@ -1811,7 +1812,7 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
63302 pipe_lock(pipe);
63303
63304 while (pipe->nrbufs >= pipe->buffers) {
63305- if (!pipe->readers) {
63306+ if (!atomic_read(&pipe->readers)) {
63307 send_sig(SIGPIPE, current, 0);
63308 ret = -EPIPE;
63309 break;
63310@@ -1824,9 +1825,9 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
63311 ret = -ERESTARTSYS;
63312 break;
63313 }
63314- pipe->waiting_writers++;
63315+ atomic_inc(&pipe->waiting_writers);
63316 pipe_wait(pipe);
63317- pipe->waiting_writers--;
63318+ atomic_dec(&pipe->waiting_writers);
63319 }
63320
63321 pipe_unlock(pipe);
63322@@ -1862,14 +1863,14 @@ retry:
63323 pipe_double_lock(ipipe, opipe);
63324
63325 do {
63326- if (!opipe->readers) {
63327+ if (!atomic_read(&opipe->readers)) {
63328 send_sig(SIGPIPE, current, 0);
63329 if (!ret)
63330 ret = -EPIPE;
63331 break;
63332 }
63333
63334- if (!ipipe->nrbufs && !ipipe->writers)
63335+ if (!ipipe->nrbufs && !atomic_read(&ipipe->writers))
63336 break;
63337
63338 /*
63339@@ -1966,7 +1967,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
63340 pipe_double_lock(ipipe, opipe);
63341
63342 do {
63343- if (!opipe->readers) {
63344+ if (!atomic_read(&opipe->readers)) {
63345 send_sig(SIGPIPE, current, 0);
63346 if (!ret)
63347 ret = -EPIPE;
63348@@ -2011,7 +2012,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
63349 * return EAGAIN if we have the potential of some data in the
63350 * future, otherwise just return 0
63351 */
63352- if (!ret && ipipe->waiting_writers && (flags & SPLICE_F_NONBLOCK))
63353+ if (!ret && atomic_read(&ipipe->waiting_writers) && (flags & SPLICE_F_NONBLOCK))
63354 ret = -EAGAIN;
63355
63356 pipe_unlock(ipipe);
63357diff --git a/fs/stat.c b/fs/stat.c
63358index ae0c3ce..9ee641c 100644
63359--- a/fs/stat.c
63360+++ b/fs/stat.c
63361@@ -28,8 +28,13 @@ void generic_fillattr(struct inode *inode, struct kstat *stat)
63362 stat->gid = inode->i_gid;
63363 stat->rdev = inode->i_rdev;
63364 stat->size = i_size_read(inode);
63365- stat->atime = inode->i_atime;
63366- stat->mtime = inode->i_mtime;
63367+ if (is_sidechannel_device(inode) && !capable_nolog(CAP_MKNOD)) {
63368+ stat->atime = inode->i_ctime;
63369+ stat->mtime = inode->i_ctime;
63370+ } else {
63371+ stat->atime = inode->i_atime;
63372+ stat->mtime = inode->i_mtime;
63373+ }
63374 stat->ctime = inode->i_ctime;
63375 stat->blksize = (1 << inode->i_blkbits);
63376 stat->blocks = inode->i_blocks;
63377@@ -52,9 +57,16 @@ EXPORT_SYMBOL(generic_fillattr);
63378 int vfs_getattr_nosec(struct path *path, struct kstat *stat)
63379 {
63380 struct inode *inode = path->dentry->d_inode;
63381+ int retval;
63382
63383- if (inode->i_op->getattr)
63384- return inode->i_op->getattr(path->mnt, path->dentry, stat);
63385+ if (inode->i_op->getattr) {
63386+ retval = inode->i_op->getattr(path->mnt, path->dentry, stat);
63387+ if (!retval && is_sidechannel_device(inode) && !capable_nolog(CAP_MKNOD)) {
63388+ stat->atime = stat->ctime;
63389+ stat->mtime = stat->ctime;
63390+ }
63391+ return retval;
63392+ }
63393
63394 generic_fillattr(inode, stat);
63395 return 0;
63396diff --git a/fs/sysfs/bin.c b/fs/sysfs/bin.c
63397index c590cab..6dfd6fc 100644
63398--- a/fs/sysfs/bin.c
63399+++ b/fs/sysfs/bin.c
63400@@ -234,13 +234,13 @@ static int bin_page_mkwrite(struct vm_area_struct *vma, struct vm_fault *vmf)
63401 return ret;
63402 }
63403
63404-static int bin_access(struct vm_area_struct *vma, unsigned long addr,
63405- void *buf, int len, int write)
63406+static ssize_t bin_access(struct vm_area_struct *vma, unsigned long addr,
63407+ void *buf, size_t len, int write)
63408 {
63409 struct file *file = vma->vm_file;
63410 struct bin_buffer *bb = file->private_data;
63411 struct sysfs_dirent *attr_sd = file->f_path.dentry->d_fsdata;
63412- int ret;
63413+ ssize_t ret;
63414
63415 if (!bb->vm_ops)
63416 return -EINVAL;
63417diff --git a/fs/sysfs/dir.c b/fs/sysfs/dir.c
63418index 4d83ced..049dc45 100644
63419--- a/fs/sysfs/dir.c
63420+++ b/fs/sysfs/dir.c
63421@@ -40,7 +40,7 @@ static DEFINE_IDA(sysfs_ino_ida);
63422 *
63423 * Returns 31 bit hash of ns + name (so it fits in an off_t )
63424 */
63425-static unsigned int sysfs_name_hash(const void *ns, const char *name)
63426+static unsigned int sysfs_name_hash(const void *ns, const unsigned char *name)
63427 {
63428 unsigned long hash = init_name_hash();
63429 unsigned int len = strlen(name);
63430@@ -675,6 +675,18 @@ static int create_dir(struct kobject *kobj, struct sysfs_dirent *parent_sd,
63431 struct sysfs_dirent *sd;
63432 int rc;
63433
63434+#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
63435+ const char *parent_name = parent_sd->s_name;
63436+
63437+ mode = S_IFDIR | S_IRWXU;
63438+
63439+ if ((!strcmp(parent_name, "") && (!strcmp(name, "devices") || !strcmp(name, "fs"))) ||
63440+ (!strcmp(parent_name, "devices") && !strcmp(name, "system")) ||
63441+ (!strcmp(parent_name, "fs") && (!strcmp(name, "selinux") || !strcmp(name, "fuse") || !strcmp(name, "ecryptfs"))) ||
63442+ (!strcmp(parent_name, "system") && !strcmp(name, "cpu")))
63443+ mode = S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO;
63444+#endif
63445+
63446 /* allocate */
63447 sd = sysfs_new_dirent(name, mode, SYSFS_DIR);
63448 if (!sd)
63449diff --git a/fs/sysfs/file.c b/fs/sysfs/file.c
63450index 15ef5eb..e474372 100644
63451--- a/fs/sysfs/file.c
63452+++ b/fs/sysfs/file.c
63453@@ -37,7 +37,7 @@ static DEFINE_SPINLOCK(sysfs_open_dirent_lock);
63454
63455 struct sysfs_open_dirent {
63456 atomic_t refcnt;
63457- atomic_t event;
63458+ atomic_unchecked_t event;
63459 wait_queue_head_t poll;
63460 struct list_head buffers; /* goes through sysfs_buffer.list */
63461 };
63462@@ -81,7 +81,7 @@ static int fill_read_buffer(struct dentry *dentry, struct sysfs_buffer *buffer)
63463 if (!sysfs_get_active(attr_sd))
63464 return -ENODEV;
63465
63466- buffer->event = atomic_read(&attr_sd->s_attr.open->event);
63467+ buffer->event = atomic_read_unchecked(&attr_sd->s_attr.open->event);
63468 count = ops->show(kobj, attr_sd->s_attr.attr, buffer->page);
63469
63470 sysfs_put_active(attr_sd);
63471@@ -284,7 +284,7 @@ static int sysfs_get_open_dirent(struct sysfs_dirent *sd,
63472 return -ENOMEM;
63473
63474 atomic_set(&new_od->refcnt, 0);
63475- atomic_set(&new_od->event, 1);
63476+ atomic_set_unchecked(&new_od->event, 1);
63477 init_waitqueue_head(&new_od->poll);
63478 INIT_LIST_HEAD(&new_od->buffers);
63479 goto retry;
63480@@ -430,7 +430,7 @@ static unsigned int sysfs_poll(struct file *filp, poll_table *wait)
63481
63482 sysfs_put_active(attr_sd);
63483
63484- if (buffer->event != atomic_read(&od->event))
63485+ if (buffer->event != atomic_read_unchecked(&od->event))
63486 goto trigger;
63487
63488 return DEFAULT_POLLMASK;
63489@@ -450,7 +450,7 @@ void sysfs_notify_dirent(struct sysfs_dirent *sd)
63490 if (!WARN_ON(sysfs_type(sd) != SYSFS_KOBJ_ATTR)) {
63491 od = sd->s_attr.open;
63492 if (od) {
63493- atomic_inc(&od->event);
63494+ atomic_inc_unchecked(&od->event);
63495 wake_up_interruptible(&od->poll);
63496 }
63497 }
63498diff --git a/fs/sysfs/symlink.c b/fs/sysfs/symlink.c
63499index 2dd4507..62a215a 100644
63500--- a/fs/sysfs/symlink.c
63501+++ b/fs/sysfs/symlink.c
63502@@ -308,7 +308,7 @@ static void *sysfs_follow_link(struct dentry *dentry, struct nameidata *nd)
63503 static void sysfs_put_link(struct dentry *dentry, struct nameidata *nd,
63504 void *cookie)
63505 {
63506- char *page = nd_get_link(nd);
63507+ const char *page = nd_get_link(nd);
63508 if (!IS_ERR(page))
63509 free_page((unsigned long)page);
63510 }
63511diff --git a/fs/sysv/sysv.h b/fs/sysv/sysv.h
63512index 69d4889..a810bd4 100644
63513--- a/fs/sysv/sysv.h
63514+++ b/fs/sysv/sysv.h
63515@@ -188,7 +188,7 @@ static inline u32 PDP_swab(u32 x)
63516 #endif
63517 }
63518
63519-static inline __u32 fs32_to_cpu(struct sysv_sb_info *sbi, __fs32 n)
63520+static inline __u32 __intentional_overflow(-1) fs32_to_cpu(struct sysv_sb_info *sbi, __fs32 n)
63521 {
63522 if (sbi->s_bytesex == BYTESEX_PDP)
63523 return PDP_swab((__force __u32)n);
63524diff --git a/fs/ubifs/io.c b/fs/ubifs/io.c
63525index e18b988..f1d4ad0f 100644
63526--- a/fs/ubifs/io.c
63527+++ b/fs/ubifs/io.c
63528@@ -155,7 +155,7 @@ int ubifs_leb_change(struct ubifs_info *c, int lnum, const void *buf, int len)
63529 return err;
63530 }
63531
63532-int ubifs_leb_unmap(struct ubifs_info *c, int lnum)
63533+int __intentional_overflow(-1) ubifs_leb_unmap(struct ubifs_info *c, int lnum)
63534 {
63535 int err;
63536
63537diff --git a/fs/udf/misc.c b/fs/udf/misc.c
63538index c175b4d..8f36a16 100644
63539--- a/fs/udf/misc.c
63540+++ b/fs/udf/misc.c
63541@@ -289,7 +289,7 @@ void udf_new_tag(char *data, uint16_t ident, uint16_t version, uint16_t snum,
63542
63543 u8 udf_tag_checksum(const struct tag *t)
63544 {
63545- u8 *data = (u8 *)t;
63546+ const u8 *data = (const u8 *)t;
63547 u8 checksum = 0;
63548 int i;
63549 for (i = 0; i < sizeof(struct tag); ++i)
63550diff --git a/fs/ufs/swab.h b/fs/ufs/swab.h
63551index 8d974c4..b82f6ec 100644
63552--- a/fs/ufs/swab.h
63553+++ b/fs/ufs/swab.h
63554@@ -22,7 +22,7 @@ enum {
63555 BYTESEX_BE
63556 };
63557
63558-static inline u64
63559+static inline u64 __intentional_overflow(-1)
63560 fs64_to_cpu(struct super_block *sbp, __fs64 n)
63561 {
63562 if (UFS_SB(sbp)->s_bytesex == BYTESEX_LE)
63563@@ -40,7 +40,7 @@ cpu_to_fs64(struct super_block *sbp, u64 n)
63564 return (__force __fs64)cpu_to_be64(n);
63565 }
63566
63567-static inline u32
63568+static inline u32 __intentional_overflow(-1)
63569 fs32_to_cpu(struct super_block *sbp, __fs32 n)
63570 {
63571 if (UFS_SB(sbp)->s_bytesex == BYTESEX_LE)
63572diff --git a/fs/utimes.c b/fs/utimes.c
63573index f4fb7ec..3fe03c0 100644
63574--- a/fs/utimes.c
63575+++ b/fs/utimes.c
63576@@ -1,6 +1,7 @@
63577 #include <linux/compiler.h>
63578 #include <linux/file.h>
63579 #include <linux/fs.h>
63580+#include <linux/security.h>
63581 #include <linux/linkage.h>
63582 #include <linux/mount.h>
63583 #include <linux/namei.h>
63584@@ -101,6 +102,12 @@ static int utimes_common(struct path *path, struct timespec *times)
63585 goto mnt_drop_write_and_out;
63586 }
63587 }
63588+
63589+ if (!gr_acl_handle_utime(path->dentry, path->mnt)) {
63590+ error = -EACCES;
63591+ goto mnt_drop_write_and_out;
63592+ }
63593+
63594 mutex_lock(&inode->i_mutex);
63595 error = notify_change(path->dentry, &newattrs);
63596 mutex_unlock(&inode->i_mutex);
63597diff --git a/fs/xattr.c b/fs/xattr.c
63598index 3377dff..f394815 100644
63599--- a/fs/xattr.c
63600+++ b/fs/xattr.c
63601@@ -227,6 +227,27 @@ int vfs_xattr_cmp(struct dentry *dentry, const char *xattr_name,
63602 return rc;
63603 }
63604
63605+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
63606+ssize_t
63607+pax_getxattr(struct dentry *dentry, void *value, size_t size)
63608+{
63609+ struct inode *inode = dentry->d_inode;
63610+ ssize_t error;
63611+
63612+ error = inode_permission(inode, MAY_EXEC);
63613+ if (error)
63614+ return error;
63615+
63616+ if (inode->i_op->getxattr)
63617+ error = inode->i_op->getxattr(dentry, XATTR_NAME_PAX_FLAGS, value, size);
63618+ else
63619+ error = -EOPNOTSUPP;
63620+
63621+ return error;
63622+}
63623+EXPORT_SYMBOL(pax_getxattr);
63624+#endif
63625+
63626 ssize_t
63627 vfs_getxattr(struct dentry *dentry, const char *name, void *value, size_t size)
63628 {
63629@@ -319,7 +340,7 @@ EXPORT_SYMBOL_GPL(vfs_removexattr);
63630 * Extended attribute SET operations
63631 */
63632 static long
63633-setxattr(struct dentry *d, const char __user *name, const void __user *value,
63634+setxattr(struct path *path, const char __user *name, const void __user *value,
63635 size_t size, int flags)
63636 {
63637 int error;
63638@@ -355,7 +376,12 @@ setxattr(struct dentry *d, const char __user *name, const void __user *value,
63639 posix_acl_fix_xattr_from_user(kvalue, size);
63640 }
63641
63642- error = vfs_setxattr(d, kname, kvalue, size, flags);
63643+ if (!gr_acl_handle_setxattr(path->dentry, path->mnt)) {
63644+ error = -EACCES;
63645+ goto out;
63646+ }
63647+
63648+ error = vfs_setxattr(path->dentry, kname, kvalue, size, flags);
63649 out:
63650 if (vvalue)
63651 vfree(vvalue);
63652@@ -377,7 +403,7 @@ retry:
63653 return error;
63654 error = mnt_want_write(path.mnt);
63655 if (!error) {
63656- error = setxattr(path.dentry, name, value, size, flags);
63657+ error = setxattr(&path, name, value, size, flags);
63658 mnt_drop_write(path.mnt);
63659 }
63660 path_put(&path);
63661@@ -401,7 +427,7 @@ retry:
63662 return error;
63663 error = mnt_want_write(path.mnt);
63664 if (!error) {
63665- error = setxattr(path.dentry, name, value, size, flags);
63666+ error = setxattr(&path, name, value, size, flags);
63667 mnt_drop_write(path.mnt);
63668 }
63669 path_put(&path);
63670@@ -416,16 +442,14 @@ SYSCALL_DEFINE5(fsetxattr, int, fd, const char __user *, name,
63671 const void __user *,value, size_t, size, int, flags)
63672 {
63673 struct fd f = fdget(fd);
63674- struct dentry *dentry;
63675 int error = -EBADF;
63676
63677 if (!f.file)
63678 return error;
63679- dentry = f.file->f_path.dentry;
63680- audit_inode(NULL, dentry, 0);
63681+ audit_inode(NULL, f.file->f_path.dentry, 0);
63682 error = mnt_want_write_file(f.file);
63683 if (!error) {
63684- error = setxattr(dentry, name, value, size, flags);
63685+ error = setxattr(&f.file->f_path, name, value, size, flags);
63686 mnt_drop_write_file(f.file);
63687 }
63688 fdput(f);
63689@@ -626,7 +650,7 @@ SYSCALL_DEFINE3(flistxattr, int, fd, char __user *, list, size_t, size)
63690 * Extended attribute REMOVE operations
63691 */
63692 static long
63693-removexattr(struct dentry *d, const char __user *name)
63694+removexattr(struct path *path, const char __user *name)
63695 {
63696 int error;
63697 char kname[XATTR_NAME_MAX + 1];
63698@@ -637,7 +661,10 @@ removexattr(struct dentry *d, const char __user *name)
63699 if (error < 0)
63700 return error;
63701
63702- return vfs_removexattr(d, kname);
63703+ if (!gr_acl_handle_removexattr(path->dentry, path->mnt))
63704+ return -EACCES;
63705+
63706+ return vfs_removexattr(path->dentry, kname);
63707 }
63708
63709 SYSCALL_DEFINE2(removexattr, const char __user *, pathname,
63710@@ -652,7 +679,7 @@ retry:
63711 return error;
63712 error = mnt_want_write(path.mnt);
63713 if (!error) {
63714- error = removexattr(path.dentry, name);
63715+ error = removexattr(&path, name);
63716 mnt_drop_write(path.mnt);
63717 }
63718 path_put(&path);
63719@@ -675,7 +702,7 @@ retry:
63720 return error;
63721 error = mnt_want_write(path.mnt);
63722 if (!error) {
63723- error = removexattr(path.dentry, name);
63724+ error = removexattr(&path, name);
63725 mnt_drop_write(path.mnt);
63726 }
63727 path_put(&path);
63728@@ -689,16 +716,16 @@ retry:
63729 SYSCALL_DEFINE2(fremovexattr, int, fd, const char __user *, name)
63730 {
63731 struct fd f = fdget(fd);
63732- struct dentry *dentry;
63733+ struct path *path;
63734 int error = -EBADF;
63735
63736 if (!f.file)
63737 return error;
63738- dentry = f.file->f_path.dentry;
63739- audit_inode(NULL, dentry, 0);
63740+ path = &f.file->f_path;
63741+ audit_inode(NULL, path->dentry, 0);
63742 error = mnt_want_write_file(f.file);
63743 if (!error) {
63744- error = removexattr(dentry, name);
63745+ error = removexattr(path, name);
63746 mnt_drop_write_file(f.file);
63747 }
63748 fdput(f);
63749diff --git a/fs/xattr_acl.c b/fs/xattr_acl.c
63750index 9fbea87..6b19972 100644
63751--- a/fs/xattr_acl.c
63752+++ b/fs/xattr_acl.c
63753@@ -76,8 +76,8 @@ struct posix_acl *
63754 posix_acl_from_xattr(struct user_namespace *user_ns,
63755 const void *value, size_t size)
63756 {
63757- posix_acl_xattr_header *header = (posix_acl_xattr_header *)value;
63758- posix_acl_xattr_entry *entry = (posix_acl_xattr_entry *)(header+1), *end;
63759+ const posix_acl_xattr_header *header = (const posix_acl_xattr_header *)value;
63760+ const posix_acl_xattr_entry *entry = (const posix_acl_xattr_entry *)(header+1), *end;
63761 int count;
63762 struct posix_acl *acl;
63763 struct posix_acl_entry *acl_e;
63764diff --git a/fs/xfs/xfs_attr_remote.c b/fs/xfs/xfs_attr_remote.c
63765index 712a502..18180a3 100644
63766--- a/fs/xfs/xfs_attr_remote.c
63767+++ b/fs/xfs/xfs_attr_remote.c
63768@@ -110,7 +110,7 @@ xfs_attr3_rmt_verify(
63769 if (be32_to_cpu(rmt->rm_bytes) > fsbsize - sizeof(*rmt))
63770 return false;
63771 if (be32_to_cpu(rmt->rm_offset) +
63772- be32_to_cpu(rmt->rm_bytes) >= XATTR_SIZE_MAX)
63773+ be32_to_cpu(rmt->rm_bytes) > XATTR_SIZE_MAX)
63774 return false;
63775 if (rmt->rm_owner == 0)
63776 return false;
63777diff --git a/fs/xfs/xfs_bmap.c b/fs/xfs/xfs_bmap.c
63778index f47e65c..e7125d9 100644
63779--- a/fs/xfs/xfs_bmap.c
63780+++ b/fs/xfs/xfs_bmap.c
63781@@ -586,7 +586,7 @@ xfs_bmap_validate_ret(
63782
63783 #else
63784 #define xfs_bmap_check_leaf_extents(cur, ip, whichfork) do { } while (0)
63785-#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap)
63786+#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap) do { } while (0)
63787 #endif /* DEBUG */
63788
63789 /*
63790diff --git a/fs/xfs/xfs_dir2_readdir.c b/fs/xfs/xfs_dir2_readdir.c
63791index 8f84153..7ce60d0 100644
63792--- a/fs/xfs/xfs_dir2_readdir.c
63793+++ b/fs/xfs/xfs_dir2_readdir.c
63794@@ -160,7 +160,12 @@ xfs_dir2_sf_getdents(
63795 ino = xfs_dir3_sfe_get_ino(mp, sfp, sfep);
63796 filetype = xfs_dir3_sfe_get_ftype(mp, sfp, sfep);
63797 ctx->pos = off & 0x7fffffff;
63798- if (!dir_emit(ctx, (char *)sfep->name, sfep->namelen, ino,
63799+ if (dp->i_df.if_u1.if_data == dp->i_df.if_u2.if_inline_data) {
63800+ char name[sfep->namelen];
63801+ memcpy(name, sfep->name, sfep->namelen);
63802+ if (!dir_emit(ctx, name, sfep->namelen, ino, xfs_dir3_get_dtype(mp, filetype)))
63803+ return 0;
63804+ } else if (!dir_emit(ctx, (char *)sfep->name, sfep->namelen, ino,
63805 xfs_dir3_get_dtype(mp, filetype)))
63806 return 0;
63807 sfep = xfs_dir3_sf_nextentry(mp, sfp, sfep);
63808diff --git a/fs/xfs/xfs_ioctl.c b/fs/xfs/xfs_ioctl.c
63809index 8c8ef24..689f742 100644
63810--- a/fs/xfs/xfs_ioctl.c
63811+++ b/fs/xfs/xfs_ioctl.c
63812@@ -127,7 +127,7 @@ xfs_find_handle(
63813 }
63814
63815 error = -EFAULT;
63816- if (copy_to_user(hreq->ohandle, &handle, hsize) ||
63817+ if (hsize > sizeof handle || copy_to_user(hreq->ohandle, &handle, hsize) ||
63818 copy_to_user(hreq->ohandlen, &hsize, sizeof(__s32)))
63819 goto out_put;
63820
63821diff --git a/fs/xfs/xfs_iops.c b/fs/xfs/xfs_iops.c
63822index 2b8952d..a60c6be 100644
63823--- a/fs/xfs/xfs_iops.c
63824+++ b/fs/xfs/xfs_iops.c
63825@@ -401,7 +401,7 @@ xfs_vn_put_link(
63826 struct nameidata *nd,
63827 void *p)
63828 {
63829- char *s = nd_get_link(nd);
63830+ const char *s = nd_get_link(nd);
63831
63832 if (!IS_ERR(s))
63833 kfree(s);
63834diff --git a/grsecurity/Kconfig b/grsecurity/Kconfig
63835new file mode 100644
63836index 0000000..bac1842
63837--- /dev/null
63838+++ b/grsecurity/Kconfig
63839@@ -0,0 +1,1145 @@
63840+#
63841+# grecurity configuration
63842+#
63843+menu "Memory Protections"
63844+depends on GRKERNSEC
63845+
63846+config GRKERNSEC_KMEM
63847+ bool "Deny reading/writing to /dev/kmem, /dev/mem, and /dev/port"
63848+ default y if GRKERNSEC_CONFIG_AUTO
63849+ select STRICT_DEVMEM if (X86 || ARM || TILE || S390)
63850+ help
63851+ If you say Y here, /dev/kmem and /dev/mem won't be allowed to
63852+ be written to or read from to modify or leak the contents of the running
63853+ kernel. /dev/port will also not be allowed to be opened, and support
63854+ for /dev/cpu/*/msr and kexec will be removed. If you have module
63855+ support disabled, enabling this will close up six ways that are
63856+ currently used to insert malicious code into the running kernel.
63857+
63858+ Even with this feature enabled, we still highly recommend that
63859+ you use the RBAC system, as it is still possible for an attacker to
63860+ modify the running kernel through other more obscure methods.
63861+
63862+ Enabling this feature will prevent the "cpupower" and "powertop" tools
63863+ from working.
63864+
63865+ It is highly recommended that you say Y here if you meet all the
63866+ conditions above.
63867+
63868+config GRKERNSEC_VM86
63869+ bool "Restrict VM86 mode"
63870+ default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
63871+ depends on X86_32
63872+
63873+ help
63874+ If you say Y here, only processes with CAP_SYS_RAWIO will be able to
63875+ make use of a special execution mode on 32bit x86 processors called
63876+ Virtual 8086 (VM86) mode. XFree86 may need vm86 mode for certain
63877+ video cards and will still work with this option enabled. The purpose
63878+ of the option is to prevent exploitation of emulation errors in
63879+ virtualization of vm86 mode like the one discovered in VMWare in 2009.
63880+ Nearly all users should be able to enable this option.
63881+
63882+config GRKERNSEC_IO
63883+ bool "Disable privileged I/O"
63884+ default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
63885+ depends on X86
63886+ select RTC_CLASS
63887+ select RTC_INTF_DEV
63888+ select RTC_DRV_CMOS
63889+
63890+ help
63891+ If you say Y here, all ioperm and iopl calls will return an error.
63892+ Ioperm and iopl can be used to modify the running kernel.
63893+ Unfortunately, some programs need this access to operate properly,
63894+ the most notable of which are XFree86 and hwclock. hwclock can be
63895+ remedied by having RTC support in the kernel, so real-time
63896+ clock support is enabled if this option is enabled, to ensure
63897+ that hwclock operates correctly.
63898+
63899+ If you're using XFree86 or a version of Xorg from 2012 or earlier,
63900+ you may not be able to boot into a graphical environment with this
63901+ option enabled. In this case, you should use the RBAC system instead.
63902+
63903+config GRKERNSEC_JIT_HARDEN
63904+ bool "Harden BPF JIT against spray attacks"
63905+ default y if GRKERNSEC_CONFIG_AUTO
63906+ depends on BPF_JIT
63907+ help
63908+ If you say Y here, the native code generated by the kernel's Berkeley
63909+ Packet Filter (BPF) JIT engine will be hardened against JIT-spraying
63910+ attacks that attempt to fit attacker-beneficial instructions in
63911+ 32bit immediate fields of JIT-generated native instructions. The
63912+ attacker will generally aim to cause an unintended instruction sequence
63913+ of JIT-generated native code to execute by jumping into the middle of
63914+ a generated instruction. This feature effectively randomizes the 32bit
63915+ immediate constants present in the generated code to thwart such attacks.
63916+
63917+ If you're using KERNEXEC, it's recommended that you enable this option
63918+ to supplement the hardening of the kernel.
63919+
63920+config GRKERNSEC_PERF_HARDEN
63921+ bool "Disable unprivileged PERF_EVENTS usage by default"
63922+ default y if GRKERNSEC_CONFIG_AUTO
63923+ depends on PERF_EVENTS
63924+ help
63925+ If you say Y here, the range of acceptable values for the
63926+ /proc/sys/kernel/perf_event_paranoid sysctl will be expanded to allow and
63927+ default to a new value: 3. When the sysctl is set to this value, no
63928+ unprivileged use of the PERF_EVENTS syscall interface will be permitted.
63929+
63930+ Though PERF_EVENTS can be used legitimately for performance monitoring
63931+ and low-level application profiling, it is forced on regardless of
63932+ configuration, has been at fault for several vulnerabilities, and
63933+ creates new opportunities for side channels and other information leaks.
63934+
63935+ This feature puts PERF_EVENTS into a secure default state and permits
63936+ the administrator to change out of it temporarily if unprivileged
63937+ application profiling is needed.
63938+
63939+config GRKERNSEC_RAND_THREADSTACK
63940+ bool "Insert random gaps between thread stacks"
63941+ default y if GRKERNSEC_CONFIG_AUTO
63942+ depends on PAX_RANDMMAP && !PPC
63943+ help
63944+ If you say Y here, a random-sized gap will be enforced between allocated
63945+ thread stacks. Glibc's NPTL and other threading libraries that
63946+ pass MAP_STACK to the kernel for thread stack allocation are supported.
63947+ The implementation currently provides 8 bits of entropy for the gap.
63948+
63949+ Many distributions do not compile threaded remote services with the
63950+ -fstack-check argument to GCC, causing the variable-sized stack-based
63951+ allocator, alloca(), to not probe the stack on allocation. This
63952+ permits an unbounded alloca() to skip over any guard page and potentially
63953+ modify another thread's stack reliably. An enforced random gap
63954+ reduces the reliability of such an attack and increases the chance
63955+ that such a read/write to another thread's stack instead lands in
63956+ an unmapped area, causing a crash and triggering grsecurity's
63957+ anti-bruteforcing logic.
63958+
63959+config GRKERNSEC_PROC_MEMMAP
63960+ bool "Harden ASLR against information leaks and entropy reduction"
63961+ default y if (GRKERNSEC_CONFIG_AUTO || PAX_NOEXEC || PAX_ASLR)
63962+ depends on PAX_NOEXEC || PAX_ASLR
63963+ help
63964+ If you say Y here, the /proc/<pid>/maps and /proc/<pid>/stat files will
63965+ give no information about the addresses of its mappings if
63966+ PaX features that rely on random addresses are enabled on the task.
63967+ In addition to sanitizing this information and disabling other
63968+ dangerous sources of information, this option causes reads of sensitive
63969+ /proc/<pid> entries where the file descriptor was opened in a different
63970+ task than the one performing the read. Such attempts are logged.
63971+ This option also limits argv/env strings for suid/sgid binaries
63972+ to 512KB to prevent a complete exhaustion of the stack entropy provided
63973+ by ASLR. Finally, it places an 8MB stack resource limit on suid/sgid
63974+ binaries to prevent alternative mmap layouts from being abused.
63975+
63976+ If you use PaX it is essential that you say Y here as it closes up
63977+ several holes that make full ASLR useless locally.
63978+
63979+config GRKERNSEC_BRUTE
63980+ bool "Deter exploit bruteforcing"
63981+ default y if GRKERNSEC_CONFIG_AUTO
63982+ help
63983+ If you say Y here, attempts to bruteforce exploits against forking
63984+ daemons such as apache or sshd, as well as against suid/sgid binaries
63985+ will be deterred. When a child of a forking daemon is killed by PaX
63986+ or crashes due to an illegal instruction or other suspicious signal,
63987+ the parent process will be delayed 30 seconds upon every subsequent
63988+ fork until the administrator is able to assess the situation and
63989+ restart the daemon.
63990+ In the suid/sgid case, the attempt is logged, the user has all their
63991+ existing instances of the suid/sgid binary terminated and will
63992+ be unable to execute any suid/sgid binaries for 15 minutes.
63993+
63994+ It is recommended that you also enable signal logging in the auditing
63995+ section so that logs are generated when a process triggers a suspicious
63996+ signal.
63997+ If the sysctl option is enabled, a sysctl option with name
63998+ "deter_bruteforce" is created.
63999+
64000+config GRKERNSEC_MODHARDEN
64001+ bool "Harden module auto-loading"
64002+ default y if GRKERNSEC_CONFIG_AUTO
64003+ depends on MODULES
64004+ help
64005+ If you say Y here, module auto-loading in response to use of some
64006+ feature implemented by an unloaded module will be restricted to
64007+ root users. Enabling this option helps defend against attacks
64008+ by unprivileged users who abuse the auto-loading behavior to
64009+ cause a vulnerable module to load that is then exploited.
64010+
64011+ If this option prevents a legitimate use of auto-loading for a
64012+ non-root user, the administrator can execute modprobe manually
64013+ with the exact name of the module mentioned in the alert log.
64014+ Alternatively, the administrator can add the module to the list
64015+ of modules loaded at boot by modifying init scripts.
64016+
64017+ Modification of init scripts will most likely be needed on
64018+ Ubuntu servers with encrypted home directory support enabled,
64019+ as the first non-root user logging in will cause the ecb(aes),
64020+ ecb(aes)-all, cbc(aes), and cbc(aes)-all modules to be loaded.
64021+
64022+config GRKERNSEC_HIDESYM
64023+ bool "Hide kernel symbols"
64024+ default y if GRKERNSEC_CONFIG_AUTO
64025+ select PAX_USERCOPY_SLABS
64026+ help
64027+ If you say Y here, getting information on loaded modules, and
64028+ displaying all kernel symbols through a syscall will be restricted
64029+ to users with CAP_SYS_MODULE. For software compatibility reasons,
64030+ /proc/kallsyms will be restricted to the root user. The RBAC
64031+ system can hide that entry even from root.
64032+
64033+ This option also prevents leaking of kernel addresses through
64034+ several /proc entries.
64035+
64036+ Note that this option is only effective provided the following
64037+ conditions are met:
64038+ 1) The kernel using grsecurity is not precompiled by some distribution
64039+ 2) You have also enabled GRKERNSEC_DMESG
64040+ 3) You are using the RBAC system and hiding other files such as your
64041+ kernel image and System.map. Alternatively, enabling this option
64042+ causes the permissions on /boot, /lib/modules, and the kernel
64043+ source directory to change at compile time to prevent
64044+ reading by non-root users.
64045+ If the above conditions are met, this option will aid in providing a
64046+ useful protection against local kernel exploitation of overflows
64047+ and arbitrary read/write vulnerabilities.
64048+
64049+ It is highly recommended that you enable GRKERNSEC_PERF_HARDEN
64050+ in addition to this feature.
64051+
64052+config GRKERNSEC_RANDSTRUCT
64053+ bool "Randomize layout of sensitive kernel structures"
64054+ default y if GRKERNSEC_CONFIG_AUTO
64055+ help
64056+ If you say Y here, the layouts of a number of sensitive kernel
64057+ structures (task, fs, cred, etc) and all structures composed entirely
64058+ of function pointers (aka "ops" structs) will be randomized at compile-time.
64059+ This can introduce the requirement of an additional infoleak
64060+ vulnerability for exploits targeting these structure types.
64061+
64062+ Enabling this feature will introduce some performance impact, slightly
64063+ increase memory usage, and prevent the use of forensic tools like
64064+ Volatility against the system (unless the kernel source tree isn't
64065+ cleaned after kernel installation).
64066+
64067+ The seed used for compilation is located at tools/gcc/randstruct.seed.
64068+ It remains after a make clean to allow for external modules to be compiled
64069+ with the existing seed and will be removed by a make mrproper or
64070+ make distclean.
64071+
64072+config GRKERNSEC_RANDSTRUCT_PERFORMANCE
64073+ bool "Use cacheline-aware structure randomization"
64074+ depends on GRKERNSEC_RANDSTRUCT
64075+ default y if GRKERNSEC_CONFIG_PRIORITY_PERF
64076+ help
64077+ If you say Y here, the RANDSTRUCT randomization will make a best effort
64078+ at restricting randomization to cacheline-sized groups of elements. It
64079+ will further not randomize bitfields in structures. This reduces the
64080+ performance hit of RANDSTRUCT at the cost of weakened randomization.
64081+
64082+config GRKERNSEC_KERN_LOCKOUT
64083+ bool "Active kernel exploit response"
64084+ default y if GRKERNSEC_CONFIG_AUTO
64085+ depends on X86 || ARM || PPC || SPARC
64086+ help
64087+ If you say Y here, when a PaX alert is triggered due to suspicious
64088+ activity in the kernel (from KERNEXEC/UDEREF/USERCOPY)
64089+ or an OOPS occurs due to bad memory accesses, instead of just
64090+ terminating the offending process (and potentially allowing
64091+ a subsequent exploit from the same user), we will take one of two
64092+ actions:
64093+ If the user was root, we will panic the system
64094+ If the user was non-root, we will log the attempt, terminate
64095+ all processes owned by the user, then prevent them from creating
64096+ any new processes until the system is restarted
64097+ This deters repeated kernel exploitation/bruteforcing attempts
64098+ and is useful for later forensics.
64099+
64100+config GRKERNSEC_OLD_ARM_USERLAND
64101+ bool "Old ARM userland compatibility"
64102+ depends on ARM && (CPU_V6 || CPU_V6K || CPU_V7)
64103+ help
64104+ If you say Y here, stubs of executable code to perform such operations
64105+ as "compare-exchange" will be placed at fixed locations in the ARM vector
64106+ table. This is unfortunately needed for old ARM userland meant to run
64107+ across a wide range of processors. Without this option enabled,
64108+ the get_tls and data memory barrier stubs will be emulated by the kernel,
64109+ which is enough for Linaro userlands or other userlands designed for v6
64110+ and newer ARM CPUs. It's recommended that you try without this option enabled
64111+ first, and only enable it if your userland does not boot (it will likely fail
64112+ at init time).
64113+
64114+endmenu
64115+menu "Role Based Access Control Options"
64116+depends on GRKERNSEC
64117+
64118+config GRKERNSEC_RBAC_DEBUG
64119+ bool
64120+
64121+config GRKERNSEC_NO_RBAC
64122+ bool "Disable RBAC system"
64123+ help
64124+ If you say Y here, the /dev/grsec device will be removed from the kernel,
64125+ preventing the RBAC system from being enabled. You should only say Y
64126+ here if you have no intention of using the RBAC system, so as to prevent
64127+ an attacker with root access from misusing the RBAC system to hide files
64128+ and processes when loadable module support and /dev/[k]mem have been
64129+ locked down.
64130+
64131+config GRKERNSEC_ACL_HIDEKERN
64132+ bool "Hide kernel processes"
64133+ help
64134+ If you say Y here, all kernel threads will be hidden to all
64135+ processes but those whose subject has the "view hidden processes"
64136+ flag.
64137+
64138+config GRKERNSEC_ACL_MAXTRIES
64139+ int "Maximum tries before password lockout"
64140+ default 3
64141+ help
64142+ This option enforces the maximum number of times a user can attempt
64143+ to authorize themselves with the grsecurity RBAC system before being
64144+ denied the ability to attempt authorization again for a specified time.
64145+ The lower the number, the harder it will be to brute-force a password.
64146+
64147+config GRKERNSEC_ACL_TIMEOUT
64148+ int "Time to wait after max password tries, in seconds"
64149+ default 30
64150+ help
64151+ This option specifies the time the user must wait after attempting to
64152+ authorize to the RBAC system with the maximum number of invalid
64153+ passwords. The higher the number, the harder it will be to brute-force
64154+ a password.
64155+
64156+endmenu
64157+menu "Filesystem Protections"
64158+depends on GRKERNSEC
64159+
64160+config GRKERNSEC_PROC
64161+ bool "Proc restrictions"
64162+ default y if GRKERNSEC_CONFIG_AUTO
64163+ help
64164+ If you say Y here, the permissions of the /proc filesystem
64165+ will be altered to enhance system security and privacy. You MUST
64166+ choose either a user only restriction or a user and group restriction.
64167+ Depending upon the option you choose, you can either restrict users to
64168+ see only the processes they themselves run, or choose a group that can
64169+ view all processes and files normally restricted to root if you choose
64170+ the "restrict to user only" option. NOTE: If you're running identd or
64171+ ntpd as a non-root user, you will have to run it as the group you
64172+ specify here.
64173+
64174+config GRKERNSEC_PROC_USER
64175+ bool "Restrict /proc to user only"
64176+ depends on GRKERNSEC_PROC
64177+ help
64178+ If you say Y here, non-root users will only be able to view their own
64179+ processes, and restricts them from viewing network-related information,
64180+ and viewing kernel symbol and module information.
64181+
64182+config GRKERNSEC_PROC_USERGROUP
64183+ bool "Allow special group"
64184+ default y if GRKERNSEC_CONFIG_AUTO
64185+ depends on GRKERNSEC_PROC && !GRKERNSEC_PROC_USER
64186+ help
64187+ If you say Y here, you will be able to select a group that will be
64188+ able to view all processes and network-related information. If you've
64189+ enabled GRKERNSEC_HIDESYM, kernel and symbol information may still
64190+ remain hidden. This option is useful if you want to run identd as
64191+ a non-root user. The group you select may also be chosen at boot time
64192+ via "grsec_proc_gid=" on the kernel commandline.
64193+
64194+config GRKERNSEC_PROC_GID
64195+ int "GID for special group"
64196+ depends on GRKERNSEC_PROC_USERGROUP
64197+ default 1001
64198+
64199+config GRKERNSEC_PROC_ADD
64200+ bool "Additional restrictions"
64201+ default y if GRKERNSEC_CONFIG_AUTO
64202+ depends on GRKERNSEC_PROC_USER || GRKERNSEC_PROC_USERGROUP
64203+ help
64204+ If you say Y here, additional restrictions will be placed on
64205+ /proc that keep normal users from viewing device information and
64206+ slabinfo information that could be useful for exploits.
64207+
64208+config GRKERNSEC_LINK
64209+ bool "Linking restrictions"
64210+ default y if GRKERNSEC_CONFIG_AUTO
64211+ help
64212+ If you say Y here, /tmp race exploits will be prevented, since users
64213+ will no longer be able to follow symlinks owned by other users in
64214+ world-writable +t directories (e.g. /tmp), unless the owner of the
64215+ symlink is the owner of the directory. users will also not be
64216+ able to hardlink to files they do not own. If the sysctl option is
64217+ enabled, a sysctl option with name "linking_restrictions" is created.
64218+
64219+config GRKERNSEC_SYMLINKOWN
64220+ bool "Kernel-enforced SymlinksIfOwnerMatch"
64221+ default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
64222+ help
64223+ Apache's SymlinksIfOwnerMatch option has an inherent race condition
64224+ that prevents it from being used as a security feature. As Apache
64225+ verifies the symlink by performing a stat() against the target of
64226+ the symlink before it is followed, an attacker can setup a symlink
64227+ to point to a same-owned file, then replace the symlink with one
64228+ that targets another user's file just after Apache "validates" the
64229+ symlink -- a classic TOCTOU race. If you say Y here, a complete,
64230+ race-free replacement for Apache's "SymlinksIfOwnerMatch" option
64231+ will be in place for the group you specify. If the sysctl option
64232+ is enabled, a sysctl option with name "enforce_symlinksifowner" is
64233+ created.
64234+
64235+config GRKERNSEC_SYMLINKOWN_GID
64236+ int "GID for users with kernel-enforced SymlinksIfOwnerMatch"
64237+ depends on GRKERNSEC_SYMLINKOWN
64238+ default 1006
64239+ help
64240+ Setting this GID determines what group kernel-enforced
64241+ SymlinksIfOwnerMatch will be enabled for. If the sysctl option
64242+ is enabled, a sysctl option with name "symlinkown_gid" is created.
64243+
64244+config GRKERNSEC_FIFO
64245+ bool "FIFO restrictions"
64246+ default y if GRKERNSEC_CONFIG_AUTO
64247+ help
64248+ If you say Y here, users will not be able to write to FIFOs they don't
64249+ own in world-writable +t directories (e.g. /tmp), unless the owner of
64250+ the FIFO is the same owner of the directory it's held in. If the sysctl
64251+ option is enabled, a sysctl option with name "fifo_restrictions" is
64252+ created.
64253+
64254+config GRKERNSEC_SYSFS_RESTRICT
64255+ bool "Sysfs/debugfs restriction"
64256+ default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
64257+ depends on SYSFS
64258+ help
64259+ If you say Y here, sysfs (the pseudo-filesystem mounted at /sys) and
64260+ any filesystem normally mounted under it (e.g. debugfs) will be
64261+ mostly accessible only by root. These filesystems generally provide access
64262+ to hardware and debug information that isn't appropriate for unprivileged
64263+ users of the system. Sysfs and debugfs have also become a large source
64264+ of new vulnerabilities, ranging from infoleaks to local compromise.
64265+ There has been very little oversight with an eye toward security involved
64266+ in adding new exporters of information to these filesystems, so their
64267+ use is discouraged.
64268+ For reasons of compatibility, a few directories have been whitelisted
64269+ for access by non-root users:
64270+ /sys/fs/selinux
64271+ /sys/fs/fuse
64272+ /sys/devices/system/cpu
64273+
64274+config GRKERNSEC_ROFS
64275+ bool "Runtime read-only mount protection"
64276+ depends on SYSCTL
64277+ help
64278+ If you say Y here, a sysctl option with name "romount_protect" will
64279+ be created. By setting this option to 1 at runtime, filesystems
64280+ will be protected in the following ways:
64281+ * No new writable mounts will be allowed
64282+ * Existing read-only mounts won't be able to be remounted read/write
64283+ * Write operations will be denied on all block devices
64284+ This option acts independently of grsec_lock: once it is set to 1,
64285+ it cannot be turned off. Therefore, please be mindful of the resulting
64286+ behavior if this option is enabled in an init script on a read-only
64287+ filesystem.
64288+ Also be aware that as with other root-focused features, GRKERNSEC_KMEM
64289+ and GRKERNSEC_IO should be enabled and module loading disabled via
64290+ config or at runtime.
64291+ This feature is mainly intended for secure embedded systems.
64292+
64293+
64294+config GRKERNSEC_DEVICE_SIDECHANNEL
64295+ bool "Eliminate stat/notify-based device sidechannels"
64296+ default y if GRKERNSEC_CONFIG_AUTO
64297+ help
64298+ If you say Y here, timing analyses on block or character
64299+ devices like /dev/ptmx using stat or inotify/dnotify/fanotify
64300+ will be thwarted for unprivileged users. If a process without
64301+ CAP_MKNOD stats such a device, the last access and last modify times
64302+ will match the device's create time. No access or modify events
64303+ will be triggered through inotify/dnotify/fanotify for such devices.
64304+ This feature will prevent attacks that may at a minimum
64305+ allow an attacker to determine the administrator's password length.
64306+
64307+config GRKERNSEC_CHROOT
64308+ bool "Chroot jail restrictions"
64309+ default y if GRKERNSEC_CONFIG_AUTO
64310+ help
64311+ If you say Y here, you will be able to choose several options that will
64312+ make breaking out of a chrooted jail much more difficult. If you
64313+ encounter no software incompatibilities with the following options, it
64314+ is recommended that you enable each one.
64315+
64316+config GRKERNSEC_CHROOT_MOUNT
64317+ bool "Deny mounts"
64318+ default y if GRKERNSEC_CONFIG_AUTO
64319+ depends on GRKERNSEC_CHROOT
64320+ help
64321+ If you say Y here, processes inside a chroot will not be able to
64322+ mount or remount filesystems. If the sysctl option is enabled, a
64323+ sysctl option with name "chroot_deny_mount" is created.
64324+
64325+config GRKERNSEC_CHROOT_DOUBLE
64326+ bool "Deny double-chroots"
64327+ default y if GRKERNSEC_CONFIG_AUTO
64328+ depends on GRKERNSEC_CHROOT
64329+ help
64330+ If you say Y here, processes inside a chroot will not be able to chroot
64331+ again outside the chroot. This is a widely used method of breaking
64332+ out of a chroot jail and should not be allowed. If the sysctl
64333+ option is enabled, a sysctl option with name
64334+ "chroot_deny_chroot" is created.
64335+
64336+config GRKERNSEC_CHROOT_PIVOT
64337+ bool "Deny pivot_root in chroot"
64338+ default y if GRKERNSEC_CONFIG_AUTO
64339+ depends on GRKERNSEC_CHROOT
64340+ help
64341+ If you say Y here, processes inside a chroot will not be able to use
64342+ a function called pivot_root() that was introduced in Linux 2.3.41. It
64343+ works similar to chroot in that it changes the root filesystem. This
64344+ function could be misused in a chrooted process to attempt to break out
64345+ of the chroot, and therefore should not be allowed. If the sysctl
64346+ option is enabled, a sysctl option with name "chroot_deny_pivot" is
64347+ created.
64348+
64349+config GRKERNSEC_CHROOT_CHDIR
64350+ bool "Enforce chdir(\"/\") on all chroots"
64351+ default y if GRKERNSEC_CONFIG_AUTO
64352+ depends on GRKERNSEC_CHROOT
64353+ help
64354+ If you say Y here, the current working directory of all newly-chrooted
64355+ applications will be set to the the root directory of the chroot.
64356+ The man page on chroot(2) states:
64357+ Note that this call does not change the current working
64358+ directory, so that `.' can be outside the tree rooted at
64359+ `/'. In particular, the super-user can escape from a
64360+ `chroot jail' by doing `mkdir foo; chroot foo; cd ..'.
64361+
64362+ It is recommended that you say Y here, since it's not known to break
64363+ any software. If the sysctl option is enabled, a sysctl option with
64364+ name "chroot_enforce_chdir" is created.
64365+
64366+config GRKERNSEC_CHROOT_CHMOD
64367+ bool "Deny (f)chmod +s"
64368+ default y if GRKERNSEC_CONFIG_AUTO
64369+ depends on GRKERNSEC_CHROOT
64370+ help
64371+ If you say Y here, processes inside a chroot will not be able to chmod
64372+ or fchmod files to make them have suid or sgid bits. This protects
64373+ against another published method of breaking a chroot. If the sysctl
64374+ option is enabled, a sysctl option with name "chroot_deny_chmod" is
64375+ created.
64376+
64377+config GRKERNSEC_CHROOT_FCHDIR
64378+ bool "Deny fchdir out of chroot"
64379+ default y if GRKERNSEC_CONFIG_AUTO
64380+ depends on GRKERNSEC_CHROOT
64381+ help
64382+ If you say Y here, a well-known method of breaking chroots by fchdir'ing
64383+ to a file descriptor of the chrooting process that points to a directory
64384+ outside the filesystem will be stopped. If the sysctl option
64385+ is enabled, a sysctl option with name "chroot_deny_fchdir" is created.
64386+
64387+config GRKERNSEC_CHROOT_MKNOD
64388+ bool "Deny mknod"
64389+ default y if GRKERNSEC_CONFIG_AUTO
64390+ depends on GRKERNSEC_CHROOT
64391+ help
64392+ If you say Y here, processes inside a chroot will not be allowed to
64393+ mknod. The problem with using mknod inside a chroot is that it
64394+ would allow an attacker to create a device entry that is the same
64395+ as one on the physical root of your system, which could range from
64396+ anything from the console device to a device for your harddrive (which
64397+ they could then use to wipe the drive or steal data). It is recommended
64398+ that you say Y here, unless you run into software incompatibilities.
64399+ If the sysctl option is enabled, a sysctl option with name
64400+ "chroot_deny_mknod" is created.
64401+
64402+config GRKERNSEC_CHROOT_SHMAT
64403+ bool "Deny shmat() out of chroot"
64404+ default y if GRKERNSEC_CONFIG_AUTO
64405+ depends on GRKERNSEC_CHROOT
64406+ help
64407+ If you say Y here, processes inside a chroot will not be able to attach
64408+ to shared memory segments that were created outside of the chroot jail.
64409+ It is recommended that you say Y here. If the sysctl option is enabled,
64410+ a sysctl option with name "chroot_deny_shmat" is created.
64411+
64412+config GRKERNSEC_CHROOT_UNIX
64413+ bool "Deny access to abstract AF_UNIX sockets out of chroot"
64414+ default y if GRKERNSEC_CONFIG_AUTO
64415+ depends on GRKERNSEC_CHROOT
64416+ help
64417+ If you say Y here, processes inside a chroot will not be able to
64418+ connect to abstract (meaning not belonging to a filesystem) Unix
64419+ domain sockets that were bound outside of a chroot. It is recommended
64420+ that you say Y here. If the sysctl option is enabled, a sysctl option
64421+ with name "chroot_deny_unix" is created.
64422+
64423+config GRKERNSEC_CHROOT_FINDTASK
64424+ bool "Protect outside processes"
64425+ default y if GRKERNSEC_CONFIG_AUTO
64426+ depends on GRKERNSEC_CHROOT
64427+ help
64428+ If you say Y here, processes inside a chroot will not be able to
64429+ kill, send signals with fcntl, ptrace, capget, getpgid, setpgid,
64430+ getsid, or view any process outside of the chroot. If the sysctl
64431+ option is enabled, a sysctl option with name "chroot_findtask" is
64432+ created.
64433+
64434+config GRKERNSEC_CHROOT_NICE
64435+ bool "Restrict priority changes"
64436+ default y if GRKERNSEC_CONFIG_AUTO
64437+ depends on GRKERNSEC_CHROOT
64438+ help
64439+ If you say Y here, processes inside a chroot will not be able to raise
64440+ the priority of processes in the chroot, or alter the priority of
64441+ processes outside the chroot. This provides more security than simply
64442+ removing CAP_SYS_NICE from the process' capability set. If the
64443+ sysctl option is enabled, a sysctl option with name "chroot_restrict_nice"
64444+ is created.
64445+
64446+config GRKERNSEC_CHROOT_SYSCTL
64447+ bool "Deny sysctl writes"
64448+ default y if GRKERNSEC_CONFIG_AUTO
64449+ depends on GRKERNSEC_CHROOT
64450+ help
64451+ If you say Y here, an attacker in a chroot will not be able to
64452+ write to sysctl entries, either by sysctl(2) or through a /proc
64453+ interface. It is strongly recommended that you say Y here. If the
64454+ sysctl option is enabled, a sysctl option with name
64455+ "chroot_deny_sysctl" is created.
64456+
64457+config GRKERNSEC_CHROOT_CAPS
64458+ bool "Capability restrictions"
64459+ default y if GRKERNSEC_CONFIG_AUTO
64460+ depends on GRKERNSEC_CHROOT
64461+ help
64462+ If you say Y here, the capabilities on all processes within a
64463+ chroot jail will be lowered to stop module insertion, raw i/o,
64464+ system and net admin tasks, rebooting the system, modifying immutable
64465+ files, modifying IPC owned by another, and changing the system time.
64466+ This is left an option because it can break some apps. Disable this
64467+ if your chrooted apps are having problems performing those kinds of
64468+ tasks. If the sysctl option is enabled, a sysctl option with
64469+ name "chroot_caps" is created.
64470+
64471+config GRKERNSEC_CHROOT_INITRD
64472+ bool "Exempt initrd tasks from restrictions"
64473+ default y if GRKERNSEC_CONFIG_AUTO
64474+ depends on GRKERNSEC_CHROOT && BLK_DEV_INITRD
64475+ help
64476+ If you say Y here, tasks started prior to init will be exempted from
64477+ grsecurity's chroot restrictions. This option is mainly meant to
64478+ resolve Plymouth's performing privileged operations unnecessarily
64479+ in a chroot.
64480+
64481+endmenu
64482+menu "Kernel Auditing"
64483+depends on GRKERNSEC
64484+
64485+config GRKERNSEC_AUDIT_GROUP
64486+ bool "Single group for auditing"
64487+ help
64488+ If you say Y here, the exec and chdir logging features will only operate
64489+ on a group you specify. This option is recommended if you only want to
64490+ watch certain users instead of having a large amount of logs from the
64491+ entire system. If the sysctl option is enabled, a sysctl option with
64492+ name "audit_group" is created.
64493+
64494+config GRKERNSEC_AUDIT_GID
64495+ int "GID for auditing"
64496+ depends on GRKERNSEC_AUDIT_GROUP
64497+ default 1007
64498+
64499+config GRKERNSEC_EXECLOG
64500+ bool "Exec logging"
64501+ help
64502+ If you say Y here, all execve() calls will be logged (since the
64503+ other exec*() calls are frontends to execve(), all execution
64504+ will be logged). Useful for shell-servers that like to keep track
64505+ of their users. If the sysctl option is enabled, a sysctl option with
64506+ name "exec_logging" is created.
64507+ WARNING: This option when enabled will produce a LOT of logs, especially
64508+ on an active system.
64509+
64510+config GRKERNSEC_RESLOG
64511+ bool "Resource logging"
64512+ default y if GRKERNSEC_CONFIG_AUTO
64513+ help
64514+ If you say Y here, all attempts to overstep resource limits will
64515+ be logged with the resource name, the requested size, and the current
64516+ limit. It is highly recommended that you say Y here. If the sysctl
64517+ option is enabled, a sysctl option with name "resource_logging" is
64518+ created. If the RBAC system is enabled, the sysctl value is ignored.
64519+
64520+config GRKERNSEC_CHROOT_EXECLOG
64521+ bool "Log execs within chroot"
64522+ help
64523+ If you say Y here, all executions inside a chroot jail will be logged
64524+ to syslog. This can cause a large amount of logs if certain
64525+ applications (eg. djb's daemontools) are installed on the system, and
64526+ is therefore left as an option. If the sysctl option is enabled, a
64527+ sysctl option with name "chroot_execlog" is created.
64528+
64529+config GRKERNSEC_AUDIT_PTRACE
64530+ bool "Ptrace logging"
64531+ help
64532+ If you say Y here, all attempts to attach to a process via ptrace
64533+ will be logged. If the sysctl option is enabled, a sysctl option
64534+ with name "audit_ptrace" is created.
64535+
64536+config GRKERNSEC_AUDIT_CHDIR
64537+ bool "Chdir logging"
64538+ help
64539+ If you say Y here, all chdir() calls will be logged. If the sysctl
64540+ option is enabled, a sysctl option with name "audit_chdir" is created.
64541+
64542+config GRKERNSEC_AUDIT_MOUNT
64543+ bool "(Un)Mount logging"
64544+ help
64545+ If you say Y here, all mounts and unmounts will be logged. If the
64546+ sysctl option is enabled, a sysctl option with name "audit_mount" is
64547+ created.
64548+
64549+config GRKERNSEC_SIGNAL
64550+ bool "Signal logging"
64551+ default y if GRKERNSEC_CONFIG_AUTO
64552+ help
64553+ If you say Y here, certain important signals will be logged, such as
64554+ SIGSEGV, which will as a result inform you of when a error in a program
64555+ occurred, which in some cases could mean a possible exploit attempt.
64556+ If the sysctl option is enabled, a sysctl option with name
64557+ "signal_logging" is created.
64558+
64559+config GRKERNSEC_FORKFAIL
64560+ bool "Fork failure logging"
64561+ help
64562+ If you say Y here, all failed fork() attempts will be logged.
64563+ This could suggest a fork bomb, or someone attempting to overstep
64564+ their process limit. If the sysctl option is enabled, a sysctl option
64565+ with name "forkfail_logging" is created.
64566+
64567+config GRKERNSEC_TIME
64568+ bool "Time change logging"
64569+ default y if GRKERNSEC_CONFIG_AUTO
64570+ help
64571+ If you say Y here, any changes of the system clock will be logged.
64572+ If the sysctl option is enabled, a sysctl option with name
64573+ "timechange_logging" is created.
64574+
64575+config GRKERNSEC_PROC_IPADDR
64576+ bool "/proc/<pid>/ipaddr support"
64577+ default y if GRKERNSEC_CONFIG_AUTO
64578+ help
64579+ If you say Y here, a new entry will be added to each /proc/<pid>
64580+ directory that contains the IP address of the person using the task.
64581+ The IP is carried across local TCP and AF_UNIX stream sockets.
64582+ This information can be useful for IDS/IPSes to perform remote response
64583+ to a local attack. The entry is readable by only the owner of the
64584+ process (and root if he has CAP_DAC_OVERRIDE, which can be removed via
64585+ the RBAC system), and thus does not create privacy concerns.
64586+
64587+config GRKERNSEC_RWXMAP_LOG
64588+ bool 'Denied RWX mmap/mprotect logging'
64589+ default y if GRKERNSEC_CONFIG_AUTO
64590+ depends on PAX_MPROTECT && !PAX_EMUPLT && !PAX_EMUSIGRT
64591+ help
64592+ If you say Y here, calls to mmap() and mprotect() with explicit
64593+ usage of PROT_WRITE and PROT_EXEC together will be logged when
64594+ denied by the PAX_MPROTECT feature. This feature will also
64595+ log other problematic scenarios that can occur when PAX_MPROTECT
64596+ is enabled on a binary, like textrels and PT_GNU_STACK. If the
64597+ sysctl option is enabled, a sysctl option with name "rwxmap_logging"
64598+ is created.
64599+
64600+endmenu
64601+
64602+menu "Executable Protections"
64603+depends on GRKERNSEC
64604+
64605+config GRKERNSEC_DMESG
64606+ bool "Dmesg(8) restriction"
64607+ default y if GRKERNSEC_CONFIG_AUTO
64608+ help
64609+ If you say Y here, non-root users will not be able to use dmesg(8)
64610+ to view the contents of the kernel's circular log buffer.
64611+ The kernel's log buffer often contains kernel addresses and other
64612+ identifying information useful to an attacker in fingerprinting a
64613+ system for a targeted exploit.
64614+ If the sysctl option is enabled, a sysctl option with name "dmesg" is
64615+ created.
64616+
64617+config GRKERNSEC_HARDEN_PTRACE
64618+ bool "Deter ptrace-based process snooping"
64619+ default y if GRKERNSEC_CONFIG_AUTO
64620+ help
64621+ If you say Y here, TTY sniffers and other malicious monitoring
64622+ programs implemented through ptrace will be defeated. If you
64623+ have been using the RBAC system, this option has already been
64624+ enabled for several years for all users, with the ability to make
64625+ fine-grained exceptions.
64626+
64627+ This option only affects the ability of non-root users to ptrace
64628+ processes that are not a descendent of the ptracing process.
64629+ This means that strace ./binary and gdb ./binary will still work,
64630+ but attaching to arbitrary processes will not. If the sysctl
64631+ option is enabled, a sysctl option with name "harden_ptrace" is
64632+ created.
64633+
64634+config GRKERNSEC_PTRACE_READEXEC
64635+ bool "Require read access to ptrace sensitive binaries"
64636+ default y if GRKERNSEC_CONFIG_AUTO
64637+ help
64638+ If you say Y here, unprivileged users will not be able to ptrace unreadable
64639+ binaries. This option is useful in environments that
64640+ remove the read bits (e.g. file mode 4711) from suid binaries to
64641+ prevent infoleaking of their contents. This option adds
64642+ consistency to the use of that file mode, as the binary could normally
64643+ be read out when run without privileges while ptracing.
64644+
64645+ If the sysctl option is enabled, a sysctl option with name "ptrace_readexec"
64646+ is created.
64647+
64648+config GRKERNSEC_SETXID
64649+ bool "Enforce consistent multithreaded privileges"
64650+ default y if GRKERNSEC_CONFIG_AUTO
64651+ depends on (X86 || SPARC64 || PPC || ARM || MIPS)
64652+ help
64653+ If you say Y here, a change from a root uid to a non-root uid
64654+ in a multithreaded application will cause the resulting uids,
64655+ gids, supplementary groups, and capabilities in that thread
64656+ to be propagated to the other threads of the process. In most
64657+ cases this is unnecessary, as glibc will emulate this behavior
64658+ on behalf of the application. Other libcs do not act in the
64659+ same way, allowing the other threads of the process to continue
64660+ running with root privileges. If the sysctl option is enabled,
64661+ a sysctl option with name "consistent_setxid" is created.
64662+
64663+config GRKERNSEC_HARDEN_IPC
64664+ bool "Disallow access to overly-permissive IPC objects"
64665+ default y if GRKERNSEC_CONFIG_AUTO
64666+ depends on SYSVIPC
64667+ help
64668+ If you say Y here, access to overly-permissive IPC objects (shared
64669+ memory, message queues, and semaphores) will be denied for processes
64670+ given the following criteria beyond normal permission checks:
64671+ 1) If the IPC object is world-accessible and the euid doesn't match
64672+ that of the creator or current uid for the IPC object
64673+ 2) If the IPC object is group-accessible and the egid doesn't
64674+ match that of the creator or current gid for the IPC object
64675+ It's a common error to grant too much permission to these objects,
64676+ with impact ranging from denial of service and information leaking to
64677+ privilege escalation. This feature was developed in response to
64678+ research by Tim Brown:
64679+ http://labs.portcullis.co.uk/whitepapers/memory-squatting-attacks-on-system-v-shared-memory/
64680+ who found hundreds of such insecure usages. Processes with
64681+ CAP_IPC_OWNER are still permitted to access these IPC objects.
64682+ If the sysctl option is enabled, a sysctl option with name
64683+ "harden_ipc" is created.
64684+
64685+config GRKERNSEC_TPE
64686+ bool "Trusted Path Execution (TPE)"
64687+ default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
64688+ help
64689+ If you say Y here, you will be able to choose a gid to add to the
64690+ supplementary groups of users you want to mark as "untrusted."
64691+ These users will not be able to execute any files that are not in
64692+ root-owned directories writable only by root. If the sysctl option
64693+ is enabled, a sysctl option with name "tpe" is created.
64694+
64695+config GRKERNSEC_TPE_ALL
64696+ bool "Partially restrict all non-root users"
64697+ depends on GRKERNSEC_TPE
64698+ help
64699+ If you say Y here, all non-root users will be covered under
64700+ a weaker TPE restriction. This is separate from, and in addition to,
64701+ the main TPE options that you have selected elsewhere. Thus, if a
64702+ "trusted" GID is chosen, this restriction applies to even that GID.
64703+ Under this restriction, all non-root users will only be allowed to
64704+ execute files in directories they own that are not group or
64705+ world-writable, or in directories owned by root and writable only by
64706+ root. If the sysctl option is enabled, a sysctl option with name
64707+ "tpe_restrict_all" is created.
64708+
64709+config GRKERNSEC_TPE_INVERT
64710+ bool "Invert GID option"
64711+ depends on GRKERNSEC_TPE
64712+ help
64713+ If you say Y here, the group you specify in the TPE configuration will
64714+ decide what group TPE restrictions will be *disabled* for. This
64715+ option is useful if you want TPE restrictions to be applied to most
64716+ users on the system. If the sysctl option is enabled, a sysctl option
64717+ with name "tpe_invert" is created. Unlike other sysctl options, this
64718+ entry will default to on for backward-compatibility.
64719+
64720+config GRKERNSEC_TPE_GID
64721+ int
64722+ default GRKERNSEC_TPE_UNTRUSTED_GID if (GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT)
64723+ default GRKERNSEC_TPE_TRUSTED_GID if (GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT)
64724+
64725+config GRKERNSEC_TPE_UNTRUSTED_GID
64726+ int "GID for TPE-untrusted users"
64727+ depends on GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT
64728+ default 1005
64729+ help
64730+ Setting this GID determines what group TPE restrictions will be
64731+ *enabled* for. If the sysctl option is enabled, a sysctl option
64732+ with name "tpe_gid" is created.
64733+
64734+config GRKERNSEC_TPE_TRUSTED_GID
64735+ int "GID for TPE-trusted users"
64736+ depends on GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT
64737+ default 1005
64738+ help
64739+ Setting this GID determines what group TPE restrictions will be
64740+ *disabled* for. If the sysctl option is enabled, a sysctl option
64741+ with name "tpe_gid" is created.
64742+
64743+endmenu
64744+menu "Network Protections"
64745+depends on GRKERNSEC
64746+
64747+config GRKERNSEC_RANDNET
64748+ bool "Larger entropy pools"
64749+ default y if GRKERNSEC_CONFIG_AUTO
64750+ help
64751+ If you say Y here, the entropy pools used for many features of Linux
64752+ and grsecurity will be doubled in size. Since several grsecurity
64753+ features use additional randomness, it is recommended that you say Y
64754+ here. Saying Y here has a similar effect as modifying
64755+ /proc/sys/kernel/random/poolsize.
64756+
64757+config GRKERNSEC_BLACKHOLE
64758+ bool "TCP/UDP blackhole and LAST_ACK DoS prevention"
64759+ default y if GRKERNSEC_CONFIG_AUTO
64760+ depends on NET
64761+ help
64762+ If you say Y here, neither TCP resets nor ICMP
64763+ destination-unreachable packets will be sent in response to packets
64764+ sent to ports for which no associated listening process exists.
64765+ This feature supports both IPV4 and IPV6 and exempts the
64766+ loopback interface from blackholing. Enabling this feature
64767+ makes a host more resilient to DoS attacks and reduces network
64768+ visibility against scanners.
64769+
64770+ The blackhole feature as-implemented is equivalent to the FreeBSD
64771+ blackhole feature, as it prevents RST responses to all packets, not
64772+ just SYNs. Under most application behavior this causes no
64773+ problems, but applications (like haproxy) may not close certain
64774+ connections in a way that cleanly terminates them on the remote
64775+ end, leaving the remote host in LAST_ACK state. Because of this
64776+ side-effect and to prevent intentional LAST_ACK DoSes, this
64777+ feature also adds automatic mitigation against such attacks.
64778+ The mitigation drastically reduces the amount of time a socket
64779+ can spend in LAST_ACK state. If you're using haproxy and not
64780+ all servers it connects to have this option enabled, consider
64781+ disabling this feature on the haproxy host.
64782+
64783+ If the sysctl option is enabled, two sysctl options with names
64784+ "ip_blackhole" and "lastack_retries" will be created.
64785+ While "ip_blackhole" takes the standard zero/non-zero on/off
64786+ toggle, "lastack_retries" uses the same kinds of values as
64787+ "tcp_retries1" and "tcp_retries2". The default value of 4
64788+ prevents a socket from lasting more than 45 seconds in LAST_ACK
64789+ state.
64790+
64791+config GRKERNSEC_NO_SIMULT_CONNECT
64792+ bool "Disable TCP Simultaneous Connect"
64793+ default y if GRKERNSEC_CONFIG_AUTO
64794+ depends on NET
64795+ help
64796+ If you say Y here, a feature by Willy Tarreau will be enabled that
64797+ removes a weakness in Linux's strict implementation of TCP that
64798+ allows two clients to connect to each other without either entering
64799+ a listening state. The weakness allows an attacker to easily prevent
64800+ a client from connecting to a known server provided the source port
64801+ for the connection is guessed correctly.
64802+
64803+ As the weakness could be used to prevent an antivirus or IPS from
64804+ fetching updates, or prevent an SSL gateway from fetching a CRL,
64805+ it should be eliminated by enabling this option. Though Linux is
64806+ one of few operating systems supporting simultaneous connect, it
64807+ has no legitimate use in practice and is rarely supported by firewalls.
64808+
64809+config GRKERNSEC_SOCKET
64810+ bool "Socket restrictions"
64811+ depends on NET
64812+ help
64813+ If you say Y here, you will be able to choose from several options.
64814+ If you assign a GID on your system and add it to the supplementary
64815+ groups of users you want to restrict socket access to, this patch
64816+ will perform up to three things, based on the option(s) you choose.
64817+
64818+config GRKERNSEC_SOCKET_ALL
64819+ bool "Deny any sockets to group"
64820+ depends on GRKERNSEC_SOCKET
64821+ help
64822+ If you say Y here, you will be able to choose a GID of whose users will
64823+ be unable to connect to other hosts from your machine or run server
64824+ applications from your machine. If the sysctl option is enabled, a
64825+ sysctl option with name "socket_all" is created.
64826+
64827+config GRKERNSEC_SOCKET_ALL_GID
64828+ int "GID to deny all sockets for"
64829+ depends on GRKERNSEC_SOCKET_ALL
64830+ default 1004
64831+ help
64832+ Here you can choose the GID to disable socket access for. Remember to
64833+ add the users you want socket access disabled for to the GID
64834+ specified here. If the sysctl option is enabled, a sysctl option
64835+ with name "socket_all_gid" is created.
64836+
64837+config GRKERNSEC_SOCKET_CLIENT
64838+ bool "Deny client sockets to group"
64839+ depends on GRKERNSEC_SOCKET
64840+ help
64841+ If you say Y here, you will be able to choose a GID of whose users will
64842+ be unable to connect to other hosts from your machine, but will be
64843+ able to run servers. If this option is enabled, all users in the group
64844+ you specify will have to use passive mode when initiating ftp transfers
64845+ from the shell on your machine. If the sysctl option is enabled, a
64846+ sysctl option with name "socket_client" is created.
64847+
64848+config GRKERNSEC_SOCKET_CLIENT_GID
64849+ int "GID to deny client sockets for"
64850+ depends on GRKERNSEC_SOCKET_CLIENT
64851+ default 1003
64852+ help
64853+ Here you can choose the GID to disable client socket access for.
64854+ Remember to add the users you want client socket access disabled for to
64855+ the GID specified here. If the sysctl option is enabled, a sysctl
64856+ option with name "socket_client_gid" is created.
64857+
64858+config GRKERNSEC_SOCKET_SERVER
64859+ bool "Deny server sockets to group"
64860+ depends on GRKERNSEC_SOCKET
64861+ help
64862+ If you say Y here, you will be able to choose a GID of whose users will
64863+ be unable to run server applications from your machine. If the sysctl
64864+ option is enabled, a sysctl option with name "socket_server" is created.
64865+
64866+config GRKERNSEC_SOCKET_SERVER_GID
64867+ int "GID to deny server sockets for"
64868+ depends on GRKERNSEC_SOCKET_SERVER
64869+ default 1002
64870+ help
64871+ Here you can choose the GID to disable server socket access for.
64872+ Remember to add the users you want server socket access disabled for to
64873+ the GID specified here. If the sysctl option is enabled, a sysctl
64874+ option with name "socket_server_gid" is created.
64875+
64876+endmenu
64877+
64878+menu "Physical Protections"
64879+depends on GRKERNSEC
64880+
64881+config GRKERNSEC_DENYUSB
64882+ bool "Deny new USB connections after toggle"
64883+ default y if GRKERNSEC_CONFIG_AUTO
64884+ depends on SYSCTL && USB_SUPPORT
64885+ help
64886+ If you say Y here, a new sysctl option with name "deny_new_usb"
64887+ will be created. Setting its value to 1 will prevent any new
64888+ USB devices from being recognized by the OS. Any attempted USB
64889+ device insertion will be logged. This option is intended to be
64890+ used against custom USB devices designed to exploit vulnerabilities
64891+ in various USB device drivers.
64892+
64893+ For greatest effectiveness, this sysctl should be set after any
64894+ relevant init scripts. This option is safe to enable in distros
64895+ as each user can choose whether or not to toggle the sysctl.
64896+
64897+config GRKERNSEC_DENYUSB_FORCE
64898+ bool "Reject all USB devices not connected at boot"
64899+ select USB
64900+ depends on GRKERNSEC_DENYUSB
64901+ help
64902+ If you say Y here, a variant of GRKERNSEC_DENYUSB will be enabled
64903+ that doesn't involve a sysctl entry. This option should only be
64904+ enabled if you're sure you want to deny all new USB connections
64905+ at runtime and don't want to modify init scripts. This should not
64906+ be enabled by distros. It forces the core USB code to be built
64907+ into the kernel image so that all devices connected at boot time
64908+ can be recognized and new USB device connections can be prevented
64909+ prior to init running.
64910+
64911+endmenu
64912+
64913+menu "Sysctl Support"
64914+depends on GRKERNSEC && SYSCTL
64915+
64916+config GRKERNSEC_SYSCTL
64917+ bool "Sysctl support"
64918+ default y if GRKERNSEC_CONFIG_AUTO
64919+ help
64920+ If you say Y here, you will be able to change the options that
64921+ grsecurity runs with at bootup, without having to recompile your
64922+ kernel. You can echo values to files in /proc/sys/kernel/grsecurity
64923+ to enable (1) or disable (0) various features. All the sysctl entries
64924+ are mutable until the "grsec_lock" entry is set to a non-zero value.
64925+ All features enabled in the kernel configuration are disabled at boot
64926+ if you do not say Y to the "Turn on features by default" option.
64927+ All options should be set at startup, and the grsec_lock entry should
64928+ be set to a non-zero value after all the options are set.
64929+ *THIS IS EXTREMELY IMPORTANT*
64930+
64931+config GRKERNSEC_SYSCTL_DISTRO
64932+ bool "Extra sysctl support for distro makers (READ HELP)"
64933+ depends on GRKERNSEC_SYSCTL && GRKERNSEC_IO
64934+ help
64935+ If you say Y here, additional sysctl options will be created
64936+ for features that affect processes running as root. Therefore,
64937+ it is critical when using this option that the grsec_lock entry be
64938+ enabled after boot. Only distros with prebuilt kernel packages
64939+ with this option enabled that can ensure grsec_lock is enabled
64940+ after boot should use this option.
64941+ *Failure to set grsec_lock after boot makes all grsec features
64942+ this option covers useless*
64943+
64944+ Currently this option creates the following sysctl entries:
64945+ "Disable Privileged I/O": "disable_priv_io"
64946+
64947+config GRKERNSEC_SYSCTL_ON
64948+ bool "Turn on features by default"
64949+ default y if GRKERNSEC_CONFIG_AUTO
64950+ depends on GRKERNSEC_SYSCTL
64951+ help
64952+ If you say Y here, instead of having all features enabled in the
64953+ kernel configuration disabled at boot time, the features will be
64954+ enabled at boot time. It is recommended you say Y here unless
64955+ there is some reason you would want all sysctl-tunable features to
64956+ be disabled by default. As mentioned elsewhere, it is important
64957+ to enable the grsec_lock entry once you have finished modifying
64958+ the sysctl entries.
64959+
64960+endmenu
64961+menu "Logging Options"
64962+depends on GRKERNSEC
64963+
64964+config GRKERNSEC_FLOODTIME
64965+ int "Seconds in between log messages (minimum)"
64966+ default 10
64967+ help
64968+ This option allows you to enforce the number of seconds between
64969+ grsecurity log messages. The default should be suitable for most
64970+ people, however, if you choose to change it, choose a value small enough
64971+ to allow informative logs to be produced, but large enough to
64972+ prevent flooding.
64973+
64974+config GRKERNSEC_FLOODBURST
64975+ int "Number of messages in a burst (maximum)"
64976+ default 6
64977+ help
64978+ This option allows you to choose the maximum number of messages allowed
64979+ within the flood time interval you chose in a separate option. The
64980+ default should be suitable for most people, however if you find that
64981+ many of your logs are being interpreted as flooding, you may want to
64982+ raise this value.
64983+
64984+endmenu
64985diff --git a/grsecurity/Makefile b/grsecurity/Makefile
64986new file mode 100644
64987index 0000000..85beb79
64988--- /dev/null
64989+++ b/grsecurity/Makefile
64990@@ -0,0 +1,43 @@
64991+# grsecurity's ACL system was originally written in 2001 by Michael Dalton
64992+# during 2001-2009 it has been completely redesigned by Brad Spengler
64993+# into an RBAC system
64994+#
64995+# All code in this directory and various hooks inserted throughout the kernel
64996+# are copyright Brad Spengler - Open Source Security, Inc., and released
64997+# under the GPL v2 or higher
64998+
64999+KBUILD_CFLAGS += -Werror
65000+
65001+obj-y = grsec_chdir.o grsec_chroot.o grsec_exec.o grsec_fifo.o grsec_fork.o \
65002+ grsec_mount.o grsec_sig.o grsec_sysctl.o \
65003+ grsec_time.o grsec_tpe.o grsec_link.o grsec_pax.o grsec_ptrace.o \
65004+ grsec_usb.o grsec_ipc.o
65005+
65006+obj-$(CONFIG_GRKERNSEC) += grsec_init.o grsum.o gracl.o gracl_segv.o \
65007+ gracl_cap.o gracl_alloc.o gracl_shm.o grsec_mem.o gracl_fs.o \
65008+ gracl_learn.o grsec_log.o gracl_policy.o
65009+ifdef CONFIG_COMPAT
65010+obj-$(CONFIG_GRKERNSEC) += gracl_compat.o
65011+endif
65012+
65013+obj-$(CONFIG_GRKERNSEC_RESLOG) += gracl_res.o
65014+
65015+ifdef CONFIG_NET
65016+obj-y += grsec_sock.o
65017+obj-$(CONFIG_GRKERNSEC) += gracl_ip.o
65018+endif
65019+
65020+ifndef CONFIG_GRKERNSEC
65021+obj-y += grsec_disabled.o
65022+endif
65023+
65024+ifdef CONFIG_GRKERNSEC_HIDESYM
65025+extra-y := grsec_hidesym.o
65026+$(obj)/grsec_hidesym.o:
65027+ @-chmod -f 500 /boot
65028+ @-chmod -f 500 /lib/modules
65029+ @-chmod -f 500 /lib64/modules
65030+ @-chmod -f 500 /lib32/modules
65031+ @-chmod -f 700 .
65032+ @echo ' grsec: protected kernel image paths'
65033+endif
65034diff --git a/grsecurity/gracl.c b/grsecurity/gracl.c
65035new file mode 100644
65036index 0000000..90f71ce
65037--- /dev/null
65038+++ b/grsecurity/gracl.c
65039@@ -0,0 +1,2679 @@
65040+#include <linux/kernel.h>
65041+#include <linux/module.h>
65042+#include <linux/sched.h>
65043+#include <linux/mm.h>
65044+#include <linux/file.h>
65045+#include <linux/fs.h>
65046+#include <linux/namei.h>
65047+#include <linux/mount.h>
65048+#include <linux/tty.h>
65049+#include <linux/proc_fs.h>
65050+#include <linux/lglock.h>
65051+#include <linux/slab.h>
65052+#include <linux/vmalloc.h>
65053+#include <linux/types.h>
65054+#include <linux/sysctl.h>
65055+#include <linux/netdevice.h>
65056+#include <linux/ptrace.h>
65057+#include <linux/gracl.h>
65058+#include <linux/gralloc.h>
65059+#include <linux/security.h>
65060+#include <linux/grinternal.h>
65061+#include <linux/pid_namespace.h>
65062+#include <linux/stop_machine.h>
65063+#include <linux/fdtable.h>
65064+#include <linux/percpu.h>
65065+#include <linux/lglock.h>
65066+#include <linux/hugetlb.h>
65067+#include <linux/posix-timers.h>
65068+#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
65069+#include <linux/magic.h>
65070+#include <linux/pagemap.h>
65071+#include "../fs/btrfs/async-thread.h"
65072+#include "../fs/btrfs/ctree.h"
65073+#include "../fs/btrfs/btrfs_inode.h"
65074+#endif
65075+#include "../fs/mount.h"
65076+
65077+#include <asm/uaccess.h>
65078+#include <asm/errno.h>
65079+#include <asm/mman.h>
65080+
65081+#define FOR_EACH_ROLE_START(role) \
65082+ role = running_polstate.role_list; \
65083+ while (role) {
65084+
65085+#define FOR_EACH_ROLE_END(role) \
65086+ role = role->prev; \
65087+ }
65088+
65089+extern struct lglock vfsmount_lock;
65090+
65091+extern struct path gr_real_root;
65092+
65093+static struct gr_policy_state running_polstate;
65094+struct gr_policy_state *polstate = &running_polstate;
65095+extern struct gr_alloc_state *current_alloc_state;
65096+
65097+extern char *gr_shared_page[4];
65098+DEFINE_RWLOCK(gr_inode_lock);
65099+
65100+static unsigned int gr_status __read_only = GR_STATUS_INIT;
65101+
65102+#ifdef CONFIG_NET
65103+extern struct vfsmount *sock_mnt;
65104+#endif
65105+
65106+extern struct vfsmount *pipe_mnt;
65107+extern struct vfsmount *shm_mnt;
65108+
65109+#ifdef CONFIG_HUGETLBFS
65110+extern struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
65111+#endif
65112+
65113+extern u16 acl_sp_role_value;
65114+extern struct acl_object_label *fakefs_obj_rw;
65115+extern struct acl_object_label *fakefs_obj_rwx;
65116+
65117+int gr_acl_is_enabled(void)
65118+{
65119+ return (gr_status & GR_READY);
65120+}
65121+
65122+void gr_enable_rbac_system(void)
65123+{
65124+ pax_open_kernel();
65125+ gr_status |= GR_READY;
65126+ pax_close_kernel();
65127+}
65128+
65129+int gr_rbac_disable(void *unused)
65130+{
65131+ pax_open_kernel();
65132+ gr_status &= ~GR_READY;
65133+ pax_close_kernel();
65134+
65135+ return 0;
65136+}
65137+
65138+static inline dev_t __get_dev(const struct dentry *dentry)
65139+{
65140+#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
65141+ if (dentry->d_sb->s_magic == BTRFS_SUPER_MAGIC)
65142+ return BTRFS_I(dentry->d_inode)->root->anon_dev;
65143+ else
65144+#endif
65145+ return dentry->d_sb->s_dev;
65146+}
65147+
65148+dev_t gr_get_dev_from_dentry(struct dentry *dentry)
65149+{
65150+ return __get_dev(dentry);
65151+}
65152+
65153+static char gr_task_roletype_to_char(struct task_struct *task)
65154+{
65155+ switch (task->role->roletype &
65156+ (GR_ROLE_DEFAULT | GR_ROLE_USER | GR_ROLE_GROUP |
65157+ GR_ROLE_SPECIAL)) {
65158+ case GR_ROLE_DEFAULT:
65159+ return 'D';
65160+ case GR_ROLE_USER:
65161+ return 'U';
65162+ case GR_ROLE_GROUP:
65163+ return 'G';
65164+ case GR_ROLE_SPECIAL:
65165+ return 'S';
65166+ }
65167+
65168+ return 'X';
65169+}
65170+
65171+char gr_roletype_to_char(void)
65172+{
65173+ return gr_task_roletype_to_char(current);
65174+}
65175+
65176+__inline__ int
65177+gr_acl_tpe_check(void)
65178+{
65179+ if (unlikely(!(gr_status & GR_READY)))
65180+ return 0;
65181+ if (current->role->roletype & GR_ROLE_TPE)
65182+ return 1;
65183+ else
65184+ return 0;
65185+}
65186+
65187+int
65188+gr_handle_rawio(const struct inode *inode)
65189+{
65190+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
65191+ if (inode && (S_ISBLK(inode->i_mode) || (S_ISCHR(inode->i_mode) && imajor(inode) == RAW_MAJOR)) &&
65192+ grsec_enable_chroot_caps && proc_is_chrooted(current) &&
65193+ !capable(CAP_SYS_RAWIO))
65194+ return 1;
65195+#endif
65196+ return 0;
65197+}
65198+
65199+int
65200+gr_streq(const char *a, const char *b, const unsigned int lena, const unsigned int lenb)
65201+{
65202+ if (likely(lena != lenb))
65203+ return 0;
65204+
65205+ return !memcmp(a, b, lena);
65206+}
65207+
65208+static int prepend(char **buffer, int *buflen, const char *str, int namelen)
65209+{
65210+ *buflen -= namelen;
65211+ if (*buflen < 0)
65212+ return -ENAMETOOLONG;
65213+ *buffer -= namelen;
65214+ memcpy(*buffer, str, namelen);
65215+ return 0;
65216+}
65217+
65218+static int prepend_name(char **buffer, int *buflen, struct qstr *name)
65219+{
65220+ return prepend(buffer, buflen, name->name, name->len);
65221+}
65222+
65223+static int prepend_path(const struct path *path, struct path *root,
65224+ char **buffer, int *buflen)
65225+{
65226+ struct dentry *dentry = path->dentry;
65227+ struct vfsmount *vfsmnt = path->mnt;
65228+ struct mount *mnt = real_mount(vfsmnt);
65229+ bool slash = false;
65230+ int error = 0;
65231+
65232+ while (dentry != root->dentry || vfsmnt != root->mnt) {
65233+ struct dentry * parent;
65234+
65235+ if (dentry == vfsmnt->mnt_root || IS_ROOT(dentry)) {
65236+ /* Global root? */
65237+ if (!mnt_has_parent(mnt)) {
65238+ goto out;
65239+ }
65240+ dentry = mnt->mnt_mountpoint;
65241+ mnt = mnt->mnt_parent;
65242+ vfsmnt = &mnt->mnt;
65243+ continue;
65244+ }
65245+ parent = dentry->d_parent;
65246+ prefetch(parent);
65247+ spin_lock(&dentry->d_lock);
65248+ error = prepend_name(buffer, buflen, &dentry->d_name);
65249+ spin_unlock(&dentry->d_lock);
65250+ if (!error)
65251+ error = prepend(buffer, buflen, "/", 1);
65252+ if (error)
65253+ break;
65254+
65255+ slash = true;
65256+ dentry = parent;
65257+ }
65258+
65259+out:
65260+ if (!error && !slash)
65261+ error = prepend(buffer, buflen, "/", 1);
65262+
65263+ return error;
65264+}
65265+
65266+/* this must be called with vfsmount_lock and rename_lock held */
65267+
65268+static char *__our_d_path(const struct path *path, struct path *root,
65269+ char *buf, int buflen)
65270+{
65271+ char *res = buf + buflen;
65272+ int error;
65273+
65274+ prepend(&res, &buflen, "\0", 1);
65275+ error = prepend_path(path, root, &res, &buflen);
65276+ if (error)
65277+ return ERR_PTR(error);
65278+
65279+ return res;
65280+}
65281+
65282+static char *
65283+gen_full_path(struct path *path, struct path *root, char *buf, int buflen)
65284+{
65285+ char *retval;
65286+
65287+ retval = __our_d_path(path, root, buf, buflen);
65288+ if (unlikely(IS_ERR(retval)))
65289+ retval = strcpy(buf, "<path too long>");
65290+ else if (unlikely(retval[1] == '/' && retval[2] == '\0'))
65291+ retval[1] = '\0';
65292+
65293+ return retval;
65294+}
65295+
65296+static char *
65297+__d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
65298+ char *buf, int buflen)
65299+{
65300+ struct path path;
65301+ char *res;
65302+
65303+ path.dentry = (struct dentry *)dentry;
65304+ path.mnt = (struct vfsmount *)vfsmnt;
65305+
65306+ /* we can use gr_real_root.dentry, gr_real_root.mnt, because this is only called
65307+ by the RBAC system */
65308+ res = gen_full_path(&path, &gr_real_root, buf, buflen);
65309+
65310+ return res;
65311+}
65312+
65313+static char *
65314+d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
65315+ char *buf, int buflen)
65316+{
65317+ char *res;
65318+ struct path path;
65319+ struct path root;
65320+ struct task_struct *reaper = init_pid_ns.child_reaper;
65321+
65322+ path.dentry = (struct dentry *)dentry;
65323+ path.mnt = (struct vfsmount *)vfsmnt;
65324+
65325+ /* we can't use gr_real_root.dentry, gr_real_root.mnt, because they belong only to the RBAC system */
65326+ get_fs_root(reaper->fs, &root);
65327+
65328+ br_read_lock(&vfsmount_lock);
65329+ write_seqlock(&rename_lock);
65330+ res = gen_full_path(&path, &root, buf, buflen);
65331+ write_sequnlock(&rename_lock);
65332+ br_read_unlock(&vfsmount_lock);
65333+
65334+ path_put(&root);
65335+ return res;
65336+}
65337+
65338+char *
65339+gr_to_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
65340+{
65341+ char *ret;
65342+ br_read_lock(&vfsmount_lock);
65343+ write_seqlock(&rename_lock);
65344+ ret = __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
65345+ PAGE_SIZE);
65346+ write_sequnlock(&rename_lock);
65347+ br_read_unlock(&vfsmount_lock);
65348+ return ret;
65349+}
65350+
65351+static char *
65352+gr_to_proc_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
65353+{
65354+ char *ret;
65355+ char *buf;
65356+ int buflen;
65357+
65358+ br_read_lock(&vfsmount_lock);
65359+ write_seqlock(&rename_lock);
65360+ buf = per_cpu_ptr(gr_shared_page[0], smp_processor_id());
65361+ ret = __d_real_path(dentry, mnt, buf, PAGE_SIZE - 6);
65362+ buflen = (int)(ret - buf);
65363+ if (buflen >= 5)
65364+ prepend(&ret, &buflen, "/proc", 5);
65365+ else
65366+ ret = strcpy(buf, "<path too long>");
65367+ write_sequnlock(&rename_lock);
65368+ br_read_unlock(&vfsmount_lock);
65369+ return ret;
65370+}
65371+
65372+char *
65373+gr_to_filename_nolock(const struct dentry *dentry, const struct vfsmount *mnt)
65374+{
65375+ return __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
65376+ PAGE_SIZE);
65377+}
65378+
65379+char *
65380+gr_to_filename(const struct dentry *dentry, const struct vfsmount *mnt)
65381+{
65382+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
65383+ PAGE_SIZE);
65384+}
65385+
65386+char *
65387+gr_to_filename1(const struct dentry *dentry, const struct vfsmount *mnt)
65388+{
65389+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[1], smp_processor_id()),
65390+ PAGE_SIZE);
65391+}
65392+
65393+char *
65394+gr_to_filename2(const struct dentry *dentry, const struct vfsmount *mnt)
65395+{
65396+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[2], smp_processor_id()),
65397+ PAGE_SIZE);
65398+}
65399+
65400+char *
65401+gr_to_filename3(const struct dentry *dentry, const struct vfsmount *mnt)
65402+{
65403+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[3], smp_processor_id()),
65404+ PAGE_SIZE);
65405+}
65406+
65407+__inline__ __u32
65408+to_gr_audit(const __u32 reqmode)
65409+{
65410+ /* masks off auditable permission flags, then shifts them to create
65411+ auditing flags, and adds the special case of append auditing if
65412+ we're requesting write */
65413+ return (((reqmode & ~GR_AUDITS) << 10) | ((reqmode & GR_WRITE) ? GR_AUDIT_APPEND : 0));
65414+}
65415+
65416+struct acl_role_label *
65417+__lookup_acl_role_label(const struct gr_policy_state *state, const struct task_struct *task, const uid_t uid,
65418+ const gid_t gid)
65419+{
65420+ unsigned int index = gr_rhash(uid, GR_ROLE_USER, state->acl_role_set.r_size);
65421+ struct acl_role_label *match;
65422+ struct role_allowed_ip *ipp;
65423+ unsigned int x;
65424+ u32 curr_ip = task->signal->saved_ip;
65425+
65426+ match = state->acl_role_set.r_hash[index];
65427+
65428+ while (match) {
65429+ if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_USER)) == (GR_ROLE_DOMAIN | GR_ROLE_USER)) {
65430+ for (x = 0; x < match->domain_child_num; x++) {
65431+ if (match->domain_children[x] == uid)
65432+ goto found;
65433+ }
65434+ } else if (match->uidgid == uid && match->roletype & GR_ROLE_USER)
65435+ break;
65436+ match = match->next;
65437+ }
65438+found:
65439+ if (match == NULL) {
65440+ try_group:
65441+ index = gr_rhash(gid, GR_ROLE_GROUP, state->acl_role_set.r_size);
65442+ match = state->acl_role_set.r_hash[index];
65443+
65444+ while (match) {
65445+ if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) == (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) {
65446+ for (x = 0; x < match->domain_child_num; x++) {
65447+ if (match->domain_children[x] == gid)
65448+ goto found2;
65449+ }
65450+ } else if (match->uidgid == gid && match->roletype & GR_ROLE_GROUP)
65451+ break;
65452+ match = match->next;
65453+ }
65454+found2:
65455+ if (match == NULL)
65456+ match = state->default_role;
65457+ if (match->allowed_ips == NULL)
65458+ return match;
65459+ else {
65460+ for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
65461+ if (likely
65462+ ((ntohl(curr_ip) & ipp->netmask) ==
65463+ (ntohl(ipp->addr) & ipp->netmask)))
65464+ return match;
65465+ }
65466+ match = state->default_role;
65467+ }
65468+ } else if (match->allowed_ips == NULL) {
65469+ return match;
65470+ } else {
65471+ for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
65472+ if (likely
65473+ ((ntohl(curr_ip) & ipp->netmask) ==
65474+ (ntohl(ipp->addr) & ipp->netmask)))
65475+ return match;
65476+ }
65477+ goto try_group;
65478+ }
65479+
65480+ return match;
65481+}
65482+
65483+static struct acl_role_label *
65484+lookup_acl_role_label(const struct task_struct *task, const uid_t uid,
65485+ const gid_t gid)
65486+{
65487+ return __lookup_acl_role_label(&running_polstate, task, uid, gid);
65488+}
65489+
65490+struct acl_subject_label *
65491+lookup_acl_subj_label(const ino_t ino, const dev_t dev,
65492+ const struct acl_role_label *role)
65493+{
65494+ unsigned int index = gr_fhash(ino, dev, role->subj_hash_size);
65495+ struct acl_subject_label *match;
65496+
65497+ match = role->subj_hash[index];
65498+
65499+ while (match && (match->inode != ino || match->device != dev ||
65500+ (match->mode & GR_DELETED))) {
65501+ match = match->next;
65502+ }
65503+
65504+ if (match && !(match->mode & GR_DELETED))
65505+ return match;
65506+ else
65507+ return NULL;
65508+}
65509+
65510+struct acl_subject_label *
65511+lookup_acl_subj_label_deleted(const ino_t ino, const dev_t dev,
65512+ const struct acl_role_label *role)
65513+{
65514+ unsigned int index = gr_fhash(ino, dev, role->subj_hash_size);
65515+ struct acl_subject_label *match;
65516+
65517+ match = role->subj_hash[index];
65518+
65519+ while (match && (match->inode != ino || match->device != dev ||
65520+ !(match->mode & GR_DELETED))) {
65521+ match = match->next;
65522+ }
65523+
65524+ if (match && (match->mode & GR_DELETED))
65525+ return match;
65526+ else
65527+ return NULL;
65528+}
65529+
65530+static struct acl_object_label *
65531+lookup_acl_obj_label(const ino_t ino, const dev_t dev,
65532+ const struct acl_subject_label *subj)
65533+{
65534+ unsigned int index = gr_fhash(ino, dev, subj->obj_hash_size);
65535+ struct acl_object_label *match;
65536+
65537+ match = subj->obj_hash[index];
65538+
65539+ while (match && (match->inode != ino || match->device != dev ||
65540+ (match->mode & GR_DELETED))) {
65541+ match = match->next;
65542+ }
65543+
65544+ if (match && !(match->mode & GR_DELETED))
65545+ return match;
65546+ else
65547+ return NULL;
65548+}
65549+
65550+static struct acl_object_label *
65551+lookup_acl_obj_label_create(const ino_t ino, const dev_t dev,
65552+ const struct acl_subject_label *subj)
65553+{
65554+ unsigned int index = gr_fhash(ino, dev, subj->obj_hash_size);
65555+ struct acl_object_label *match;
65556+
65557+ match = subj->obj_hash[index];
65558+
65559+ while (match && (match->inode != ino || match->device != dev ||
65560+ !(match->mode & GR_DELETED))) {
65561+ match = match->next;
65562+ }
65563+
65564+ if (match && (match->mode & GR_DELETED))
65565+ return match;
65566+
65567+ match = subj->obj_hash[index];
65568+
65569+ while (match && (match->inode != ino || match->device != dev ||
65570+ (match->mode & GR_DELETED))) {
65571+ match = match->next;
65572+ }
65573+
65574+ if (match && !(match->mode & GR_DELETED))
65575+ return match;
65576+ else
65577+ return NULL;
65578+}
65579+
65580+struct name_entry *
65581+__lookup_name_entry(const struct gr_policy_state *state, const char *name)
65582+{
65583+ unsigned int len = strlen(name);
65584+ unsigned int key = full_name_hash(name, len);
65585+ unsigned int index = key % state->name_set.n_size;
65586+ struct name_entry *match;
65587+
65588+ match = state->name_set.n_hash[index];
65589+
65590+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len)))
65591+ match = match->next;
65592+
65593+ return match;
65594+}
65595+
65596+static struct name_entry *
65597+lookup_name_entry(const char *name)
65598+{
65599+ return __lookup_name_entry(&running_polstate, name);
65600+}
65601+
65602+static struct name_entry *
65603+lookup_name_entry_create(const char *name)
65604+{
65605+ unsigned int len = strlen(name);
65606+ unsigned int key = full_name_hash(name, len);
65607+ unsigned int index = key % running_polstate.name_set.n_size;
65608+ struct name_entry *match;
65609+
65610+ match = running_polstate.name_set.n_hash[index];
65611+
65612+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
65613+ !match->deleted))
65614+ match = match->next;
65615+
65616+ if (match && match->deleted)
65617+ return match;
65618+
65619+ match = running_polstate.name_set.n_hash[index];
65620+
65621+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
65622+ match->deleted))
65623+ match = match->next;
65624+
65625+ if (match && !match->deleted)
65626+ return match;
65627+ else
65628+ return NULL;
65629+}
65630+
65631+static struct inodev_entry *
65632+lookup_inodev_entry(const ino_t ino, const dev_t dev)
65633+{
65634+ unsigned int index = gr_fhash(ino, dev, running_polstate.inodev_set.i_size);
65635+ struct inodev_entry *match;
65636+
65637+ match = running_polstate.inodev_set.i_hash[index];
65638+
65639+ while (match && (match->nentry->inode != ino || match->nentry->device != dev))
65640+ match = match->next;
65641+
65642+ return match;
65643+}
65644+
65645+void
65646+__insert_inodev_entry(const struct gr_policy_state *state, struct inodev_entry *entry)
65647+{
65648+ unsigned int index = gr_fhash(entry->nentry->inode, entry->nentry->device,
65649+ state->inodev_set.i_size);
65650+ struct inodev_entry **curr;
65651+
65652+ entry->prev = NULL;
65653+
65654+ curr = &state->inodev_set.i_hash[index];
65655+ if (*curr != NULL)
65656+ (*curr)->prev = entry;
65657+
65658+ entry->next = *curr;
65659+ *curr = entry;
65660+
65661+ return;
65662+}
65663+
65664+static void
65665+insert_inodev_entry(struct inodev_entry *entry)
65666+{
65667+ __insert_inodev_entry(&running_polstate, entry);
65668+}
65669+
65670+void
65671+insert_acl_obj_label(struct acl_object_label *obj,
65672+ struct acl_subject_label *subj)
65673+{
65674+ unsigned int index =
65675+ gr_fhash(obj->inode, obj->device, subj->obj_hash_size);
65676+ struct acl_object_label **curr;
65677+
65678+ obj->prev = NULL;
65679+
65680+ curr = &subj->obj_hash[index];
65681+ if (*curr != NULL)
65682+ (*curr)->prev = obj;
65683+
65684+ obj->next = *curr;
65685+ *curr = obj;
65686+
65687+ return;
65688+}
65689+
65690+void
65691+insert_acl_subj_label(struct acl_subject_label *obj,
65692+ struct acl_role_label *role)
65693+{
65694+ unsigned int index = gr_fhash(obj->inode, obj->device, role->subj_hash_size);
65695+ struct acl_subject_label **curr;
65696+
65697+ obj->prev = NULL;
65698+
65699+ curr = &role->subj_hash[index];
65700+ if (*curr != NULL)
65701+ (*curr)->prev = obj;
65702+
65703+ obj->next = *curr;
65704+ *curr = obj;
65705+
65706+ return;
65707+}
65708+
65709+/* derived from glibc fnmatch() 0: match, 1: no match*/
65710+
65711+static int
65712+glob_match(const char *p, const char *n)
65713+{
65714+ char c;
65715+
65716+ while ((c = *p++) != '\0') {
65717+ switch (c) {
65718+ case '?':
65719+ if (*n == '\0')
65720+ return 1;
65721+ else if (*n == '/')
65722+ return 1;
65723+ break;
65724+ case '\\':
65725+ if (*n != c)
65726+ return 1;
65727+ break;
65728+ case '*':
65729+ for (c = *p++; c == '?' || c == '*'; c = *p++) {
65730+ if (*n == '/')
65731+ return 1;
65732+ else if (c == '?') {
65733+ if (*n == '\0')
65734+ return 1;
65735+ else
65736+ ++n;
65737+ }
65738+ }
65739+ if (c == '\0') {
65740+ return 0;
65741+ } else {
65742+ const char *endp;
65743+
65744+ if ((endp = strchr(n, '/')) == NULL)
65745+ endp = n + strlen(n);
65746+
65747+ if (c == '[') {
65748+ for (--p; n < endp; ++n)
65749+ if (!glob_match(p, n))
65750+ return 0;
65751+ } else if (c == '/') {
65752+ while (*n != '\0' && *n != '/')
65753+ ++n;
65754+ if (*n == '/' && !glob_match(p, n + 1))
65755+ return 0;
65756+ } else {
65757+ for (--p; n < endp; ++n)
65758+ if (*n == c && !glob_match(p, n))
65759+ return 0;
65760+ }
65761+
65762+ return 1;
65763+ }
65764+ case '[':
65765+ {
65766+ int not;
65767+ char cold;
65768+
65769+ if (*n == '\0' || *n == '/')
65770+ return 1;
65771+
65772+ not = (*p == '!' || *p == '^');
65773+ if (not)
65774+ ++p;
65775+
65776+ c = *p++;
65777+ for (;;) {
65778+ unsigned char fn = (unsigned char)*n;
65779+
65780+ if (c == '\0')
65781+ return 1;
65782+ else {
65783+ if (c == fn)
65784+ goto matched;
65785+ cold = c;
65786+ c = *p++;
65787+
65788+ if (c == '-' && *p != ']') {
65789+ unsigned char cend = *p++;
65790+
65791+ if (cend == '\0')
65792+ return 1;
65793+
65794+ if (cold <= fn && fn <= cend)
65795+ goto matched;
65796+
65797+ c = *p++;
65798+ }
65799+ }
65800+
65801+ if (c == ']')
65802+ break;
65803+ }
65804+ if (!not)
65805+ return 1;
65806+ break;
65807+ matched:
65808+ while (c != ']') {
65809+ if (c == '\0')
65810+ return 1;
65811+
65812+ c = *p++;
65813+ }
65814+ if (not)
65815+ return 1;
65816+ }
65817+ break;
65818+ default:
65819+ if (c != *n)
65820+ return 1;
65821+ }
65822+
65823+ ++n;
65824+ }
65825+
65826+ if (*n == '\0')
65827+ return 0;
65828+
65829+ if (*n == '/')
65830+ return 0;
65831+
65832+ return 1;
65833+}
65834+
65835+static struct acl_object_label *
65836+chk_glob_label(struct acl_object_label *globbed,
65837+ const struct dentry *dentry, const struct vfsmount *mnt, char **path)
65838+{
65839+ struct acl_object_label *tmp;
65840+
65841+ if (*path == NULL)
65842+ *path = gr_to_filename_nolock(dentry, mnt);
65843+
65844+ tmp = globbed;
65845+
65846+ while (tmp) {
65847+ if (!glob_match(tmp->filename, *path))
65848+ return tmp;
65849+ tmp = tmp->next;
65850+ }
65851+
65852+ return NULL;
65853+}
65854+
65855+static struct acl_object_label *
65856+__full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
65857+ const ino_t curr_ino, const dev_t curr_dev,
65858+ const struct acl_subject_label *subj, char **path, const int checkglob)
65859+{
65860+ struct acl_subject_label *tmpsubj;
65861+ struct acl_object_label *retval;
65862+ struct acl_object_label *retval2;
65863+
65864+ tmpsubj = (struct acl_subject_label *) subj;
65865+ read_lock(&gr_inode_lock);
65866+ do {
65867+ retval = lookup_acl_obj_label(curr_ino, curr_dev, tmpsubj);
65868+ if (retval) {
65869+ if (checkglob && retval->globbed) {
65870+ retval2 = chk_glob_label(retval->globbed, orig_dentry, orig_mnt, path);
65871+ if (retval2)
65872+ retval = retval2;
65873+ }
65874+ break;
65875+ }
65876+ } while ((tmpsubj = tmpsubj->parent_subject));
65877+ read_unlock(&gr_inode_lock);
65878+
65879+ return retval;
65880+}
65881+
65882+static __inline__ struct acl_object_label *
65883+full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
65884+ struct dentry *curr_dentry,
65885+ const struct acl_subject_label *subj, char **path, const int checkglob)
65886+{
65887+ int newglob = checkglob;
65888+ ino_t inode;
65889+ dev_t device;
65890+
65891+ /* if we aren't checking a subdirectory of the original path yet, don't do glob checking
65892+ as we don't want a / * rule to match instead of the / object
65893+ don't do this for create lookups that call this function though, since they're looking up
65894+ on the parent and thus need globbing checks on all paths
65895+ */
65896+ if (orig_dentry == curr_dentry && newglob != GR_CREATE_GLOB)
65897+ newglob = GR_NO_GLOB;
65898+
65899+ spin_lock(&curr_dentry->d_lock);
65900+ inode = curr_dentry->d_inode->i_ino;
65901+ device = __get_dev(curr_dentry);
65902+ spin_unlock(&curr_dentry->d_lock);
65903+
65904+ return __full_lookup(orig_dentry, orig_mnt, inode, device, subj, path, newglob);
65905+}
65906+
65907+#ifdef CONFIG_HUGETLBFS
65908+static inline bool
65909+is_hugetlbfs_mnt(const struct vfsmount *mnt)
65910+{
65911+ int i;
65912+ for (i = 0; i < HUGE_MAX_HSTATE; i++) {
65913+ if (unlikely(hugetlbfs_vfsmount[i] == mnt))
65914+ return true;
65915+ }
65916+
65917+ return false;
65918+}
65919+#endif
65920+
65921+static struct acl_object_label *
65922+__chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
65923+ const struct acl_subject_label *subj, char *path, const int checkglob)
65924+{
65925+ struct dentry *dentry = (struct dentry *) l_dentry;
65926+ struct vfsmount *mnt = (struct vfsmount *) l_mnt;
65927+ struct mount *real_mnt = real_mount(mnt);
65928+ struct acl_object_label *retval;
65929+ struct dentry *parent;
65930+
65931+ br_read_lock(&vfsmount_lock);
65932+ write_seqlock(&rename_lock);
65933+
65934+ if (unlikely((mnt == shm_mnt && dentry->d_inode->i_nlink == 0) || mnt == pipe_mnt ||
65935+#ifdef CONFIG_NET
65936+ mnt == sock_mnt ||
65937+#endif
65938+#ifdef CONFIG_HUGETLBFS
65939+ (is_hugetlbfs_mnt(mnt) && dentry->d_inode->i_nlink == 0) ||
65940+#endif
65941+ /* ignore Eric Biederman */
65942+ IS_PRIVATE(l_dentry->d_inode))) {
65943+ retval = (subj->mode & GR_SHMEXEC) ? fakefs_obj_rwx : fakefs_obj_rw;
65944+ goto out;
65945+ }
65946+
65947+ for (;;) {
65948+ if (dentry == gr_real_root.dentry && mnt == gr_real_root.mnt)
65949+ break;
65950+
65951+ if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
65952+ if (!mnt_has_parent(real_mnt))
65953+ break;
65954+
65955+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
65956+ if (retval != NULL)
65957+ goto out;
65958+
65959+ dentry = real_mnt->mnt_mountpoint;
65960+ real_mnt = real_mnt->mnt_parent;
65961+ mnt = &real_mnt->mnt;
65962+ continue;
65963+ }
65964+
65965+ parent = dentry->d_parent;
65966+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
65967+ if (retval != NULL)
65968+ goto out;
65969+
65970+ dentry = parent;
65971+ }
65972+
65973+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
65974+
65975+ /* gr_real_root is pinned so we don't have to hold a reference */
65976+ if (retval == NULL)
65977+ retval = full_lookup(l_dentry, l_mnt, gr_real_root.dentry, subj, &path, checkglob);
65978+out:
65979+ write_sequnlock(&rename_lock);
65980+ br_read_unlock(&vfsmount_lock);
65981+
65982+ BUG_ON(retval == NULL);
65983+
65984+ return retval;
65985+}
65986+
65987+static __inline__ struct acl_object_label *
65988+chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
65989+ const struct acl_subject_label *subj)
65990+{
65991+ char *path = NULL;
65992+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_REG_GLOB);
65993+}
65994+
65995+static __inline__ struct acl_object_label *
65996+chk_obj_label_noglob(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
65997+ const struct acl_subject_label *subj)
65998+{
65999+ char *path = NULL;
66000+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_NO_GLOB);
66001+}
66002+
66003+static __inline__ struct acl_object_label *
66004+chk_obj_create_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
66005+ const struct acl_subject_label *subj, char *path)
66006+{
66007+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_CREATE_GLOB);
66008+}
66009+
66010+struct acl_subject_label *
66011+chk_subj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
66012+ const struct acl_role_label *role)
66013+{
66014+ struct dentry *dentry = (struct dentry *) l_dentry;
66015+ struct vfsmount *mnt = (struct vfsmount *) l_mnt;
66016+ struct mount *real_mnt = real_mount(mnt);
66017+ struct acl_subject_label *retval;
66018+ struct dentry *parent;
66019+
66020+ br_read_lock(&vfsmount_lock);
66021+ write_seqlock(&rename_lock);
66022+
66023+ for (;;) {
66024+ if (dentry == gr_real_root.dentry && mnt == gr_real_root.mnt)
66025+ break;
66026+ if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
66027+ if (!mnt_has_parent(real_mnt))
66028+ break;
66029+
66030+ spin_lock(&dentry->d_lock);
66031+ read_lock(&gr_inode_lock);
66032+ retval =
66033+ lookup_acl_subj_label(dentry->d_inode->i_ino,
66034+ __get_dev(dentry), role);
66035+ read_unlock(&gr_inode_lock);
66036+ spin_unlock(&dentry->d_lock);
66037+ if (retval != NULL)
66038+ goto out;
66039+
66040+ dentry = real_mnt->mnt_mountpoint;
66041+ real_mnt = real_mnt->mnt_parent;
66042+ mnt = &real_mnt->mnt;
66043+ continue;
66044+ }
66045+
66046+ spin_lock(&dentry->d_lock);
66047+ read_lock(&gr_inode_lock);
66048+ retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
66049+ __get_dev(dentry), role);
66050+ read_unlock(&gr_inode_lock);
66051+ parent = dentry->d_parent;
66052+ spin_unlock(&dentry->d_lock);
66053+
66054+ if (retval != NULL)
66055+ goto out;
66056+
66057+ dentry = parent;
66058+ }
66059+
66060+ spin_lock(&dentry->d_lock);
66061+ read_lock(&gr_inode_lock);
66062+ retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
66063+ __get_dev(dentry), role);
66064+ read_unlock(&gr_inode_lock);
66065+ spin_unlock(&dentry->d_lock);
66066+
66067+ if (unlikely(retval == NULL)) {
66068+ /* gr_real_root is pinned, we don't need to hold a reference */
66069+ read_lock(&gr_inode_lock);
66070+ retval = lookup_acl_subj_label(gr_real_root.dentry->d_inode->i_ino,
66071+ __get_dev(gr_real_root.dentry), role);
66072+ read_unlock(&gr_inode_lock);
66073+ }
66074+out:
66075+ write_sequnlock(&rename_lock);
66076+ br_read_unlock(&vfsmount_lock);
66077+
66078+ BUG_ON(retval == NULL);
66079+
66080+ return retval;
66081+}
66082+
66083+void
66084+assign_special_role(const char *rolename)
66085+{
66086+ struct acl_object_label *obj;
66087+ struct acl_role_label *r;
66088+ struct acl_role_label *assigned = NULL;
66089+ struct task_struct *tsk;
66090+ struct file *filp;
66091+
66092+ FOR_EACH_ROLE_START(r)
66093+ if (!strcmp(rolename, r->rolename) &&
66094+ (r->roletype & GR_ROLE_SPECIAL)) {
66095+ assigned = r;
66096+ break;
66097+ }
66098+ FOR_EACH_ROLE_END(r)
66099+
66100+ if (!assigned)
66101+ return;
66102+
66103+ read_lock(&tasklist_lock);
66104+ read_lock(&grsec_exec_file_lock);
66105+
66106+ tsk = current->real_parent;
66107+ if (tsk == NULL)
66108+ goto out_unlock;
66109+
66110+ filp = tsk->exec_file;
66111+ if (filp == NULL)
66112+ goto out_unlock;
66113+
66114+ tsk->is_writable = 0;
66115+ tsk->inherited = 0;
66116+
66117+ tsk->acl_sp_role = 1;
66118+ tsk->acl_role_id = ++acl_sp_role_value;
66119+ tsk->role = assigned;
66120+ tsk->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role);
66121+
66122+ /* ignore additional mmap checks for processes that are writable
66123+ by the default ACL */
66124+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, running_polstate.default_role->root_label);
66125+ if (unlikely(obj->mode & GR_WRITE))
66126+ tsk->is_writable = 1;
66127+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role->root_label);
66128+ if (unlikely(obj->mode & GR_WRITE))
66129+ tsk->is_writable = 1;
66130+
66131+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
66132+ printk(KERN_ALERT "Assigning special role:%s subject:%s to process (%s:%d)\n", tsk->role->rolename,
66133+ tsk->acl->filename, tsk->comm, task_pid_nr(tsk));
66134+#endif
66135+
66136+out_unlock:
66137+ read_unlock(&grsec_exec_file_lock);
66138+ read_unlock(&tasklist_lock);
66139+ return;
66140+}
66141+
66142+
66143+static void
66144+gr_log_learn(const struct dentry *dentry, const struct vfsmount *mnt, const __u32 mode)
66145+{
66146+ struct task_struct *task = current;
66147+ const struct cred *cred = current_cred();
66148+
66149+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename, task->role->roletype,
66150+ GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
66151+ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
66152+ 1UL, 1UL, gr_to_filename(dentry, mnt), (unsigned long) mode, &task->signal->saved_ip);
66153+
66154+ return;
66155+}
66156+
66157+static void
66158+gr_log_learn_uid_change(const kuid_t real, const kuid_t effective, const kuid_t fs)
66159+{
66160+ struct task_struct *task = current;
66161+ const struct cred *cred = current_cred();
66162+
66163+ security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
66164+ GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
66165+ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
66166+ 'u', GR_GLOBAL_UID(real), GR_GLOBAL_UID(effective), GR_GLOBAL_UID(fs), &task->signal->saved_ip);
66167+
66168+ return;
66169+}
66170+
66171+static void
66172+gr_log_learn_gid_change(const kgid_t real, const kgid_t effective, const kgid_t fs)
66173+{
66174+ struct task_struct *task = current;
66175+ const struct cred *cred = current_cred();
66176+
66177+ security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
66178+ GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
66179+ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
66180+ 'g', GR_GLOBAL_GID(real), GR_GLOBAL_GID(effective), GR_GLOBAL_GID(fs), &task->signal->saved_ip);
66181+
66182+ return;
66183+}
66184+
66185+static void
66186+gr_set_proc_res(struct task_struct *task)
66187+{
66188+ struct acl_subject_label *proc;
66189+ unsigned short i;
66190+
66191+ proc = task->acl;
66192+
66193+ if (proc->mode & (GR_LEARN | GR_INHERITLEARN))
66194+ return;
66195+
66196+ for (i = 0; i < RLIM_NLIMITS; i++) {
66197+ if (!(proc->resmask & (1U << i)))
66198+ continue;
66199+
66200+ task->signal->rlim[i].rlim_cur = proc->res[i].rlim_cur;
66201+ task->signal->rlim[i].rlim_max = proc->res[i].rlim_max;
66202+
66203+ if (i == RLIMIT_CPU)
66204+ update_rlimit_cpu(task, proc->res[i].rlim_cur);
66205+ }
66206+
66207+ return;
66208+}
66209+
66210+/* both of the below must be called with
66211+ rcu_read_lock();
66212+ read_lock(&tasklist_lock);
66213+ read_lock(&grsec_exec_file_lock);
66214+*/
66215+
66216+struct acl_subject_label *__gr_get_subject_for_task(const struct gr_policy_state *state, struct task_struct *task, const char *filename)
66217+{
66218+ char *tmpname;
66219+ struct acl_subject_label *tmpsubj;
66220+ struct file *filp;
66221+ struct name_entry *nmatch;
66222+
66223+ filp = task->exec_file;
66224+ if (filp == NULL)
66225+ return NULL;
66226+
66227+ /* the following is to apply the correct subject
66228+ on binaries running when the RBAC system
66229+ is enabled, when the binaries have been
66230+ replaced or deleted since their execution
66231+ -----
66232+ when the RBAC system starts, the inode/dev
66233+ from exec_file will be one the RBAC system
66234+ is unaware of. It only knows the inode/dev
66235+ of the present file on disk, or the absence
66236+ of it.
66237+ */
66238+
66239+ if (filename)
66240+ nmatch = __lookup_name_entry(state, filename);
66241+ else {
66242+ preempt_disable();
66243+ tmpname = gr_to_filename_rbac(filp->f_path.dentry, filp->f_path.mnt);
66244+
66245+ nmatch = __lookup_name_entry(state, tmpname);
66246+ preempt_enable();
66247+ }
66248+ tmpsubj = NULL;
66249+ if (nmatch) {
66250+ if (nmatch->deleted)
66251+ tmpsubj = lookup_acl_subj_label_deleted(nmatch->inode, nmatch->device, task->role);
66252+ else
66253+ tmpsubj = lookup_acl_subj_label(nmatch->inode, nmatch->device, task->role);
66254+ }
66255+ /* this also works for the reload case -- if we don't match a potentially inherited subject
66256+ then we fall back to a normal lookup based on the binary's ino/dev
66257+ */
66258+ if (tmpsubj == NULL)
66259+ tmpsubj = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, task->role);
66260+
66261+ return tmpsubj;
66262+}
66263+
66264+static struct acl_subject_label *gr_get_subject_for_task(struct task_struct *task, const char *filename)
66265+{
66266+ return __gr_get_subject_for_task(&running_polstate, task, filename);
66267+}
66268+
66269+void __gr_apply_subject_to_task(const struct gr_policy_state *state, struct task_struct *task, struct acl_subject_label *subj)
66270+{
66271+ struct acl_object_label *obj;
66272+ struct file *filp;
66273+
66274+ filp = task->exec_file;
66275+
66276+ task->acl = subj;
66277+ task->is_writable = 0;
66278+ /* ignore additional mmap checks for processes that are writable
66279+ by the default ACL */
66280+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, state->default_role->root_label);
66281+ if (unlikely(obj->mode & GR_WRITE))
66282+ task->is_writable = 1;
66283+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
66284+ if (unlikely(obj->mode & GR_WRITE))
66285+ task->is_writable = 1;
66286+
66287+ gr_set_proc_res(task);
66288+
66289+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
66290+ printk(KERN_ALERT "gr_set_acls for (%s:%d): role:%s, subject:%s\n", task->comm, task_pid_nr(task), task->role->rolename, task->acl->filename);
66291+#endif
66292+}
66293+
66294+static void gr_apply_subject_to_task(struct task_struct *task, struct acl_subject_label *subj)
66295+{
66296+ __gr_apply_subject_to_task(&running_polstate, task, subj);
66297+}
66298+
66299+__u32
66300+gr_search_file(const struct dentry * dentry, const __u32 mode,
66301+ const struct vfsmount * mnt)
66302+{
66303+ __u32 retval = mode;
66304+ struct acl_subject_label *curracl;
66305+ struct acl_object_label *currobj;
66306+
66307+ if (unlikely(!(gr_status & GR_READY)))
66308+ return (mode & ~GR_AUDITS);
66309+
66310+ curracl = current->acl;
66311+
66312+ currobj = chk_obj_label(dentry, mnt, curracl);
66313+ retval = currobj->mode & mode;
66314+
66315+ /* if we're opening a specified transfer file for writing
66316+ (e.g. /dev/initctl), then transfer our role to init
66317+ */
66318+ if (unlikely(currobj->mode & GR_INIT_TRANSFER && retval & GR_WRITE &&
66319+ current->role->roletype & GR_ROLE_PERSIST)) {
66320+ struct task_struct *task = init_pid_ns.child_reaper;
66321+
66322+ if (task->role != current->role) {
66323+ struct acl_subject_label *subj;
66324+
66325+ task->acl_sp_role = 0;
66326+ task->acl_role_id = current->acl_role_id;
66327+ task->role = current->role;
66328+ rcu_read_lock();
66329+ read_lock(&grsec_exec_file_lock);
66330+ subj = gr_get_subject_for_task(task, NULL);
66331+ gr_apply_subject_to_task(task, subj);
66332+ read_unlock(&grsec_exec_file_lock);
66333+ rcu_read_unlock();
66334+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_INIT_TRANSFER_MSG);
66335+ }
66336+ }
66337+
66338+ if (unlikely
66339+ ((curracl->mode & (GR_LEARN | GR_INHERITLEARN)) && !(mode & GR_NOPTRACE)
66340+ && (retval != (mode & ~(GR_AUDITS | GR_SUPPRESS))))) {
66341+ __u32 new_mode = mode;
66342+
66343+ new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
66344+
66345+ retval = new_mode;
66346+
66347+ if (new_mode & GR_EXEC && curracl->mode & GR_INHERITLEARN)
66348+ new_mode |= GR_INHERIT;
66349+
66350+ if (!(mode & GR_NOLEARN))
66351+ gr_log_learn(dentry, mnt, new_mode);
66352+ }
66353+
66354+ return retval;
66355+}
66356+
66357+struct acl_object_label *gr_get_create_object(const struct dentry *new_dentry,
66358+ const struct dentry *parent,
66359+ const struct vfsmount *mnt)
66360+{
66361+ struct name_entry *match;
66362+ struct acl_object_label *matchpo;
66363+ struct acl_subject_label *curracl;
66364+ char *path;
66365+
66366+ if (unlikely(!(gr_status & GR_READY)))
66367+ return NULL;
66368+
66369+ preempt_disable();
66370+ path = gr_to_filename_rbac(new_dentry, mnt);
66371+ match = lookup_name_entry_create(path);
66372+
66373+ curracl = current->acl;
66374+
66375+ if (match) {
66376+ read_lock(&gr_inode_lock);
66377+ matchpo = lookup_acl_obj_label_create(match->inode, match->device, curracl);
66378+ read_unlock(&gr_inode_lock);
66379+
66380+ if (matchpo) {
66381+ preempt_enable();
66382+ return matchpo;
66383+ }
66384+ }
66385+
66386+ // lookup parent
66387+
66388+ matchpo = chk_obj_create_label(parent, mnt, curracl, path);
66389+
66390+ preempt_enable();
66391+ return matchpo;
66392+}
66393+
66394+__u32
66395+gr_check_create(const struct dentry * new_dentry, const struct dentry * parent,
66396+ const struct vfsmount * mnt, const __u32 mode)
66397+{
66398+ struct acl_object_label *matchpo;
66399+ __u32 retval;
66400+
66401+ if (unlikely(!(gr_status & GR_READY)))
66402+ return (mode & ~GR_AUDITS);
66403+
66404+ matchpo = gr_get_create_object(new_dentry, parent, mnt);
66405+
66406+ retval = matchpo->mode & mode;
66407+
66408+ if ((retval != (mode & ~(GR_AUDITS | GR_SUPPRESS)))
66409+ && (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
66410+ __u32 new_mode = mode;
66411+
66412+ new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
66413+
66414+ gr_log_learn(new_dentry, mnt, new_mode);
66415+ return new_mode;
66416+ }
66417+
66418+ return retval;
66419+}
66420+
66421+__u32
66422+gr_check_link(const struct dentry * new_dentry,
66423+ const struct dentry * parent_dentry,
66424+ const struct vfsmount * parent_mnt,
66425+ const struct dentry * old_dentry, const struct vfsmount * old_mnt)
66426+{
66427+ struct acl_object_label *obj;
66428+ __u32 oldmode, newmode;
66429+ __u32 needmode;
66430+ __u32 checkmodes = GR_FIND | GR_APPEND | GR_WRITE | GR_EXEC | GR_SETID | GR_READ |
66431+ GR_DELETE | GR_INHERIT;
66432+
66433+ if (unlikely(!(gr_status & GR_READY)))
66434+ return (GR_CREATE | GR_LINK);
66435+
66436+ obj = chk_obj_label(old_dentry, old_mnt, current->acl);
66437+ oldmode = obj->mode;
66438+
66439+ obj = gr_get_create_object(new_dentry, parent_dentry, parent_mnt);
66440+ newmode = obj->mode;
66441+
66442+ needmode = newmode & checkmodes;
66443+
66444+ // old name for hardlink must have at least the permissions of the new name
66445+ if ((oldmode & needmode) != needmode)
66446+ goto bad;
66447+
66448+ // if old name had restrictions/auditing, make sure the new name does as well
66449+ needmode = oldmode & (GR_NOPTRACE | GR_PTRACERD | GR_INHERIT | GR_AUDITS);
66450+
66451+ // don't allow hardlinking of suid/sgid/fcapped files without permission
66452+ if (is_privileged_binary(old_dentry))
66453+ needmode |= GR_SETID;
66454+
66455+ if ((newmode & needmode) != needmode)
66456+ goto bad;
66457+
66458+ // enforce minimum permissions
66459+ if ((newmode & (GR_CREATE | GR_LINK)) == (GR_CREATE | GR_LINK))
66460+ return newmode;
66461+bad:
66462+ needmode = oldmode;
66463+ if (is_privileged_binary(old_dentry))
66464+ needmode |= GR_SETID;
66465+
66466+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN)) {
66467+ gr_log_learn(old_dentry, old_mnt, needmode | GR_CREATE | GR_LINK);
66468+ return (GR_CREATE | GR_LINK);
66469+ } else if (newmode & GR_SUPPRESS)
66470+ return GR_SUPPRESS;
66471+ else
66472+ return 0;
66473+}
66474+
66475+int
66476+gr_check_hidden_task(const struct task_struct *task)
66477+{
66478+ if (unlikely(!(gr_status & GR_READY)))
66479+ return 0;
66480+
66481+ if (!(task->acl->mode & GR_PROCFIND) && !(current->acl->mode & GR_VIEW))
66482+ return 1;
66483+
66484+ return 0;
66485+}
66486+
66487+int
66488+gr_check_protected_task(const struct task_struct *task)
66489+{
66490+ if (unlikely(!(gr_status & GR_READY) || !task))
66491+ return 0;
66492+
66493+ if ((task->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
66494+ task->acl != current->acl)
66495+ return 1;
66496+
66497+ return 0;
66498+}
66499+
66500+int
66501+gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
66502+{
66503+ struct task_struct *p;
66504+ int ret = 0;
66505+
66506+ if (unlikely(!(gr_status & GR_READY) || !pid))
66507+ return ret;
66508+
66509+ read_lock(&tasklist_lock);
66510+ do_each_pid_task(pid, type, p) {
66511+ if ((p->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
66512+ p->acl != current->acl) {
66513+ ret = 1;
66514+ goto out;
66515+ }
66516+ } while_each_pid_task(pid, type, p);
66517+out:
66518+ read_unlock(&tasklist_lock);
66519+
66520+ return ret;
66521+}
66522+
66523+void
66524+gr_copy_label(struct task_struct *tsk)
66525+{
66526+ struct task_struct *p = current;
66527+
66528+ tsk->inherited = p->inherited;
66529+ tsk->acl_sp_role = 0;
66530+ tsk->acl_role_id = p->acl_role_id;
66531+ tsk->acl = p->acl;
66532+ tsk->role = p->role;
66533+ tsk->signal->used_accept = 0;
66534+ tsk->signal->curr_ip = p->signal->curr_ip;
66535+ tsk->signal->saved_ip = p->signal->saved_ip;
66536+ if (p->exec_file)
66537+ get_file(p->exec_file);
66538+ tsk->exec_file = p->exec_file;
66539+ tsk->is_writable = p->is_writable;
66540+ if (unlikely(p->signal->used_accept)) {
66541+ p->signal->curr_ip = 0;
66542+ p->signal->saved_ip = 0;
66543+ }
66544+
66545+ return;
66546+}
66547+
66548+extern int gr_process_kernel_setuid_ban(struct user_struct *user);
66549+
66550+int
66551+gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs)
66552+{
66553+ unsigned int i;
66554+ __u16 num;
66555+ uid_t *uidlist;
66556+ uid_t curuid;
66557+ int realok = 0;
66558+ int effectiveok = 0;
66559+ int fsok = 0;
66560+ uid_t globalreal, globaleffective, globalfs;
66561+
66562+#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT)
66563+ struct user_struct *user;
66564+
66565+ if (!uid_valid(real))
66566+ goto skipit;
66567+
66568+ /* find user based on global namespace */
66569+
66570+ globalreal = GR_GLOBAL_UID(real);
66571+
66572+ user = find_user(make_kuid(&init_user_ns, globalreal));
66573+ if (user == NULL)
66574+ goto skipit;
66575+
66576+ if (gr_process_kernel_setuid_ban(user)) {
66577+ /* for find_user */
66578+ free_uid(user);
66579+ return 1;
66580+ }
66581+
66582+ /* for find_user */
66583+ free_uid(user);
66584+
66585+skipit:
66586+#endif
66587+
66588+ if (unlikely(!(gr_status & GR_READY)))
66589+ return 0;
66590+
66591+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
66592+ gr_log_learn_uid_change(real, effective, fs);
66593+
66594+ num = current->acl->user_trans_num;
66595+ uidlist = current->acl->user_transitions;
66596+
66597+ if (uidlist == NULL)
66598+ return 0;
66599+
66600+ if (!uid_valid(real)) {
66601+ realok = 1;
66602+ globalreal = (uid_t)-1;
66603+ } else {
66604+ globalreal = GR_GLOBAL_UID(real);
66605+ }
66606+ if (!uid_valid(effective)) {
66607+ effectiveok = 1;
66608+ globaleffective = (uid_t)-1;
66609+ } else {
66610+ globaleffective = GR_GLOBAL_UID(effective);
66611+ }
66612+ if (!uid_valid(fs)) {
66613+ fsok = 1;
66614+ globalfs = (uid_t)-1;
66615+ } else {
66616+ globalfs = GR_GLOBAL_UID(fs);
66617+ }
66618+
66619+ if (current->acl->user_trans_type & GR_ID_ALLOW) {
66620+ for (i = 0; i < num; i++) {
66621+ curuid = uidlist[i];
66622+ if (globalreal == curuid)
66623+ realok = 1;
66624+ if (globaleffective == curuid)
66625+ effectiveok = 1;
66626+ if (globalfs == curuid)
66627+ fsok = 1;
66628+ }
66629+ } else if (current->acl->user_trans_type & GR_ID_DENY) {
66630+ for (i = 0; i < num; i++) {
66631+ curuid = uidlist[i];
66632+ if (globalreal == curuid)
66633+ break;
66634+ if (globaleffective == curuid)
66635+ break;
66636+ if (globalfs == curuid)
66637+ break;
66638+ }
66639+ /* not in deny list */
66640+ if (i == num) {
66641+ realok = 1;
66642+ effectiveok = 1;
66643+ fsok = 1;
66644+ }
66645+ }
66646+
66647+ if (realok && effectiveok && fsok)
66648+ return 0;
66649+ else {
66650+ gr_log_int(GR_DONT_AUDIT, GR_USRCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : globalfs) : globaleffective) : globalreal);
66651+ return 1;
66652+ }
66653+}
66654+
66655+int
66656+gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs)
66657+{
66658+ unsigned int i;
66659+ __u16 num;
66660+ gid_t *gidlist;
66661+ gid_t curgid;
66662+ int realok = 0;
66663+ int effectiveok = 0;
66664+ int fsok = 0;
66665+ gid_t globalreal, globaleffective, globalfs;
66666+
66667+ if (unlikely(!(gr_status & GR_READY)))
66668+ return 0;
66669+
66670+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
66671+ gr_log_learn_gid_change(real, effective, fs);
66672+
66673+ num = current->acl->group_trans_num;
66674+ gidlist = current->acl->group_transitions;
66675+
66676+ if (gidlist == NULL)
66677+ return 0;
66678+
66679+ if (!gid_valid(real)) {
66680+ realok = 1;
66681+ globalreal = (gid_t)-1;
66682+ } else {
66683+ globalreal = GR_GLOBAL_GID(real);
66684+ }
66685+ if (!gid_valid(effective)) {
66686+ effectiveok = 1;
66687+ globaleffective = (gid_t)-1;
66688+ } else {
66689+ globaleffective = GR_GLOBAL_GID(effective);
66690+ }
66691+ if (!gid_valid(fs)) {
66692+ fsok = 1;
66693+ globalfs = (gid_t)-1;
66694+ } else {
66695+ globalfs = GR_GLOBAL_GID(fs);
66696+ }
66697+
66698+ if (current->acl->group_trans_type & GR_ID_ALLOW) {
66699+ for (i = 0; i < num; i++) {
66700+ curgid = gidlist[i];
66701+ if (globalreal == curgid)
66702+ realok = 1;
66703+ if (globaleffective == curgid)
66704+ effectiveok = 1;
66705+ if (globalfs == curgid)
66706+ fsok = 1;
66707+ }
66708+ } else if (current->acl->group_trans_type & GR_ID_DENY) {
66709+ for (i = 0; i < num; i++) {
66710+ curgid = gidlist[i];
66711+ if (globalreal == curgid)
66712+ break;
66713+ if (globaleffective == curgid)
66714+ break;
66715+ if (globalfs == curgid)
66716+ break;
66717+ }
66718+ /* not in deny list */
66719+ if (i == num) {
66720+ realok = 1;
66721+ effectiveok = 1;
66722+ fsok = 1;
66723+ }
66724+ }
66725+
66726+ if (realok && effectiveok && fsok)
66727+ return 0;
66728+ else {
66729+ gr_log_int(GR_DONT_AUDIT, GR_GRPCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : globalfs) : globaleffective) : globalreal);
66730+ return 1;
66731+ }
66732+}
66733+
66734+extern int gr_acl_is_capable(const int cap);
66735+
66736+void
66737+gr_set_role_label(struct task_struct *task, const kuid_t kuid, const kgid_t kgid)
66738+{
66739+ struct acl_role_label *role = task->role;
66740+ struct acl_subject_label *subj = NULL;
66741+ struct acl_object_label *obj;
66742+ struct file *filp;
66743+ uid_t uid;
66744+ gid_t gid;
66745+
66746+ if (unlikely(!(gr_status & GR_READY)))
66747+ return;
66748+
66749+ uid = GR_GLOBAL_UID(kuid);
66750+ gid = GR_GLOBAL_GID(kgid);
66751+
66752+ filp = task->exec_file;
66753+
66754+ /* kernel process, we'll give them the kernel role */
66755+ if (unlikely(!filp)) {
66756+ task->role = running_polstate.kernel_role;
66757+ task->acl = running_polstate.kernel_role->root_label;
66758+ return;
66759+ } else if (!task->role || !(task->role->roletype & GR_ROLE_SPECIAL)) {
66760+ /* save the current ip at time of role lookup so that the proper
66761+ IP will be learned for role_allowed_ip */
66762+ task->signal->saved_ip = task->signal->curr_ip;
66763+ role = lookup_acl_role_label(task, uid, gid);
66764+ }
66765+
66766+ /* don't change the role if we're not a privileged process */
66767+ if (role && task->role != role &&
66768+ (((role->roletype & GR_ROLE_USER) && !gr_acl_is_capable(CAP_SETUID)) ||
66769+ ((role->roletype & GR_ROLE_GROUP) && !gr_acl_is_capable(CAP_SETGID))))
66770+ return;
66771+
66772+ /* perform subject lookup in possibly new role
66773+ we can use this result below in the case where role == task->role
66774+ */
66775+ subj = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, role);
66776+
66777+ /* if we changed uid/gid, but result in the same role
66778+ and are using inheritance, don't lose the inherited subject
66779+ if current subject is other than what normal lookup
66780+ would result in, we arrived via inheritance, don't
66781+ lose subject
66782+ */
66783+ if (role != task->role || (!(task->acl->mode & GR_INHERITLEARN) &&
66784+ (subj == task->acl)))
66785+ task->acl = subj;
66786+
66787+ /* leave task->inherited unaffected */
66788+
66789+ task->role = role;
66790+
66791+ task->is_writable = 0;
66792+
66793+ /* ignore additional mmap checks for processes that are writable
66794+ by the default ACL */
66795+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, running_polstate.default_role->root_label);
66796+ if (unlikely(obj->mode & GR_WRITE))
66797+ task->is_writable = 1;
66798+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
66799+ if (unlikely(obj->mode & GR_WRITE))
66800+ task->is_writable = 1;
66801+
66802+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
66803+ printk(KERN_ALERT "Set role label for (%s:%d): role:%s, subject:%s\n", task->comm, task_pid_nr(task), task->role->rolename, task->acl->filename);
66804+#endif
66805+
66806+ gr_set_proc_res(task);
66807+
66808+ return;
66809+}
66810+
66811+int
66812+gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
66813+ const int unsafe_flags)
66814+{
66815+ struct task_struct *task = current;
66816+ struct acl_subject_label *newacl;
66817+ struct acl_object_label *obj;
66818+ __u32 retmode;
66819+
66820+ if (unlikely(!(gr_status & GR_READY)))
66821+ return 0;
66822+
66823+ newacl = chk_subj_label(dentry, mnt, task->role);
66824+
66825+ /* special handling for if we did an strace -f -p <pid> from an admin role, where pid then
66826+ did an exec
66827+ */
66828+ rcu_read_lock();
66829+ read_lock(&tasklist_lock);
66830+ if (task->ptrace && task->parent && ((task->parent->role->roletype & GR_ROLE_GOD) ||
66831+ (task->parent->acl->mode & GR_POVERRIDE))) {
66832+ read_unlock(&tasklist_lock);
66833+ rcu_read_unlock();
66834+ goto skip_check;
66835+ }
66836+ read_unlock(&tasklist_lock);
66837+ rcu_read_unlock();
66838+
66839+ if (unsafe_flags && !(task->acl->mode & GR_POVERRIDE) && (task->acl != newacl) &&
66840+ !(task->role->roletype & GR_ROLE_GOD) &&
66841+ !gr_search_file(dentry, GR_PTRACERD, mnt) &&
66842+ !(task->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
66843+ if (unsafe_flags & LSM_UNSAFE_SHARE)
66844+ gr_log_fs_generic(GR_DONT_AUDIT, GR_UNSAFESHARE_EXEC_ACL_MSG, dentry, mnt);
66845+ else
66846+ gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_EXEC_ACL_MSG, dentry, mnt);
66847+ return -EACCES;
66848+ }
66849+
66850+skip_check:
66851+
66852+ obj = chk_obj_label(dentry, mnt, task->acl);
66853+ retmode = obj->mode & (GR_INHERIT | GR_AUDIT_INHERIT);
66854+
66855+ if (!(task->acl->mode & GR_INHERITLEARN) &&
66856+ ((newacl->mode & GR_LEARN) || !(retmode & GR_INHERIT))) {
66857+ if (obj->nested)
66858+ task->acl = obj->nested;
66859+ else
66860+ task->acl = newacl;
66861+ task->inherited = 0;
66862+ } else {
66863+ task->inherited = 1;
66864+ if (retmode & GR_INHERIT && retmode & GR_AUDIT_INHERIT)
66865+ gr_log_str_fs(GR_DO_AUDIT, GR_INHERIT_ACL_MSG, task->acl->filename, dentry, mnt);
66866+ }
66867+
66868+ task->is_writable = 0;
66869+
66870+ /* ignore additional mmap checks for processes that are writable
66871+ by the default ACL */
66872+ obj = chk_obj_label(dentry, mnt, running_polstate.default_role->root_label);
66873+ if (unlikely(obj->mode & GR_WRITE))
66874+ task->is_writable = 1;
66875+ obj = chk_obj_label(dentry, mnt, task->role->root_label);
66876+ if (unlikely(obj->mode & GR_WRITE))
66877+ task->is_writable = 1;
66878+
66879+ gr_set_proc_res(task);
66880+
66881+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
66882+ printk(KERN_ALERT "Set subject label for (%s:%d): role:%s, subject:%s\n", task->comm, task_pid_nr(task), task->role->rolename, task->acl->filename);
66883+#endif
66884+ return 0;
66885+}
66886+
66887+/* always called with valid inodev ptr */
66888+static void
66889+do_handle_delete(struct inodev_entry *inodev, const ino_t ino, const dev_t dev)
66890+{
66891+ struct acl_object_label *matchpo;
66892+ struct acl_subject_label *matchps;
66893+ struct acl_subject_label *subj;
66894+ struct acl_role_label *role;
66895+ unsigned int x;
66896+
66897+ FOR_EACH_ROLE_START(role)
66898+ FOR_EACH_SUBJECT_START(role, subj, x)
66899+ if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
66900+ matchpo->mode |= GR_DELETED;
66901+ FOR_EACH_SUBJECT_END(subj,x)
66902+ FOR_EACH_NESTED_SUBJECT_START(role, subj)
66903+ /* nested subjects aren't in the role's subj_hash table */
66904+ if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
66905+ matchpo->mode |= GR_DELETED;
66906+ FOR_EACH_NESTED_SUBJECT_END(subj)
66907+ if ((matchps = lookup_acl_subj_label(ino, dev, role)) != NULL)
66908+ matchps->mode |= GR_DELETED;
66909+ FOR_EACH_ROLE_END(role)
66910+
66911+ inodev->nentry->deleted = 1;
66912+
66913+ return;
66914+}
66915+
66916+void
66917+gr_handle_delete(const ino_t ino, const dev_t dev)
66918+{
66919+ struct inodev_entry *inodev;
66920+
66921+ if (unlikely(!(gr_status & GR_READY)))
66922+ return;
66923+
66924+ write_lock(&gr_inode_lock);
66925+ inodev = lookup_inodev_entry(ino, dev);
66926+ if (inodev != NULL)
66927+ do_handle_delete(inodev, ino, dev);
66928+ write_unlock(&gr_inode_lock);
66929+
66930+ return;
66931+}
66932+
66933+static void
66934+update_acl_obj_label(const ino_t oldinode, const dev_t olddevice,
66935+ const ino_t newinode, const dev_t newdevice,
66936+ struct acl_subject_label *subj)
66937+{
66938+ unsigned int index = gr_fhash(oldinode, olddevice, subj->obj_hash_size);
66939+ struct acl_object_label *match;
66940+
66941+ match = subj->obj_hash[index];
66942+
66943+ while (match && (match->inode != oldinode ||
66944+ match->device != olddevice ||
66945+ !(match->mode & GR_DELETED)))
66946+ match = match->next;
66947+
66948+ if (match && (match->inode == oldinode)
66949+ && (match->device == olddevice)
66950+ && (match->mode & GR_DELETED)) {
66951+ if (match->prev == NULL) {
66952+ subj->obj_hash[index] = match->next;
66953+ if (match->next != NULL)
66954+ match->next->prev = NULL;
66955+ } else {
66956+ match->prev->next = match->next;
66957+ if (match->next != NULL)
66958+ match->next->prev = match->prev;
66959+ }
66960+ match->prev = NULL;
66961+ match->next = NULL;
66962+ match->inode = newinode;
66963+ match->device = newdevice;
66964+ match->mode &= ~GR_DELETED;
66965+
66966+ insert_acl_obj_label(match, subj);
66967+ }
66968+
66969+ return;
66970+}
66971+
66972+static void
66973+update_acl_subj_label(const ino_t oldinode, const dev_t olddevice,
66974+ const ino_t newinode, const dev_t newdevice,
66975+ struct acl_role_label *role)
66976+{
66977+ unsigned int index = gr_fhash(oldinode, olddevice, role->subj_hash_size);
66978+ struct acl_subject_label *match;
66979+
66980+ match = role->subj_hash[index];
66981+
66982+ while (match && (match->inode != oldinode ||
66983+ match->device != olddevice ||
66984+ !(match->mode & GR_DELETED)))
66985+ match = match->next;
66986+
66987+ if (match && (match->inode == oldinode)
66988+ && (match->device == olddevice)
66989+ && (match->mode & GR_DELETED)) {
66990+ if (match->prev == NULL) {
66991+ role->subj_hash[index] = match->next;
66992+ if (match->next != NULL)
66993+ match->next->prev = NULL;
66994+ } else {
66995+ match->prev->next = match->next;
66996+ if (match->next != NULL)
66997+ match->next->prev = match->prev;
66998+ }
66999+ match->prev = NULL;
67000+ match->next = NULL;
67001+ match->inode = newinode;
67002+ match->device = newdevice;
67003+ match->mode &= ~GR_DELETED;
67004+
67005+ insert_acl_subj_label(match, role);
67006+ }
67007+
67008+ return;
67009+}
67010+
67011+static void
67012+update_inodev_entry(const ino_t oldinode, const dev_t olddevice,
67013+ const ino_t newinode, const dev_t newdevice)
67014+{
67015+ unsigned int index = gr_fhash(oldinode, olddevice, running_polstate.inodev_set.i_size);
67016+ struct inodev_entry *match;
67017+
67018+ match = running_polstate.inodev_set.i_hash[index];
67019+
67020+ while (match && (match->nentry->inode != oldinode ||
67021+ match->nentry->device != olddevice || !match->nentry->deleted))
67022+ match = match->next;
67023+
67024+ if (match && (match->nentry->inode == oldinode)
67025+ && (match->nentry->device == olddevice) &&
67026+ match->nentry->deleted) {
67027+ if (match->prev == NULL) {
67028+ running_polstate.inodev_set.i_hash[index] = match->next;
67029+ if (match->next != NULL)
67030+ match->next->prev = NULL;
67031+ } else {
67032+ match->prev->next = match->next;
67033+ if (match->next != NULL)
67034+ match->next->prev = match->prev;
67035+ }
67036+ match->prev = NULL;
67037+ match->next = NULL;
67038+ match->nentry->inode = newinode;
67039+ match->nentry->device = newdevice;
67040+ match->nentry->deleted = 0;
67041+
67042+ insert_inodev_entry(match);
67043+ }
67044+
67045+ return;
67046+}
67047+
67048+static void
67049+__do_handle_create(const struct name_entry *matchn, ino_t ino, dev_t dev)
67050+{
67051+ struct acl_subject_label *subj;
67052+ struct acl_role_label *role;
67053+ unsigned int x;
67054+
67055+ FOR_EACH_ROLE_START(role)
67056+ update_acl_subj_label(matchn->inode, matchn->device, ino, dev, role);
67057+
67058+ FOR_EACH_NESTED_SUBJECT_START(role, subj)
67059+ if ((subj->inode == ino) && (subj->device == dev)) {
67060+ subj->inode = ino;
67061+ subj->device = dev;
67062+ }
67063+ /* nested subjects aren't in the role's subj_hash table */
67064+ update_acl_obj_label(matchn->inode, matchn->device,
67065+ ino, dev, subj);
67066+ FOR_EACH_NESTED_SUBJECT_END(subj)
67067+ FOR_EACH_SUBJECT_START(role, subj, x)
67068+ update_acl_obj_label(matchn->inode, matchn->device,
67069+ ino, dev, subj);
67070+ FOR_EACH_SUBJECT_END(subj,x)
67071+ FOR_EACH_ROLE_END(role)
67072+
67073+ update_inodev_entry(matchn->inode, matchn->device, ino, dev);
67074+
67075+ return;
67076+}
67077+
67078+static void
67079+do_handle_create(const struct name_entry *matchn, const struct dentry *dentry,
67080+ const struct vfsmount *mnt)
67081+{
67082+ ino_t ino = dentry->d_inode->i_ino;
67083+ dev_t dev = __get_dev(dentry);
67084+
67085+ __do_handle_create(matchn, ino, dev);
67086+
67087+ return;
67088+}
67089+
67090+void
67091+gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
67092+{
67093+ struct name_entry *matchn;
67094+
67095+ if (unlikely(!(gr_status & GR_READY)))
67096+ return;
67097+
67098+ preempt_disable();
67099+ matchn = lookup_name_entry(gr_to_filename_rbac(dentry, mnt));
67100+
67101+ if (unlikely((unsigned long)matchn)) {
67102+ write_lock(&gr_inode_lock);
67103+ do_handle_create(matchn, dentry, mnt);
67104+ write_unlock(&gr_inode_lock);
67105+ }
67106+ preempt_enable();
67107+
67108+ return;
67109+}
67110+
67111+void
67112+gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
67113+{
67114+ struct name_entry *matchn;
67115+
67116+ if (unlikely(!(gr_status & GR_READY)))
67117+ return;
67118+
67119+ preempt_disable();
67120+ matchn = lookup_name_entry(gr_to_proc_filename_rbac(dentry, init_pid_ns.proc_mnt));
67121+
67122+ if (unlikely((unsigned long)matchn)) {
67123+ write_lock(&gr_inode_lock);
67124+ __do_handle_create(matchn, inode->i_ino, inode->i_sb->s_dev);
67125+ write_unlock(&gr_inode_lock);
67126+ }
67127+ preempt_enable();
67128+
67129+ return;
67130+}
67131+
67132+void
67133+gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
67134+ struct dentry *old_dentry,
67135+ struct dentry *new_dentry,
67136+ struct vfsmount *mnt, const __u8 replace)
67137+{
67138+ struct name_entry *matchn;
67139+ struct inodev_entry *inodev;
67140+ struct inode *inode = new_dentry->d_inode;
67141+ ino_t old_ino = old_dentry->d_inode->i_ino;
67142+ dev_t old_dev = __get_dev(old_dentry);
67143+
67144+ /* vfs_rename swaps the name and parent link for old_dentry and
67145+ new_dentry
67146+ at this point, old_dentry has the new name, parent link, and inode
67147+ for the renamed file
67148+ if a file is being replaced by a rename, new_dentry has the inode
67149+ and name for the replaced file
67150+ */
67151+
67152+ if (unlikely(!(gr_status & GR_READY)))
67153+ return;
67154+
67155+ preempt_disable();
67156+ matchn = lookup_name_entry(gr_to_filename_rbac(old_dentry, mnt));
67157+
67158+ /* we wouldn't have to check d_inode if it weren't for
67159+ NFS silly-renaming
67160+ */
67161+
67162+ write_lock(&gr_inode_lock);
67163+ if (unlikely(replace && inode)) {
67164+ ino_t new_ino = inode->i_ino;
67165+ dev_t new_dev = __get_dev(new_dentry);
67166+
67167+ inodev = lookup_inodev_entry(new_ino, new_dev);
67168+ if (inodev != NULL && ((inode->i_nlink <= 1) || S_ISDIR(inode->i_mode)))
67169+ do_handle_delete(inodev, new_ino, new_dev);
67170+ }
67171+
67172+ inodev = lookup_inodev_entry(old_ino, old_dev);
67173+ if (inodev != NULL && ((old_dentry->d_inode->i_nlink <= 1) || S_ISDIR(old_dentry->d_inode->i_mode)))
67174+ do_handle_delete(inodev, old_ino, old_dev);
67175+
67176+ if (unlikely((unsigned long)matchn))
67177+ do_handle_create(matchn, old_dentry, mnt);
67178+
67179+ write_unlock(&gr_inode_lock);
67180+ preempt_enable();
67181+
67182+ return;
67183+}
67184+
67185+#if defined(CONFIG_GRKERNSEC_RESLOG) || !defined(CONFIG_GRKERNSEC_NO_RBAC)
67186+static const unsigned long res_learn_bumps[GR_NLIMITS] = {
67187+ [RLIMIT_CPU] = GR_RLIM_CPU_BUMP,
67188+ [RLIMIT_FSIZE] = GR_RLIM_FSIZE_BUMP,
67189+ [RLIMIT_DATA] = GR_RLIM_DATA_BUMP,
67190+ [RLIMIT_STACK] = GR_RLIM_STACK_BUMP,
67191+ [RLIMIT_CORE] = GR_RLIM_CORE_BUMP,
67192+ [RLIMIT_RSS] = GR_RLIM_RSS_BUMP,
67193+ [RLIMIT_NPROC] = GR_RLIM_NPROC_BUMP,
67194+ [RLIMIT_NOFILE] = GR_RLIM_NOFILE_BUMP,
67195+ [RLIMIT_MEMLOCK] = GR_RLIM_MEMLOCK_BUMP,
67196+ [RLIMIT_AS] = GR_RLIM_AS_BUMP,
67197+ [RLIMIT_LOCKS] = GR_RLIM_LOCKS_BUMP,
67198+ [RLIMIT_SIGPENDING] = GR_RLIM_SIGPENDING_BUMP,
67199+ [RLIMIT_MSGQUEUE] = GR_RLIM_MSGQUEUE_BUMP,
67200+ [RLIMIT_NICE] = GR_RLIM_NICE_BUMP,
67201+ [RLIMIT_RTPRIO] = GR_RLIM_RTPRIO_BUMP,
67202+ [RLIMIT_RTTIME] = GR_RLIM_RTTIME_BUMP
67203+};
67204+
67205+void
67206+gr_learn_resource(const struct task_struct *task,
67207+ const int res, const unsigned long wanted, const int gt)
67208+{
67209+ struct acl_subject_label *acl;
67210+ const struct cred *cred;
67211+
67212+ if (unlikely((gr_status & GR_READY) &&
67213+ task->acl && (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))))
67214+ goto skip_reslog;
67215+
67216+ gr_log_resource(task, res, wanted, gt);
67217+skip_reslog:
67218+
67219+ if (unlikely(!(gr_status & GR_READY) || !wanted || res >= GR_NLIMITS))
67220+ return;
67221+
67222+ acl = task->acl;
67223+
67224+ if (likely(!acl || !(acl->mode & (GR_LEARN | GR_INHERITLEARN)) ||
67225+ !(acl->resmask & (1U << (unsigned short) res))))
67226+ return;
67227+
67228+ if (wanted >= acl->res[res].rlim_cur) {
67229+ unsigned long res_add;
67230+
67231+ res_add = wanted + res_learn_bumps[res];
67232+
67233+ acl->res[res].rlim_cur = res_add;
67234+
67235+ if (wanted > acl->res[res].rlim_max)
67236+ acl->res[res].rlim_max = res_add;
67237+
67238+ /* only log the subject filename, since resource logging is supported for
67239+ single-subject learning only */
67240+ rcu_read_lock();
67241+ cred = __task_cred(task);
67242+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
67243+ task->role->roletype, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), acl->filename,
67244+ acl->filename, acl->res[res].rlim_cur, acl->res[res].rlim_max,
67245+ "", (unsigned long) res, &task->signal->saved_ip);
67246+ rcu_read_unlock();
67247+ }
67248+
67249+ return;
67250+}
67251+EXPORT_SYMBOL(gr_learn_resource);
67252+#endif
67253+
67254+#if defined(CONFIG_PAX_HAVE_ACL_FLAGS) && (defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR))
67255+void
67256+pax_set_initial_flags(struct linux_binprm *bprm)
67257+{
67258+ struct task_struct *task = current;
67259+ struct acl_subject_label *proc;
67260+ unsigned long flags;
67261+
67262+ if (unlikely(!(gr_status & GR_READY)))
67263+ return;
67264+
67265+ flags = pax_get_flags(task);
67266+
67267+ proc = task->acl;
67268+
67269+ if (proc->pax_flags & GR_PAX_DISABLE_PAGEEXEC)
67270+ flags &= ~MF_PAX_PAGEEXEC;
67271+ if (proc->pax_flags & GR_PAX_DISABLE_SEGMEXEC)
67272+ flags &= ~MF_PAX_SEGMEXEC;
67273+ if (proc->pax_flags & GR_PAX_DISABLE_RANDMMAP)
67274+ flags &= ~MF_PAX_RANDMMAP;
67275+ if (proc->pax_flags & GR_PAX_DISABLE_EMUTRAMP)
67276+ flags &= ~MF_PAX_EMUTRAMP;
67277+ if (proc->pax_flags & GR_PAX_DISABLE_MPROTECT)
67278+ flags &= ~MF_PAX_MPROTECT;
67279+
67280+ if (proc->pax_flags & GR_PAX_ENABLE_PAGEEXEC)
67281+ flags |= MF_PAX_PAGEEXEC;
67282+ if (proc->pax_flags & GR_PAX_ENABLE_SEGMEXEC)
67283+ flags |= MF_PAX_SEGMEXEC;
67284+ if (proc->pax_flags & GR_PAX_ENABLE_RANDMMAP)
67285+ flags |= MF_PAX_RANDMMAP;
67286+ if (proc->pax_flags & GR_PAX_ENABLE_EMUTRAMP)
67287+ flags |= MF_PAX_EMUTRAMP;
67288+ if (proc->pax_flags & GR_PAX_ENABLE_MPROTECT)
67289+ flags |= MF_PAX_MPROTECT;
67290+
67291+ pax_set_flags(task, flags);
67292+
67293+ return;
67294+}
67295+#endif
67296+
67297+int
67298+gr_handle_proc_ptrace(struct task_struct *task)
67299+{
67300+ struct file *filp;
67301+ struct task_struct *tmp = task;
67302+ struct task_struct *curtemp = current;
67303+ __u32 retmode;
67304+
67305+#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
67306+ if (unlikely(!(gr_status & GR_READY)))
67307+ return 0;
67308+#endif
67309+
67310+ read_lock(&tasklist_lock);
67311+ read_lock(&grsec_exec_file_lock);
67312+ filp = task->exec_file;
67313+
67314+ while (task_pid_nr(tmp) > 0) {
67315+ if (tmp == curtemp)
67316+ break;
67317+ tmp = tmp->real_parent;
67318+ }
67319+
67320+ if (!filp || (task_pid_nr(tmp) == 0 && ((grsec_enable_harden_ptrace && gr_is_global_nonroot(current_uid()) && !(gr_status & GR_READY)) ||
67321+ ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE))))) {
67322+ read_unlock(&grsec_exec_file_lock);
67323+ read_unlock(&tasklist_lock);
67324+ return 1;
67325+ }
67326+
67327+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
67328+ if (!(gr_status & GR_READY)) {
67329+ read_unlock(&grsec_exec_file_lock);
67330+ read_unlock(&tasklist_lock);
67331+ return 0;
67332+ }
67333+#endif
67334+
67335+ retmode = gr_search_file(filp->f_path.dentry, GR_NOPTRACE, filp->f_path.mnt);
67336+ read_unlock(&grsec_exec_file_lock);
67337+ read_unlock(&tasklist_lock);
67338+
67339+ if (retmode & GR_NOPTRACE)
67340+ return 1;
67341+
67342+ if (!(current->acl->mode & GR_POVERRIDE) && !(current->role->roletype & GR_ROLE_GOD)
67343+ && (current->acl != task->acl || (current->acl != current->role->root_label
67344+ && task_pid_nr(current) != task_pid_nr(task))))
67345+ return 1;
67346+
67347+ return 0;
67348+}
67349+
67350+void task_grsec_rbac(struct seq_file *m, struct task_struct *p)
67351+{
67352+ if (unlikely(!(gr_status & GR_READY)))
67353+ return;
67354+
67355+ if (!(current->role->roletype & GR_ROLE_GOD))
67356+ return;
67357+
67358+ seq_printf(m, "RBAC:\t%.64s:%c:%.950s\n",
67359+ p->role->rolename, gr_task_roletype_to_char(p),
67360+ p->acl->filename);
67361+}
67362+
67363+int
67364+gr_handle_ptrace(struct task_struct *task, const long request)
67365+{
67366+ struct task_struct *tmp = task;
67367+ struct task_struct *curtemp = current;
67368+ __u32 retmode;
67369+
67370+#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
67371+ if (unlikely(!(gr_status & GR_READY)))
67372+ return 0;
67373+#endif
67374+ if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
67375+ read_lock(&tasklist_lock);
67376+ while (task_pid_nr(tmp) > 0) {
67377+ if (tmp == curtemp)
67378+ break;
67379+ tmp = tmp->real_parent;
67380+ }
67381+
67382+ if (task_pid_nr(tmp) == 0 && ((grsec_enable_harden_ptrace && gr_is_global_nonroot(current_uid()) && !(gr_status & GR_READY)) ||
67383+ ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE)))) {
67384+ read_unlock(&tasklist_lock);
67385+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
67386+ return 1;
67387+ }
67388+ read_unlock(&tasklist_lock);
67389+ }
67390+
67391+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
67392+ if (!(gr_status & GR_READY))
67393+ return 0;
67394+#endif
67395+
67396+ read_lock(&grsec_exec_file_lock);
67397+ if (unlikely(!task->exec_file)) {
67398+ read_unlock(&grsec_exec_file_lock);
67399+ return 0;
67400+ }
67401+
67402+ retmode = gr_search_file(task->exec_file->f_path.dentry, GR_PTRACERD | GR_NOPTRACE, task->exec_file->f_path.mnt);
67403+ read_unlock(&grsec_exec_file_lock);
67404+
67405+ if (retmode & GR_NOPTRACE) {
67406+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
67407+ return 1;
67408+ }
67409+
67410+ if (retmode & GR_PTRACERD) {
67411+ switch (request) {
67412+ case PTRACE_SEIZE:
67413+ case PTRACE_POKETEXT:
67414+ case PTRACE_POKEDATA:
67415+ case PTRACE_POKEUSR:
67416+#if !defined(CONFIG_PPC32) && !defined(CONFIG_PPC64) && !defined(CONFIG_PARISC) && !defined(CONFIG_ALPHA) && !defined(CONFIG_IA64)
67417+ case PTRACE_SETREGS:
67418+ case PTRACE_SETFPREGS:
67419+#endif
67420+#ifdef CONFIG_X86
67421+ case PTRACE_SETFPXREGS:
67422+#endif
67423+#ifdef CONFIG_ALTIVEC
67424+ case PTRACE_SETVRREGS:
67425+#endif
67426+ return 1;
67427+ default:
67428+ return 0;
67429+ }
67430+ } else if (!(current->acl->mode & GR_POVERRIDE) &&
67431+ !(current->role->roletype & GR_ROLE_GOD) &&
67432+ (current->acl != task->acl)) {
67433+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
67434+ return 1;
67435+ }
67436+
67437+ return 0;
67438+}
67439+
67440+static int is_writable_mmap(const struct file *filp)
67441+{
67442+ struct task_struct *task = current;
67443+ struct acl_object_label *obj, *obj2;
67444+
67445+ if (gr_status & GR_READY && !(task->acl->mode & GR_OVERRIDE) &&
67446+ !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))) {
67447+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, running_polstate.default_role->root_label);
67448+ obj2 = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt,
67449+ task->role->root_label);
67450+ if (unlikely((obj->mode & GR_WRITE) || (obj2->mode & GR_WRITE))) {
67451+ gr_log_fs_generic(GR_DONT_AUDIT, GR_WRITLIB_ACL_MSG, filp->f_path.dentry, filp->f_path.mnt);
67452+ return 1;
67453+ }
67454+ }
67455+ return 0;
67456+}
67457+
67458+int
67459+gr_acl_handle_mmap(const struct file *file, const unsigned long prot)
67460+{
67461+ __u32 mode;
67462+
67463+ if (unlikely(!file || !(prot & PROT_EXEC)))
67464+ return 1;
67465+
67466+ if (is_writable_mmap(file))
67467+ return 0;
67468+
67469+ mode =
67470+ gr_search_file(file->f_path.dentry,
67471+ GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
67472+ file->f_path.mnt);
67473+
67474+ if (!gr_tpe_allow(file))
67475+ return 0;
67476+
67477+ if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
67478+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
67479+ return 0;
67480+ } else if (unlikely(!(mode & GR_EXEC))) {
67481+ return 0;
67482+ } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
67483+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
67484+ return 1;
67485+ }
67486+
67487+ return 1;
67488+}
67489+
67490+int
67491+gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
67492+{
67493+ __u32 mode;
67494+
67495+ if (unlikely(!file || !(prot & PROT_EXEC)))
67496+ return 1;
67497+
67498+ if (is_writable_mmap(file))
67499+ return 0;
67500+
67501+ mode =
67502+ gr_search_file(file->f_path.dentry,
67503+ GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
67504+ file->f_path.mnt);
67505+
67506+ if (!gr_tpe_allow(file))
67507+ return 0;
67508+
67509+ if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
67510+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
67511+ return 0;
67512+ } else if (unlikely(!(mode & GR_EXEC))) {
67513+ return 0;
67514+ } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
67515+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
67516+ return 1;
67517+ }
67518+
67519+ return 1;
67520+}
67521+
67522+void
67523+gr_acl_handle_psacct(struct task_struct *task, const long code)
67524+{
67525+ unsigned long runtime;
67526+ unsigned long cputime;
67527+ unsigned int wday, cday;
67528+ __u8 whr, chr;
67529+ __u8 wmin, cmin;
67530+ __u8 wsec, csec;
67531+ struct timespec timeval;
67532+
67533+ if (unlikely(!(gr_status & GR_READY) || !task->acl ||
67534+ !(task->acl->mode & GR_PROCACCT)))
67535+ return;
67536+
67537+ do_posix_clock_monotonic_gettime(&timeval);
67538+ runtime = timeval.tv_sec - task->start_time.tv_sec;
67539+ wday = runtime / (3600 * 24);
67540+ runtime -= wday * (3600 * 24);
67541+ whr = runtime / 3600;
67542+ runtime -= whr * 3600;
67543+ wmin = runtime / 60;
67544+ runtime -= wmin * 60;
67545+ wsec = runtime;
67546+
67547+ cputime = (task->utime + task->stime) / HZ;
67548+ cday = cputime / (3600 * 24);
67549+ cputime -= cday * (3600 * 24);
67550+ chr = cputime / 3600;
67551+ cputime -= chr * 3600;
67552+ cmin = cputime / 60;
67553+ cputime -= cmin * 60;
67554+ csec = cputime;
67555+
67556+ gr_log_procacct(GR_DO_AUDIT, GR_ACL_PROCACCT_MSG, task, wday, whr, wmin, wsec, cday, chr, cmin, csec, code);
67557+
67558+ return;
67559+}
67560+
67561+#ifdef CONFIG_TASKSTATS
67562+int gr_is_taskstats_denied(int pid)
67563+{
67564+ struct task_struct *task;
67565+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
67566+ const struct cred *cred;
67567+#endif
67568+ int ret = 0;
67569+
67570+ /* restrict taskstats viewing to un-chrooted root users
67571+ who have the 'view' subject flag if the RBAC system is enabled
67572+ */
67573+
67574+ rcu_read_lock();
67575+ read_lock(&tasklist_lock);
67576+ task = find_task_by_vpid(pid);
67577+ if (task) {
67578+#ifdef CONFIG_GRKERNSEC_CHROOT
67579+ if (proc_is_chrooted(task))
67580+ ret = -EACCES;
67581+#endif
67582+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
67583+ cred = __task_cred(task);
67584+#ifdef CONFIG_GRKERNSEC_PROC_USER
67585+ if (gr_is_global_nonroot(cred->uid))
67586+ ret = -EACCES;
67587+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
67588+ if (gr_is_global_nonroot(cred->uid) && !groups_search(cred->group_info, grsec_proc_gid))
67589+ ret = -EACCES;
67590+#endif
67591+#endif
67592+ if (gr_status & GR_READY) {
67593+ if (!(task->acl->mode & GR_VIEW))
67594+ ret = -EACCES;
67595+ }
67596+ } else
67597+ ret = -ENOENT;
67598+
67599+ read_unlock(&tasklist_lock);
67600+ rcu_read_unlock();
67601+
67602+ return ret;
67603+}
67604+#endif
67605+
67606+/* AUXV entries are filled via a descendant of search_binary_handler
67607+ after we've already applied the subject for the target
67608+*/
67609+int gr_acl_enable_at_secure(void)
67610+{
67611+ if (unlikely(!(gr_status & GR_READY)))
67612+ return 0;
67613+
67614+ if (current->acl->mode & GR_ATSECURE)
67615+ return 1;
67616+
67617+ return 0;
67618+}
67619+
67620+int gr_acl_handle_filldir(const struct file *file, const char *name, const unsigned int namelen, const ino_t ino)
67621+{
67622+ struct task_struct *task = current;
67623+ struct dentry *dentry = file->f_path.dentry;
67624+ struct vfsmount *mnt = file->f_path.mnt;
67625+ struct acl_object_label *obj, *tmp;
67626+ struct acl_subject_label *subj;
67627+ unsigned int bufsize;
67628+ int is_not_root;
67629+ char *path;
67630+ dev_t dev = __get_dev(dentry);
67631+
67632+ if (unlikely(!(gr_status & GR_READY)))
67633+ return 1;
67634+
67635+ if (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))
67636+ return 1;
67637+
67638+ /* ignore Eric Biederman */
67639+ if (IS_PRIVATE(dentry->d_inode))
67640+ return 1;
67641+
67642+ subj = task->acl;
67643+ read_lock(&gr_inode_lock);
67644+ do {
67645+ obj = lookup_acl_obj_label(ino, dev, subj);
67646+ if (obj != NULL) {
67647+ read_unlock(&gr_inode_lock);
67648+ return (obj->mode & GR_FIND) ? 1 : 0;
67649+ }
67650+ } while ((subj = subj->parent_subject));
67651+ read_unlock(&gr_inode_lock);
67652+
67653+ /* this is purely an optimization since we're looking for an object
67654+ for the directory we're doing a readdir on
67655+ if it's possible for any globbed object to match the entry we're
67656+ filling into the directory, then the object we find here will be
67657+ an anchor point with attached globbed objects
67658+ */
67659+ obj = chk_obj_label_noglob(dentry, mnt, task->acl);
67660+ if (obj->globbed == NULL)
67661+ return (obj->mode & GR_FIND) ? 1 : 0;
67662+
67663+ is_not_root = ((obj->filename[0] == '/') &&
67664+ (obj->filename[1] == '\0')) ? 0 : 1;
67665+ bufsize = PAGE_SIZE - namelen - is_not_root;
67666+
67667+ /* check bufsize > PAGE_SIZE || bufsize == 0 */
67668+ if (unlikely((bufsize - 1) > (PAGE_SIZE - 1)))
67669+ return 1;
67670+
67671+ preempt_disable();
67672+ path = d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
67673+ bufsize);
67674+
67675+ bufsize = strlen(path);
67676+
67677+ /* if base is "/", don't append an additional slash */
67678+ if (is_not_root)
67679+ *(path + bufsize) = '/';
67680+ memcpy(path + bufsize + is_not_root, name, namelen);
67681+ *(path + bufsize + namelen + is_not_root) = '\0';
67682+
67683+ tmp = obj->globbed;
67684+ while (tmp) {
67685+ if (!glob_match(tmp->filename, path)) {
67686+ preempt_enable();
67687+ return (tmp->mode & GR_FIND) ? 1 : 0;
67688+ }
67689+ tmp = tmp->next;
67690+ }
67691+ preempt_enable();
67692+ return (obj->mode & GR_FIND) ? 1 : 0;
67693+}
67694+
67695+void gr_put_exec_file(struct task_struct *task)
67696+{
67697+ struct file *filp;
67698+
67699+ write_lock(&grsec_exec_file_lock);
67700+ filp = task->exec_file;
67701+ task->exec_file = NULL;
67702+ write_unlock(&grsec_exec_file_lock);
67703+
67704+ if (filp)
67705+ fput(filp);
67706+
67707+ return;
67708+}
67709+
67710+
67711+#ifdef CONFIG_NETFILTER_XT_MATCH_GRADM_MODULE
67712+EXPORT_SYMBOL(gr_acl_is_enabled);
67713+#endif
67714+#ifdef CONFIG_SECURITY
67715+EXPORT_SYMBOL(gr_check_user_change);
67716+EXPORT_SYMBOL(gr_check_group_change);
67717+#endif
67718+
67719diff --git a/grsecurity/gracl_alloc.c b/grsecurity/gracl_alloc.c
67720new file mode 100644
67721index 0000000..18ffbbd
67722--- /dev/null
67723+++ b/grsecurity/gracl_alloc.c
67724@@ -0,0 +1,105 @@
67725+#include <linux/kernel.h>
67726+#include <linux/mm.h>
67727+#include <linux/slab.h>
67728+#include <linux/vmalloc.h>
67729+#include <linux/gracl.h>
67730+#include <linux/grsecurity.h>
67731+
67732+static struct gr_alloc_state __current_alloc_state = { 1, 1, NULL };
67733+struct gr_alloc_state *current_alloc_state = &__current_alloc_state;
67734+
67735+static __inline__ int
67736+alloc_pop(void)
67737+{
67738+ if (current_alloc_state->alloc_stack_next == 1)
67739+ return 0;
67740+
67741+ kfree(current_alloc_state->alloc_stack[current_alloc_state->alloc_stack_next - 2]);
67742+
67743+ current_alloc_state->alloc_stack_next--;
67744+
67745+ return 1;
67746+}
67747+
67748+static __inline__ int
67749+alloc_push(void *buf)
67750+{
67751+ if (current_alloc_state->alloc_stack_next >= current_alloc_state->alloc_stack_size)
67752+ return 1;
67753+
67754+ current_alloc_state->alloc_stack[current_alloc_state->alloc_stack_next - 1] = buf;
67755+
67756+ current_alloc_state->alloc_stack_next++;
67757+
67758+ return 0;
67759+}
67760+
67761+void *
67762+acl_alloc(unsigned long len)
67763+{
67764+ void *ret = NULL;
67765+
67766+ if (!len || len > PAGE_SIZE)
67767+ goto out;
67768+
67769+ ret = kmalloc(len, GFP_KERNEL);
67770+
67771+ if (ret) {
67772+ if (alloc_push(ret)) {
67773+ kfree(ret);
67774+ ret = NULL;
67775+ }
67776+ }
67777+
67778+out:
67779+ return ret;
67780+}
67781+
67782+void *
67783+acl_alloc_num(unsigned long num, unsigned long len)
67784+{
67785+ if (!len || (num > (PAGE_SIZE / len)))
67786+ return NULL;
67787+
67788+ return acl_alloc(num * len);
67789+}
67790+
67791+void
67792+acl_free_all(void)
67793+{
67794+ if (!current_alloc_state->alloc_stack)
67795+ return;
67796+
67797+ while (alloc_pop()) ;
67798+
67799+ if (current_alloc_state->alloc_stack) {
67800+ if ((current_alloc_state->alloc_stack_size * sizeof (void *)) <= PAGE_SIZE)
67801+ kfree(current_alloc_state->alloc_stack);
67802+ else
67803+ vfree(current_alloc_state->alloc_stack);
67804+ }
67805+
67806+ current_alloc_state->alloc_stack = NULL;
67807+ current_alloc_state->alloc_stack_size = 1;
67808+ current_alloc_state->alloc_stack_next = 1;
67809+
67810+ return;
67811+}
67812+
67813+int
67814+acl_alloc_stack_init(unsigned long size)
67815+{
67816+ if ((size * sizeof (void *)) <= PAGE_SIZE)
67817+ current_alloc_state->alloc_stack =
67818+ (void **) kmalloc(size * sizeof (void *), GFP_KERNEL);
67819+ else
67820+ current_alloc_state->alloc_stack = (void **) vmalloc(size * sizeof (void *));
67821+
67822+ current_alloc_state->alloc_stack_size = size;
67823+ current_alloc_state->alloc_stack_next = 1;
67824+
67825+ if (!current_alloc_state->alloc_stack)
67826+ return 0;
67827+ else
67828+ return 1;
67829+}
67830diff --git a/grsecurity/gracl_cap.c b/grsecurity/gracl_cap.c
67831new file mode 100644
67832index 0000000..bdd51ea
67833--- /dev/null
67834+++ b/grsecurity/gracl_cap.c
67835@@ -0,0 +1,110 @@
67836+#include <linux/kernel.h>
67837+#include <linux/module.h>
67838+#include <linux/sched.h>
67839+#include <linux/gracl.h>
67840+#include <linux/grsecurity.h>
67841+#include <linux/grinternal.h>
67842+
67843+extern const char *captab_log[];
67844+extern int captab_log_entries;
67845+
67846+int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
67847+{
67848+ struct acl_subject_label *curracl;
67849+ kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
67850+ kernel_cap_t cap_audit = __cap_empty_set;
67851+
67852+ if (!gr_acl_is_enabled())
67853+ return 1;
67854+
67855+ curracl = task->acl;
67856+
67857+ cap_drop = curracl->cap_lower;
67858+ cap_mask = curracl->cap_mask;
67859+ cap_audit = curracl->cap_invert_audit;
67860+
67861+ while ((curracl = curracl->parent_subject)) {
67862+ /* if the cap isn't specified in the current computed mask but is specified in the
67863+ current level subject, and is lowered in the current level subject, then add
67864+ it to the set of dropped capabilities
67865+ otherwise, add the current level subject's mask to the current computed mask
67866+ */
67867+ if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
67868+ cap_raise(cap_mask, cap);
67869+ if (cap_raised(curracl->cap_lower, cap))
67870+ cap_raise(cap_drop, cap);
67871+ if (cap_raised(curracl->cap_invert_audit, cap))
67872+ cap_raise(cap_audit, cap);
67873+ }
67874+ }
67875+
67876+ if (!cap_raised(cap_drop, cap)) {
67877+ if (cap_raised(cap_audit, cap))
67878+ gr_log_cap(GR_DO_AUDIT, GR_CAP_ACL_MSG2, task, captab_log[cap]);
67879+ return 1;
67880+ }
67881+
67882+ curracl = task->acl;
67883+
67884+ if ((curracl->mode & (GR_LEARN | GR_INHERITLEARN))
67885+ && cap_raised(cred->cap_effective, cap)) {
67886+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
67887+ task->role->roletype, GR_GLOBAL_UID(cred->uid),
67888+ GR_GLOBAL_GID(cred->gid), task->exec_file ?
67889+ gr_to_filename(task->exec_file->f_path.dentry,
67890+ task->exec_file->f_path.mnt) : curracl->filename,
67891+ curracl->filename, 0UL,
67892+ 0UL, "", (unsigned long) cap, &task->signal->saved_ip);
67893+ return 1;
67894+ }
67895+
67896+ if ((cap >= 0) && (cap < captab_log_entries) && cap_raised(cred->cap_effective, cap) && !cap_raised(cap_audit, cap))
67897+ gr_log_cap(GR_DONT_AUDIT, GR_CAP_ACL_MSG, task, captab_log[cap]);
67898+
67899+ return 0;
67900+}
67901+
67902+int
67903+gr_acl_is_capable(const int cap)
67904+{
67905+ return gr_task_acl_is_capable(current, current_cred(), cap);
67906+}
67907+
67908+int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap)
67909+{
67910+ struct acl_subject_label *curracl;
67911+ kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
67912+
67913+ if (!gr_acl_is_enabled())
67914+ return 1;
67915+
67916+ curracl = task->acl;
67917+
67918+ cap_drop = curracl->cap_lower;
67919+ cap_mask = curracl->cap_mask;
67920+
67921+ while ((curracl = curracl->parent_subject)) {
67922+ /* if the cap isn't specified in the current computed mask but is specified in the
67923+ current level subject, and is lowered in the current level subject, then add
67924+ it to the set of dropped capabilities
67925+ otherwise, add the current level subject's mask to the current computed mask
67926+ */
67927+ if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
67928+ cap_raise(cap_mask, cap);
67929+ if (cap_raised(curracl->cap_lower, cap))
67930+ cap_raise(cap_drop, cap);
67931+ }
67932+ }
67933+
67934+ if (!cap_raised(cap_drop, cap))
67935+ return 1;
67936+
67937+ return 0;
67938+}
67939+
67940+int
67941+gr_acl_is_capable_nolog(const int cap)
67942+{
67943+ return gr_task_acl_is_capable_nolog(current, cap);
67944+}
67945+
67946diff --git a/grsecurity/gracl_compat.c b/grsecurity/gracl_compat.c
67947new file mode 100644
67948index 0000000..ca25605
67949--- /dev/null
67950+++ b/grsecurity/gracl_compat.c
67951@@ -0,0 +1,270 @@
67952+#include <linux/kernel.h>
67953+#include <linux/gracl.h>
67954+#include <linux/compat.h>
67955+#include <linux/gracl_compat.h>
67956+
67957+#include <asm/uaccess.h>
67958+
67959+int copy_gr_arg_wrapper_compat(const char *buf, struct gr_arg_wrapper *uwrap)
67960+{
67961+ struct gr_arg_wrapper_compat uwrapcompat;
67962+
67963+ if (copy_from_user(&uwrapcompat, buf, sizeof(uwrapcompat)))
67964+ return -EFAULT;
67965+
67966+ if (((uwrapcompat.version != GRSECURITY_VERSION) &&
67967+ (uwrapcompat.version != 0x2901)) ||
67968+ (uwrapcompat.size != sizeof(struct gr_arg_compat)))
67969+ return -EINVAL;
67970+
67971+ uwrap->arg = compat_ptr(uwrapcompat.arg);
67972+ uwrap->version = uwrapcompat.version;
67973+ uwrap->size = sizeof(struct gr_arg);
67974+
67975+ return 0;
67976+}
67977+
67978+int copy_gr_arg_compat(const struct gr_arg __user *buf, struct gr_arg *arg)
67979+{
67980+ struct gr_arg_compat argcompat;
67981+
67982+ if (copy_from_user(&argcompat, buf, sizeof(argcompat)))
67983+ return -EFAULT;
67984+
67985+ arg->role_db.r_table = compat_ptr(argcompat.role_db.r_table);
67986+ arg->role_db.num_pointers = argcompat.role_db.num_pointers;
67987+ arg->role_db.num_roles = argcompat.role_db.num_roles;
67988+ arg->role_db.num_domain_children = argcompat.role_db.num_domain_children;
67989+ arg->role_db.num_subjects = argcompat.role_db.num_subjects;
67990+ arg->role_db.num_objects = argcompat.role_db.num_objects;
67991+
67992+ memcpy(&arg->pw, &argcompat.pw, sizeof(arg->pw));
67993+ memcpy(&arg->salt, &argcompat.salt, sizeof(arg->salt));
67994+ memcpy(&arg->sum, &argcompat.sum, sizeof(arg->sum));
67995+ memcpy(&arg->sp_role, &argcompat.sp_role, sizeof(arg->sp_role));
67996+ arg->sprole_pws = compat_ptr(argcompat.sprole_pws);
67997+ arg->segv_device = argcompat.segv_device;
67998+ arg->segv_inode = argcompat.segv_inode;
67999+ arg->segv_uid = argcompat.segv_uid;
68000+ arg->num_sprole_pws = argcompat.num_sprole_pws;
68001+ arg->mode = argcompat.mode;
68002+
68003+ return 0;
68004+}
68005+
68006+int copy_acl_object_label_compat(struct acl_object_label *obj, const struct acl_object_label *userp)
68007+{
68008+ struct acl_object_label_compat objcompat;
68009+
68010+ if (copy_from_user(&objcompat, userp, sizeof(objcompat)))
68011+ return -EFAULT;
68012+
68013+ obj->filename = compat_ptr(objcompat.filename);
68014+ obj->inode = objcompat.inode;
68015+ obj->device = objcompat.device;
68016+ obj->mode = objcompat.mode;
68017+
68018+ obj->nested = compat_ptr(objcompat.nested);
68019+ obj->globbed = compat_ptr(objcompat.globbed);
68020+
68021+ obj->prev = compat_ptr(objcompat.prev);
68022+ obj->next = compat_ptr(objcompat.next);
68023+
68024+ return 0;
68025+}
68026+
68027+int copy_acl_subject_label_compat(struct acl_subject_label *subj, const struct acl_subject_label *userp)
68028+{
68029+ unsigned int i;
68030+ struct acl_subject_label_compat subjcompat;
68031+
68032+ if (copy_from_user(&subjcompat, userp, sizeof(subjcompat)))
68033+ return -EFAULT;
68034+
68035+ subj->filename = compat_ptr(subjcompat.filename);
68036+ subj->inode = subjcompat.inode;
68037+ subj->device = subjcompat.device;
68038+ subj->mode = subjcompat.mode;
68039+ subj->cap_mask = subjcompat.cap_mask;
68040+ subj->cap_lower = subjcompat.cap_lower;
68041+ subj->cap_invert_audit = subjcompat.cap_invert_audit;
68042+
68043+ for (i = 0; i < GR_NLIMITS; i++) {
68044+ if (subjcompat.res[i].rlim_cur == COMPAT_RLIM_INFINITY)
68045+ subj->res[i].rlim_cur = RLIM_INFINITY;
68046+ else
68047+ subj->res[i].rlim_cur = subjcompat.res[i].rlim_cur;
68048+ if (subjcompat.res[i].rlim_max == COMPAT_RLIM_INFINITY)
68049+ subj->res[i].rlim_max = RLIM_INFINITY;
68050+ else
68051+ subj->res[i].rlim_max = subjcompat.res[i].rlim_max;
68052+ }
68053+ subj->resmask = subjcompat.resmask;
68054+
68055+ subj->user_trans_type = subjcompat.user_trans_type;
68056+ subj->group_trans_type = subjcompat.group_trans_type;
68057+ subj->user_transitions = compat_ptr(subjcompat.user_transitions);
68058+ subj->group_transitions = compat_ptr(subjcompat.group_transitions);
68059+ subj->user_trans_num = subjcompat.user_trans_num;
68060+ subj->group_trans_num = subjcompat.group_trans_num;
68061+
68062+ memcpy(&subj->sock_families, &subjcompat.sock_families, sizeof(subj->sock_families));
68063+ memcpy(&subj->ip_proto, &subjcompat.ip_proto, sizeof(subj->ip_proto));
68064+ subj->ip_type = subjcompat.ip_type;
68065+ subj->ips = compat_ptr(subjcompat.ips);
68066+ subj->ip_num = subjcompat.ip_num;
68067+ subj->inaddr_any_override = subjcompat.inaddr_any_override;
68068+
68069+ subj->crashes = subjcompat.crashes;
68070+ subj->expires = subjcompat.expires;
68071+
68072+ subj->parent_subject = compat_ptr(subjcompat.parent_subject);
68073+ subj->hash = compat_ptr(subjcompat.hash);
68074+ subj->prev = compat_ptr(subjcompat.prev);
68075+ subj->next = compat_ptr(subjcompat.next);
68076+
68077+ subj->obj_hash = compat_ptr(subjcompat.obj_hash);
68078+ subj->obj_hash_size = subjcompat.obj_hash_size;
68079+ subj->pax_flags = subjcompat.pax_flags;
68080+
68081+ return 0;
68082+}
68083+
68084+int copy_acl_role_label_compat(struct acl_role_label *role, const struct acl_role_label *userp)
68085+{
68086+ struct acl_role_label_compat rolecompat;
68087+
68088+ if (copy_from_user(&rolecompat, userp, sizeof(rolecompat)))
68089+ return -EFAULT;
68090+
68091+ role->rolename = compat_ptr(rolecompat.rolename);
68092+ role->uidgid = rolecompat.uidgid;
68093+ role->roletype = rolecompat.roletype;
68094+
68095+ role->auth_attempts = rolecompat.auth_attempts;
68096+ role->expires = rolecompat.expires;
68097+
68098+ role->root_label = compat_ptr(rolecompat.root_label);
68099+ role->hash = compat_ptr(rolecompat.hash);
68100+
68101+ role->prev = compat_ptr(rolecompat.prev);
68102+ role->next = compat_ptr(rolecompat.next);
68103+
68104+ role->transitions = compat_ptr(rolecompat.transitions);
68105+ role->allowed_ips = compat_ptr(rolecompat.allowed_ips);
68106+ role->domain_children = compat_ptr(rolecompat.domain_children);
68107+ role->domain_child_num = rolecompat.domain_child_num;
68108+
68109+ role->umask = rolecompat.umask;
68110+
68111+ role->subj_hash = compat_ptr(rolecompat.subj_hash);
68112+ role->subj_hash_size = rolecompat.subj_hash_size;
68113+
68114+ return 0;
68115+}
68116+
68117+int copy_role_allowed_ip_compat(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp)
68118+{
68119+ struct role_allowed_ip_compat roleip_compat;
68120+
68121+ if (copy_from_user(&roleip_compat, userp, sizeof(roleip_compat)))
68122+ return -EFAULT;
68123+
68124+ roleip->addr = roleip_compat.addr;
68125+ roleip->netmask = roleip_compat.netmask;
68126+
68127+ roleip->prev = compat_ptr(roleip_compat.prev);
68128+ roleip->next = compat_ptr(roleip_compat.next);
68129+
68130+ return 0;
68131+}
68132+
68133+int copy_role_transition_compat(struct role_transition *trans, const struct role_transition *userp)
68134+{
68135+ struct role_transition_compat trans_compat;
68136+
68137+ if (copy_from_user(&trans_compat, userp, sizeof(trans_compat)))
68138+ return -EFAULT;
68139+
68140+ trans->rolename = compat_ptr(trans_compat.rolename);
68141+
68142+ trans->prev = compat_ptr(trans_compat.prev);
68143+ trans->next = compat_ptr(trans_compat.next);
68144+
68145+ return 0;
68146+
68147+}
68148+
68149+int copy_gr_hash_struct_compat(struct gr_hash_struct *hash, const struct gr_hash_struct *userp)
68150+{
68151+ struct gr_hash_struct_compat hash_compat;
68152+
68153+ if (copy_from_user(&hash_compat, userp, sizeof(hash_compat)))
68154+ return -EFAULT;
68155+
68156+ hash->table = compat_ptr(hash_compat.table);
68157+ hash->nametable = compat_ptr(hash_compat.nametable);
68158+ hash->first = compat_ptr(hash_compat.first);
68159+
68160+ hash->table_size = hash_compat.table_size;
68161+ hash->used_size = hash_compat.used_size;
68162+
68163+ hash->type = hash_compat.type;
68164+
68165+ return 0;
68166+}
68167+
68168+int copy_pointer_from_array_compat(void *ptr, unsigned long idx, const void *userp)
68169+{
68170+ compat_uptr_t ptrcompat;
68171+
68172+ if (copy_from_user(&ptrcompat, userp + (idx * sizeof(ptrcompat)), sizeof(ptrcompat)))
68173+ return -EFAULT;
68174+
68175+ *(void **)ptr = compat_ptr(ptrcompat);
68176+
68177+ return 0;
68178+}
68179+
68180+int copy_acl_ip_label_compat(struct acl_ip_label *ip, const struct acl_ip_label *userp)
68181+{
68182+ struct acl_ip_label_compat ip_compat;
68183+
68184+ if (copy_from_user(&ip_compat, userp, sizeof(ip_compat)))
68185+ return -EFAULT;
68186+
68187+ ip->iface = compat_ptr(ip_compat.iface);
68188+ ip->addr = ip_compat.addr;
68189+ ip->netmask = ip_compat.netmask;
68190+ ip->low = ip_compat.low;
68191+ ip->high = ip_compat.high;
68192+ ip->mode = ip_compat.mode;
68193+ ip->type = ip_compat.type;
68194+
68195+ memcpy(&ip->proto, &ip_compat.proto, sizeof(ip->proto));
68196+
68197+ ip->prev = compat_ptr(ip_compat.prev);
68198+ ip->next = compat_ptr(ip_compat.next);
68199+
68200+ return 0;
68201+}
68202+
68203+int copy_sprole_pw_compat(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp)
68204+{
68205+ struct sprole_pw_compat pw_compat;
68206+
68207+ if (copy_from_user(&pw_compat, (const void *)userp + (sizeof(pw_compat) * idx), sizeof(pw_compat)))
68208+ return -EFAULT;
68209+
68210+ pw->rolename = compat_ptr(pw_compat.rolename);
68211+ memcpy(&pw->salt, pw_compat.salt, sizeof(pw->salt));
68212+ memcpy(&pw->sum, pw_compat.sum, sizeof(pw->sum));
68213+
68214+ return 0;
68215+}
68216+
68217+size_t get_gr_arg_wrapper_size_compat(void)
68218+{
68219+ return sizeof(struct gr_arg_wrapper_compat);
68220+}
68221+
68222diff --git a/grsecurity/gracl_fs.c b/grsecurity/gracl_fs.c
68223new file mode 100644
68224index 0000000..deb6f3b
68225--- /dev/null
68226+++ b/grsecurity/gracl_fs.c
68227@@ -0,0 +1,437 @@
68228+#include <linux/kernel.h>
68229+#include <linux/sched.h>
68230+#include <linux/types.h>
68231+#include <linux/fs.h>
68232+#include <linux/file.h>
68233+#include <linux/stat.h>
68234+#include <linux/grsecurity.h>
68235+#include <linux/grinternal.h>
68236+#include <linux/gracl.h>
68237+
68238+umode_t
68239+gr_acl_umask(void)
68240+{
68241+ if (unlikely(!gr_acl_is_enabled()))
68242+ return 0;
68243+
68244+ return current->role->umask;
68245+}
68246+
68247+__u32
68248+gr_acl_handle_hidden_file(const struct dentry * dentry,
68249+ const struct vfsmount * mnt)
68250+{
68251+ __u32 mode;
68252+
68253+ if (unlikely(!dentry->d_inode))
68254+ return GR_FIND;
68255+
68256+ mode =
68257+ gr_search_file(dentry, GR_FIND | GR_AUDIT_FIND | GR_SUPPRESS, mnt);
68258+
68259+ if (unlikely(mode & GR_FIND && mode & GR_AUDIT_FIND)) {
68260+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
68261+ return mode;
68262+ } else if (unlikely(!(mode & GR_FIND) && !(mode & GR_SUPPRESS))) {
68263+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
68264+ return 0;
68265+ } else if (unlikely(!(mode & GR_FIND)))
68266+ return 0;
68267+
68268+ return GR_FIND;
68269+}
68270+
68271+__u32
68272+gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
68273+ int acc_mode)
68274+{
68275+ __u32 reqmode = GR_FIND;
68276+ __u32 mode;
68277+
68278+ if (unlikely(!dentry->d_inode))
68279+ return reqmode;
68280+
68281+ if (acc_mode & MAY_APPEND)
68282+ reqmode |= GR_APPEND;
68283+ else if (acc_mode & MAY_WRITE)
68284+ reqmode |= GR_WRITE;
68285+ if ((acc_mode & MAY_READ) && !S_ISDIR(dentry->d_inode->i_mode))
68286+ reqmode |= GR_READ;
68287+
68288+ mode =
68289+ gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
68290+ mnt);
68291+
68292+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
68293+ gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
68294+ reqmode & GR_READ ? " reading" : "",
68295+ reqmode & GR_WRITE ? " writing" : reqmode &
68296+ GR_APPEND ? " appending" : "");
68297+ return reqmode;
68298+ } else
68299+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
68300+ {
68301+ gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
68302+ reqmode & GR_READ ? " reading" : "",
68303+ reqmode & GR_WRITE ? " writing" : reqmode &
68304+ GR_APPEND ? " appending" : "");
68305+ return 0;
68306+ } else if (unlikely((mode & reqmode) != reqmode))
68307+ return 0;
68308+
68309+ return reqmode;
68310+}
68311+
68312+__u32
68313+gr_acl_handle_creat(const struct dentry * dentry,
68314+ const struct dentry * p_dentry,
68315+ const struct vfsmount * p_mnt, int open_flags, int acc_mode,
68316+ const int imode)
68317+{
68318+ __u32 reqmode = GR_WRITE | GR_CREATE;
68319+ __u32 mode;
68320+
68321+ if (acc_mode & MAY_APPEND)
68322+ reqmode |= GR_APPEND;
68323+ // if a directory was required or the directory already exists, then
68324+ // don't count this open as a read
68325+ if ((acc_mode & MAY_READ) &&
68326+ !((open_flags & O_DIRECTORY) || (dentry->d_inode && S_ISDIR(dentry->d_inode->i_mode))))
68327+ reqmode |= GR_READ;
68328+ if ((open_flags & O_CREAT) &&
68329+ ((imode & S_ISUID) || ((imode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
68330+ reqmode |= GR_SETID;
68331+
68332+ mode =
68333+ gr_check_create(dentry, p_dentry, p_mnt,
68334+ reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
68335+
68336+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
68337+ gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
68338+ reqmode & GR_READ ? " reading" : "",
68339+ reqmode & GR_WRITE ? " writing" : reqmode &
68340+ GR_APPEND ? " appending" : "");
68341+ return reqmode;
68342+ } else
68343+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
68344+ {
68345+ gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
68346+ reqmode & GR_READ ? " reading" : "",
68347+ reqmode & GR_WRITE ? " writing" : reqmode &
68348+ GR_APPEND ? " appending" : "");
68349+ return 0;
68350+ } else if (unlikely((mode & reqmode) != reqmode))
68351+ return 0;
68352+
68353+ return reqmode;
68354+}
68355+
68356+__u32
68357+gr_acl_handle_access(const struct dentry * dentry, const struct vfsmount * mnt,
68358+ const int fmode)
68359+{
68360+ __u32 mode, reqmode = GR_FIND;
68361+
68362+ if ((fmode & S_IXOTH) && !S_ISDIR(dentry->d_inode->i_mode))
68363+ reqmode |= GR_EXEC;
68364+ if (fmode & S_IWOTH)
68365+ reqmode |= GR_WRITE;
68366+ if (fmode & S_IROTH)
68367+ reqmode |= GR_READ;
68368+
68369+ mode =
68370+ gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
68371+ mnt);
68372+
68373+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
68374+ gr_log_fs_rbac_mode3(GR_DO_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
68375+ reqmode & GR_READ ? " reading" : "",
68376+ reqmode & GR_WRITE ? " writing" : "",
68377+ reqmode & GR_EXEC ? " executing" : "");
68378+ return reqmode;
68379+ } else
68380+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
68381+ {
68382+ gr_log_fs_rbac_mode3(GR_DONT_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
68383+ reqmode & GR_READ ? " reading" : "",
68384+ reqmode & GR_WRITE ? " writing" : "",
68385+ reqmode & GR_EXEC ? " executing" : "");
68386+ return 0;
68387+ } else if (unlikely((mode & reqmode) != reqmode))
68388+ return 0;
68389+
68390+ return reqmode;
68391+}
68392+
68393+static __u32 generic_fs_handler(const struct dentry *dentry, const struct vfsmount *mnt, __u32 reqmode, const char *fmt)
68394+{
68395+ __u32 mode;
68396+
68397+ mode = gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS, mnt);
68398+
68399+ if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
68400+ gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, dentry, mnt);
68401+ return mode;
68402+ } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
68403+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, dentry, mnt);
68404+ return 0;
68405+ } else if (unlikely((mode & (reqmode)) != (reqmode)))
68406+ return 0;
68407+
68408+ return (reqmode);
68409+}
68410+
68411+__u32
68412+gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
68413+{
68414+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_RMDIR_ACL_MSG);
68415+}
68416+
68417+__u32
68418+gr_acl_handle_unlink(const struct dentry *dentry, const struct vfsmount *mnt)
68419+{
68420+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_UNLINK_ACL_MSG);
68421+}
68422+
68423+__u32
68424+gr_acl_handle_truncate(const struct dentry *dentry, const struct vfsmount *mnt)
68425+{
68426+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_TRUNCATE_ACL_MSG);
68427+}
68428+
68429+__u32
68430+gr_acl_handle_utime(const struct dentry *dentry, const struct vfsmount *mnt)
68431+{
68432+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_ATIME_ACL_MSG);
68433+}
68434+
68435+__u32
68436+gr_acl_handle_chmod(const struct dentry *dentry, const struct vfsmount *mnt,
68437+ umode_t *modeptr)
68438+{
68439+ umode_t mode;
68440+
68441+ *modeptr &= ~gr_acl_umask();
68442+ mode = *modeptr;
68443+
68444+ if (unlikely(dentry->d_inode && S_ISSOCK(dentry->d_inode->i_mode)))
68445+ return 1;
68446+
68447+ if (unlikely(dentry->d_inode && !S_ISDIR(dentry->d_inode->i_mode) &&
68448+ ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))) {
68449+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_SETID,
68450+ GR_CHMOD_ACL_MSG);
68451+ } else {
68452+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHMOD_ACL_MSG);
68453+ }
68454+}
68455+
68456+__u32
68457+gr_acl_handle_chown(const struct dentry *dentry, const struct vfsmount *mnt)
68458+{
68459+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHOWN_ACL_MSG);
68460+}
68461+
68462+__u32
68463+gr_acl_handle_setxattr(const struct dentry *dentry, const struct vfsmount *mnt)
68464+{
68465+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_SETXATTR_ACL_MSG);
68466+}
68467+
68468+__u32
68469+gr_acl_handle_removexattr(const struct dentry *dentry, const struct vfsmount *mnt)
68470+{
68471+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_REMOVEXATTR_ACL_MSG);
68472+}
68473+
68474+__u32
68475+gr_acl_handle_execve(const struct dentry *dentry, const struct vfsmount *mnt)
68476+{
68477+ return generic_fs_handler(dentry, mnt, GR_EXEC, GR_EXEC_ACL_MSG);
68478+}
68479+
68480+__u32
68481+gr_acl_handle_unix(const struct dentry *dentry, const struct vfsmount *mnt)
68482+{
68483+ return generic_fs_handler(dentry, mnt, GR_READ | GR_WRITE,
68484+ GR_UNIXCONNECT_ACL_MSG);
68485+}
68486+
68487+/* hardlinks require at minimum create and link permission,
68488+ any additional privilege required is based on the
68489+ privilege of the file being linked to
68490+*/
68491+__u32
68492+gr_acl_handle_link(const struct dentry * new_dentry,
68493+ const struct dentry * parent_dentry,
68494+ const struct vfsmount * parent_mnt,
68495+ const struct dentry * old_dentry,
68496+ const struct vfsmount * old_mnt, const struct filename *to)
68497+{
68498+ __u32 mode;
68499+ __u32 needmode = GR_CREATE | GR_LINK;
68500+ __u32 needaudit = GR_AUDIT_CREATE | GR_AUDIT_LINK;
68501+
68502+ mode =
68503+ gr_check_link(new_dentry, parent_dentry, parent_mnt, old_dentry,
68504+ old_mnt);
68505+
68506+ if (unlikely(((mode & needmode) == needmode) && (mode & needaudit))) {
68507+ gr_log_fs_rbac_str(GR_DO_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to->name);
68508+ return mode;
68509+ } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
68510+ gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to->name);
68511+ return 0;
68512+ } else if (unlikely((mode & needmode) != needmode))
68513+ return 0;
68514+
68515+ return 1;
68516+}
68517+
68518+__u32
68519+gr_acl_handle_symlink(const struct dentry * new_dentry,
68520+ const struct dentry * parent_dentry,
68521+ const struct vfsmount * parent_mnt, const struct filename *from)
68522+{
68523+ __u32 needmode = GR_WRITE | GR_CREATE;
68524+ __u32 mode;
68525+
68526+ mode =
68527+ gr_check_create(new_dentry, parent_dentry, parent_mnt,
68528+ GR_CREATE | GR_AUDIT_CREATE |
68529+ GR_WRITE | GR_AUDIT_WRITE | GR_SUPPRESS);
68530+
68531+ if (unlikely(mode & GR_WRITE && mode & GR_AUDITS)) {
68532+ gr_log_fs_str_rbac(GR_DO_AUDIT, GR_SYMLINK_ACL_MSG, from->name, new_dentry, parent_mnt);
68533+ return mode;
68534+ } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
68535+ gr_log_fs_str_rbac(GR_DONT_AUDIT, GR_SYMLINK_ACL_MSG, from->name, new_dentry, parent_mnt);
68536+ return 0;
68537+ } else if (unlikely((mode & needmode) != needmode))
68538+ return 0;
68539+
68540+ return (GR_WRITE | GR_CREATE);
68541+}
68542+
68543+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)
68544+{
68545+ __u32 mode;
68546+
68547+ mode = gr_check_create(new_dentry, parent_dentry, parent_mnt, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
68548+
68549+ if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
68550+ gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, new_dentry, parent_mnt);
68551+ return mode;
68552+ } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
68553+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, new_dentry, parent_mnt);
68554+ return 0;
68555+ } else if (unlikely((mode & (reqmode)) != (reqmode)))
68556+ return 0;
68557+
68558+ return (reqmode);
68559+}
68560+
68561+__u32
68562+gr_acl_handle_mknod(const struct dentry * new_dentry,
68563+ const struct dentry * parent_dentry,
68564+ const struct vfsmount * parent_mnt,
68565+ const int mode)
68566+{
68567+ __u32 reqmode = GR_WRITE | GR_CREATE;
68568+ if (unlikely((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
68569+ reqmode |= GR_SETID;
68570+
68571+ return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
68572+ reqmode, GR_MKNOD_ACL_MSG);
68573+}
68574+
68575+__u32
68576+gr_acl_handle_mkdir(const struct dentry *new_dentry,
68577+ const struct dentry *parent_dentry,
68578+ const struct vfsmount *parent_mnt)
68579+{
68580+ return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
68581+ GR_WRITE | GR_CREATE, GR_MKDIR_ACL_MSG);
68582+}
68583+
68584+#define RENAME_CHECK_SUCCESS(old, new) \
68585+ (((old & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)) && \
68586+ ((new & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)))
68587+
68588+int
68589+gr_acl_handle_rename(struct dentry *new_dentry,
68590+ struct dentry *parent_dentry,
68591+ const struct vfsmount *parent_mnt,
68592+ struct dentry *old_dentry,
68593+ struct inode *old_parent_inode,
68594+ struct vfsmount *old_mnt, const struct filename *newname)
68595+{
68596+ __u32 comp1, comp2;
68597+ int error = 0;
68598+
68599+ if (unlikely(!gr_acl_is_enabled()))
68600+ return 0;
68601+
68602+ if (!new_dentry->d_inode) {
68603+ comp1 = gr_check_create(new_dentry, parent_dentry, parent_mnt,
68604+ GR_READ | GR_WRITE | GR_CREATE | GR_AUDIT_READ |
68605+ GR_AUDIT_WRITE | GR_AUDIT_CREATE | GR_SUPPRESS);
68606+ comp2 = gr_search_file(old_dentry, GR_READ | GR_WRITE |
68607+ GR_DELETE | GR_AUDIT_DELETE |
68608+ GR_AUDIT_READ | GR_AUDIT_WRITE |
68609+ GR_SUPPRESS, old_mnt);
68610+ } else {
68611+ comp1 = gr_search_file(new_dentry, GR_READ | GR_WRITE |
68612+ GR_CREATE | GR_DELETE |
68613+ GR_AUDIT_CREATE | GR_AUDIT_DELETE |
68614+ GR_AUDIT_READ | GR_AUDIT_WRITE |
68615+ GR_SUPPRESS, parent_mnt);
68616+ comp2 =
68617+ gr_search_file(old_dentry,
68618+ GR_READ | GR_WRITE | GR_AUDIT_READ |
68619+ GR_DELETE | GR_AUDIT_DELETE |
68620+ GR_AUDIT_WRITE | GR_SUPPRESS, old_mnt);
68621+ }
68622+
68623+ if (RENAME_CHECK_SUCCESS(comp1, comp2) &&
68624+ ((comp1 & GR_AUDITS) || (comp2 & GR_AUDITS)))
68625+ gr_log_fs_rbac_str(GR_DO_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname->name);
68626+ else if (!RENAME_CHECK_SUCCESS(comp1, comp2) && !(comp1 & GR_SUPPRESS)
68627+ && !(comp2 & GR_SUPPRESS)) {
68628+ gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname->name);
68629+ error = -EACCES;
68630+ } else if (unlikely(!RENAME_CHECK_SUCCESS(comp1, comp2)))
68631+ error = -EACCES;
68632+
68633+ return error;
68634+}
68635+
68636+void
68637+gr_acl_handle_exit(void)
68638+{
68639+ u16 id;
68640+ char *rolename;
68641+
68642+ if (unlikely(current->acl_sp_role && gr_acl_is_enabled() &&
68643+ !(current->role->roletype & GR_ROLE_PERSIST))) {
68644+ id = current->acl_role_id;
68645+ rolename = current->role->rolename;
68646+ gr_set_acls(1);
68647+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLEL_ACL_MSG, rolename, id);
68648+ }
68649+
68650+ gr_put_exec_file(current);
68651+ return;
68652+}
68653+
68654+int
68655+gr_acl_handle_procpidmem(const struct task_struct *task)
68656+{
68657+ if (unlikely(!gr_acl_is_enabled()))
68658+ return 0;
68659+
68660+ if (task != current && task->acl->mode & GR_PROTPROCFD)
68661+ return -EACCES;
68662+
68663+ return 0;
68664+}
68665diff --git a/grsecurity/gracl_ip.c b/grsecurity/gracl_ip.c
68666new file mode 100644
68667index 0000000..f056b81
68668--- /dev/null
68669+++ b/grsecurity/gracl_ip.c
68670@@ -0,0 +1,386 @@
68671+#include <linux/kernel.h>
68672+#include <asm/uaccess.h>
68673+#include <asm/errno.h>
68674+#include <net/sock.h>
68675+#include <linux/file.h>
68676+#include <linux/fs.h>
68677+#include <linux/net.h>
68678+#include <linux/in.h>
68679+#include <linux/skbuff.h>
68680+#include <linux/ip.h>
68681+#include <linux/udp.h>
68682+#include <linux/types.h>
68683+#include <linux/sched.h>
68684+#include <linux/netdevice.h>
68685+#include <linux/inetdevice.h>
68686+#include <linux/gracl.h>
68687+#include <linux/grsecurity.h>
68688+#include <linux/grinternal.h>
68689+
68690+#define GR_BIND 0x01
68691+#define GR_CONNECT 0x02
68692+#define GR_INVERT 0x04
68693+#define GR_BINDOVERRIDE 0x08
68694+#define GR_CONNECTOVERRIDE 0x10
68695+#define GR_SOCK_FAMILY 0x20
68696+
68697+static const char * gr_protocols[IPPROTO_MAX] = {
68698+ "ip", "icmp", "igmp", "ggp", "ipencap", "st", "tcp", "cbt",
68699+ "egp", "igp", "bbn-rcc", "nvp", "pup", "argus", "emcon", "xnet",
68700+ "chaos", "udp", "mux", "dcn", "hmp", "prm", "xns-idp", "trunk-1",
68701+ "trunk-2", "leaf-1", "leaf-2", "rdp", "irtp", "iso-tp4", "netblt", "mfe-nsp",
68702+ "merit-inp", "sep", "3pc", "idpr", "xtp", "ddp", "idpr-cmtp", "tp++",
68703+ "il", "ipv6", "sdrp", "ipv6-route", "ipv6-frag", "idrp", "rsvp", "gre",
68704+ "mhrp", "bna", "ipv6-crypt", "ipv6-auth", "i-nlsp", "swipe", "narp", "mobile",
68705+ "tlsp", "skip", "ipv6-icmp", "ipv6-nonxt", "ipv6-opts", "unknown:61", "cftp", "unknown:63",
68706+ "sat-expak", "kryptolan", "rvd", "ippc", "unknown:68", "sat-mon", "visa", "ipcv",
68707+ "cpnx", "cphb", "wsn", "pvp", "br-sat-mon", "sun-nd", "wb-mon", "wb-expak",
68708+ "iso-ip", "vmtp", "secure-vmtp", "vines", "ttp", "nfsnet-igp", "dgp", "tcf",
68709+ "eigrp", "ospf", "sprite-rpc", "larp", "mtp", "ax.25", "ipip", "micp",
68710+ "scc-sp", "etherip", "encap", "unknown:99", "gmtp", "ifmp", "pnni", "pim",
68711+ "aris", "scps", "qnx", "a/n", "ipcomp", "snp", "compaq-peer", "ipx-in-ip",
68712+ "vrrp", "pgm", "unknown:114", "l2tp", "ddx", "iatp", "stp", "srp",
68713+ "uti", "smp", "sm", "ptp", "isis", "fire", "crtp", "crdup",
68714+ "sscopmce", "iplt", "sps", "pipe", "sctp", "fc", "unkown:134", "unknown:135",
68715+ "unknown:136", "unknown:137", "unknown:138", "unknown:139", "unknown:140", "unknown:141", "unknown:142", "unknown:143",
68716+ "unknown:144", "unknown:145", "unknown:146", "unknown:147", "unknown:148", "unknown:149", "unknown:150", "unknown:151",
68717+ "unknown:152", "unknown:153", "unknown:154", "unknown:155", "unknown:156", "unknown:157", "unknown:158", "unknown:159",
68718+ "unknown:160", "unknown:161", "unknown:162", "unknown:163", "unknown:164", "unknown:165", "unknown:166", "unknown:167",
68719+ "unknown:168", "unknown:169", "unknown:170", "unknown:171", "unknown:172", "unknown:173", "unknown:174", "unknown:175",
68720+ "unknown:176", "unknown:177", "unknown:178", "unknown:179", "unknown:180", "unknown:181", "unknown:182", "unknown:183",
68721+ "unknown:184", "unknown:185", "unknown:186", "unknown:187", "unknown:188", "unknown:189", "unknown:190", "unknown:191",
68722+ "unknown:192", "unknown:193", "unknown:194", "unknown:195", "unknown:196", "unknown:197", "unknown:198", "unknown:199",
68723+ "unknown:200", "unknown:201", "unknown:202", "unknown:203", "unknown:204", "unknown:205", "unknown:206", "unknown:207",
68724+ "unknown:208", "unknown:209", "unknown:210", "unknown:211", "unknown:212", "unknown:213", "unknown:214", "unknown:215",
68725+ "unknown:216", "unknown:217", "unknown:218", "unknown:219", "unknown:220", "unknown:221", "unknown:222", "unknown:223",
68726+ "unknown:224", "unknown:225", "unknown:226", "unknown:227", "unknown:228", "unknown:229", "unknown:230", "unknown:231",
68727+ "unknown:232", "unknown:233", "unknown:234", "unknown:235", "unknown:236", "unknown:237", "unknown:238", "unknown:239",
68728+ "unknown:240", "unknown:241", "unknown:242", "unknown:243", "unknown:244", "unknown:245", "unknown:246", "unknown:247",
68729+ "unknown:248", "unknown:249", "unknown:250", "unknown:251", "unknown:252", "unknown:253", "unknown:254", "unknown:255",
68730+ };
68731+
68732+static const char * gr_socktypes[SOCK_MAX] = {
68733+ "unknown:0", "stream", "dgram", "raw", "rdm", "seqpacket", "unknown:6",
68734+ "unknown:7", "unknown:8", "unknown:9", "packet"
68735+ };
68736+
68737+static const char * gr_sockfamilies[AF_MAX+1] = {
68738+ "unspec", "unix", "inet", "ax25", "ipx", "appletalk", "netrom", "bridge", "atmpvc", "x25",
68739+ "inet6", "rose", "decnet", "netbeui", "security", "key", "netlink", "packet", "ash",
68740+ "econet", "atmsvc", "rds", "sna", "irda", "ppox", "wanpipe", "llc", "fam_27", "fam_28",
68741+ "tipc", "bluetooth", "iucv", "rxrpc", "isdn", "phonet", "ieee802154", "ciaf"
68742+ };
68743+
68744+const char *
68745+gr_proto_to_name(unsigned char proto)
68746+{
68747+ return gr_protocols[proto];
68748+}
68749+
68750+const char *
68751+gr_socktype_to_name(unsigned char type)
68752+{
68753+ return gr_socktypes[type];
68754+}
68755+
68756+const char *
68757+gr_sockfamily_to_name(unsigned char family)
68758+{
68759+ return gr_sockfamilies[family];
68760+}
68761+
68762+extern const struct net_proto_family __rcu *net_families[NPROTO] __read_mostly;
68763+
68764+int
68765+gr_search_socket(const int domain, const int type, const int protocol)
68766+{
68767+ struct acl_subject_label *curr;
68768+ const struct cred *cred = current_cred();
68769+
68770+ if (unlikely(!gr_acl_is_enabled()))
68771+ goto exit;
68772+
68773+ if ((domain < 0) || (type < 0) || (protocol < 0) ||
68774+ (domain >= AF_MAX) || (type >= SOCK_MAX) || (protocol >= IPPROTO_MAX))
68775+ goto exit; // let the kernel handle it
68776+
68777+ curr = current->acl;
68778+
68779+ if (curr->sock_families[domain / 32] & (1U << (domain % 32))) {
68780+ /* the family is allowed, if this is PF_INET allow it only if
68781+ the extra sock type/protocol checks pass */
68782+ if (domain == PF_INET)
68783+ goto inet_check;
68784+ goto exit;
68785+ } else {
68786+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
68787+ __u32 fakeip = 0;
68788+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
68789+ current->role->roletype, GR_GLOBAL_UID(cred->uid),
68790+ GR_GLOBAL_GID(cred->gid), current->exec_file ?
68791+ gr_to_filename(current->exec_file->f_path.dentry,
68792+ current->exec_file->f_path.mnt) :
68793+ curr->filename, curr->filename,
68794+ &fakeip, domain, 0, 0, GR_SOCK_FAMILY,
68795+ &current->signal->saved_ip);
68796+ goto exit;
68797+ }
68798+ goto exit_fail;
68799+ }
68800+
68801+inet_check:
68802+ /* the rest of this checking is for IPv4 only */
68803+ if (!curr->ips)
68804+ goto exit;
68805+
68806+ if ((curr->ip_type & (1U << type)) &&
68807+ (curr->ip_proto[protocol / 32] & (1U << (protocol % 32))))
68808+ goto exit;
68809+
68810+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
68811+ /* we don't place acls on raw sockets , and sometimes
68812+ dgram/ip sockets are opened for ioctl and not
68813+ bind/connect, so we'll fake a bind learn log */
68814+ if (type == SOCK_RAW || type == SOCK_PACKET) {
68815+ __u32 fakeip = 0;
68816+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
68817+ current->role->roletype, GR_GLOBAL_UID(cred->uid),
68818+ GR_GLOBAL_GID(cred->gid), current->exec_file ?
68819+ gr_to_filename(current->exec_file->f_path.dentry,
68820+ current->exec_file->f_path.mnt) :
68821+ curr->filename, curr->filename,
68822+ &fakeip, 0, type,
68823+ protocol, GR_CONNECT, &current->signal->saved_ip);
68824+ } else if ((type == SOCK_DGRAM) && (protocol == IPPROTO_IP)) {
68825+ __u32 fakeip = 0;
68826+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
68827+ current->role->roletype, GR_GLOBAL_UID(cred->uid),
68828+ GR_GLOBAL_GID(cred->gid), current->exec_file ?
68829+ gr_to_filename(current->exec_file->f_path.dentry,
68830+ current->exec_file->f_path.mnt) :
68831+ curr->filename, curr->filename,
68832+ &fakeip, 0, type,
68833+ protocol, GR_BIND, &current->signal->saved_ip);
68834+ }
68835+ /* we'll log when they use connect or bind */
68836+ goto exit;
68837+ }
68838+
68839+exit_fail:
68840+ if (domain == PF_INET)
68841+ gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(domain),
68842+ gr_socktype_to_name(type), gr_proto_to_name(protocol));
68843+ else if (rcu_access_pointer(net_families[domain]) != NULL)
68844+ gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(domain),
68845+ gr_socktype_to_name(type), protocol);
68846+
68847+ return 0;
68848+exit:
68849+ return 1;
68850+}
68851+
68852+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)
68853+{
68854+ if ((ip->mode & mode) &&
68855+ (ip_port >= ip->low) &&
68856+ (ip_port <= ip->high) &&
68857+ ((ntohl(ip_addr) & our_netmask) ==
68858+ (ntohl(our_addr) & our_netmask))
68859+ && (ip->proto[protocol / 32] & (1U << (protocol % 32)))
68860+ && (ip->type & (1U << type))) {
68861+ if (ip->mode & GR_INVERT)
68862+ return 2; // specifically denied
68863+ else
68864+ return 1; // allowed
68865+ }
68866+
68867+ return 0; // not specifically allowed, may continue parsing
68868+}
68869+
68870+static int
68871+gr_search_connectbind(const int full_mode, struct sock *sk,
68872+ struct sockaddr_in *addr, const int type)
68873+{
68874+ char iface[IFNAMSIZ] = {0};
68875+ struct acl_subject_label *curr;
68876+ struct acl_ip_label *ip;
68877+ struct inet_sock *isk;
68878+ struct net_device *dev;
68879+ struct in_device *idev;
68880+ unsigned long i;
68881+ int ret;
68882+ int mode = full_mode & (GR_BIND | GR_CONNECT);
68883+ __u32 ip_addr = 0;
68884+ __u32 our_addr;
68885+ __u32 our_netmask;
68886+ char *p;
68887+ __u16 ip_port = 0;
68888+ const struct cred *cred = current_cred();
68889+
68890+ if (unlikely(!gr_acl_is_enabled() || sk->sk_family != PF_INET))
68891+ return 0;
68892+
68893+ curr = current->acl;
68894+ isk = inet_sk(sk);
68895+
68896+ /* INADDR_ANY overriding for binds, inaddr_any_override is already in network order */
68897+ if ((full_mode & GR_BINDOVERRIDE) && addr->sin_addr.s_addr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0)
68898+ addr->sin_addr.s_addr = curr->inaddr_any_override;
68899+ if ((full_mode & GR_CONNECT) && isk->inet_saddr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0) {
68900+ struct sockaddr_in saddr;
68901+ int err;
68902+
68903+ saddr.sin_family = AF_INET;
68904+ saddr.sin_addr.s_addr = curr->inaddr_any_override;
68905+ saddr.sin_port = isk->inet_sport;
68906+
68907+ err = security_socket_bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
68908+ if (err)
68909+ return err;
68910+
68911+ err = sk->sk_socket->ops->bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
68912+ if (err)
68913+ return err;
68914+ }
68915+
68916+ if (!curr->ips)
68917+ return 0;
68918+
68919+ ip_addr = addr->sin_addr.s_addr;
68920+ ip_port = ntohs(addr->sin_port);
68921+
68922+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
68923+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
68924+ current->role->roletype, GR_GLOBAL_UID(cred->uid),
68925+ GR_GLOBAL_GID(cred->gid), current->exec_file ?
68926+ gr_to_filename(current->exec_file->f_path.dentry,
68927+ current->exec_file->f_path.mnt) :
68928+ curr->filename, curr->filename,
68929+ &ip_addr, ip_port, type,
68930+ sk->sk_protocol, mode, &current->signal->saved_ip);
68931+ return 0;
68932+ }
68933+
68934+ for (i = 0; i < curr->ip_num; i++) {
68935+ ip = *(curr->ips + i);
68936+ if (ip->iface != NULL) {
68937+ strncpy(iface, ip->iface, IFNAMSIZ - 1);
68938+ p = strchr(iface, ':');
68939+ if (p != NULL)
68940+ *p = '\0';
68941+ dev = dev_get_by_name(sock_net(sk), iface);
68942+ if (dev == NULL)
68943+ continue;
68944+ idev = in_dev_get(dev);
68945+ if (idev == NULL) {
68946+ dev_put(dev);
68947+ continue;
68948+ }
68949+ rcu_read_lock();
68950+ for_ifa(idev) {
68951+ if (!strcmp(ip->iface, ifa->ifa_label)) {
68952+ our_addr = ifa->ifa_address;
68953+ our_netmask = 0xffffffff;
68954+ ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
68955+ if (ret == 1) {
68956+ rcu_read_unlock();
68957+ in_dev_put(idev);
68958+ dev_put(dev);
68959+ return 0;
68960+ } else if (ret == 2) {
68961+ rcu_read_unlock();
68962+ in_dev_put(idev);
68963+ dev_put(dev);
68964+ goto denied;
68965+ }
68966+ }
68967+ } endfor_ifa(idev);
68968+ rcu_read_unlock();
68969+ in_dev_put(idev);
68970+ dev_put(dev);
68971+ } else {
68972+ our_addr = ip->addr;
68973+ our_netmask = ip->netmask;
68974+ ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
68975+ if (ret == 1)
68976+ return 0;
68977+ else if (ret == 2)
68978+ goto denied;
68979+ }
68980+ }
68981+
68982+denied:
68983+ if (mode == GR_BIND)
68984+ 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));
68985+ else if (mode == GR_CONNECT)
68986+ 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));
68987+
68988+ return -EACCES;
68989+}
68990+
68991+int
68992+gr_search_connect(struct socket *sock, struct sockaddr_in *addr)
68993+{
68994+ /* always allow disconnection of dgram sockets with connect */
68995+ if (addr->sin_family == AF_UNSPEC)
68996+ return 0;
68997+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sock->sk, addr, sock->type);
68998+}
68999+
69000+int
69001+gr_search_bind(struct socket *sock, struct sockaddr_in *addr)
69002+{
69003+ return gr_search_connectbind(GR_BIND | GR_BINDOVERRIDE, sock->sk, addr, sock->type);
69004+}
69005+
69006+int gr_search_listen(struct socket *sock)
69007+{
69008+ struct sock *sk = sock->sk;
69009+ struct sockaddr_in addr;
69010+
69011+ addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
69012+ addr.sin_port = inet_sk(sk)->inet_sport;
69013+
69014+ return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
69015+}
69016+
69017+int gr_search_accept(struct socket *sock)
69018+{
69019+ struct sock *sk = sock->sk;
69020+ struct sockaddr_in addr;
69021+
69022+ addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
69023+ addr.sin_port = inet_sk(sk)->inet_sport;
69024+
69025+ return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
69026+}
69027+
69028+int
69029+gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr)
69030+{
69031+ if (addr)
69032+ return gr_search_connectbind(GR_CONNECT, sk, addr, SOCK_DGRAM);
69033+ else {
69034+ struct sockaddr_in sin;
69035+ const struct inet_sock *inet = inet_sk(sk);
69036+
69037+ sin.sin_addr.s_addr = inet->inet_daddr;
69038+ sin.sin_port = inet->inet_dport;
69039+
69040+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
69041+ }
69042+}
69043+
69044+int
69045+gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb)
69046+{
69047+ struct sockaddr_in sin;
69048+
69049+ if (unlikely(skb->len < sizeof (struct udphdr)))
69050+ return 0; // skip this packet
69051+
69052+ sin.sin_addr.s_addr = ip_hdr(skb)->saddr;
69053+ sin.sin_port = udp_hdr(skb)->source;
69054+
69055+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
69056+}
69057diff --git a/grsecurity/gracl_learn.c b/grsecurity/gracl_learn.c
69058new file mode 100644
69059index 0000000..25f54ef
69060--- /dev/null
69061+++ b/grsecurity/gracl_learn.c
69062@@ -0,0 +1,207 @@
69063+#include <linux/kernel.h>
69064+#include <linux/mm.h>
69065+#include <linux/sched.h>
69066+#include <linux/poll.h>
69067+#include <linux/string.h>
69068+#include <linux/file.h>
69069+#include <linux/types.h>
69070+#include <linux/vmalloc.h>
69071+#include <linux/grinternal.h>
69072+
69073+extern ssize_t write_grsec_handler(struct file * file, const char __user * buf,
69074+ size_t count, loff_t *ppos);
69075+extern int gr_acl_is_enabled(void);
69076+
69077+static DECLARE_WAIT_QUEUE_HEAD(learn_wait);
69078+static int gr_learn_attached;
69079+
69080+/* use a 512k buffer */
69081+#define LEARN_BUFFER_SIZE (512 * 1024)
69082+
69083+static DEFINE_SPINLOCK(gr_learn_lock);
69084+static DEFINE_MUTEX(gr_learn_user_mutex);
69085+
69086+/* we need to maintain two buffers, so that the kernel context of grlearn
69087+ uses a semaphore around the userspace copying, and the other kernel contexts
69088+ use a spinlock when copying into the buffer, since they cannot sleep
69089+*/
69090+static char *learn_buffer;
69091+static char *learn_buffer_user;
69092+static int learn_buffer_len;
69093+static int learn_buffer_user_len;
69094+
69095+static ssize_t
69096+read_learn(struct file *file, char __user * buf, size_t count, loff_t * ppos)
69097+{
69098+ DECLARE_WAITQUEUE(wait, current);
69099+ ssize_t retval = 0;
69100+
69101+ add_wait_queue(&learn_wait, &wait);
69102+ set_current_state(TASK_INTERRUPTIBLE);
69103+ do {
69104+ mutex_lock(&gr_learn_user_mutex);
69105+ spin_lock(&gr_learn_lock);
69106+ if (learn_buffer_len)
69107+ break;
69108+ spin_unlock(&gr_learn_lock);
69109+ mutex_unlock(&gr_learn_user_mutex);
69110+ if (file->f_flags & O_NONBLOCK) {
69111+ retval = -EAGAIN;
69112+ goto out;
69113+ }
69114+ if (signal_pending(current)) {
69115+ retval = -ERESTARTSYS;
69116+ goto out;
69117+ }
69118+
69119+ schedule();
69120+ } while (1);
69121+
69122+ memcpy(learn_buffer_user, learn_buffer, learn_buffer_len);
69123+ learn_buffer_user_len = learn_buffer_len;
69124+ retval = learn_buffer_len;
69125+ learn_buffer_len = 0;
69126+
69127+ spin_unlock(&gr_learn_lock);
69128+
69129+ if (copy_to_user(buf, learn_buffer_user, learn_buffer_user_len))
69130+ retval = -EFAULT;
69131+
69132+ mutex_unlock(&gr_learn_user_mutex);
69133+out:
69134+ set_current_state(TASK_RUNNING);
69135+ remove_wait_queue(&learn_wait, &wait);
69136+ return retval;
69137+}
69138+
69139+static unsigned int
69140+poll_learn(struct file * file, poll_table * wait)
69141+{
69142+ poll_wait(file, &learn_wait, wait);
69143+
69144+ if (learn_buffer_len)
69145+ return (POLLIN | POLLRDNORM);
69146+
69147+ return 0;
69148+}
69149+
69150+void
69151+gr_clear_learn_entries(void)
69152+{
69153+ char *tmp;
69154+
69155+ mutex_lock(&gr_learn_user_mutex);
69156+ spin_lock(&gr_learn_lock);
69157+ tmp = learn_buffer;
69158+ learn_buffer = NULL;
69159+ spin_unlock(&gr_learn_lock);
69160+ if (tmp)
69161+ vfree(tmp);
69162+ if (learn_buffer_user != NULL) {
69163+ vfree(learn_buffer_user);
69164+ learn_buffer_user = NULL;
69165+ }
69166+ learn_buffer_len = 0;
69167+ mutex_unlock(&gr_learn_user_mutex);
69168+
69169+ return;
69170+}
69171+
69172+void
69173+gr_add_learn_entry(const char *fmt, ...)
69174+{
69175+ va_list args;
69176+ unsigned int len;
69177+
69178+ if (!gr_learn_attached)
69179+ return;
69180+
69181+ spin_lock(&gr_learn_lock);
69182+
69183+ /* leave a gap at the end so we know when it's "full" but don't have to
69184+ compute the exact length of the string we're trying to append
69185+ */
69186+ if (learn_buffer_len > LEARN_BUFFER_SIZE - 16384) {
69187+ spin_unlock(&gr_learn_lock);
69188+ wake_up_interruptible(&learn_wait);
69189+ return;
69190+ }
69191+ if (learn_buffer == NULL) {
69192+ spin_unlock(&gr_learn_lock);
69193+ return;
69194+ }
69195+
69196+ va_start(args, fmt);
69197+ len = vsnprintf(learn_buffer + learn_buffer_len, LEARN_BUFFER_SIZE - learn_buffer_len, fmt, args);
69198+ va_end(args);
69199+
69200+ learn_buffer_len += len + 1;
69201+
69202+ spin_unlock(&gr_learn_lock);
69203+ wake_up_interruptible(&learn_wait);
69204+
69205+ return;
69206+}
69207+
69208+static int
69209+open_learn(struct inode *inode, struct file *file)
69210+{
69211+ if (file->f_mode & FMODE_READ && gr_learn_attached)
69212+ return -EBUSY;
69213+ if (file->f_mode & FMODE_READ) {
69214+ int retval = 0;
69215+ mutex_lock(&gr_learn_user_mutex);
69216+ if (learn_buffer == NULL)
69217+ learn_buffer = vmalloc(LEARN_BUFFER_SIZE);
69218+ if (learn_buffer_user == NULL)
69219+ learn_buffer_user = vmalloc(LEARN_BUFFER_SIZE);
69220+ if (learn_buffer == NULL) {
69221+ retval = -ENOMEM;
69222+ goto out_error;
69223+ }
69224+ if (learn_buffer_user == NULL) {
69225+ retval = -ENOMEM;
69226+ goto out_error;
69227+ }
69228+ learn_buffer_len = 0;
69229+ learn_buffer_user_len = 0;
69230+ gr_learn_attached = 1;
69231+out_error:
69232+ mutex_unlock(&gr_learn_user_mutex);
69233+ return retval;
69234+ }
69235+ return 0;
69236+}
69237+
69238+static int
69239+close_learn(struct inode *inode, struct file *file)
69240+{
69241+ if (file->f_mode & FMODE_READ) {
69242+ char *tmp = NULL;
69243+ mutex_lock(&gr_learn_user_mutex);
69244+ spin_lock(&gr_learn_lock);
69245+ tmp = learn_buffer;
69246+ learn_buffer = NULL;
69247+ spin_unlock(&gr_learn_lock);
69248+ if (tmp)
69249+ vfree(tmp);
69250+ if (learn_buffer_user != NULL) {
69251+ vfree(learn_buffer_user);
69252+ learn_buffer_user = NULL;
69253+ }
69254+ learn_buffer_len = 0;
69255+ learn_buffer_user_len = 0;
69256+ gr_learn_attached = 0;
69257+ mutex_unlock(&gr_learn_user_mutex);
69258+ }
69259+
69260+ return 0;
69261+}
69262+
69263+const struct file_operations grsec_fops = {
69264+ .read = read_learn,
69265+ .write = write_grsec_handler,
69266+ .open = open_learn,
69267+ .release = close_learn,
69268+ .poll = poll_learn,
69269+};
69270diff --git a/grsecurity/gracl_policy.c b/grsecurity/gracl_policy.c
69271new file mode 100644
69272index 0000000..361a099
69273--- /dev/null
69274+++ b/grsecurity/gracl_policy.c
69275@@ -0,0 +1,1782 @@
69276+#include <linux/kernel.h>
69277+#include <linux/module.h>
69278+#include <linux/sched.h>
69279+#include <linux/mm.h>
69280+#include <linux/file.h>
69281+#include <linux/fs.h>
69282+#include <linux/namei.h>
69283+#include <linux/mount.h>
69284+#include <linux/tty.h>
69285+#include <linux/proc_fs.h>
69286+#include <linux/lglock.h>
69287+#include <linux/slab.h>
69288+#include <linux/vmalloc.h>
69289+#include <linux/types.h>
69290+#include <linux/sysctl.h>
69291+#include <linux/netdevice.h>
69292+#include <linux/ptrace.h>
69293+#include <linux/gracl.h>
69294+#include <linux/gralloc.h>
69295+#include <linux/security.h>
69296+#include <linux/grinternal.h>
69297+#include <linux/pid_namespace.h>
69298+#include <linux/stop_machine.h>
69299+#include <linux/fdtable.h>
69300+#include <linux/percpu.h>
69301+#include <linux/lglock.h>
69302+#include <linux/hugetlb.h>
69303+#include <linux/posix-timers.h>
69304+#include "../fs/mount.h"
69305+
69306+#include <asm/uaccess.h>
69307+#include <asm/errno.h>
69308+#include <asm/mman.h>
69309+
69310+extern struct gr_policy_state *polstate;
69311+
69312+#define FOR_EACH_ROLE_START(role) \
69313+ role = polstate->role_list; \
69314+ while (role) {
69315+
69316+#define FOR_EACH_ROLE_END(role) \
69317+ role = role->prev; \
69318+ }
69319+
69320+struct path gr_real_root;
69321+
69322+extern struct gr_alloc_state *current_alloc_state;
69323+
69324+u16 acl_sp_role_value;
69325+
69326+static DEFINE_MUTEX(gr_dev_mutex);
69327+
69328+extern int chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum);
69329+extern void gr_clear_learn_entries(void);
69330+
69331+static struct gr_arg gr_usermode;
69332+static unsigned char gr_system_salt[GR_SALT_LEN];
69333+static unsigned char gr_system_sum[GR_SHA_LEN];
69334+
69335+static unsigned int gr_auth_attempts = 0;
69336+static unsigned long gr_auth_expires = 0UL;
69337+
69338+struct acl_object_label *fakefs_obj_rw;
69339+struct acl_object_label *fakefs_obj_rwx;
69340+
69341+extern int gr_init_uidset(void);
69342+extern void gr_free_uidset(void);
69343+extern void gr_remove_uid(uid_t uid);
69344+extern int gr_find_uid(uid_t uid);
69345+
69346+extern struct acl_subject_label *__gr_get_subject_for_task(const struct gr_policy_state *state, struct task_struct *task, const char *filename);
69347+extern void __gr_apply_subject_to_task(struct gr_policy_state *state, struct task_struct *task, struct acl_subject_label *subj);
69348+extern int gr_streq(const char *a, const char *b, const unsigned int lena, const unsigned int lenb);
69349+extern void __insert_inodev_entry(const struct gr_policy_state *state, struct inodev_entry *entry);
69350+extern struct acl_role_label *__lookup_acl_role_label(const struct gr_policy_state *state, const struct task_struct *task, const uid_t uid, const gid_t gid);
69351+extern void insert_acl_obj_label(struct acl_object_label *obj, struct acl_subject_label *subj);
69352+extern void insert_acl_subj_label(struct acl_subject_label *obj, struct acl_role_label *role);
69353+extern struct name_entry * __lookup_name_entry(const struct gr_policy_state *state, const char *name);
69354+extern char *gr_to_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt);
69355+extern struct acl_subject_label *lookup_acl_subj_label(const ino_t ino, const dev_t dev, const struct acl_role_label *role);
69356+extern struct acl_subject_label *lookup_acl_subj_label_deleted(const ino_t ino, const dev_t dev, const struct acl_role_label *role);
69357+extern void assign_special_role(const char *rolename);
69358+extern struct acl_subject_label *chk_subj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt, const struct acl_role_label *role);
69359+extern int gr_rbac_disable(void *unused);
69360+extern void gr_enable_rbac_system(void);
69361+
69362+static int copy_acl_object_label_normal(struct acl_object_label *obj, const struct acl_object_label *userp)
69363+{
69364+ if (copy_from_user(obj, userp, sizeof(struct acl_object_label)))
69365+ return -EFAULT;
69366+
69367+ return 0;
69368+}
69369+
69370+static int copy_acl_ip_label_normal(struct acl_ip_label *ip, const struct acl_ip_label *userp)
69371+{
69372+ if (copy_from_user(ip, userp, sizeof(struct acl_ip_label)))
69373+ return -EFAULT;
69374+
69375+ return 0;
69376+}
69377+
69378+static int copy_acl_subject_label_normal(struct acl_subject_label *subj, const struct acl_subject_label *userp)
69379+{
69380+ if (copy_from_user(subj, userp, sizeof(struct acl_subject_label)))
69381+ return -EFAULT;
69382+
69383+ return 0;
69384+}
69385+
69386+static int copy_acl_role_label_normal(struct acl_role_label *role, const struct acl_role_label *userp)
69387+{
69388+ if (copy_from_user(role, userp, sizeof(struct acl_role_label)))
69389+ return -EFAULT;
69390+
69391+ return 0;
69392+}
69393+
69394+static int copy_role_allowed_ip_normal(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp)
69395+{
69396+ if (copy_from_user(roleip, userp, sizeof(struct role_allowed_ip)))
69397+ return -EFAULT;
69398+
69399+ return 0;
69400+}
69401+
69402+static int copy_sprole_pw_normal(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp)
69403+{
69404+ if (copy_from_user(pw, userp + idx, sizeof(struct sprole_pw)))
69405+ return -EFAULT;
69406+
69407+ return 0;
69408+}
69409+
69410+static int copy_gr_hash_struct_normal(struct gr_hash_struct *hash, const struct gr_hash_struct *userp)
69411+{
69412+ if (copy_from_user(hash, userp, sizeof(struct gr_hash_struct)))
69413+ return -EFAULT;
69414+
69415+ return 0;
69416+}
69417+
69418+static int copy_role_transition_normal(struct role_transition *trans, const struct role_transition *userp)
69419+{
69420+ if (copy_from_user(trans, userp, sizeof(struct role_transition)))
69421+ return -EFAULT;
69422+
69423+ return 0;
69424+}
69425+
69426+int copy_pointer_from_array_normal(void *ptr, unsigned long idx, const void *userp)
69427+{
69428+ if (copy_from_user(ptr, userp + (idx * sizeof(void *)), sizeof(void *)))
69429+ return -EFAULT;
69430+
69431+ return 0;
69432+}
69433+
69434+static int copy_gr_arg_wrapper_normal(const char __user *buf, struct gr_arg_wrapper *uwrap)
69435+{
69436+ if (copy_from_user(uwrap, buf, sizeof (struct gr_arg_wrapper)))
69437+ return -EFAULT;
69438+
69439+ if (((uwrap->version != GRSECURITY_VERSION) &&
69440+ (uwrap->version != 0x2901)) ||
69441+ (uwrap->size != sizeof(struct gr_arg)))
69442+ return -EINVAL;
69443+
69444+ return 0;
69445+}
69446+
69447+static int copy_gr_arg_normal(const struct gr_arg __user *buf, struct gr_arg *arg)
69448+{
69449+ if (copy_from_user(arg, buf, sizeof (struct gr_arg)))
69450+ return -EFAULT;
69451+
69452+ return 0;
69453+}
69454+
69455+static size_t get_gr_arg_wrapper_size_normal(void)
69456+{
69457+ return sizeof(struct gr_arg_wrapper);
69458+}
69459+
69460+#ifdef CONFIG_COMPAT
69461+extern int copy_gr_arg_wrapper_compat(const char *buf, struct gr_arg_wrapper *uwrap);
69462+extern int copy_gr_arg_compat(const struct gr_arg __user *buf, struct gr_arg *arg);
69463+extern int copy_acl_object_label_compat(struct acl_object_label *obj, const struct acl_object_label *userp);
69464+extern int copy_acl_subject_label_compat(struct acl_subject_label *subj, const struct acl_subject_label *userp);
69465+extern int copy_acl_role_label_compat(struct acl_role_label *role, const struct acl_role_label *userp);
69466+extern int copy_role_allowed_ip_compat(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp);
69467+extern int copy_role_transition_compat(struct role_transition *trans, const struct role_transition *userp);
69468+extern int copy_gr_hash_struct_compat(struct gr_hash_struct *hash, const struct gr_hash_struct *userp);
69469+extern int copy_pointer_from_array_compat(void *ptr, unsigned long idx, const void *userp);
69470+extern int copy_acl_ip_label_compat(struct acl_ip_label *ip, const struct acl_ip_label *userp);
69471+extern int copy_sprole_pw_compat(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp);
69472+extern size_t get_gr_arg_wrapper_size_compat(void);
69473+
69474+int (* copy_gr_arg_wrapper)(const char *buf, struct gr_arg_wrapper *uwrap) __read_only;
69475+int (* copy_gr_arg)(const struct gr_arg *buf, struct gr_arg *arg) __read_only;
69476+int (* copy_acl_object_label)(struct acl_object_label *obj, const struct acl_object_label *userp) __read_only;
69477+int (* copy_acl_subject_label)(struct acl_subject_label *subj, const struct acl_subject_label *userp) __read_only;
69478+int (* copy_acl_role_label)(struct acl_role_label *role, const struct acl_role_label *userp) __read_only;
69479+int (* copy_acl_ip_label)(struct acl_ip_label *ip, const struct acl_ip_label *userp) __read_only;
69480+int (* copy_pointer_from_array)(void *ptr, unsigned long idx, const void *userp) __read_only;
69481+int (* copy_sprole_pw)(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp) __read_only;
69482+int (* copy_gr_hash_struct)(struct gr_hash_struct *hash, const struct gr_hash_struct *userp) __read_only;
69483+int (* copy_role_transition)(struct role_transition *trans, const struct role_transition *userp) __read_only;
69484+int (* copy_role_allowed_ip)(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp) __read_only;
69485+size_t (* get_gr_arg_wrapper_size)(void) __read_only;
69486+
69487+#else
69488+#define copy_gr_arg_wrapper copy_gr_arg_wrapper_normal
69489+#define copy_gr_arg copy_gr_arg_normal
69490+#define copy_gr_hash_struct copy_gr_hash_struct_normal
69491+#define copy_acl_object_label copy_acl_object_label_normal
69492+#define copy_acl_subject_label copy_acl_subject_label_normal
69493+#define copy_acl_role_label copy_acl_role_label_normal
69494+#define copy_acl_ip_label copy_acl_ip_label_normal
69495+#define copy_pointer_from_array copy_pointer_from_array_normal
69496+#define copy_sprole_pw copy_sprole_pw_normal
69497+#define copy_role_transition copy_role_transition_normal
69498+#define copy_role_allowed_ip copy_role_allowed_ip_normal
69499+#define get_gr_arg_wrapper_size get_gr_arg_wrapper_size_normal
69500+#endif
69501+
69502+static struct acl_subject_label *
69503+lookup_subject_map(const struct acl_subject_label *userp)
69504+{
69505+ unsigned int index = gr_shash(userp, polstate->subj_map_set.s_size);
69506+ struct subject_map *match;
69507+
69508+ match = polstate->subj_map_set.s_hash[index];
69509+
69510+ while (match && match->user != userp)
69511+ match = match->next;
69512+
69513+ if (match != NULL)
69514+ return match->kernel;
69515+ else
69516+ return NULL;
69517+}
69518+
69519+static void
69520+insert_subj_map_entry(struct subject_map *subjmap)
69521+{
69522+ unsigned int index = gr_shash(subjmap->user, polstate->subj_map_set.s_size);
69523+ struct subject_map **curr;
69524+
69525+ subjmap->prev = NULL;
69526+
69527+ curr = &polstate->subj_map_set.s_hash[index];
69528+ if (*curr != NULL)
69529+ (*curr)->prev = subjmap;
69530+
69531+ subjmap->next = *curr;
69532+ *curr = subjmap;
69533+
69534+ return;
69535+}
69536+
69537+static void
69538+__insert_acl_role_label(struct acl_role_label *role, uid_t uidgid)
69539+{
69540+ unsigned int index =
69541+ gr_rhash(uidgid, role->roletype & (GR_ROLE_USER | GR_ROLE_GROUP), polstate->acl_role_set.r_size);
69542+ struct acl_role_label **curr;
69543+ struct acl_role_label *tmp, *tmp2;
69544+
69545+ curr = &polstate->acl_role_set.r_hash[index];
69546+
69547+ /* simple case, slot is empty, just set it to our role */
69548+ if (*curr == NULL) {
69549+ *curr = role;
69550+ } else {
69551+ /* example:
69552+ 1 -> 2 -> 3 (adding 2 -> 3 to here)
69553+ 2 -> 3
69554+ */
69555+ /* first check to see if we can already be reached via this slot */
69556+ tmp = *curr;
69557+ while (tmp && tmp != role)
69558+ tmp = tmp->next;
69559+ if (tmp == role) {
69560+ /* we don't need to add ourselves to this slot's chain */
69561+ return;
69562+ }
69563+ /* we need to add ourselves to this chain, two cases */
69564+ if (role->next == NULL) {
69565+ /* simple case, append the current chain to our role */
69566+ role->next = *curr;
69567+ *curr = role;
69568+ } else {
69569+ /* 1 -> 2 -> 3 -> 4
69570+ 2 -> 3 -> 4
69571+ 3 -> 4 (adding 1 -> 2 -> 3 -> 4 to here)
69572+ */
69573+ /* trickier case: walk our role's chain until we find
69574+ the role for the start of the current slot's chain */
69575+ tmp = role;
69576+ tmp2 = *curr;
69577+ while (tmp->next && tmp->next != tmp2)
69578+ tmp = tmp->next;
69579+ if (tmp->next == tmp2) {
69580+ /* from example above, we found 3, so just
69581+ replace this slot's chain with ours */
69582+ *curr = role;
69583+ } else {
69584+ /* we didn't find a subset of our role's chain
69585+ in the current slot's chain, so append their
69586+ chain to ours, and set us as the first role in
69587+ the slot's chain
69588+
69589+ we could fold this case with the case above,
69590+ but making it explicit for clarity
69591+ */
69592+ tmp->next = tmp2;
69593+ *curr = role;
69594+ }
69595+ }
69596+ }
69597+
69598+ return;
69599+}
69600+
69601+static void
69602+insert_acl_role_label(struct acl_role_label *role)
69603+{
69604+ int i;
69605+
69606+ if (polstate->role_list == NULL) {
69607+ polstate->role_list = role;
69608+ role->prev = NULL;
69609+ } else {
69610+ role->prev = polstate->role_list;
69611+ polstate->role_list = role;
69612+ }
69613+
69614+ /* used for hash chains */
69615+ role->next = NULL;
69616+
69617+ if (role->roletype & GR_ROLE_DOMAIN) {
69618+ for (i = 0; i < role->domain_child_num; i++)
69619+ __insert_acl_role_label(role, role->domain_children[i]);
69620+ } else
69621+ __insert_acl_role_label(role, role->uidgid);
69622+}
69623+
69624+static int
69625+insert_name_entry(char *name, const ino_t inode, const dev_t device, __u8 deleted)
69626+{
69627+ struct name_entry **curr, *nentry;
69628+ struct inodev_entry *ientry;
69629+ unsigned int len = strlen(name);
69630+ unsigned int key = full_name_hash(name, len);
69631+ unsigned int index = key % polstate->name_set.n_size;
69632+
69633+ curr = &polstate->name_set.n_hash[index];
69634+
69635+ while (*curr && ((*curr)->key != key || !gr_streq((*curr)->name, name, (*curr)->len, len)))
69636+ curr = &((*curr)->next);
69637+
69638+ if (*curr != NULL)
69639+ return 1;
69640+
69641+ nentry = acl_alloc(sizeof (struct name_entry));
69642+ if (nentry == NULL)
69643+ return 0;
69644+ ientry = acl_alloc(sizeof (struct inodev_entry));
69645+ if (ientry == NULL)
69646+ return 0;
69647+ ientry->nentry = nentry;
69648+
69649+ nentry->key = key;
69650+ nentry->name = name;
69651+ nentry->inode = inode;
69652+ nentry->device = device;
69653+ nentry->len = len;
69654+ nentry->deleted = deleted;
69655+
69656+ nentry->prev = NULL;
69657+ curr = &polstate->name_set.n_hash[index];
69658+ if (*curr != NULL)
69659+ (*curr)->prev = nentry;
69660+ nentry->next = *curr;
69661+ *curr = nentry;
69662+
69663+ /* insert us into the table searchable by inode/dev */
69664+ __insert_inodev_entry(polstate, ientry);
69665+
69666+ return 1;
69667+}
69668+
69669+/* allocating chained hash tables, so optimal size is where lambda ~ 1 */
69670+
69671+static void *
69672+create_table(__u32 * len, int elementsize)
69673+{
69674+ unsigned int table_sizes[] = {
69675+ 7, 13, 31, 61, 127, 251, 509, 1021, 2039, 4093, 8191, 16381,
69676+ 32749, 65521, 131071, 262139, 524287, 1048573, 2097143,
69677+ 4194301, 8388593, 16777213, 33554393, 67108859
69678+ };
69679+ void *newtable = NULL;
69680+ unsigned int pwr = 0;
69681+
69682+ while ((pwr < ((sizeof (table_sizes) / sizeof (table_sizes[0])) - 1)) &&
69683+ table_sizes[pwr] <= *len)
69684+ pwr++;
69685+
69686+ if (table_sizes[pwr] <= *len || (table_sizes[pwr] > ULONG_MAX / elementsize))
69687+ return newtable;
69688+
69689+ if ((table_sizes[pwr] * elementsize) <= PAGE_SIZE)
69690+ newtable =
69691+ kmalloc(table_sizes[pwr] * elementsize, GFP_KERNEL);
69692+ else
69693+ newtable = vmalloc(table_sizes[pwr] * elementsize);
69694+
69695+ *len = table_sizes[pwr];
69696+
69697+ return newtable;
69698+}
69699+
69700+static int
69701+init_variables(const struct gr_arg *arg, bool reload)
69702+{
69703+ struct task_struct *reaper = init_pid_ns.child_reaper;
69704+ unsigned int stacksize;
69705+
69706+ polstate->subj_map_set.s_size = arg->role_db.num_subjects;
69707+ polstate->acl_role_set.r_size = arg->role_db.num_roles + arg->role_db.num_domain_children;
69708+ polstate->name_set.n_size = arg->role_db.num_objects;
69709+ polstate->inodev_set.i_size = arg->role_db.num_objects;
69710+
69711+ if (!polstate->subj_map_set.s_size || !polstate->acl_role_set.r_size ||
69712+ !polstate->name_set.n_size || !polstate->inodev_set.i_size)
69713+ return 1;
69714+
69715+ if (!reload) {
69716+ if (!gr_init_uidset())
69717+ return 1;
69718+ }
69719+
69720+ /* set up the stack that holds allocation info */
69721+
69722+ stacksize = arg->role_db.num_pointers + 5;
69723+
69724+ if (!acl_alloc_stack_init(stacksize))
69725+ return 1;
69726+
69727+ if (!reload) {
69728+ /* grab reference for the real root dentry and vfsmount */
69729+ get_fs_root(reaper->fs, &gr_real_root);
69730+
69731+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
69732+ printk(KERN_ALERT "Obtained real root device=%d, inode=%lu\n", __get_dev(gr_real_root.dentry), gr_real_root.dentry->d_inode->i_ino);
69733+#endif
69734+
69735+ fakefs_obj_rw = kzalloc(sizeof(struct acl_object_label), GFP_KERNEL);
69736+ if (fakefs_obj_rw == NULL)
69737+ return 1;
69738+ fakefs_obj_rw->mode = GR_FIND | GR_READ | GR_WRITE;
69739+
69740+ fakefs_obj_rwx = kzalloc(sizeof(struct acl_object_label), GFP_KERNEL);
69741+ if (fakefs_obj_rwx == NULL)
69742+ return 1;
69743+ fakefs_obj_rwx->mode = GR_FIND | GR_READ | GR_WRITE | GR_EXEC;
69744+ }
69745+
69746+ polstate->subj_map_set.s_hash =
69747+ (struct subject_map **) create_table(&polstate->subj_map_set.s_size, sizeof(void *));
69748+ polstate->acl_role_set.r_hash =
69749+ (struct acl_role_label **) create_table(&polstate->acl_role_set.r_size, sizeof(void *));
69750+ polstate->name_set.n_hash = (struct name_entry **) create_table(&polstate->name_set.n_size, sizeof(void *));
69751+ polstate->inodev_set.i_hash =
69752+ (struct inodev_entry **) create_table(&polstate->inodev_set.i_size, sizeof(void *));
69753+
69754+ if (!polstate->subj_map_set.s_hash || !polstate->acl_role_set.r_hash ||
69755+ !polstate->name_set.n_hash || !polstate->inodev_set.i_hash)
69756+ return 1;
69757+
69758+ memset(polstate->subj_map_set.s_hash, 0,
69759+ sizeof(struct subject_map *) * polstate->subj_map_set.s_size);
69760+ memset(polstate->acl_role_set.r_hash, 0,
69761+ sizeof (struct acl_role_label *) * polstate->acl_role_set.r_size);
69762+ memset(polstate->name_set.n_hash, 0,
69763+ sizeof (struct name_entry *) * polstate->name_set.n_size);
69764+ memset(polstate->inodev_set.i_hash, 0,
69765+ sizeof (struct inodev_entry *) * polstate->inodev_set.i_size);
69766+
69767+ return 0;
69768+}
69769+
69770+/* free information not needed after startup
69771+ currently contains user->kernel pointer mappings for subjects
69772+*/
69773+
69774+static void
69775+free_init_variables(void)
69776+{
69777+ __u32 i;
69778+
69779+ if (polstate->subj_map_set.s_hash) {
69780+ for (i = 0; i < polstate->subj_map_set.s_size; i++) {
69781+ if (polstate->subj_map_set.s_hash[i]) {
69782+ kfree(polstate->subj_map_set.s_hash[i]);
69783+ polstate->subj_map_set.s_hash[i] = NULL;
69784+ }
69785+ }
69786+
69787+ if ((polstate->subj_map_set.s_size * sizeof (struct subject_map *)) <=
69788+ PAGE_SIZE)
69789+ kfree(polstate->subj_map_set.s_hash);
69790+ else
69791+ vfree(polstate->subj_map_set.s_hash);
69792+ }
69793+
69794+ return;
69795+}
69796+
69797+static void
69798+free_variables(bool reload)
69799+{
69800+ struct acl_subject_label *s;
69801+ struct acl_role_label *r;
69802+ struct task_struct *task, *task2;
69803+ unsigned int x;
69804+
69805+ if (!reload) {
69806+ gr_clear_learn_entries();
69807+
69808+ read_lock(&tasklist_lock);
69809+ do_each_thread(task2, task) {
69810+ task->acl_sp_role = 0;
69811+ task->acl_role_id = 0;
69812+ task->inherited = 0;
69813+ task->acl = NULL;
69814+ task->role = NULL;
69815+ } while_each_thread(task2, task);
69816+ read_unlock(&tasklist_lock);
69817+
69818+ kfree(fakefs_obj_rw);
69819+ fakefs_obj_rw = NULL;
69820+ kfree(fakefs_obj_rwx);
69821+ fakefs_obj_rwx = NULL;
69822+
69823+ /* release the reference to the real root dentry and vfsmount */
69824+ path_put(&gr_real_root);
69825+ memset(&gr_real_root, 0, sizeof(gr_real_root));
69826+ }
69827+
69828+ /* free all object hash tables */
69829+
69830+ FOR_EACH_ROLE_START(r)
69831+ if (r->subj_hash == NULL)
69832+ goto next_role;
69833+ FOR_EACH_SUBJECT_START(r, s, x)
69834+ if (s->obj_hash == NULL)
69835+ break;
69836+ if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
69837+ kfree(s->obj_hash);
69838+ else
69839+ vfree(s->obj_hash);
69840+ FOR_EACH_SUBJECT_END(s, x)
69841+ FOR_EACH_NESTED_SUBJECT_START(r, s)
69842+ if (s->obj_hash == NULL)
69843+ break;
69844+ if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
69845+ kfree(s->obj_hash);
69846+ else
69847+ vfree(s->obj_hash);
69848+ FOR_EACH_NESTED_SUBJECT_END(s)
69849+ if ((r->subj_hash_size * sizeof (struct acl_subject_label *)) <= PAGE_SIZE)
69850+ kfree(r->subj_hash);
69851+ else
69852+ vfree(r->subj_hash);
69853+ r->subj_hash = NULL;
69854+next_role:
69855+ FOR_EACH_ROLE_END(r)
69856+
69857+ acl_free_all();
69858+
69859+ if (polstate->acl_role_set.r_hash) {
69860+ if ((polstate->acl_role_set.r_size * sizeof (struct acl_role_label *)) <=
69861+ PAGE_SIZE)
69862+ kfree(polstate->acl_role_set.r_hash);
69863+ else
69864+ vfree(polstate->acl_role_set.r_hash);
69865+ }
69866+ if (polstate->name_set.n_hash) {
69867+ if ((polstate->name_set.n_size * sizeof (struct name_entry *)) <=
69868+ PAGE_SIZE)
69869+ kfree(polstate->name_set.n_hash);
69870+ else
69871+ vfree(polstate->name_set.n_hash);
69872+ }
69873+
69874+ if (polstate->inodev_set.i_hash) {
69875+ if ((polstate->inodev_set.i_size * sizeof (struct inodev_entry *)) <=
69876+ PAGE_SIZE)
69877+ kfree(polstate->inodev_set.i_hash);
69878+ else
69879+ vfree(polstate->inodev_set.i_hash);
69880+ }
69881+
69882+ if (!reload)
69883+ gr_free_uidset();
69884+
69885+ memset(&polstate->name_set, 0, sizeof (struct name_db));
69886+ memset(&polstate->inodev_set, 0, sizeof (struct inodev_db));
69887+ memset(&polstate->acl_role_set, 0, sizeof (struct acl_role_db));
69888+ memset(&polstate->subj_map_set, 0, sizeof (struct acl_subj_map_db));
69889+
69890+ polstate->default_role = NULL;
69891+ polstate->kernel_role = NULL;
69892+ polstate->role_list = NULL;
69893+
69894+ return;
69895+}
69896+
69897+static struct acl_subject_label *
69898+do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role, int *already_copied);
69899+
69900+static int alloc_and_copy_string(char **name, unsigned int maxlen)
69901+{
69902+ unsigned int len = strnlen_user(*name, maxlen);
69903+ char *tmp;
69904+
69905+ if (!len || len >= maxlen)
69906+ return -EINVAL;
69907+
69908+ if ((tmp = (char *) acl_alloc(len)) == NULL)
69909+ return -ENOMEM;
69910+
69911+ if (copy_from_user(tmp, *name, len))
69912+ return -EFAULT;
69913+
69914+ tmp[len-1] = '\0';
69915+ *name = tmp;
69916+
69917+ return 0;
69918+}
69919+
69920+static int
69921+copy_user_glob(struct acl_object_label *obj)
69922+{
69923+ struct acl_object_label *g_tmp, **guser;
69924+ int error;
69925+
69926+ if (obj->globbed == NULL)
69927+ return 0;
69928+
69929+ guser = &obj->globbed;
69930+ while (*guser) {
69931+ g_tmp = (struct acl_object_label *)
69932+ acl_alloc(sizeof (struct acl_object_label));
69933+ if (g_tmp == NULL)
69934+ return -ENOMEM;
69935+
69936+ if (copy_acl_object_label(g_tmp, *guser))
69937+ return -EFAULT;
69938+
69939+ error = alloc_and_copy_string(&g_tmp->filename, PATH_MAX);
69940+ if (error)
69941+ return error;
69942+
69943+ *guser = g_tmp;
69944+ guser = &(g_tmp->next);
69945+ }
69946+
69947+ return 0;
69948+}
69949+
69950+static int
69951+copy_user_objs(struct acl_object_label *userp, struct acl_subject_label *subj,
69952+ struct acl_role_label *role)
69953+{
69954+ struct acl_object_label *o_tmp;
69955+ int ret;
69956+
69957+ while (userp) {
69958+ if ((o_tmp = (struct acl_object_label *)
69959+ acl_alloc(sizeof (struct acl_object_label))) == NULL)
69960+ return -ENOMEM;
69961+
69962+ if (copy_acl_object_label(o_tmp, userp))
69963+ return -EFAULT;
69964+
69965+ userp = o_tmp->prev;
69966+
69967+ ret = alloc_and_copy_string(&o_tmp->filename, PATH_MAX);
69968+ if (ret)
69969+ return ret;
69970+
69971+ insert_acl_obj_label(o_tmp, subj);
69972+ if (!insert_name_entry(o_tmp->filename, o_tmp->inode,
69973+ o_tmp->device, (o_tmp->mode & GR_DELETED) ? 1 : 0))
69974+ return -ENOMEM;
69975+
69976+ ret = copy_user_glob(o_tmp);
69977+ if (ret)
69978+ return ret;
69979+
69980+ if (o_tmp->nested) {
69981+ int already_copied;
69982+
69983+ o_tmp->nested = do_copy_user_subj(o_tmp->nested, role, &already_copied);
69984+ if (IS_ERR(o_tmp->nested))
69985+ return PTR_ERR(o_tmp->nested);
69986+
69987+ /* insert into nested subject list if we haven't copied this one yet
69988+ to prevent duplicate entries */
69989+ if (!already_copied) {
69990+ o_tmp->nested->next = role->hash->first;
69991+ role->hash->first = o_tmp->nested;
69992+ }
69993+ }
69994+ }
69995+
69996+ return 0;
69997+}
69998+
69999+static __u32
70000+count_user_subjs(struct acl_subject_label *userp)
70001+{
70002+ struct acl_subject_label s_tmp;
70003+ __u32 num = 0;
70004+
70005+ while (userp) {
70006+ if (copy_acl_subject_label(&s_tmp, userp))
70007+ break;
70008+
70009+ userp = s_tmp.prev;
70010+ }
70011+
70012+ return num;
70013+}
70014+
70015+static int
70016+copy_user_allowedips(struct acl_role_label *rolep)
70017+{
70018+ struct role_allowed_ip *ruserip, *rtmp = NULL, *rlast;
70019+
70020+ ruserip = rolep->allowed_ips;
70021+
70022+ while (ruserip) {
70023+ rlast = rtmp;
70024+
70025+ if ((rtmp = (struct role_allowed_ip *)
70026+ acl_alloc(sizeof (struct role_allowed_ip))) == NULL)
70027+ return -ENOMEM;
70028+
70029+ if (copy_role_allowed_ip(rtmp, ruserip))
70030+ return -EFAULT;
70031+
70032+ ruserip = rtmp->prev;
70033+
70034+ if (!rlast) {
70035+ rtmp->prev = NULL;
70036+ rolep->allowed_ips = rtmp;
70037+ } else {
70038+ rlast->next = rtmp;
70039+ rtmp->prev = rlast;
70040+ }
70041+
70042+ if (!ruserip)
70043+ rtmp->next = NULL;
70044+ }
70045+
70046+ return 0;
70047+}
70048+
70049+static int
70050+copy_user_transitions(struct acl_role_label *rolep)
70051+{
70052+ struct role_transition *rusertp, *rtmp = NULL, *rlast;
70053+ int error;
70054+
70055+ rusertp = rolep->transitions;
70056+
70057+ while (rusertp) {
70058+ rlast = rtmp;
70059+
70060+ if ((rtmp = (struct role_transition *)
70061+ acl_alloc(sizeof (struct role_transition))) == NULL)
70062+ return -ENOMEM;
70063+
70064+ if (copy_role_transition(rtmp, rusertp))
70065+ return -EFAULT;
70066+
70067+ rusertp = rtmp->prev;
70068+
70069+ error = alloc_and_copy_string(&rtmp->rolename, GR_SPROLE_LEN);
70070+ if (error)
70071+ return error;
70072+
70073+ if (!rlast) {
70074+ rtmp->prev = NULL;
70075+ rolep->transitions = rtmp;
70076+ } else {
70077+ rlast->next = rtmp;
70078+ rtmp->prev = rlast;
70079+ }
70080+
70081+ if (!rusertp)
70082+ rtmp->next = NULL;
70083+ }
70084+
70085+ return 0;
70086+}
70087+
70088+static __u32 count_user_objs(const struct acl_object_label __user *userp)
70089+{
70090+ struct acl_object_label o_tmp;
70091+ __u32 num = 0;
70092+
70093+ while (userp) {
70094+ if (copy_acl_object_label(&o_tmp, userp))
70095+ break;
70096+
70097+ userp = o_tmp.prev;
70098+ num++;
70099+ }
70100+
70101+ return num;
70102+}
70103+
70104+static struct acl_subject_label *
70105+do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role, int *already_copied)
70106+{
70107+ struct acl_subject_label *s_tmp = NULL, *s_tmp2;
70108+ __u32 num_objs;
70109+ struct acl_ip_label **i_tmp, *i_utmp2;
70110+ struct gr_hash_struct ghash;
70111+ struct subject_map *subjmap;
70112+ unsigned int i_num;
70113+ int err;
70114+
70115+ if (already_copied != NULL)
70116+ *already_copied = 0;
70117+
70118+ s_tmp = lookup_subject_map(userp);
70119+
70120+ /* we've already copied this subject into the kernel, just return
70121+ the reference to it, and don't copy it over again
70122+ */
70123+ if (s_tmp) {
70124+ if (already_copied != NULL)
70125+ *already_copied = 1;
70126+ return(s_tmp);
70127+ }
70128+
70129+ if ((s_tmp = (struct acl_subject_label *)
70130+ acl_alloc(sizeof (struct acl_subject_label))) == NULL)
70131+ return ERR_PTR(-ENOMEM);
70132+
70133+ subjmap = (struct subject_map *)kmalloc(sizeof (struct subject_map), GFP_KERNEL);
70134+ if (subjmap == NULL)
70135+ return ERR_PTR(-ENOMEM);
70136+
70137+ subjmap->user = userp;
70138+ subjmap->kernel = s_tmp;
70139+ insert_subj_map_entry(subjmap);
70140+
70141+ if (copy_acl_subject_label(s_tmp, userp))
70142+ return ERR_PTR(-EFAULT);
70143+
70144+ err = alloc_and_copy_string(&s_tmp->filename, PATH_MAX);
70145+ if (err)
70146+ return ERR_PTR(err);
70147+
70148+ if (!strcmp(s_tmp->filename, "/"))
70149+ role->root_label = s_tmp;
70150+
70151+ if (copy_gr_hash_struct(&ghash, s_tmp->hash))
70152+ return ERR_PTR(-EFAULT);
70153+
70154+ /* copy user and group transition tables */
70155+
70156+ if (s_tmp->user_trans_num) {
70157+ uid_t *uidlist;
70158+
70159+ uidlist = (uid_t *)acl_alloc_num(s_tmp->user_trans_num, sizeof(uid_t));
70160+ if (uidlist == NULL)
70161+ return ERR_PTR(-ENOMEM);
70162+ if (copy_from_user(uidlist, s_tmp->user_transitions, s_tmp->user_trans_num * sizeof(uid_t)))
70163+ return ERR_PTR(-EFAULT);
70164+
70165+ s_tmp->user_transitions = uidlist;
70166+ }
70167+
70168+ if (s_tmp->group_trans_num) {
70169+ gid_t *gidlist;
70170+
70171+ gidlist = (gid_t *)acl_alloc_num(s_tmp->group_trans_num, sizeof(gid_t));
70172+ if (gidlist == NULL)
70173+ return ERR_PTR(-ENOMEM);
70174+ if (copy_from_user(gidlist, s_tmp->group_transitions, s_tmp->group_trans_num * sizeof(gid_t)))
70175+ return ERR_PTR(-EFAULT);
70176+
70177+ s_tmp->group_transitions = gidlist;
70178+ }
70179+
70180+ /* set up object hash table */
70181+ num_objs = count_user_objs(ghash.first);
70182+
70183+ s_tmp->obj_hash_size = num_objs;
70184+ s_tmp->obj_hash =
70185+ (struct acl_object_label **)
70186+ create_table(&(s_tmp->obj_hash_size), sizeof(void *));
70187+
70188+ if (!s_tmp->obj_hash)
70189+ return ERR_PTR(-ENOMEM);
70190+
70191+ memset(s_tmp->obj_hash, 0,
70192+ s_tmp->obj_hash_size *
70193+ sizeof (struct acl_object_label *));
70194+
70195+ /* add in objects */
70196+ err = copy_user_objs(ghash.first, s_tmp, role);
70197+
70198+ if (err)
70199+ return ERR_PTR(err);
70200+
70201+ /* set pointer for parent subject */
70202+ if (s_tmp->parent_subject) {
70203+ s_tmp2 = do_copy_user_subj(s_tmp->parent_subject, role, NULL);
70204+
70205+ if (IS_ERR(s_tmp2))
70206+ return s_tmp2;
70207+
70208+ s_tmp->parent_subject = s_tmp2;
70209+ }
70210+
70211+ /* add in ip acls */
70212+
70213+ if (!s_tmp->ip_num) {
70214+ s_tmp->ips = NULL;
70215+ goto insert;
70216+ }
70217+
70218+ i_tmp =
70219+ (struct acl_ip_label **) acl_alloc_num(s_tmp->ip_num,
70220+ sizeof (struct acl_ip_label *));
70221+
70222+ if (!i_tmp)
70223+ return ERR_PTR(-ENOMEM);
70224+
70225+ for (i_num = 0; i_num < s_tmp->ip_num; i_num++) {
70226+ *(i_tmp + i_num) =
70227+ (struct acl_ip_label *)
70228+ acl_alloc(sizeof (struct acl_ip_label));
70229+ if (!*(i_tmp + i_num))
70230+ return ERR_PTR(-ENOMEM);
70231+
70232+ if (copy_pointer_from_array(&i_utmp2, i_num, s_tmp->ips))
70233+ return ERR_PTR(-EFAULT);
70234+
70235+ if (copy_acl_ip_label(*(i_tmp + i_num), i_utmp2))
70236+ return ERR_PTR(-EFAULT);
70237+
70238+ if ((*(i_tmp + i_num))->iface == NULL)
70239+ continue;
70240+
70241+ err = alloc_and_copy_string(&(*(i_tmp + i_num))->iface, IFNAMSIZ);
70242+ if (err)
70243+ return ERR_PTR(err);
70244+ }
70245+
70246+ s_tmp->ips = i_tmp;
70247+
70248+insert:
70249+ if (!insert_name_entry(s_tmp->filename, s_tmp->inode,
70250+ s_tmp->device, (s_tmp->mode & GR_DELETED) ? 1 : 0))
70251+ return ERR_PTR(-ENOMEM);
70252+
70253+ return s_tmp;
70254+}
70255+
70256+static int
70257+copy_user_subjs(struct acl_subject_label *userp, struct acl_role_label *role)
70258+{
70259+ struct acl_subject_label s_pre;
70260+ struct acl_subject_label * ret;
70261+ int err;
70262+
70263+ while (userp) {
70264+ if (copy_acl_subject_label(&s_pre, userp))
70265+ return -EFAULT;
70266+
70267+ ret = do_copy_user_subj(userp, role, NULL);
70268+
70269+ err = PTR_ERR(ret);
70270+ if (IS_ERR(ret))
70271+ return err;
70272+
70273+ insert_acl_subj_label(ret, role);
70274+
70275+ userp = s_pre.prev;
70276+ }
70277+
70278+ return 0;
70279+}
70280+
70281+static int
70282+copy_user_acl(struct gr_arg *arg)
70283+{
70284+ struct acl_role_label *r_tmp = NULL, **r_utmp, *r_utmp2;
70285+ struct acl_subject_label *subj_list;
70286+ struct sprole_pw *sptmp;
70287+ struct gr_hash_struct *ghash;
70288+ uid_t *domainlist;
70289+ unsigned int r_num;
70290+ int err = 0;
70291+ __u16 i;
70292+ __u32 num_subjs;
70293+
70294+ /* we need a default and kernel role */
70295+ if (arg->role_db.num_roles < 2)
70296+ return -EINVAL;
70297+
70298+ /* copy special role authentication info from userspace */
70299+
70300+ polstate->num_sprole_pws = arg->num_sprole_pws;
70301+ polstate->acl_special_roles = (struct sprole_pw **) acl_alloc_num(polstate->num_sprole_pws, sizeof(struct sprole_pw *));
70302+
70303+ if (!polstate->acl_special_roles && polstate->num_sprole_pws)
70304+ return -ENOMEM;
70305+
70306+ for (i = 0; i < polstate->num_sprole_pws; i++) {
70307+ sptmp = (struct sprole_pw *) acl_alloc(sizeof(struct sprole_pw));
70308+ if (!sptmp)
70309+ return -ENOMEM;
70310+ if (copy_sprole_pw(sptmp, i, arg->sprole_pws))
70311+ return -EFAULT;
70312+
70313+ err = alloc_and_copy_string((char **)&sptmp->rolename, GR_SPROLE_LEN);
70314+ if (err)
70315+ return err;
70316+
70317+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
70318+ printk(KERN_ALERT "Copying special role %s\n", sptmp->rolename);
70319+#endif
70320+
70321+ polstate->acl_special_roles[i] = sptmp;
70322+ }
70323+
70324+ r_utmp = (struct acl_role_label **) arg->role_db.r_table;
70325+
70326+ for (r_num = 0; r_num < arg->role_db.num_roles; r_num++) {
70327+ r_tmp = acl_alloc(sizeof (struct acl_role_label));
70328+
70329+ if (!r_tmp)
70330+ return -ENOMEM;
70331+
70332+ if (copy_pointer_from_array(&r_utmp2, r_num, r_utmp))
70333+ return -EFAULT;
70334+
70335+ if (copy_acl_role_label(r_tmp, r_utmp2))
70336+ return -EFAULT;
70337+
70338+ err = alloc_and_copy_string(&r_tmp->rolename, GR_SPROLE_LEN);
70339+ if (err)
70340+ return err;
70341+
70342+ if (!strcmp(r_tmp->rolename, "default")
70343+ && (r_tmp->roletype & GR_ROLE_DEFAULT)) {
70344+ polstate->default_role = r_tmp;
70345+ } else if (!strcmp(r_tmp->rolename, ":::kernel:::")) {
70346+ polstate->kernel_role = r_tmp;
70347+ }
70348+
70349+ if ((ghash = (struct gr_hash_struct *) acl_alloc(sizeof(struct gr_hash_struct))) == NULL)
70350+ return -ENOMEM;
70351+
70352+ if (copy_gr_hash_struct(ghash, r_tmp->hash))
70353+ return -EFAULT;
70354+
70355+ r_tmp->hash = ghash;
70356+
70357+ num_subjs = count_user_subjs(r_tmp->hash->first);
70358+
70359+ r_tmp->subj_hash_size = num_subjs;
70360+ r_tmp->subj_hash =
70361+ (struct acl_subject_label **)
70362+ create_table(&(r_tmp->subj_hash_size), sizeof(void *));
70363+
70364+ if (!r_tmp->subj_hash)
70365+ return -ENOMEM;
70366+
70367+ err = copy_user_allowedips(r_tmp);
70368+ if (err)
70369+ return err;
70370+
70371+ /* copy domain info */
70372+ if (r_tmp->domain_children != NULL) {
70373+ domainlist = acl_alloc_num(r_tmp->domain_child_num, sizeof(uid_t));
70374+ if (domainlist == NULL)
70375+ return -ENOMEM;
70376+
70377+ if (copy_from_user(domainlist, r_tmp->domain_children, r_tmp->domain_child_num * sizeof(uid_t)))
70378+ return -EFAULT;
70379+
70380+ r_tmp->domain_children = domainlist;
70381+ }
70382+
70383+ err = copy_user_transitions(r_tmp);
70384+ if (err)
70385+ return err;
70386+
70387+ memset(r_tmp->subj_hash, 0,
70388+ r_tmp->subj_hash_size *
70389+ sizeof (struct acl_subject_label *));
70390+
70391+ /* acquire the list of subjects, then NULL out
70392+ the list prior to parsing the subjects for this role,
70393+ as during this parsing the list is replaced with a list
70394+ of *nested* subjects for the role
70395+ */
70396+ subj_list = r_tmp->hash->first;
70397+
70398+ /* set nested subject list to null */
70399+ r_tmp->hash->first = NULL;
70400+
70401+ err = copy_user_subjs(subj_list, r_tmp);
70402+
70403+ if (err)
70404+ return err;
70405+
70406+ insert_acl_role_label(r_tmp);
70407+ }
70408+
70409+ if (polstate->default_role == NULL || polstate->kernel_role == NULL)
70410+ return -EINVAL;
70411+
70412+ return err;
70413+}
70414+
70415+static int gracl_reload_apply_policies(void *reload)
70416+{
70417+ struct gr_reload_state *reload_state = (struct gr_reload_state *)reload;
70418+ struct task_struct *task, *task2;
70419+ struct acl_role_label *role, *rtmp;
70420+ struct acl_subject_label *subj;
70421+ const struct cred *cred;
70422+ int role_applied;
70423+ int ret = 0;
70424+
70425+ memcpy(&reload_state->oldpolicy, reload_state->oldpolicy_ptr, sizeof(struct gr_policy_state));
70426+ memcpy(&reload_state->oldalloc, reload_state->oldalloc_ptr, sizeof(struct gr_alloc_state));
70427+
70428+ /* first make sure we'll be able to apply the new policy cleanly */
70429+ do_each_thread(task2, task) {
70430+ if (task->exec_file == NULL)
70431+ continue;
70432+ role_applied = 0;
70433+ if (!reload_state->oldmode && task->role->roletype & GR_ROLE_SPECIAL) {
70434+ /* preserve special roles */
70435+ FOR_EACH_ROLE_START(role)
70436+ if ((role->roletype & GR_ROLE_SPECIAL) && !strcmp(task->role->rolename, role->rolename)) {
70437+ rtmp = task->role;
70438+ task->role = role;
70439+ role_applied = 1;
70440+ break;
70441+ }
70442+ FOR_EACH_ROLE_END(role)
70443+ }
70444+ if (!role_applied) {
70445+ cred = __task_cred(task);
70446+ rtmp = task->role;
70447+ task->role = __lookup_acl_role_label(polstate, task, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid));
70448+ }
70449+ /* this handles non-nested inherited subjects, nested subjects will still
70450+ be dropped currently */
70451+ subj = __gr_get_subject_for_task(polstate, task, task->acl->filename);
70452+ task->tmpacl = __gr_get_subject_for_task(polstate, task, NULL);
70453+ /* change the role back so that we've made no modifications to the policy */
70454+ task->role = rtmp;
70455+
70456+ if (subj == NULL || task->tmpacl == NULL) {
70457+ ret = -EINVAL;
70458+ goto out;
70459+ }
70460+ } while_each_thread(task2, task);
70461+
70462+ /* now actually apply the policy */
70463+
70464+ do_each_thread(task2, task) {
70465+ if (task->exec_file) {
70466+ role_applied = 0;
70467+ if (!reload_state->oldmode && task->role->roletype & GR_ROLE_SPECIAL) {
70468+ /* preserve special roles */
70469+ FOR_EACH_ROLE_START(role)
70470+ if ((role->roletype & GR_ROLE_SPECIAL) && !strcmp(task->role->rolename, role->rolename)) {
70471+ task->role = role;
70472+ role_applied = 1;
70473+ break;
70474+ }
70475+ FOR_EACH_ROLE_END(role)
70476+ }
70477+ if (!role_applied) {
70478+ cred = __task_cred(task);
70479+ task->role = __lookup_acl_role_label(polstate, task, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid));
70480+ }
70481+ /* this handles non-nested inherited subjects, nested subjects will still
70482+ be dropped currently */
70483+ if (!reload_state->oldmode && task->inherited)
70484+ subj = __gr_get_subject_for_task(polstate, task, task->acl->filename);
70485+ else {
70486+ /* looked up and tagged to the task previously */
70487+ subj = task->tmpacl;
70488+ }
70489+ /* subj will be non-null */
70490+ __gr_apply_subject_to_task(polstate, task, subj);
70491+ if (reload_state->oldmode) {
70492+ task->acl_role_id = 0;
70493+ task->acl_sp_role = 0;
70494+ task->inherited = 0;
70495+ }
70496+ } else {
70497+ // it's a kernel process
70498+ task->role = polstate->kernel_role;
70499+ task->acl = polstate->kernel_role->root_label;
70500+#ifdef CONFIG_GRKERNSEC_ACL_HIDEKERN
70501+ task->acl->mode &= ~GR_PROCFIND;
70502+#endif
70503+ }
70504+ } while_each_thread(task2, task);
70505+
70506+ memcpy(reload_state->oldpolicy_ptr, &reload_state->newpolicy, sizeof(struct gr_policy_state));
70507+ memcpy(reload_state->oldalloc_ptr, &reload_state->newalloc, sizeof(struct gr_alloc_state));
70508+
70509+out:
70510+
70511+ return ret;
70512+}
70513+
70514+static int gracl_reload(struct gr_arg *args, unsigned char oldmode)
70515+{
70516+ struct gr_reload_state new_reload_state = { };
70517+ int err;
70518+
70519+ new_reload_state.oldpolicy_ptr = polstate;
70520+ new_reload_state.oldalloc_ptr = current_alloc_state;
70521+ new_reload_state.oldmode = oldmode;
70522+
70523+ current_alloc_state = &new_reload_state.newalloc;
70524+ polstate = &new_reload_state.newpolicy;
70525+
70526+ /* everything relevant is now saved off, copy in the new policy */
70527+ if (init_variables(args, true)) {
70528+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_INITF_ACL_MSG, GR_VERSION);
70529+ err = -ENOMEM;
70530+ goto error;
70531+ }
70532+
70533+ err = copy_user_acl(args);
70534+ free_init_variables();
70535+ if (err)
70536+ goto error;
70537+ /* the new policy is copied in, with the old policy available via saved_state
70538+ first go through applying roles, making sure to preserve special roles
70539+ then apply new subjects, making sure to preserve inherited and nested subjects,
70540+ though currently only inherited subjects will be preserved
70541+ */
70542+ err = stop_machine(gracl_reload_apply_policies, &new_reload_state, NULL);
70543+ if (err)
70544+ goto error;
70545+
70546+ /* we've now applied the new policy, so restore the old policy state to free it */
70547+ polstate = &new_reload_state.oldpolicy;
70548+ current_alloc_state = &new_reload_state.oldalloc;
70549+ free_variables(true);
70550+
70551+ /* oldpolicy/oldalloc_ptr point to the new policy/alloc states as they were copied
70552+ to running_polstate/current_alloc_state inside stop_machine
70553+ */
70554+ err = 0;
70555+ goto out;
70556+error:
70557+ /* on error of loading the new policy, we'll just keep the previous
70558+ policy set around
70559+ */
70560+ free_variables(true);
70561+
70562+ /* doesn't affect runtime, but maintains consistent state */
70563+out:
70564+ polstate = new_reload_state.oldpolicy_ptr;
70565+ current_alloc_state = new_reload_state.oldalloc_ptr;
70566+
70567+ return err;
70568+}
70569+
70570+static int
70571+gracl_init(struct gr_arg *args)
70572+{
70573+ int error = 0;
70574+
70575+ memcpy(&gr_system_salt, args->salt, sizeof(gr_system_salt));
70576+ memcpy(&gr_system_sum, args->sum, sizeof(gr_system_sum));
70577+
70578+ if (init_variables(args, false)) {
70579+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_INITF_ACL_MSG, GR_VERSION);
70580+ error = -ENOMEM;
70581+ goto out;
70582+ }
70583+
70584+ error = copy_user_acl(args);
70585+ free_init_variables();
70586+ if (error)
70587+ goto out;
70588+
70589+ error = gr_set_acls(0);
70590+ if (error)
70591+ goto out;
70592+
70593+ gr_enable_rbac_system();
70594+
70595+ return 0;
70596+
70597+out:
70598+ free_variables(false);
70599+ return error;
70600+}
70601+
70602+static int
70603+lookup_special_role_auth(__u16 mode, const char *rolename, unsigned char **salt,
70604+ unsigned char **sum)
70605+{
70606+ struct acl_role_label *r;
70607+ struct role_allowed_ip *ipp;
70608+ struct role_transition *trans;
70609+ unsigned int i;
70610+ int found = 0;
70611+ u32 curr_ip = current->signal->curr_ip;
70612+
70613+ current->signal->saved_ip = curr_ip;
70614+
70615+ /* check transition table */
70616+
70617+ for (trans = current->role->transitions; trans; trans = trans->next) {
70618+ if (!strcmp(rolename, trans->rolename)) {
70619+ found = 1;
70620+ break;
70621+ }
70622+ }
70623+
70624+ if (!found)
70625+ return 0;
70626+
70627+ /* handle special roles that do not require authentication
70628+ and check ip */
70629+
70630+ FOR_EACH_ROLE_START(r)
70631+ if (!strcmp(rolename, r->rolename) &&
70632+ (r->roletype & GR_ROLE_SPECIAL)) {
70633+ found = 0;
70634+ if (r->allowed_ips != NULL) {
70635+ for (ipp = r->allowed_ips; ipp; ipp = ipp->next) {
70636+ if ((ntohl(curr_ip) & ipp->netmask) ==
70637+ (ntohl(ipp->addr) & ipp->netmask))
70638+ found = 1;
70639+ }
70640+ } else
70641+ found = 2;
70642+ if (!found)
70643+ return 0;
70644+
70645+ if (((mode == GR_SPROLE) && (r->roletype & GR_ROLE_NOPW)) ||
70646+ ((mode == GR_SPROLEPAM) && (r->roletype & GR_ROLE_PAM))) {
70647+ *salt = NULL;
70648+ *sum = NULL;
70649+ return 1;
70650+ }
70651+ }
70652+ FOR_EACH_ROLE_END(r)
70653+
70654+ for (i = 0; i < polstate->num_sprole_pws; i++) {
70655+ if (!strcmp(rolename, polstate->acl_special_roles[i]->rolename)) {
70656+ *salt = polstate->acl_special_roles[i]->salt;
70657+ *sum = polstate->acl_special_roles[i]->sum;
70658+ return 1;
70659+ }
70660+ }
70661+
70662+ return 0;
70663+}
70664+
70665+int gr_check_secure_terminal(struct task_struct *task)
70666+{
70667+ struct task_struct *p, *p2, *p3;
70668+ struct files_struct *files;
70669+ struct fdtable *fdt;
70670+ struct file *our_file = NULL, *file;
70671+ int i;
70672+
70673+ if (task->signal->tty == NULL)
70674+ return 1;
70675+
70676+ files = get_files_struct(task);
70677+ if (files != NULL) {
70678+ rcu_read_lock();
70679+ fdt = files_fdtable(files);
70680+ for (i=0; i < fdt->max_fds; i++) {
70681+ file = fcheck_files(files, i);
70682+ if (file && (our_file == NULL) && (file->private_data == task->signal->tty)) {
70683+ get_file(file);
70684+ our_file = file;
70685+ }
70686+ }
70687+ rcu_read_unlock();
70688+ put_files_struct(files);
70689+ }
70690+
70691+ if (our_file == NULL)
70692+ return 1;
70693+
70694+ read_lock(&tasklist_lock);
70695+ do_each_thread(p2, p) {
70696+ files = get_files_struct(p);
70697+ if (files == NULL ||
70698+ (p->signal && p->signal->tty == task->signal->tty)) {
70699+ if (files != NULL)
70700+ put_files_struct(files);
70701+ continue;
70702+ }
70703+ rcu_read_lock();
70704+ fdt = files_fdtable(files);
70705+ for (i=0; i < fdt->max_fds; i++) {
70706+ file = fcheck_files(files, i);
70707+ if (file && S_ISCHR(file->f_path.dentry->d_inode->i_mode) &&
70708+ file->f_path.dentry->d_inode->i_rdev == our_file->f_path.dentry->d_inode->i_rdev) {
70709+ p3 = task;
70710+ while (task_pid_nr(p3) > 0) {
70711+ if (p3 == p)
70712+ break;
70713+ p3 = p3->real_parent;
70714+ }
70715+ if (p3 == p)
70716+ break;
70717+ gr_log_ttysniff(GR_DONT_AUDIT_GOOD, GR_TTYSNIFF_ACL_MSG, p);
70718+ gr_handle_alertkill(p);
70719+ rcu_read_unlock();
70720+ put_files_struct(files);
70721+ read_unlock(&tasklist_lock);
70722+ fput(our_file);
70723+ return 0;
70724+ }
70725+ }
70726+ rcu_read_unlock();
70727+ put_files_struct(files);
70728+ } while_each_thread(p2, p);
70729+ read_unlock(&tasklist_lock);
70730+
70731+ fput(our_file);
70732+ return 1;
70733+}
70734+
70735+ssize_t
70736+write_grsec_handler(struct file *file, const char __user * buf, size_t count, loff_t *ppos)
70737+{
70738+ struct gr_arg_wrapper uwrap;
70739+ unsigned char *sprole_salt = NULL;
70740+ unsigned char *sprole_sum = NULL;
70741+ int error = 0;
70742+ int error2 = 0;
70743+ size_t req_count = 0;
70744+ unsigned char oldmode = 0;
70745+
70746+ mutex_lock(&gr_dev_mutex);
70747+
70748+ if (gr_acl_is_enabled() && !(current->acl->mode & GR_KERNELAUTH)) {
70749+ error = -EPERM;
70750+ goto out;
70751+ }
70752+
70753+#ifdef CONFIG_COMPAT
70754+ pax_open_kernel();
70755+ if (is_compat_task()) {
70756+ copy_gr_arg_wrapper = &copy_gr_arg_wrapper_compat;
70757+ copy_gr_arg = &copy_gr_arg_compat;
70758+ copy_acl_object_label = &copy_acl_object_label_compat;
70759+ copy_acl_subject_label = &copy_acl_subject_label_compat;
70760+ copy_acl_role_label = &copy_acl_role_label_compat;
70761+ copy_acl_ip_label = &copy_acl_ip_label_compat;
70762+ copy_role_allowed_ip = &copy_role_allowed_ip_compat;
70763+ copy_role_transition = &copy_role_transition_compat;
70764+ copy_sprole_pw = &copy_sprole_pw_compat;
70765+ copy_gr_hash_struct = &copy_gr_hash_struct_compat;
70766+ copy_pointer_from_array = &copy_pointer_from_array_compat;
70767+ get_gr_arg_wrapper_size = &get_gr_arg_wrapper_size_compat;
70768+ } else {
70769+ copy_gr_arg_wrapper = &copy_gr_arg_wrapper_normal;
70770+ copy_gr_arg = &copy_gr_arg_normal;
70771+ copy_acl_object_label = &copy_acl_object_label_normal;
70772+ copy_acl_subject_label = &copy_acl_subject_label_normal;
70773+ copy_acl_role_label = &copy_acl_role_label_normal;
70774+ copy_acl_ip_label = &copy_acl_ip_label_normal;
70775+ copy_role_allowed_ip = &copy_role_allowed_ip_normal;
70776+ copy_role_transition = &copy_role_transition_normal;
70777+ copy_sprole_pw = &copy_sprole_pw_normal;
70778+ copy_gr_hash_struct = &copy_gr_hash_struct_normal;
70779+ copy_pointer_from_array = &copy_pointer_from_array_normal;
70780+ get_gr_arg_wrapper_size = &get_gr_arg_wrapper_size_normal;
70781+ }
70782+ pax_close_kernel();
70783+#endif
70784+
70785+ req_count = get_gr_arg_wrapper_size();
70786+
70787+ if (count != req_count) {
70788+ gr_log_int_int(GR_DONT_AUDIT_GOOD, GR_DEV_ACL_MSG, (int)count, (int)req_count);
70789+ error = -EINVAL;
70790+ goto out;
70791+ }
70792+
70793+
70794+ if (gr_auth_expires && time_after_eq(get_seconds(), gr_auth_expires)) {
70795+ gr_auth_expires = 0;
70796+ gr_auth_attempts = 0;
70797+ }
70798+
70799+ error = copy_gr_arg_wrapper(buf, &uwrap);
70800+ if (error)
70801+ goto out;
70802+
70803+ error = copy_gr_arg(uwrap.arg, &gr_usermode);
70804+ if (error)
70805+ goto out;
70806+
70807+ if (gr_usermode.mode != GR_SPROLE && gr_usermode.mode != GR_SPROLEPAM &&
70808+ gr_auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
70809+ time_after(gr_auth_expires, get_seconds())) {
70810+ error = -EBUSY;
70811+ goto out;
70812+ }
70813+
70814+ /* if non-root trying to do anything other than use a special role,
70815+ do not attempt authentication, do not count towards authentication
70816+ locking
70817+ */
70818+
70819+ if (gr_usermode.mode != GR_SPROLE && gr_usermode.mode != GR_STATUS &&
70820+ gr_usermode.mode != GR_UNSPROLE && gr_usermode.mode != GR_SPROLEPAM &&
70821+ gr_is_global_nonroot(current_uid())) {
70822+ error = -EPERM;
70823+ goto out;
70824+ }
70825+
70826+ /* ensure pw and special role name are null terminated */
70827+
70828+ gr_usermode.pw[GR_PW_LEN - 1] = '\0';
70829+ gr_usermode.sp_role[GR_SPROLE_LEN - 1] = '\0';
70830+
70831+ /* Okay.
70832+ * We have our enough of the argument structure..(we have yet
70833+ * to copy_from_user the tables themselves) . Copy the tables
70834+ * only if we need them, i.e. for loading operations. */
70835+
70836+ switch (gr_usermode.mode) {
70837+ case GR_STATUS:
70838+ if (gr_acl_is_enabled()) {
70839+ error = 1;
70840+ if (!gr_check_secure_terminal(current))
70841+ error = 3;
70842+ } else
70843+ error = 2;
70844+ goto out;
70845+ case GR_SHUTDOWN:
70846+ if (gr_acl_is_enabled() && !(chkpw(&gr_usermode, (unsigned char *)&gr_system_salt, (unsigned char *)&gr_system_sum))) {
70847+ stop_machine(gr_rbac_disable, NULL, NULL);
70848+ free_variables(false);
70849+ memset(&gr_usermode, 0, sizeof(gr_usermode));
70850+ memset(&gr_system_salt, 0, sizeof(gr_system_salt));
70851+ memset(&gr_system_sum, 0, sizeof(gr_system_sum));
70852+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTS_ACL_MSG);
70853+ } else if (gr_acl_is_enabled()) {
70854+ gr_log_noargs(GR_DONT_AUDIT, GR_SHUTF_ACL_MSG);
70855+ error = -EPERM;
70856+ } else {
70857+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTI_ACL_MSG);
70858+ error = -EAGAIN;
70859+ }
70860+ break;
70861+ case GR_ENABLE:
70862+ if (!gr_acl_is_enabled() && !(error2 = gracl_init(&gr_usermode)))
70863+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_ENABLE_ACL_MSG, GR_VERSION);
70864+ else {
70865+ if (gr_acl_is_enabled())
70866+ error = -EAGAIN;
70867+ else
70868+ error = error2;
70869+ gr_log_str(GR_DONT_AUDIT, GR_ENABLEF_ACL_MSG, GR_VERSION);
70870+ }
70871+ break;
70872+ case GR_OLDRELOAD:
70873+ oldmode = 1;
70874+ case GR_RELOAD:
70875+ if (!gr_acl_is_enabled()) {
70876+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOADI_ACL_MSG, GR_VERSION);
70877+ error = -EAGAIN;
70878+ } else if (!(chkpw(&gr_usermode, (unsigned char *)&gr_system_salt, (unsigned char *)&gr_system_sum))) {
70879+ error2 = gracl_reload(&gr_usermode, oldmode);
70880+ if (!error2)
70881+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOAD_ACL_MSG, GR_VERSION);
70882+ else {
70883+ gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
70884+ error = error2;
70885+ }
70886+ } else {
70887+ gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
70888+ error = -EPERM;
70889+ }
70890+ break;
70891+ case GR_SEGVMOD:
70892+ if (unlikely(!gr_acl_is_enabled())) {
70893+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODI_ACL_MSG);
70894+ error = -EAGAIN;
70895+ break;
70896+ }
70897+
70898+ if (!(chkpw(&gr_usermode, (unsigned char *)&gr_system_salt, (unsigned char *)&gr_system_sum))) {
70899+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODS_ACL_MSG);
70900+ if (gr_usermode.segv_device && gr_usermode.segv_inode) {
70901+ struct acl_subject_label *segvacl;
70902+ segvacl =
70903+ lookup_acl_subj_label(gr_usermode.segv_inode,
70904+ gr_usermode.segv_device,
70905+ current->role);
70906+ if (segvacl) {
70907+ segvacl->crashes = 0;
70908+ segvacl->expires = 0;
70909+ }
70910+ } else if (gr_find_uid(gr_usermode.segv_uid) >= 0) {
70911+ gr_remove_uid(gr_usermode.segv_uid);
70912+ }
70913+ } else {
70914+ gr_log_noargs(GR_DONT_AUDIT, GR_SEGVMODF_ACL_MSG);
70915+ error = -EPERM;
70916+ }
70917+ break;
70918+ case GR_SPROLE:
70919+ case GR_SPROLEPAM:
70920+ if (unlikely(!gr_acl_is_enabled())) {
70921+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SPROLEI_ACL_MSG);
70922+ error = -EAGAIN;
70923+ break;
70924+ }
70925+
70926+ if (current->role->expires && time_after_eq(get_seconds(), current->role->expires)) {
70927+ current->role->expires = 0;
70928+ current->role->auth_attempts = 0;
70929+ }
70930+
70931+ if (current->role->auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
70932+ time_after(current->role->expires, get_seconds())) {
70933+ error = -EBUSY;
70934+ goto out;
70935+ }
70936+
70937+ if (lookup_special_role_auth
70938+ (gr_usermode.mode, gr_usermode.sp_role, &sprole_salt, &sprole_sum)
70939+ && ((!sprole_salt && !sprole_sum)
70940+ || !(chkpw(&gr_usermode, sprole_salt, sprole_sum)))) {
70941+ char *p = "";
70942+ assign_special_role(gr_usermode.sp_role);
70943+ read_lock(&tasklist_lock);
70944+ if (current->real_parent)
70945+ p = current->real_parent->role->rolename;
70946+ read_unlock(&tasklist_lock);
70947+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLES_ACL_MSG,
70948+ p, acl_sp_role_value);
70949+ } else {
70950+ gr_log_str(GR_DONT_AUDIT, GR_SPROLEF_ACL_MSG, gr_usermode.sp_role);
70951+ error = -EPERM;
70952+ if(!(current->role->auth_attempts++))
70953+ current->role->expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
70954+
70955+ goto out;
70956+ }
70957+ break;
70958+ case GR_UNSPROLE:
70959+ if (unlikely(!gr_acl_is_enabled())) {
70960+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_UNSPROLEI_ACL_MSG);
70961+ error = -EAGAIN;
70962+ break;
70963+ }
70964+
70965+ if (current->role->roletype & GR_ROLE_SPECIAL) {
70966+ char *p = "";
70967+ int i = 0;
70968+
70969+ read_lock(&tasklist_lock);
70970+ if (current->real_parent) {
70971+ p = current->real_parent->role->rolename;
70972+ i = current->real_parent->acl_role_id;
70973+ }
70974+ read_unlock(&tasklist_lock);
70975+
70976+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_UNSPROLES_ACL_MSG, p, i);
70977+ gr_set_acls(1);
70978+ } else {
70979+ error = -EPERM;
70980+ goto out;
70981+ }
70982+ break;
70983+ default:
70984+ gr_log_int(GR_DONT_AUDIT, GR_INVMODE_ACL_MSG, gr_usermode.mode);
70985+ error = -EINVAL;
70986+ break;
70987+ }
70988+
70989+ if (error != -EPERM)
70990+ goto out;
70991+
70992+ if(!(gr_auth_attempts++))
70993+ gr_auth_expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
70994+
70995+ out:
70996+ mutex_unlock(&gr_dev_mutex);
70997+
70998+ if (!error)
70999+ error = req_count;
71000+
71001+ return error;
71002+}
71003+
71004+int
71005+gr_set_acls(const int type)
71006+{
71007+ struct task_struct *task, *task2;
71008+ struct acl_role_label *role = current->role;
71009+ struct acl_subject_label *subj;
71010+ __u16 acl_role_id = current->acl_role_id;
71011+ const struct cred *cred;
71012+ int ret;
71013+
71014+ rcu_read_lock();
71015+ read_lock(&tasklist_lock);
71016+ read_lock(&grsec_exec_file_lock);
71017+ do_each_thread(task2, task) {
71018+ /* check to see if we're called from the exit handler,
71019+ if so, only replace ACLs that have inherited the admin
71020+ ACL */
71021+
71022+ if (type && (task->role != role ||
71023+ task->acl_role_id != acl_role_id))
71024+ continue;
71025+
71026+ task->acl_role_id = 0;
71027+ task->acl_sp_role = 0;
71028+ task->inherited = 0;
71029+
71030+ if (task->exec_file) {
71031+ cred = __task_cred(task);
71032+ task->role = __lookup_acl_role_label(polstate, task, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid));
71033+ subj = __gr_get_subject_for_task(polstate, task, NULL);
71034+ if (subj == NULL) {
71035+ ret = -EINVAL;
71036+ read_unlock(&grsec_exec_file_lock);
71037+ read_unlock(&tasklist_lock);
71038+ rcu_read_unlock();
71039+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_DEFACL_MSG, task->comm, task_pid_nr(task));
71040+ return ret;
71041+ }
71042+ __gr_apply_subject_to_task(polstate, task, subj);
71043+ } else {
71044+ // it's a kernel process
71045+ task->role = polstate->kernel_role;
71046+ task->acl = polstate->kernel_role->root_label;
71047+#ifdef CONFIG_GRKERNSEC_ACL_HIDEKERN
71048+ task->acl->mode &= ~GR_PROCFIND;
71049+#endif
71050+ }
71051+ } while_each_thread(task2, task);
71052+ read_unlock(&grsec_exec_file_lock);
71053+ read_unlock(&tasklist_lock);
71054+ rcu_read_unlock();
71055+
71056+ return 0;
71057+}
71058diff --git a/grsecurity/gracl_res.c b/grsecurity/gracl_res.c
71059new file mode 100644
71060index 0000000..39645c9
71061--- /dev/null
71062+++ b/grsecurity/gracl_res.c
71063@@ -0,0 +1,68 @@
71064+#include <linux/kernel.h>
71065+#include <linux/sched.h>
71066+#include <linux/gracl.h>
71067+#include <linux/grinternal.h>
71068+
71069+static const char *restab_log[] = {
71070+ [RLIMIT_CPU] = "RLIMIT_CPU",
71071+ [RLIMIT_FSIZE] = "RLIMIT_FSIZE",
71072+ [RLIMIT_DATA] = "RLIMIT_DATA",
71073+ [RLIMIT_STACK] = "RLIMIT_STACK",
71074+ [RLIMIT_CORE] = "RLIMIT_CORE",
71075+ [RLIMIT_RSS] = "RLIMIT_RSS",
71076+ [RLIMIT_NPROC] = "RLIMIT_NPROC",
71077+ [RLIMIT_NOFILE] = "RLIMIT_NOFILE",
71078+ [RLIMIT_MEMLOCK] = "RLIMIT_MEMLOCK",
71079+ [RLIMIT_AS] = "RLIMIT_AS",
71080+ [RLIMIT_LOCKS] = "RLIMIT_LOCKS",
71081+ [RLIMIT_SIGPENDING] = "RLIMIT_SIGPENDING",
71082+ [RLIMIT_MSGQUEUE] = "RLIMIT_MSGQUEUE",
71083+ [RLIMIT_NICE] = "RLIMIT_NICE",
71084+ [RLIMIT_RTPRIO] = "RLIMIT_RTPRIO",
71085+ [RLIMIT_RTTIME] = "RLIMIT_RTTIME",
71086+ [GR_CRASH_RES] = "RLIMIT_CRASH"
71087+};
71088+
71089+void
71090+gr_log_resource(const struct task_struct *task,
71091+ const int res, const unsigned long wanted, const int gt)
71092+{
71093+ const struct cred *cred;
71094+ unsigned long rlim;
71095+
71096+ if (!gr_acl_is_enabled() && !grsec_resource_logging)
71097+ return;
71098+
71099+ // not yet supported resource
71100+ if (unlikely(!restab_log[res]))
71101+ return;
71102+
71103+ if (res == RLIMIT_CPU || res == RLIMIT_RTTIME)
71104+ rlim = task_rlimit_max(task, res);
71105+ else
71106+ rlim = task_rlimit(task, res);
71107+
71108+ if (likely((rlim == RLIM_INFINITY) || (gt && wanted <= rlim) || (!gt && wanted < rlim)))
71109+ return;
71110+
71111+ rcu_read_lock();
71112+ cred = __task_cred(task);
71113+
71114+ if (res == RLIMIT_NPROC &&
71115+ (cap_raised(cred->cap_effective, CAP_SYS_ADMIN) ||
71116+ cap_raised(cred->cap_effective, CAP_SYS_RESOURCE)))
71117+ goto out_rcu_unlock;
71118+ else if (res == RLIMIT_MEMLOCK &&
71119+ cap_raised(cred->cap_effective, CAP_IPC_LOCK))
71120+ goto out_rcu_unlock;
71121+ else if (res == RLIMIT_NICE && cap_raised(cred->cap_effective, CAP_SYS_NICE))
71122+ goto out_rcu_unlock;
71123+ rcu_read_unlock();
71124+
71125+ gr_log_res_ulong2_str(GR_DONT_AUDIT, GR_RESOURCE_MSG, task, wanted, restab_log[res], rlim);
71126+
71127+ return;
71128+out_rcu_unlock:
71129+ rcu_read_unlock();
71130+ return;
71131+}
71132diff --git a/grsecurity/gracl_segv.c b/grsecurity/gracl_segv.c
71133new file mode 100644
71134index 0000000..2040e61
71135--- /dev/null
71136+++ b/grsecurity/gracl_segv.c
71137@@ -0,0 +1,313 @@
71138+#include <linux/kernel.h>
71139+#include <linux/mm.h>
71140+#include <asm/uaccess.h>
71141+#include <asm/errno.h>
71142+#include <asm/mman.h>
71143+#include <net/sock.h>
71144+#include <linux/file.h>
71145+#include <linux/fs.h>
71146+#include <linux/net.h>
71147+#include <linux/in.h>
71148+#include <linux/slab.h>
71149+#include <linux/types.h>
71150+#include <linux/sched.h>
71151+#include <linux/timer.h>
71152+#include <linux/gracl.h>
71153+#include <linux/grsecurity.h>
71154+#include <linux/grinternal.h>
71155+#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
71156+#include <linux/magic.h>
71157+#include <linux/pagemap.h>
71158+#include "../fs/btrfs/async-thread.h"
71159+#include "../fs/btrfs/ctree.h"
71160+#include "../fs/btrfs/btrfs_inode.h"
71161+#endif
71162+
71163+static struct crash_uid *uid_set;
71164+static unsigned short uid_used;
71165+static DEFINE_SPINLOCK(gr_uid_lock);
71166+extern rwlock_t gr_inode_lock;
71167+extern struct acl_subject_label *
71168+ lookup_acl_subj_label(const ino_t inode, const dev_t dev,
71169+ struct acl_role_label *role);
71170+
71171+static inline dev_t __get_dev(const struct dentry *dentry)
71172+{
71173+#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
71174+ if (dentry->d_sb->s_magic == BTRFS_SUPER_MAGIC)
71175+ return BTRFS_I(dentry->d_inode)->root->anon_dev;
71176+ else
71177+#endif
71178+ return dentry->d_sb->s_dev;
71179+}
71180+
71181+int
71182+gr_init_uidset(void)
71183+{
71184+ uid_set =
71185+ kmalloc(GR_UIDTABLE_MAX * sizeof (struct crash_uid), GFP_KERNEL);
71186+ uid_used = 0;
71187+
71188+ return uid_set ? 1 : 0;
71189+}
71190+
71191+void
71192+gr_free_uidset(void)
71193+{
71194+ if (uid_set) {
71195+ struct crash_uid *tmpset;
71196+ spin_lock(&gr_uid_lock);
71197+ tmpset = uid_set;
71198+ uid_set = NULL;
71199+ uid_used = 0;
71200+ spin_unlock(&gr_uid_lock);
71201+ if (tmpset)
71202+ kfree(tmpset);
71203+ }
71204+
71205+ return;
71206+}
71207+
71208+int
71209+gr_find_uid(const uid_t uid)
71210+{
71211+ struct crash_uid *tmp = uid_set;
71212+ uid_t buid;
71213+ int low = 0, high = uid_used - 1, mid;
71214+
71215+ while (high >= low) {
71216+ mid = (low + high) >> 1;
71217+ buid = tmp[mid].uid;
71218+ if (buid == uid)
71219+ return mid;
71220+ if (buid > uid)
71221+ high = mid - 1;
71222+ if (buid < uid)
71223+ low = mid + 1;
71224+ }
71225+
71226+ return -1;
71227+}
71228+
71229+static __inline__ void
71230+gr_insertsort(void)
71231+{
71232+ unsigned short i, j;
71233+ struct crash_uid index;
71234+
71235+ for (i = 1; i < uid_used; i++) {
71236+ index = uid_set[i];
71237+ j = i;
71238+ while ((j > 0) && uid_set[j - 1].uid > index.uid) {
71239+ uid_set[j] = uid_set[j - 1];
71240+ j--;
71241+ }
71242+ uid_set[j] = index;
71243+ }
71244+
71245+ return;
71246+}
71247+
71248+static __inline__ void
71249+gr_insert_uid(const kuid_t kuid, const unsigned long expires)
71250+{
71251+ int loc;
71252+ uid_t uid = GR_GLOBAL_UID(kuid);
71253+
71254+ if (uid_used == GR_UIDTABLE_MAX)
71255+ return;
71256+
71257+ loc = gr_find_uid(uid);
71258+
71259+ if (loc >= 0) {
71260+ uid_set[loc].expires = expires;
71261+ return;
71262+ }
71263+
71264+ uid_set[uid_used].uid = uid;
71265+ uid_set[uid_used].expires = expires;
71266+ uid_used++;
71267+
71268+ gr_insertsort();
71269+
71270+ return;
71271+}
71272+
71273+void
71274+gr_remove_uid(const unsigned short loc)
71275+{
71276+ unsigned short i;
71277+
71278+ for (i = loc + 1; i < uid_used; i++)
71279+ uid_set[i - 1] = uid_set[i];
71280+
71281+ uid_used--;
71282+
71283+ return;
71284+}
71285+
71286+int
71287+gr_check_crash_uid(const kuid_t kuid)
71288+{
71289+ int loc;
71290+ int ret = 0;
71291+ uid_t uid;
71292+
71293+ if (unlikely(!gr_acl_is_enabled()))
71294+ return 0;
71295+
71296+ uid = GR_GLOBAL_UID(kuid);
71297+
71298+ spin_lock(&gr_uid_lock);
71299+ loc = gr_find_uid(uid);
71300+
71301+ if (loc < 0)
71302+ goto out_unlock;
71303+
71304+ if (time_before_eq(uid_set[loc].expires, get_seconds()))
71305+ gr_remove_uid(loc);
71306+ else
71307+ ret = 1;
71308+
71309+out_unlock:
71310+ spin_unlock(&gr_uid_lock);
71311+ return ret;
71312+}
71313+
71314+static __inline__ int
71315+proc_is_setxid(const struct cred *cred)
71316+{
71317+ if (!uid_eq(cred->uid, cred->euid) || !uid_eq(cred->uid, cred->suid) ||
71318+ !uid_eq(cred->uid, cred->fsuid))
71319+ return 1;
71320+ if (!gid_eq(cred->gid, cred->egid) || !gid_eq(cred->gid, cred->sgid) ||
71321+ !gid_eq(cred->gid, cred->fsgid))
71322+ return 1;
71323+
71324+ return 0;
71325+}
71326+
71327+extern int gr_fake_force_sig(int sig, struct task_struct *t);
71328+
71329+void
71330+gr_handle_crash(struct task_struct *task, const int sig)
71331+{
71332+ struct acl_subject_label *curr;
71333+ struct task_struct *tsk, *tsk2;
71334+ const struct cred *cred;
71335+ const struct cred *cred2;
71336+
71337+ if (sig != SIGSEGV && sig != SIGKILL && sig != SIGBUS && sig != SIGILL)
71338+ return;
71339+
71340+ if (unlikely(!gr_acl_is_enabled()))
71341+ return;
71342+
71343+ curr = task->acl;
71344+
71345+ if (!(curr->resmask & (1U << GR_CRASH_RES)))
71346+ return;
71347+
71348+ if (time_before_eq(curr->expires, get_seconds())) {
71349+ curr->expires = 0;
71350+ curr->crashes = 0;
71351+ }
71352+
71353+ curr->crashes++;
71354+
71355+ if (!curr->expires)
71356+ curr->expires = get_seconds() + curr->res[GR_CRASH_RES].rlim_max;
71357+
71358+ if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
71359+ time_after(curr->expires, get_seconds())) {
71360+ rcu_read_lock();
71361+ cred = __task_cred(task);
71362+ if (gr_is_global_nonroot(cred->uid) && proc_is_setxid(cred)) {
71363+ gr_log_crash1(GR_DONT_AUDIT, GR_SEGVSTART_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
71364+ spin_lock(&gr_uid_lock);
71365+ gr_insert_uid(cred->uid, curr->expires);
71366+ spin_unlock(&gr_uid_lock);
71367+ curr->expires = 0;
71368+ curr->crashes = 0;
71369+ read_lock(&tasklist_lock);
71370+ do_each_thread(tsk2, tsk) {
71371+ cred2 = __task_cred(tsk);
71372+ if (tsk != task && uid_eq(cred2->uid, cred->uid))
71373+ gr_fake_force_sig(SIGKILL, tsk);
71374+ } while_each_thread(tsk2, tsk);
71375+ read_unlock(&tasklist_lock);
71376+ } else {
71377+ gr_log_crash2(GR_DONT_AUDIT, GR_SEGVNOSUID_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
71378+ read_lock(&tasklist_lock);
71379+ read_lock(&grsec_exec_file_lock);
71380+ do_each_thread(tsk2, tsk) {
71381+ if (likely(tsk != task)) {
71382+ // if this thread has the same subject as the one that triggered
71383+ // RES_CRASH and it's the same binary, kill it
71384+ if (tsk->acl == task->acl && gr_is_same_file(tsk->exec_file, task->exec_file))
71385+ gr_fake_force_sig(SIGKILL, tsk);
71386+ }
71387+ } while_each_thread(tsk2, tsk);
71388+ read_unlock(&grsec_exec_file_lock);
71389+ read_unlock(&tasklist_lock);
71390+ }
71391+ rcu_read_unlock();
71392+ }
71393+
71394+ return;
71395+}
71396+
71397+int
71398+gr_check_crash_exec(const struct file *filp)
71399+{
71400+ struct acl_subject_label *curr;
71401+
71402+ if (unlikely(!gr_acl_is_enabled()))
71403+ return 0;
71404+
71405+ read_lock(&gr_inode_lock);
71406+ curr = lookup_acl_subj_label(filp->f_path.dentry->d_inode->i_ino,
71407+ __get_dev(filp->f_path.dentry),
71408+ current->role);
71409+ read_unlock(&gr_inode_lock);
71410+
71411+ if (!curr || !(curr->resmask & (1U << GR_CRASH_RES)) ||
71412+ (!curr->crashes && !curr->expires))
71413+ return 0;
71414+
71415+ if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
71416+ time_after(curr->expires, get_seconds()))
71417+ return 1;
71418+ else if (time_before_eq(curr->expires, get_seconds())) {
71419+ curr->crashes = 0;
71420+ curr->expires = 0;
71421+ }
71422+
71423+ return 0;
71424+}
71425+
71426+void
71427+gr_handle_alertkill(struct task_struct *task)
71428+{
71429+ struct acl_subject_label *curracl;
71430+ __u32 curr_ip;
71431+ struct task_struct *p, *p2;
71432+
71433+ if (unlikely(!gr_acl_is_enabled()))
71434+ return;
71435+
71436+ curracl = task->acl;
71437+ curr_ip = task->signal->curr_ip;
71438+
71439+ if ((curracl->mode & GR_KILLIPPROC) && curr_ip) {
71440+ read_lock(&tasklist_lock);
71441+ do_each_thread(p2, p) {
71442+ if (p->signal->curr_ip == curr_ip)
71443+ gr_fake_force_sig(SIGKILL, p);
71444+ } while_each_thread(p2, p);
71445+ read_unlock(&tasklist_lock);
71446+ } else if (curracl->mode & GR_KILLPROC)
71447+ gr_fake_force_sig(SIGKILL, task);
71448+
71449+ return;
71450+}
71451diff --git a/grsecurity/gracl_shm.c b/grsecurity/gracl_shm.c
71452new file mode 100644
71453index 0000000..98011b0
71454--- /dev/null
71455+++ b/grsecurity/gracl_shm.c
71456@@ -0,0 +1,40 @@
71457+#include <linux/kernel.h>
71458+#include <linux/mm.h>
71459+#include <linux/sched.h>
71460+#include <linux/file.h>
71461+#include <linux/ipc.h>
71462+#include <linux/gracl.h>
71463+#include <linux/grsecurity.h>
71464+#include <linux/grinternal.h>
71465+
71466+int
71467+gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
71468+ const time_t shm_createtime, const kuid_t cuid, const int shmid)
71469+{
71470+ struct task_struct *task;
71471+
71472+ if (!gr_acl_is_enabled())
71473+ return 1;
71474+
71475+ rcu_read_lock();
71476+ read_lock(&tasklist_lock);
71477+
71478+ task = find_task_by_vpid(shm_cprid);
71479+
71480+ if (unlikely(!task))
71481+ task = find_task_by_vpid(shm_lapid);
71482+
71483+ if (unlikely(task && (time_before_eq((unsigned long)task->start_time.tv_sec, (unsigned long)shm_createtime) ||
71484+ (task_pid_nr(task) == shm_lapid)) &&
71485+ (task->acl->mode & GR_PROTSHM) &&
71486+ (task->acl != current->acl))) {
71487+ read_unlock(&tasklist_lock);
71488+ rcu_read_unlock();
71489+ gr_log_int3(GR_DONT_AUDIT, GR_SHMAT_ACL_MSG, GR_GLOBAL_UID(cuid), shm_cprid, shmid);
71490+ return 0;
71491+ }
71492+ read_unlock(&tasklist_lock);
71493+ rcu_read_unlock();
71494+
71495+ return 1;
71496+}
71497diff --git a/grsecurity/grsec_chdir.c b/grsecurity/grsec_chdir.c
71498new file mode 100644
71499index 0000000..bc0be01
71500--- /dev/null
71501+++ b/grsecurity/grsec_chdir.c
71502@@ -0,0 +1,19 @@
71503+#include <linux/kernel.h>
71504+#include <linux/sched.h>
71505+#include <linux/fs.h>
71506+#include <linux/file.h>
71507+#include <linux/grsecurity.h>
71508+#include <linux/grinternal.h>
71509+
71510+void
71511+gr_log_chdir(const struct dentry *dentry, const struct vfsmount *mnt)
71512+{
71513+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
71514+ if ((grsec_enable_chdir && grsec_enable_group &&
71515+ in_group_p(grsec_audit_gid)) || (grsec_enable_chdir &&
71516+ !grsec_enable_group)) {
71517+ gr_log_fs_generic(GR_DO_AUDIT, GR_CHDIR_AUDIT_MSG, dentry, mnt);
71518+ }
71519+#endif
71520+ return;
71521+}
71522diff --git a/grsecurity/grsec_chroot.c b/grsecurity/grsec_chroot.c
71523new file mode 100644
71524index 0000000..e10b319
71525--- /dev/null
71526+++ b/grsecurity/grsec_chroot.c
71527@@ -0,0 +1,370 @@
71528+#include <linux/kernel.h>
71529+#include <linux/module.h>
71530+#include <linux/sched.h>
71531+#include <linux/file.h>
71532+#include <linux/fs.h>
71533+#include <linux/mount.h>
71534+#include <linux/types.h>
71535+#include "../fs/mount.h"
71536+#include <linux/grsecurity.h>
71537+#include <linux/grinternal.h>
71538+
71539+#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
71540+int gr_init_ran;
71541+#endif
71542+
71543+void gr_set_chroot_entries(struct task_struct *task, const struct path *path)
71544+{
71545+#ifdef CONFIG_GRKERNSEC
71546+ if (task_pid_nr(task) > 1 && path->dentry != init_task.fs->root.dentry &&
71547+ path->dentry != task->nsproxy->mnt_ns->root->mnt.mnt_root
71548+#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
71549+ && gr_init_ran
71550+#endif
71551+ )
71552+ task->gr_is_chrooted = 1;
71553+ else {
71554+#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
71555+ if (task_pid_nr(task) == 1 && !gr_init_ran)
71556+ gr_init_ran = 1;
71557+#endif
71558+ task->gr_is_chrooted = 0;
71559+ }
71560+
71561+ task->gr_chroot_dentry = path->dentry;
71562+#endif
71563+ return;
71564+}
71565+
71566+void gr_clear_chroot_entries(struct task_struct *task)
71567+{
71568+#ifdef CONFIG_GRKERNSEC
71569+ task->gr_is_chrooted = 0;
71570+ task->gr_chroot_dentry = NULL;
71571+#endif
71572+ return;
71573+}
71574+
71575+int
71576+gr_handle_chroot_unix(const pid_t pid)
71577+{
71578+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
71579+ struct task_struct *p;
71580+
71581+ if (unlikely(!grsec_enable_chroot_unix))
71582+ return 1;
71583+
71584+ if (likely(!proc_is_chrooted(current)))
71585+ return 1;
71586+
71587+ rcu_read_lock();
71588+ read_lock(&tasklist_lock);
71589+ p = find_task_by_vpid_unrestricted(pid);
71590+ if (unlikely(p && !have_same_root(current, p))) {
71591+ read_unlock(&tasklist_lock);
71592+ rcu_read_unlock();
71593+ gr_log_noargs(GR_DONT_AUDIT, GR_UNIX_CHROOT_MSG);
71594+ return 0;
71595+ }
71596+ read_unlock(&tasklist_lock);
71597+ rcu_read_unlock();
71598+#endif
71599+ return 1;
71600+}
71601+
71602+int
71603+gr_handle_chroot_nice(void)
71604+{
71605+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
71606+ if (grsec_enable_chroot_nice && proc_is_chrooted(current)) {
71607+ gr_log_noargs(GR_DONT_AUDIT, GR_NICE_CHROOT_MSG);
71608+ return -EPERM;
71609+ }
71610+#endif
71611+ return 0;
71612+}
71613+
71614+int
71615+gr_handle_chroot_setpriority(struct task_struct *p, const int niceval)
71616+{
71617+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
71618+ if (grsec_enable_chroot_nice && (niceval < task_nice(p))
71619+ && proc_is_chrooted(current)) {
71620+ gr_log_str_int(GR_DONT_AUDIT, GR_PRIORITY_CHROOT_MSG, p->comm, task_pid_nr(p));
71621+ return -EACCES;
71622+ }
71623+#endif
71624+ return 0;
71625+}
71626+
71627+int
71628+gr_handle_chroot_fowner(struct pid *pid, enum pid_type type)
71629+{
71630+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
71631+ struct task_struct *p;
71632+ int ret = 0;
71633+ if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || !pid)
71634+ return ret;
71635+
71636+ read_lock(&tasklist_lock);
71637+ do_each_pid_task(pid, type, p) {
71638+ if (!have_same_root(current, p)) {
71639+ ret = 1;
71640+ goto out;
71641+ }
71642+ } while_each_pid_task(pid, type, p);
71643+out:
71644+ read_unlock(&tasklist_lock);
71645+ return ret;
71646+#endif
71647+ return 0;
71648+}
71649+
71650+int
71651+gr_pid_is_chrooted(struct task_struct *p)
71652+{
71653+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
71654+ if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || p == NULL)
71655+ return 0;
71656+
71657+ if ((p->exit_state & (EXIT_ZOMBIE | EXIT_DEAD)) ||
71658+ !have_same_root(current, p)) {
71659+ return 1;
71660+ }
71661+#endif
71662+ return 0;
71663+}
71664+
71665+EXPORT_SYMBOL(gr_pid_is_chrooted);
71666+
71667+#if defined(CONFIG_GRKERNSEC_CHROOT_DOUBLE) || defined(CONFIG_GRKERNSEC_CHROOT_FCHDIR)
71668+int gr_is_outside_chroot(const struct dentry *u_dentry, const struct vfsmount *u_mnt)
71669+{
71670+ struct path path, currentroot;
71671+ int ret = 0;
71672+
71673+ path.dentry = (struct dentry *)u_dentry;
71674+ path.mnt = (struct vfsmount *)u_mnt;
71675+ get_fs_root(current->fs, &currentroot);
71676+ if (path_is_under(&path, &currentroot))
71677+ ret = 1;
71678+ path_put(&currentroot);
71679+
71680+ return ret;
71681+}
71682+#endif
71683+
71684+int
71685+gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt)
71686+{
71687+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
71688+ if (!grsec_enable_chroot_fchdir)
71689+ return 1;
71690+
71691+ if (!proc_is_chrooted(current))
71692+ return 1;
71693+ else if (!gr_is_outside_chroot(u_dentry, u_mnt)) {
71694+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_FCHDIR_MSG, u_dentry, u_mnt);
71695+ return 0;
71696+ }
71697+#endif
71698+ return 1;
71699+}
71700+
71701+int
71702+gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
71703+ const time_t shm_createtime)
71704+{
71705+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
71706+ struct task_struct *p;
71707+ time_t starttime;
71708+
71709+ if (unlikely(!grsec_enable_chroot_shmat))
71710+ return 1;
71711+
71712+ if (likely(!proc_is_chrooted(current)))
71713+ return 1;
71714+
71715+ rcu_read_lock();
71716+ read_lock(&tasklist_lock);
71717+
71718+ if ((p = find_task_by_vpid_unrestricted(shm_cprid))) {
71719+ starttime = p->start_time.tv_sec;
71720+ if (time_before_eq((unsigned long)starttime, (unsigned long)shm_createtime)) {
71721+ if (have_same_root(current, p)) {
71722+ goto allow;
71723+ } else {
71724+ read_unlock(&tasklist_lock);
71725+ rcu_read_unlock();
71726+ gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
71727+ return 0;
71728+ }
71729+ }
71730+ /* creator exited, pid reuse, fall through to next check */
71731+ }
71732+ if ((p = find_task_by_vpid_unrestricted(shm_lapid))) {
71733+ if (unlikely(!have_same_root(current, p))) {
71734+ read_unlock(&tasklist_lock);
71735+ rcu_read_unlock();
71736+ gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
71737+ return 0;
71738+ }
71739+ }
71740+
71741+allow:
71742+ read_unlock(&tasklist_lock);
71743+ rcu_read_unlock();
71744+#endif
71745+ return 1;
71746+}
71747+
71748+void
71749+gr_log_chroot_exec(const struct dentry *dentry, const struct vfsmount *mnt)
71750+{
71751+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
71752+ if (grsec_enable_chroot_execlog && proc_is_chrooted(current))
71753+ gr_log_fs_generic(GR_DO_AUDIT, GR_EXEC_CHROOT_MSG, dentry, mnt);
71754+#endif
71755+ return;
71756+}
71757+
71758+int
71759+gr_handle_chroot_mknod(const struct dentry *dentry,
71760+ const struct vfsmount *mnt, const int mode)
71761+{
71762+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
71763+ if (grsec_enable_chroot_mknod && !S_ISFIFO(mode) && !S_ISREG(mode) &&
71764+ proc_is_chrooted(current)) {
71765+ gr_log_fs_generic(GR_DONT_AUDIT, GR_MKNOD_CHROOT_MSG, dentry, mnt);
71766+ return -EPERM;
71767+ }
71768+#endif
71769+ return 0;
71770+}
71771+
71772+int
71773+gr_handle_chroot_mount(const struct dentry *dentry,
71774+ const struct vfsmount *mnt, const char *dev_name)
71775+{
71776+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
71777+ if (grsec_enable_chroot_mount && proc_is_chrooted(current)) {
71778+ gr_log_str_fs(GR_DONT_AUDIT, GR_MOUNT_CHROOT_MSG, dev_name ? dev_name : "none", dentry, mnt);
71779+ return -EPERM;
71780+ }
71781+#endif
71782+ return 0;
71783+}
71784+
71785+int
71786+gr_handle_chroot_pivot(void)
71787+{
71788+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
71789+ if (grsec_enable_chroot_pivot && proc_is_chrooted(current)) {
71790+ gr_log_noargs(GR_DONT_AUDIT, GR_PIVOT_CHROOT_MSG);
71791+ return -EPERM;
71792+ }
71793+#endif
71794+ return 0;
71795+}
71796+
71797+int
71798+gr_handle_chroot_chroot(const struct dentry *dentry, const struct vfsmount *mnt)
71799+{
71800+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
71801+ if (grsec_enable_chroot_double && proc_is_chrooted(current) &&
71802+ !gr_is_outside_chroot(dentry, mnt)) {
71803+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_CHROOT_MSG, dentry, mnt);
71804+ return -EPERM;
71805+ }
71806+#endif
71807+ return 0;
71808+}
71809+
71810+extern const char *captab_log[];
71811+extern int captab_log_entries;
71812+
71813+int
71814+gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
71815+{
71816+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
71817+ if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
71818+ kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
71819+ if (cap_raised(chroot_caps, cap)) {
71820+ if (cap_raised(cred->cap_effective, cap) && cap < captab_log_entries) {
71821+ gr_log_cap(GR_DONT_AUDIT, GR_CAP_CHROOT_MSG, task, captab_log[cap]);
71822+ }
71823+ return 0;
71824+ }
71825+ }
71826+#endif
71827+ return 1;
71828+}
71829+
71830+int
71831+gr_chroot_is_capable(const int cap)
71832+{
71833+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
71834+ return gr_task_chroot_is_capable(current, current_cred(), cap);
71835+#endif
71836+ return 1;
71837+}
71838+
71839+int
71840+gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap)
71841+{
71842+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
71843+ if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
71844+ kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
71845+ if (cap_raised(chroot_caps, cap)) {
71846+ return 0;
71847+ }
71848+ }
71849+#endif
71850+ return 1;
71851+}
71852+
71853+int
71854+gr_chroot_is_capable_nolog(const int cap)
71855+{
71856+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
71857+ return gr_task_chroot_is_capable_nolog(current, cap);
71858+#endif
71859+ return 1;
71860+}
71861+
71862+int
71863+gr_handle_chroot_sysctl(const int op)
71864+{
71865+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
71866+ if (grsec_enable_chroot_sysctl && (op & MAY_WRITE) &&
71867+ proc_is_chrooted(current))
71868+ return -EACCES;
71869+#endif
71870+ return 0;
71871+}
71872+
71873+void
71874+gr_handle_chroot_chdir(const struct path *path)
71875+{
71876+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
71877+ if (grsec_enable_chroot_chdir)
71878+ set_fs_pwd(current->fs, path);
71879+#endif
71880+ return;
71881+}
71882+
71883+int
71884+gr_handle_chroot_chmod(const struct dentry *dentry,
71885+ const struct vfsmount *mnt, const int mode)
71886+{
71887+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
71888+ /* allow chmod +s on directories, but not files */
71889+ if (grsec_enable_chroot_chmod && !S_ISDIR(dentry->d_inode->i_mode) &&
71890+ ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))) &&
71891+ proc_is_chrooted(current)) {
71892+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHMOD_CHROOT_MSG, dentry, mnt);
71893+ return -EPERM;
71894+ }
71895+#endif
71896+ return 0;
71897+}
71898diff --git a/grsecurity/grsec_disabled.c b/grsecurity/grsec_disabled.c
71899new file mode 100644
71900index 0000000..52b3e30
71901--- /dev/null
71902+++ b/grsecurity/grsec_disabled.c
71903@@ -0,0 +1,433 @@
71904+#include <linux/kernel.h>
71905+#include <linux/module.h>
71906+#include <linux/sched.h>
71907+#include <linux/file.h>
71908+#include <linux/fs.h>
71909+#include <linux/kdev_t.h>
71910+#include <linux/net.h>
71911+#include <linux/in.h>
71912+#include <linux/ip.h>
71913+#include <linux/skbuff.h>
71914+#include <linux/sysctl.h>
71915+
71916+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
71917+void
71918+pax_set_initial_flags(struct linux_binprm *bprm)
71919+{
71920+ return;
71921+}
71922+#endif
71923+
71924+#ifdef CONFIG_SYSCTL
71925+__u32
71926+gr_handle_sysctl(const struct ctl_table * table, const int op)
71927+{
71928+ return 0;
71929+}
71930+#endif
71931+
71932+#ifdef CONFIG_TASKSTATS
71933+int gr_is_taskstats_denied(int pid)
71934+{
71935+ return 0;
71936+}
71937+#endif
71938+
71939+int
71940+gr_acl_is_enabled(void)
71941+{
71942+ return 0;
71943+}
71944+
71945+void
71946+gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
71947+{
71948+ return;
71949+}
71950+
71951+int
71952+gr_handle_rawio(const struct inode *inode)
71953+{
71954+ return 0;
71955+}
71956+
71957+void
71958+gr_acl_handle_psacct(struct task_struct *task, const long code)
71959+{
71960+ return;
71961+}
71962+
71963+int
71964+gr_handle_ptrace(struct task_struct *task, const long request)
71965+{
71966+ return 0;
71967+}
71968+
71969+int
71970+gr_handle_proc_ptrace(struct task_struct *task)
71971+{
71972+ return 0;
71973+}
71974+
71975+int
71976+gr_set_acls(const int type)
71977+{
71978+ return 0;
71979+}
71980+
71981+int
71982+gr_check_hidden_task(const struct task_struct *tsk)
71983+{
71984+ return 0;
71985+}
71986+
71987+int
71988+gr_check_protected_task(const struct task_struct *task)
71989+{
71990+ return 0;
71991+}
71992+
71993+int
71994+gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
71995+{
71996+ return 0;
71997+}
71998+
71999+void
72000+gr_copy_label(struct task_struct *tsk)
72001+{
72002+ return;
72003+}
72004+
72005+void
72006+gr_set_pax_flags(struct task_struct *task)
72007+{
72008+ return;
72009+}
72010+
72011+int
72012+gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
72013+ const int unsafe_share)
72014+{
72015+ return 0;
72016+}
72017+
72018+void
72019+gr_handle_delete(const ino_t ino, const dev_t dev)
72020+{
72021+ return;
72022+}
72023+
72024+void
72025+gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
72026+{
72027+ return;
72028+}
72029+
72030+void
72031+gr_handle_crash(struct task_struct *task, const int sig)
72032+{
72033+ return;
72034+}
72035+
72036+int
72037+gr_check_crash_exec(const struct file *filp)
72038+{
72039+ return 0;
72040+}
72041+
72042+int
72043+gr_check_crash_uid(const kuid_t uid)
72044+{
72045+ return 0;
72046+}
72047+
72048+void
72049+gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
72050+ struct dentry *old_dentry,
72051+ struct dentry *new_dentry,
72052+ struct vfsmount *mnt, const __u8 replace)
72053+{
72054+ return;
72055+}
72056+
72057+int
72058+gr_search_socket(const int family, const int type, const int protocol)
72059+{
72060+ return 1;
72061+}
72062+
72063+int
72064+gr_search_connectbind(const int mode, const struct socket *sock,
72065+ const struct sockaddr_in *addr)
72066+{
72067+ return 0;
72068+}
72069+
72070+void
72071+gr_handle_alertkill(struct task_struct *task)
72072+{
72073+ return;
72074+}
72075+
72076+__u32
72077+gr_acl_handle_execve(const struct dentry * dentry, const struct vfsmount * mnt)
72078+{
72079+ return 1;
72080+}
72081+
72082+__u32
72083+gr_acl_handle_hidden_file(const struct dentry * dentry,
72084+ const struct vfsmount * mnt)
72085+{
72086+ return 1;
72087+}
72088+
72089+__u32
72090+gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
72091+ int acc_mode)
72092+{
72093+ return 1;
72094+}
72095+
72096+__u32
72097+gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
72098+{
72099+ return 1;
72100+}
72101+
72102+__u32
72103+gr_acl_handle_unlink(const struct dentry * dentry, const struct vfsmount * mnt)
72104+{
72105+ return 1;
72106+}
72107+
72108+int
72109+gr_acl_handle_mmap(const struct file *file, const unsigned long prot,
72110+ unsigned int *vm_flags)
72111+{
72112+ return 1;
72113+}
72114+
72115+__u32
72116+gr_acl_handle_truncate(const struct dentry * dentry,
72117+ const struct vfsmount * mnt)
72118+{
72119+ return 1;
72120+}
72121+
72122+__u32
72123+gr_acl_handle_utime(const struct dentry * dentry, const struct vfsmount * mnt)
72124+{
72125+ return 1;
72126+}
72127+
72128+__u32
72129+gr_acl_handle_access(const struct dentry * dentry,
72130+ const struct vfsmount * mnt, const int fmode)
72131+{
72132+ return 1;
72133+}
72134+
72135+__u32
72136+gr_acl_handle_chmod(const struct dentry * dentry, const struct vfsmount * mnt,
72137+ umode_t *mode)
72138+{
72139+ return 1;
72140+}
72141+
72142+__u32
72143+gr_acl_handle_chown(const struct dentry * dentry, const struct vfsmount * mnt)
72144+{
72145+ return 1;
72146+}
72147+
72148+__u32
72149+gr_acl_handle_setxattr(const struct dentry * dentry, const struct vfsmount * mnt)
72150+{
72151+ return 1;
72152+}
72153+
72154+__u32
72155+gr_acl_handle_removexattr(const struct dentry * dentry, const struct vfsmount * mnt)
72156+{
72157+ return 1;
72158+}
72159+
72160+void
72161+grsecurity_init(void)
72162+{
72163+ return;
72164+}
72165+
72166+umode_t gr_acl_umask(void)
72167+{
72168+ return 0;
72169+}
72170+
72171+__u32
72172+gr_acl_handle_mknod(const struct dentry * new_dentry,
72173+ const struct dentry * parent_dentry,
72174+ const struct vfsmount * parent_mnt,
72175+ const int mode)
72176+{
72177+ return 1;
72178+}
72179+
72180+__u32
72181+gr_acl_handle_mkdir(const struct dentry * new_dentry,
72182+ const struct dentry * parent_dentry,
72183+ const struct vfsmount * parent_mnt)
72184+{
72185+ return 1;
72186+}
72187+
72188+__u32
72189+gr_acl_handle_symlink(const struct dentry * new_dentry,
72190+ const struct dentry * parent_dentry,
72191+ const struct vfsmount * parent_mnt, const struct filename *from)
72192+{
72193+ return 1;
72194+}
72195+
72196+__u32
72197+gr_acl_handle_link(const struct dentry * new_dentry,
72198+ const struct dentry * parent_dentry,
72199+ const struct vfsmount * parent_mnt,
72200+ const struct dentry * old_dentry,
72201+ const struct vfsmount * old_mnt, const struct filename *to)
72202+{
72203+ return 1;
72204+}
72205+
72206+int
72207+gr_acl_handle_rename(const struct dentry *new_dentry,
72208+ const struct dentry *parent_dentry,
72209+ const struct vfsmount *parent_mnt,
72210+ const struct dentry *old_dentry,
72211+ const struct inode *old_parent_inode,
72212+ const struct vfsmount *old_mnt, const struct filename *newname)
72213+{
72214+ return 0;
72215+}
72216+
72217+int
72218+gr_acl_handle_filldir(const struct file *file, const char *name,
72219+ const int namelen, const ino_t ino)
72220+{
72221+ return 1;
72222+}
72223+
72224+int
72225+gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
72226+ const time_t shm_createtime, const kuid_t cuid, const int shmid)
72227+{
72228+ return 1;
72229+}
72230+
72231+int
72232+gr_search_bind(const struct socket *sock, const struct sockaddr_in *addr)
72233+{
72234+ return 0;
72235+}
72236+
72237+int
72238+gr_search_accept(const struct socket *sock)
72239+{
72240+ return 0;
72241+}
72242+
72243+int
72244+gr_search_listen(const struct socket *sock)
72245+{
72246+ return 0;
72247+}
72248+
72249+int
72250+gr_search_connect(const struct socket *sock, const struct sockaddr_in *addr)
72251+{
72252+ return 0;
72253+}
72254+
72255+__u32
72256+gr_acl_handle_unix(const struct dentry * dentry, const struct vfsmount * mnt)
72257+{
72258+ return 1;
72259+}
72260+
72261+__u32
72262+gr_acl_handle_creat(const struct dentry * dentry,
72263+ const struct dentry * p_dentry,
72264+ const struct vfsmount * p_mnt, int open_flags, int acc_mode,
72265+ const int imode)
72266+{
72267+ return 1;
72268+}
72269+
72270+void
72271+gr_acl_handle_exit(void)
72272+{
72273+ return;
72274+}
72275+
72276+int
72277+gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
72278+{
72279+ return 1;
72280+}
72281+
72282+void
72283+gr_set_role_label(const kuid_t uid, const kgid_t gid)
72284+{
72285+ return;
72286+}
72287+
72288+int
72289+gr_acl_handle_procpidmem(const struct task_struct *task)
72290+{
72291+ return 0;
72292+}
72293+
72294+int
72295+gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb)
72296+{
72297+ return 0;
72298+}
72299+
72300+int
72301+gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr)
72302+{
72303+ return 0;
72304+}
72305+
72306+int
72307+gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs)
72308+{
72309+ return 0;
72310+}
72311+
72312+int
72313+gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs)
72314+{
72315+ return 0;
72316+}
72317+
72318+int gr_acl_enable_at_secure(void)
72319+{
72320+ return 0;
72321+}
72322+
72323+dev_t gr_get_dev_from_dentry(struct dentry *dentry)
72324+{
72325+ return dentry->d_sb->s_dev;
72326+}
72327+
72328+void gr_put_exec_file(struct task_struct *task)
72329+{
72330+ return;
72331+}
72332+
72333+#ifdef CONFIG_SECURITY
72334+EXPORT_SYMBOL(gr_check_user_change);
72335+EXPORT_SYMBOL(gr_check_group_change);
72336+#endif
72337diff --git a/grsecurity/grsec_exec.c b/grsecurity/grsec_exec.c
72338new file mode 100644
72339index 0000000..387032b
72340--- /dev/null
72341+++ b/grsecurity/grsec_exec.c
72342@@ -0,0 +1,187 @@
72343+#include <linux/kernel.h>
72344+#include <linux/sched.h>
72345+#include <linux/file.h>
72346+#include <linux/binfmts.h>
72347+#include <linux/fs.h>
72348+#include <linux/types.h>
72349+#include <linux/grdefs.h>
72350+#include <linux/grsecurity.h>
72351+#include <linux/grinternal.h>
72352+#include <linux/capability.h>
72353+#include <linux/module.h>
72354+#include <linux/compat.h>
72355+
72356+#include <asm/uaccess.h>
72357+
72358+#ifdef CONFIG_GRKERNSEC_EXECLOG
72359+static char gr_exec_arg_buf[132];
72360+static DEFINE_MUTEX(gr_exec_arg_mutex);
72361+#endif
72362+
72363+struct user_arg_ptr {
72364+#ifdef CONFIG_COMPAT
72365+ bool is_compat;
72366+#endif
72367+ union {
72368+ const char __user *const __user *native;
72369+#ifdef CONFIG_COMPAT
72370+ const compat_uptr_t __user *compat;
72371+#endif
72372+ } ptr;
72373+};
72374+
72375+extern const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr);
72376+
72377+void
72378+gr_handle_exec_args(struct linux_binprm *bprm, struct user_arg_ptr argv)
72379+{
72380+#ifdef CONFIG_GRKERNSEC_EXECLOG
72381+ char *grarg = gr_exec_arg_buf;
72382+ unsigned int i, x, execlen = 0;
72383+ char c;
72384+
72385+ if (!((grsec_enable_execlog && grsec_enable_group &&
72386+ in_group_p(grsec_audit_gid))
72387+ || (grsec_enable_execlog && !grsec_enable_group)))
72388+ return;
72389+
72390+ mutex_lock(&gr_exec_arg_mutex);
72391+ memset(grarg, 0, sizeof(gr_exec_arg_buf));
72392+
72393+ for (i = 0; i < bprm->argc && execlen < 128; i++) {
72394+ const char __user *p;
72395+ unsigned int len;
72396+
72397+ p = get_user_arg_ptr(argv, i);
72398+ if (IS_ERR(p))
72399+ goto log;
72400+
72401+ len = strnlen_user(p, 128 - execlen);
72402+ if (len > 128 - execlen)
72403+ len = 128 - execlen;
72404+ else if (len > 0)
72405+ len--;
72406+ if (copy_from_user(grarg + execlen, p, len))
72407+ goto log;
72408+
72409+ /* rewrite unprintable characters */
72410+ for (x = 0; x < len; x++) {
72411+ c = *(grarg + execlen + x);
72412+ if (c < 32 || c > 126)
72413+ *(grarg + execlen + x) = ' ';
72414+ }
72415+
72416+ execlen += len;
72417+ *(grarg + execlen) = ' ';
72418+ *(grarg + execlen + 1) = '\0';
72419+ execlen++;
72420+ }
72421+
72422+ log:
72423+ gr_log_fs_str(GR_DO_AUDIT, GR_EXEC_AUDIT_MSG, bprm->file->f_path.dentry,
72424+ bprm->file->f_path.mnt, grarg);
72425+ mutex_unlock(&gr_exec_arg_mutex);
72426+#endif
72427+ return;
72428+}
72429+
72430+#ifdef CONFIG_GRKERNSEC
72431+extern int gr_acl_is_capable(const int cap);
72432+extern int gr_acl_is_capable_nolog(const int cap);
72433+extern int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
72434+extern int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap);
72435+extern int gr_chroot_is_capable(const int cap);
72436+extern int gr_chroot_is_capable_nolog(const int cap);
72437+extern int gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
72438+extern int gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap);
72439+#endif
72440+
72441+const char *captab_log[] = {
72442+ "CAP_CHOWN",
72443+ "CAP_DAC_OVERRIDE",
72444+ "CAP_DAC_READ_SEARCH",
72445+ "CAP_FOWNER",
72446+ "CAP_FSETID",
72447+ "CAP_KILL",
72448+ "CAP_SETGID",
72449+ "CAP_SETUID",
72450+ "CAP_SETPCAP",
72451+ "CAP_LINUX_IMMUTABLE",
72452+ "CAP_NET_BIND_SERVICE",
72453+ "CAP_NET_BROADCAST",
72454+ "CAP_NET_ADMIN",
72455+ "CAP_NET_RAW",
72456+ "CAP_IPC_LOCK",
72457+ "CAP_IPC_OWNER",
72458+ "CAP_SYS_MODULE",
72459+ "CAP_SYS_RAWIO",
72460+ "CAP_SYS_CHROOT",
72461+ "CAP_SYS_PTRACE",
72462+ "CAP_SYS_PACCT",
72463+ "CAP_SYS_ADMIN",
72464+ "CAP_SYS_BOOT",
72465+ "CAP_SYS_NICE",
72466+ "CAP_SYS_RESOURCE",
72467+ "CAP_SYS_TIME",
72468+ "CAP_SYS_TTY_CONFIG",
72469+ "CAP_MKNOD",
72470+ "CAP_LEASE",
72471+ "CAP_AUDIT_WRITE",
72472+ "CAP_AUDIT_CONTROL",
72473+ "CAP_SETFCAP",
72474+ "CAP_MAC_OVERRIDE",
72475+ "CAP_MAC_ADMIN",
72476+ "CAP_SYSLOG",
72477+ "CAP_WAKE_ALARM"
72478+};
72479+
72480+int captab_log_entries = sizeof(captab_log)/sizeof(captab_log[0]);
72481+
72482+int gr_is_capable(const int cap)
72483+{
72484+#ifdef CONFIG_GRKERNSEC
72485+ if (gr_acl_is_capable(cap) && gr_chroot_is_capable(cap))
72486+ return 1;
72487+ return 0;
72488+#else
72489+ return 1;
72490+#endif
72491+}
72492+
72493+int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
72494+{
72495+#ifdef CONFIG_GRKERNSEC
72496+ if (gr_task_acl_is_capable(task, cred, cap) && gr_task_chroot_is_capable(task, cred, cap))
72497+ return 1;
72498+ return 0;
72499+#else
72500+ return 1;
72501+#endif
72502+}
72503+
72504+int gr_is_capable_nolog(const int cap)
72505+{
72506+#ifdef CONFIG_GRKERNSEC
72507+ if (gr_acl_is_capable_nolog(cap) && gr_chroot_is_capable_nolog(cap))
72508+ return 1;
72509+ return 0;
72510+#else
72511+ return 1;
72512+#endif
72513+}
72514+
72515+int gr_task_is_capable_nolog(const struct task_struct *task, const int cap)
72516+{
72517+#ifdef CONFIG_GRKERNSEC
72518+ if (gr_task_acl_is_capable_nolog(task, cap) && gr_task_chroot_is_capable_nolog(task, cap))
72519+ return 1;
72520+ return 0;
72521+#else
72522+ return 1;
72523+#endif
72524+}
72525+
72526+EXPORT_SYMBOL(gr_is_capable);
72527+EXPORT_SYMBOL(gr_is_capable_nolog);
72528+EXPORT_SYMBOL(gr_task_is_capable);
72529+EXPORT_SYMBOL(gr_task_is_capable_nolog);
72530diff --git a/grsecurity/grsec_fifo.c b/grsecurity/grsec_fifo.c
72531new file mode 100644
72532index 0000000..06cc6ea
72533--- /dev/null
72534+++ b/grsecurity/grsec_fifo.c
72535@@ -0,0 +1,24 @@
72536+#include <linux/kernel.h>
72537+#include <linux/sched.h>
72538+#include <linux/fs.h>
72539+#include <linux/file.h>
72540+#include <linux/grinternal.h>
72541+
72542+int
72543+gr_handle_fifo(const struct dentry *dentry, const struct vfsmount *mnt,
72544+ const struct dentry *dir, const int flag, const int acc_mode)
72545+{
72546+#ifdef CONFIG_GRKERNSEC_FIFO
72547+ const struct cred *cred = current_cred();
72548+
72549+ if (grsec_enable_fifo && S_ISFIFO(dentry->d_inode->i_mode) &&
72550+ !(flag & O_EXCL) && (dir->d_inode->i_mode & S_ISVTX) &&
72551+ !uid_eq(dentry->d_inode->i_uid, dir->d_inode->i_uid) &&
72552+ !uid_eq(cred->fsuid, dentry->d_inode->i_uid)) {
72553+ if (!inode_permission(dentry->d_inode, acc_mode))
72554+ gr_log_fs_int2(GR_DONT_AUDIT, GR_FIFO_MSG, dentry, mnt, GR_GLOBAL_UID(dentry->d_inode->i_uid), GR_GLOBAL_GID(dentry->d_inode->i_gid));
72555+ return -EACCES;
72556+ }
72557+#endif
72558+ return 0;
72559+}
72560diff --git a/grsecurity/grsec_fork.c b/grsecurity/grsec_fork.c
72561new file mode 100644
72562index 0000000..8ca18bf
72563--- /dev/null
72564+++ b/grsecurity/grsec_fork.c
72565@@ -0,0 +1,23 @@
72566+#include <linux/kernel.h>
72567+#include <linux/sched.h>
72568+#include <linux/grsecurity.h>
72569+#include <linux/grinternal.h>
72570+#include <linux/errno.h>
72571+
72572+void
72573+gr_log_forkfail(const int retval)
72574+{
72575+#ifdef CONFIG_GRKERNSEC_FORKFAIL
72576+ if (grsec_enable_forkfail && (retval == -EAGAIN || retval == -ENOMEM)) {
72577+ switch (retval) {
72578+ case -EAGAIN:
72579+ gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "EAGAIN");
72580+ break;
72581+ case -ENOMEM:
72582+ gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "ENOMEM");
72583+ break;
72584+ }
72585+ }
72586+#endif
72587+ return;
72588+}
72589diff --git a/grsecurity/grsec_init.c b/grsecurity/grsec_init.c
72590new file mode 100644
72591index 0000000..a88e901
72592--- /dev/null
72593+++ b/grsecurity/grsec_init.c
72594@@ -0,0 +1,272 @@
72595+#include <linux/kernel.h>
72596+#include <linux/sched.h>
72597+#include <linux/mm.h>
72598+#include <linux/gracl.h>
72599+#include <linux/slab.h>
72600+#include <linux/vmalloc.h>
72601+#include <linux/percpu.h>
72602+#include <linux/module.h>
72603+
72604+int grsec_enable_ptrace_readexec;
72605+int grsec_enable_setxid;
72606+int grsec_enable_symlinkown;
72607+kgid_t grsec_symlinkown_gid;
72608+int grsec_enable_brute;
72609+int grsec_enable_link;
72610+int grsec_enable_dmesg;
72611+int grsec_enable_harden_ptrace;
72612+int grsec_enable_harden_ipc;
72613+int grsec_enable_fifo;
72614+int grsec_enable_execlog;
72615+int grsec_enable_signal;
72616+int grsec_enable_forkfail;
72617+int grsec_enable_audit_ptrace;
72618+int grsec_enable_time;
72619+int grsec_enable_group;
72620+kgid_t grsec_audit_gid;
72621+int grsec_enable_chdir;
72622+int grsec_enable_mount;
72623+int grsec_enable_rofs;
72624+int grsec_deny_new_usb;
72625+int grsec_enable_chroot_findtask;
72626+int grsec_enable_chroot_mount;
72627+int grsec_enable_chroot_shmat;
72628+int grsec_enable_chroot_fchdir;
72629+int grsec_enable_chroot_double;
72630+int grsec_enable_chroot_pivot;
72631+int grsec_enable_chroot_chdir;
72632+int grsec_enable_chroot_chmod;
72633+int grsec_enable_chroot_mknod;
72634+int grsec_enable_chroot_nice;
72635+int grsec_enable_chroot_execlog;
72636+int grsec_enable_chroot_caps;
72637+int grsec_enable_chroot_sysctl;
72638+int grsec_enable_chroot_unix;
72639+int grsec_enable_tpe;
72640+kgid_t grsec_tpe_gid;
72641+int grsec_enable_blackhole;
72642+#ifdef CONFIG_IPV6_MODULE
72643+EXPORT_SYMBOL(grsec_enable_blackhole);
72644+#endif
72645+int grsec_lastack_retries;
72646+int grsec_enable_tpe_all;
72647+int grsec_enable_tpe_invert;
72648+int grsec_enable_socket_all;
72649+kgid_t grsec_socket_all_gid;
72650+int grsec_enable_socket_client;
72651+kgid_t grsec_socket_client_gid;
72652+int grsec_enable_socket_server;
72653+kgid_t grsec_socket_server_gid;
72654+int grsec_resource_logging;
72655+int grsec_disable_privio;
72656+int grsec_enable_log_rwxmaps;
72657+int grsec_lock;
72658+
72659+DEFINE_SPINLOCK(grsec_alert_lock);
72660+unsigned long grsec_alert_wtime = 0;
72661+unsigned long grsec_alert_fyet = 0;
72662+
72663+DEFINE_SPINLOCK(grsec_audit_lock);
72664+
72665+DEFINE_RWLOCK(grsec_exec_file_lock);
72666+
72667+char *gr_shared_page[4];
72668+
72669+char *gr_alert_log_fmt;
72670+char *gr_audit_log_fmt;
72671+char *gr_alert_log_buf;
72672+char *gr_audit_log_buf;
72673+
72674+void __init
72675+grsecurity_init(void)
72676+{
72677+ int j;
72678+ /* create the per-cpu shared pages */
72679+
72680+#ifdef CONFIG_X86
72681+ memset((char *)(0x41a + PAGE_OFFSET), 0, 36);
72682+#endif
72683+
72684+ for (j = 0; j < 4; j++) {
72685+ gr_shared_page[j] = (char *)__alloc_percpu(PAGE_SIZE, __alignof__(unsigned long long));
72686+ if (gr_shared_page[j] == NULL) {
72687+ panic("Unable to allocate grsecurity shared page");
72688+ return;
72689+ }
72690+ }
72691+
72692+ /* allocate log buffers */
72693+ gr_alert_log_fmt = kmalloc(512, GFP_KERNEL);
72694+ if (!gr_alert_log_fmt) {
72695+ panic("Unable to allocate grsecurity alert log format buffer");
72696+ return;
72697+ }
72698+ gr_audit_log_fmt = kmalloc(512, GFP_KERNEL);
72699+ if (!gr_audit_log_fmt) {
72700+ panic("Unable to allocate grsecurity audit log format buffer");
72701+ return;
72702+ }
72703+ gr_alert_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
72704+ if (!gr_alert_log_buf) {
72705+ panic("Unable to allocate grsecurity alert log buffer");
72706+ return;
72707+ }
72708+ gr_audit_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
72709+ if (!gr_audit_log_buf) {
72710+ panic("Unable to allocate grsecurity audit log buffer");
72711+ return;
72712+ }
72713+
72714+#ifdef CONFIG_GRKERNSEC_IO
72715+#if !defined(CONFIG_GRKERNSEC_SYSCTL_DISTRO)
72716+ grsec_disable_privio = 1;
72717+#elif defined(CONFIG_GRKERNSEC_SYSCTL_ON)
72718+ grsec_disable_privio = 1;
72719+#else
72720+ grsec_disable_privio = 0;
72721+#endif
72722+#endif
72723+
72724+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
72725+ /* for backward compatibility, tpe_invert always defaults to on if
72726+ enabled in the kernel
72727+ */
72728+ grsec_enable_tpe_invert = 1;
72729+#endif
72730+
72731+#if !defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_SYSCTL_ON)
72732+#ifndef CONFIG_GRKERNSEC_SYSCTL
72733+ grsec_lock = 1;
72734+#endif
72735+
72736+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
72737+ grsec_enable_log_rwxmaps = 1;
72738+#endif
72739+#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
72740+ grsec_enable_group = 1;
72741+ grsec_audit_gid = KGIDT_INIT(CONFIG_GRKERNSEC_AUDIT_GID);
72742+#endif
72743+#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
72744+ grsec_enable_ptrace_readexec = 1;
72745+#endif
72746+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
72747+ grsec_enable_chdir = 1;
72748+#endif
72749+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
72750+ grsec_enable_harden_ptrace = 1;
72751+#endif
72752+#ifdef CONFIG_GRKERNSEC_HARDEN_IPC
72753+ grsec_enable_harden_ipc = 1;
72754+#endif
72755+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
72756+ grsec_enable_mount = 1;
72757+#endif
72758+#ifdef CONFIG_GRKERNSEC_LINK
72759+ grsec_enable_link = 1;
72760+#endif
72761+#ifdef CONFIG_GRKERNSEC_BRUTE
72762+ grsec_enable_brute = 1;
72763+#endif
72764+#ifdef CONFIG_GRKERNSEC_DMESG
72765+ grsec_enable_dmesg = 1;
72766+#endif
72767+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
72768+ grsec_enable_blackhole = 1;
72769+ grsec_lastack_retries = 4;
72770+#endif
72771+#ifdef CONFIG_GRKERNSEC_FIFO
72772+ grsec_enable_fifo = 1;
72773+#endif
72774+#ifdef CONFIG_GRKERNSEC_EXECLOG
72775+ grsec_enable_execlog = 1;
72776+#endif
72777+#ifdef CONFIG_GRKERNSEC_SETXID
72778+ grsec_enable_setxid = 1;
72779+#endif
72780+#ifdef CONFIG_GRKERNSEC_SIGNAL
72781+ grsec_enable_signal = 1;
72782+#endif
72783+#ifdef CONFIG_GRKERNSEC_FORKFAIL
72784+ grsec_enable_forkfail = 1;
72785+#endif
72786+#ifdef CONFIG_GRKERNSEC_TIME
72787+ grsec_enable_time = 1;
72788+#endif
72789+#ifdef CONFIG_GRKERNSEC_RESLOG
72790+ grsec_resource_logging = 1;
72791+#endif
72792+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
72793+ grsec_enable_chroot_findtask = 1;
72794+#endif
72795+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
72796+ grsec_enable_chroot_unix = 1;
72797+#endif
72798+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
72799+ grsec_enable_chroot_mount = 1;
72800+#endif
72801+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
72802+ grsec_enable_chroot_fchdir = 1;
72803+#endif
72804+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
72805+ grsec_enable_chroot_shmat = 1;
72806+#endif
72807+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
72808+ grsec_enable_audit_ptrace = 1;
72809+#endif
72810+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
72811+ grsec_enable_chroot_double = 1;
72812+#endif
72813+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
72814+ grsec_enable_chroot_pivot = 1;
72815+#endif
72816+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
72817+ grsec_enable_chroot_chdir = 1;
72818+#endif
72819+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
72820+ grsec_enable_chroot_chmod = 1;
72821+#endif
72822+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
72823+ grsec_enable_chroot_mknod = 1;
72824+#endif
72825+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
72826+ grsec_enable_chroot_nice = 1;
72827+#endif
72828+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
72829+ grsec_enable_chroot_execlog = 1;
72830+#endif
72831+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
72832+ grsec_enable_chroot_caps = 1;
72833+#endif
72834+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
72835+ grsec_enable_chroot_sysctl = 1;
72836+#endif
72837+#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
72838+ grsec_enable_symlinkown = 1;
72839+ grsec_symlinkown_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SYMLINKOWN_GID);
72840+#endif
72841+#ifdef CONFIG_GRKERNSEC_TPE
72842+ grsec_enable_tpe = 1;
72843+ grsec_tpe_gid = KGIDT_INIT(CONFIG_GRKERNSEC_TPE_GID);
72844+#ifdef CONFIG_GRKERNSEC_TPE_ALL
72845+ grsec_enable_tpe_all = 1;
72846+#endif
72847+#endif
72848+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
72849+ grsec_enable_socket_all = 1;
72850+ grsec_socket_all_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_ALL_GID);
72851+#endif
72852+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
72853+ grsec_enable_socket_client = 1;
72854+ grsec_socket_client_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_CLIENT_GID);
72855+#endif
72856+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
72857+ grsec_enable_socket_server = 1;
72858+ grsec_socket_server_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_SERVER_GID);
72859+#endif
72860+#endif
72861+#ifdef CONFIG_GRKERNSEC_DENYUSB_FORCE
72862+ grsec_deny_new_usb = 1;
72863+#endif
72864+
72865+ return;
72866+}
72867diff --git a/grsecurity/grsec_ipc.c b/grsecurity/grsec_ipc.c
72868new file mode 100644
72869index 0000000..78d1680
72870--- /dev/null
72871+++ b/grsecurity/grsec_ipc.c
72872@@ -0,0 +1,48 @@
72873+#include <linux/kernel.h>
72874+#include <linux/mm.h>
72875+#include <linux/sched.h>
72876+#include <linux/file.h>
72877+#include <linux/ipc.h>
72878+#include <linux/ipc_namespace.h>
72879+#include <linux/grsecurity.h>
72880+#include <linux/grinternal.h>
72881+
72882+int
72883+gr_ipc_permitted(struct ipc_namespace *ns, struct kern_ipc_perm *ipcp, int requested_mode, int granted_mode)
72884+{
72885+#ifdef CONFIG_GRKERNSEC_HARDEN_IPC
72886+ int write;
72887+ int orig_granted_mode;
72888+ kuid_t euid;
72889+ kgid_t egid;
72890+
72891+ if (!grsec_enable_harden_ipc)
72892+ return 0;
72893+
72894+ euid = current_euid();
72895+ egid = current_egid();
72896+
72897+ write = requested_mode & 00002;
72898+ orig_granted_mode = ipcp->mode;
72899+
72900+ if (uid_eq(euid, ipcp->cuid) || uid_eq(euid, ipcp->uid))
72901+ orig_granted_mode >>= 6;
72902+ else {
72903+ /* if likely wrong permissions, lock to user */
72904+ if (orig_granted_mode & 0007)
72905+ orig_granted_mode = 0;
72906+ /* otherwise do a egid-only check */
72907+ else if (gid_eq(egid, ipcp->cgid) || gid_eq(egid, ipcp->gid))
72908+ orig_granted_mode >>= 3;
72909+ /* otherwise, no access */
72910+ else
72911+ orig_granted_mode = 0;
72912+ }
72913+ if (!(requested_mode & ~granted_mode & 0007) && (requested_mode & ~orig_granted_mode & 0007) &&
72914+ !ns_capable_nolog(ns->user_ns, CAP_IPC_OWNER)) {
72915+ gr_log_str_int(GR_DONT_AUDIT, GR_IPC_DENIED_MSG, write ? "write" : "read", GR_GLOBAL_UID(ipcp->cuid));
72916+ return 0;
72917+ }
72918+#endif
72919+ return 1;
72920+}
72921diff --git a/grsecurity/grsec_link.c b/grsecurity/grsec_link.c
72922new file mode 100644
72923index 0000000..5e05e20
72924--- /dev/null
72925+++ b/grsecurity/grsec_link.c
72926@@ -0,0 +1,58 @@
72927+#include <linux/kernel.h>
72928+#include <linux/sched.h>
72929+#include <linux/fs.h>
72930+#include <linux/file.h>
72931+#include <linux/grinternal.h>
72932+
72933+int gr_handle_symlink_owner(const struct path *link, const struct inode *target)
72934+{
72935+#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
72936+ const struct inode *link_inode = link->dentry->d_inode;
72937+
72938+ if (grsec_enable_symlinkown && in_group_p(grsec_symlinkown_gid) &&
72939+ /* ignore root-owned links, e.g. /proc/self */
72940+ gr_is_global_nonroot(link_inode->i_uid) && target &&
72941+ !uid_eq(link_inode->i_uid, target->i_uid)) {
72942+ gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINKOWNER_MSG, link->dentry, link->mnt, link_inode->i_uid, target->i_uid);
72943+ return 1;
72944+ }
72945+#endif
72946+ return 0;
72947+}
72948+
72949+int
72950+gr_handle_follow_link(const struct inode *parent,
72951+ const struct inode *inode,
72952+ const struct dentry *dentry, const struct vfsmount *mnt)
72953+{
72954+#ifdef CONFIG_GRKERNSEC_LINK
72955+ const struct cred *cred = current_cred();
72956+
72957+ if (grsec_enable_link && S_ISLNK(inode->i_mode) &&
72958+ (parent->i_mode & S_ISVTX) && !uid_eq(parent->i_uid, inode->i_uid) &&
72959+ (parent->i_mode & S_IWOTH) && !uid_eq(cred->fsuid, inode->i_uid)) {
72960+ gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid);
72961+ return -EACCES;
72962+ }
72963+#endif
72964+ return 0;
72965+}
72966+
72967+int
72968+gr_handle_hardlink(const struct dentry *dentry,
72969+ const struct vfsmount *mnt,
72970+ struct inode *inode, const int mode, const struct filename *to)
72971+{
72972+#ifdef CONFIG_GRKERNSEC_LINK
72973+ const struct cred *cred = current_cred();
72974+
72975+ if (grsec_enable_link && !uid_eq(cred->fsuid, inode->i_uid) &&
72976+ (!S_ISREG(mode) || is_privileged_binary(dentry) ||
72977+ (inode_permission(inode, MAY_READ | MAY_WRITE))) &&
72978+ !capable(CAP_FOWNER) && gr_is_global_nonroot(cred->uid)) {
72979+ gr_log_fs_int2_str(GR_DONT_AUDIT, GR_HARDLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid, to->name);
72980+ return -EPERM;
72981+ }
72982+#endif
72983+ return 0;
72984+}
72985diff --git a/grsecurity/grsec_log.c b/grsecurity/grsec_log.c
72986new file mode 100644
72987index 0000000..dbe0a6b
72988--- /dev/null
72989+++ b/grsecurity/grsec_log.c
72990@@ -0,0 +1,341 @@
72991+#include <linux/kernel.h>
72992+#include <linux/sched.h>
72993+#include <linux/file.h>
72994+#include <linux/tty.h>
72995+#include <linux/fs.h>
72996+#include <linux/mm.h>
72997+#include <linux/grinternal.h>
72998+
72999+#ifdef CONFIG_TREE_PREEMPT_RCU
73000+#define DISABLE_PREEMPT() preempt_disable()
73001+#define ENABLE_PREEMPT() preempt_enable()
73002+#else
73003+#define DISABLE_PREEMPT()
73004+#define ENABLE_PREEMPT()
73005+#endif
73006+
73007+#define BEGIN_LOCKS(x) \
73008+ DISABLE_PREEMPT(); \
73009+ rcu_read_lock(); \
73010+ read_lock(&tasklist_lock); \
73011+ read_lock(&grsec_exec_file_lock); \
73012+ if (x != GR_DO_AUDIT) \
73013+ spin_lock(&grsec_alert_lock); \
73014+ else \
73015+ spin_lock(&grsec_audit_lock)
73016+
73017+#define END_LOCKS(x) \
73018+ if (x != GR_DO_AUDIT) \
73019+ spin_unlock(&grsec_alert_lock); \
73020+ else \
73021+ spin_unlock(&grsec_audit_lock); \
73022+ read_unlock(&grsec_exec_file_lock); \
73023+ read_unlock(&tasklist_lock); \
73024+ rcu_read_unlock(); \
73025+ ENABLE_PREEMPT(); \
73026+ if (x == GR_DONT_AUDIT) \
73027+ gr_handle_alertkill(current)
73028+
73029+enum {
73030+ FLOODING,
73031+ NO_FLOODING
73032+};
73033+
73034+extern char *gr_alert_log_fmt;
73035+extern char *gr_audit_log_fmt;
73036+extern char *gr_alert_log_buf;
73037+extern char *gr_audit_log_buf;
73038+
73039+static int gr_log_start(int audit)
73040+{
73041+ char *loglevel = (audit == GR_DO_AUDIT) ? KERN_INFO : KERN_ALERT;
73042+ char *fmt = (audit == GR_DO_AUDIT) ? gr_audit_log_fmt : gr_alert_log_fmt;
73043+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
73044+#if (CONFIG_GRKERNSEC_FLOODTIME > 0 && CONFIG_GRKERNSEC_FLOODBURST > 0)
73045+ unsigned long curr_secs = get_seconds();
73046+
73047+ if (audit == GR_DO_AUDIT)
73048+ goto set_fmt;
73049+
73050+ if (!grsec_alert_wtime || time_after(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)) {
73051+ grsec_alert_wtime = curr_secs;
73052+ grsec_alert_fyet = 0;
73053+ } else if (time_before_eq(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)
73054+ && (grsec_alert_fyet < CONFIG_GRKERNSEC_FLOODBURST)) {
73055+ grsec_alert_fyet++;
73056+ } else if (grsec_alert_fyet == CONFIG_GRKERNSEC_FLOODBURST) {
73057+ grsec_alert_wtime = curr_secs;
73058+ grsec_alert_fyet++;
73059+ printk(KERN_ALERT "grsec: more alerts, logging disabled for %d seconds\n", CONFIG_GRKERNSEC_FLOODTIME);
73060+ return FLOODING;
73061+ }
73062+ else return FLOODING;
73063+
73064+set_fmt:
73065+#endif
73066+ memset(buf, 0, PAGE_SIZE);
73067+ if (current->signal->curr_ip && gr_acl_is_enabled()) {
73068+ sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: (%.64s:%c:%.950s) ");
73069+ snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
73070+ } else if (current->signal->curr_ip) {
73071+ sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: ");
73072+ snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip);
73073+ } else if (gr_acl_is_enabled()) {
73074+ sprintf(fmt, "%s%s", loglevel, "grsec: (%.64s:%c:%.950s) ");
73075+ snprintf(buf, PAGE_SIZE - 1, fmt, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
73076+ } else {
73077+ sprintf(fmt, "%s%s", loglevel, "grsec: ");
73078+ strcpy(buf, fmt);
73079+ }
73080+
73081+ return NO_FLOODING;
73082+}
73083+
73084+static void gr_log_middle(int audit, const char *msg, va_list ap)
73085+ __attribute__ ((format (printf, 2, 0)));
73086+
73087+static void gr_log_middle(int audit, const char *msg, va_list ap)
73088+{
73089+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
73090+ unsigned int len = strlen(buf);
73091+
73092+ vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
73093+
73094+ return;
73095+}
73096+
73097+static void gr_log_middle_varargs(int audit, const char *msg, ...)
73098+ __attribute__ ((format (printf, 2, 3)));
73099+
73100+static void gr_log_middle_varargs(int audit, const char *msg, ...)
73101+{
73102+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
73103+ unsigned int len = strlen(buf);
73104+ va_list ap;
73105+
73106+ va_start(ap, msg);
73107+ vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
73108+ va_end(ap);
73109+
73110+ return;
73111+}
73112+
73113+static void gr_log_end(int audit, int append_default)
73114+{
73115+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
73116+ if (append_default) {
73117+ struct task_struct *task = current;
73118+ struct task_struct *parent = task->real_parent;
73119+ const struct cred *cred = __task_cred(task);
73120+ const struct cred *pcred = __task_cred(parent);
73121+ unsigned int len = strlen(buf);
73122+
73123+ snprintf(buf + len, PAGE_SIZE - len - 1, DEFAULTSECMSG, gr_task_fullpath(task), task->comm, task_pid_nr(task), GR_GLOBAL_UID(cred->uid), GR_GLOBAL_UID(cred->euid), GR_GLOBAL_GID(cred->gid), GR_GLOBAL_GID(cred->egid), gr_parent_task_fullpath(task), parent->comm, task_pid_nr(task->real_parent), GR_GLOBAL_UID(pcred->uid), GR_GLOBAL_UID(pcred->euid), GR_GLOBAL_GID(pcred->gid), GR_GLOBAL_GID(pcred->egid));
73124+ }
73125+
73126+ printk("%s\n", buf);
73127+
73128+ return;
73129+}
73130+
73131+void gr_log_varargs(int audit, const char *msg, int argtypes, ...)
73132+{
73133+ int logtype;
73134+ char *result = (audit == GR_DO_AUDIT) ? "successful" : "denied";
73135+ char *str1 = NULL, *str2 = NULL, *str3 = NULL;
73136+ void *voidptr = NULL;
73137+ int num1 = 0, num2 = 0;
73138+ unsigned long ulong1 = 0, ulong2 = 0;
73139+ struct dentry *dentry = NULL;
73140+ struct vfsmount *mnt = NULL;
73141+ struct file *file = NULL;
73142+ struct task_struct *task = NULL;
73143+ struct vm_area_struct *vma = NULL;
73144+ const struct cred *cred, *pcred;
73145+ va_list ap;
73146+
73147+ BEGIN_LOCKS(audit);
73148+ logtype = gr_log_start(audit);
73149+ if (logtype == FLOODING) {
73150+ END_LOCKS(audit);
73151+ return;
73152+ }
73153+ va_start(ap, argtypes);
73154+ switch (argtypes) {
73155+ case GR_TTYSNIFF:
73156+ task = va_arg(ap, struct task_struct *);
73157+ gr_log_middle_varargs(audit, msg, &task->signal->curr_ip, gr_task_fullpath0(task), task->comm, task_pid_nr(task), gr_parent_task_fullpath0(task), task->real_parent->comm, task_pid_nr(task->real_parent));
73158+ break;
73159+ case GR_SYSCTL_HIDDEN:
73160+ str1 = va_arg(ap, char *);
73161+ gr_log_middle_varargs(audit, msg, result, str1);
73162+ break;
73163+ case GR_RBAC:
73164+ dentry = va_arg(ap, struct dentry *);
73165+ mnt = va_arg(ap, struct vfsmount *);
73166+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt));
73167+ break;
73168+ case GR_RBAC_STR:
73169+ dentry = va_arg(ap, struct dentry *);
73170+ mnt = va_arg(ap, struct vfsmount *);
73171+ str1 = va_arg(ap, char *);
73172+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1);
73173+ break;
73174+ case GR_STR_RBAC:
73175+ str1 = va_arg(ap, char *);
73176+ dentry = va_arg(ap, struct dentry *);
73177+ mnt = va_arg(ap, struct vfsmount *);
73178+ gr_log_middle_varargs(audit, msg, result, str1, gr_to_filename(dentry, mnt));
73179+ break;
73180+ case GR_RBAC_MODE2:
73181+ dentry = va_arg(ap, struct dentry *);
73182+ mnt = va_arg(ap, struct vfsmount *);
73183+ str1 = va_arg(ap, char *);
73184+ str2 = va_arg(ap, char *);
73185+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2);
73186+ break;
73187+ case GR_RBAC_MODE3:
73188+ dentry = va_arg(ap, struct dentry *);
73189+ mnt = va_arg(ap, struct vfsmount *);
73190+ str1 = va_arg(ap, char *);
73191+ str2 = va_arg(ap, char *);
73192+ str3 = va_arg(ap, char *);
73193+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2, str3);
73194+ break;
73195+ case GR_FILENAME:
73196+ dentry = va_arg(ap, struct dentry *);
73197+ mnt = va_arg(ap, struct vfsmount *);
73198+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt));
73199+ break;
73200+ case GR_STR_FILENAME:
73201+ str1 = va_arg(ap, char *);
73202+ dentry = va_arg(ap, struct dentry *);
73203+ mnt = va_arg(ap, struct vfsmount *);
73204+ gr_log_middle_varargs(audit, msg, str1, gr_to_filename(dentry, mnt));
73205+ break;
73206+ case GR_FILENAME_STR:
73207+ dentry = va_arg(ap, struct dentry *);
73208+ mnt = va_arg(ap, struct vfsmount *);
73209+ str1 = va_arg(ap, char *);
73210+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), str1);
73211+ break;
73212+ case GR_FILENAME_TWO_INT:
73213+ dentry = va_arg(ap, struct dentry *);
73214+ mnt = va_arg(ap, struct vfsmount *);
73215+ num1 = va_arg(ap, int);
73216+ num2 = va_arg(ap, int);
73217+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2);
73218+ break;
73219+ case GR_FILENAME_TWO_INT_STR:
73220+ dentry = va_arg(ap, struct dentry *);
73221+ mnt = va_arg(ap, struct vfsmount *);
73222+ num1 = va_arg(ap, int);
73223+ num2 = va_arg(ap, int);
73224+ str1 = va_arg(ap, char *);
73225+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2, str1);
73226+ break;
73227+ case GR_TEXTREL:
73228+ file = va_arg(ap, struct file *);
73229+ ulong1 = va_arg(ap, unsigned long);
73230+ ulong2 = va_arg(ap, unsigned long);
73231+ gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>", ulong1, ulong2);
73232+ break;
73233+ case GR_PTRACE:
73234+ task = va_arg(ap, struct task_struct *);
73235+ 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_nr(task));
73236+ break;
73237+ case GR_RESOURCE:
73238+ task = va_arg(ap, struct task_struct *);
73239+ cred = __task_cred(task);
73240+ pcred = __task_cred(task->real_parent);
73241+ ulong1 = va_arg(ap, unsigned long);
73242+ str1 = va_arg(ap, char *);
73243+ ulong2 = va_arg(ap, unsigned long);
73244+ gr_log_middle_varargs(audit, msg, ulong1, str1, ulong2, gr_task_fullpath(task), task->comm, task_pid_nr(task), GR_GLOBAL_UID(cred->uid), GR_GLOBAL_UID(cred->euid), GR_GLOBAL_GID(cred->gid), GR_GLOBAL_GID(cred->egid), gr_parent_task_fullpath(task), task->real_parent->comm, task_pid_nr(task->real_parent), GR_GLOBAL_UID(pcred->uid), GR_GLOBAL_UID(pcred->euid), GR_GLOBAL_GID(pcred->gid), GR_GLOBAL_GID(pcred->egid));
73245+ break;
73246+ case GR_CAP:
73247+ task = va_arg(ap, struct task_struct *);
73248+ cred = __task_cred(task);
73249+ pcred = __task_cred(task->real_parent);
73250+ str1 = va_arg(ap, char *);
73251+ gr_log_middle_varargs(audit, msg, str1, gr_task_fullpath(task), task->comm, task_pid_nr(task), GR_GLOBAL_UID(cred->uid), GR_GLOBAL_UID(cred->euid), GR_GLOBAL_GID(cred->gid), GR_GLOBAL_GID(cred->egid), gr_parent_task_fullpath(task), task->real_parent->comm, task_pid_nr(task->real_parent), GR_GLOBAL_UID(pcred->uid), GR_GLOBAL_UID(pcred->euid), GR_GLOBAL_GID(pcred->gid), GR_GLOBAL_GID(pcred->egid));
73252+ break;
73253+ case GR_SIG:
73254+ str1 = va_arg(ap, char *);
73255+ voidptr = va_arg(ap, void *);
73256+ gr_log_middle_varargs(audit, msg, str1, voidptr);
73257+ break;
73258+ case GR_SIG2:
73259+ task = va_arg(ap, struct task_struct *);
73260+ cred = __task_cred(task);
73261+ pcred = __task_cred(task->real_parent);
73262+ num1 = va_arg(ap, int);
73263+ gr_log_middle_varargs(audit, msg, num1, gr_task_fullpath0(task), task->comm, task_pid_nr(task), GR_GLOBAL_UID(cred->uid), GR_GLOBAL_UID(cred->euid), GR_GLOBAL_GID(cred->gid), GR_GLOBAL_GID(cred->egid), gr_parent_task_fullpath0(task), task->real_parent->comm, task_pid_nr(task->real_parent), GR_GLOBAL_UID(pcred->uid), GR_GLOBAL_UID(pcred->euid), GR_GLOBAL_GID(pcred->gid), GR_GLOBAL_GID(pcred->egid));
73264+ break;
73265+ case GR_CRASH1:
73266+ task = va_arg(ap, struct task_struct *);
73267+ cred = __task_cred(task);
73268+ pcred = __task_cred(task->real_parent);
73269+ ulong1 = va_arg(ap, unsigned long);
73270+ gr_log_middle_varargs(audit, msg, gr_task_fullpath(task), task->comm, task_pid_nr(task), GR_GLOBAL_UID(cred->uid), GR_GLOBAL_UID(cred->euid), GR_GLOBAL_GID(cred->gid), GR_GLOBAL_GID(cred->egid), gr_parent_task_fullpath(task), task->real_parent->comm, task_pid_nr(task->real_parent), GR_GLOBAL_UID(pcred->uid), GR_GLOBAL_UID(pcred->euid), GR_GLOBAL_GID(pcred->gid), GR_GLOBAL_GID(pcred->egid), GR_GLOBAL_UID(cred->uid), ulong1);
73271+ break;
73272+ case GR_CRASH2:
73273+ task = va_arg(ap, struct task_struct *);
73274+ cred = __task_cred(task);
73275+ pcred = __task_cred(task->real_parent);
73276+ ulong1 = va_arg(ap, unsigned long);
73277+ gr_log_middle_varargs(audit, msg, gr_task_fullpath(task), task->comm, task_pid_nr(task), GR_GLOBAL_UID(cred->uid), GR_GLOBAL_UID(cred->euid), GR_GLOBAL_GID(cred->gid), GR_GLOBAL_GID(cred->egid), gr_parent_task_fullpath(task), task->real_parent->comm, task_pid_nr(task->real_parent), GR_GLOBAL_UID(pcred->uid), GR_GLOBAL_UID(pcred->euid), GR_GLOBAL_GID(pcred->gid), GR_GLOBAL_GID(pcred->egid), ulong1);
73278+ break;
73279+ case GR_RWXMAP:
73280+ file = va_arg(ap, struct file *);
73281+ gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>");
73282+ break;
73283+ case GR_RWXMAPVMA:
73284+ vma = va_arg(ap, struct vm_area_struct *);
73285+ if (vma->vm_file)
73286+ str1 = gr_to_filename(vma->vm_file->f_path.dentry, vma->vm_file->f_path.mnt);
73287+ else if (vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP))
73288+ str1 = "<stack>";
73289+ else if (vma->vm_start <= current->mm->brk &&
73290+ vma->vm_end >= current->mm->start_brk)
73291+ str1 = "<heap>";
73292+ else
73293+ str1 = "<anonymous mapping>";
73294+ gr_log_middle_varargs(audit, msg, str1);
73295+ break;
73296+ case GR_PSACCT:
73297+ {
73298+ unsigned int wday, cday;
73299+ __u8 whr, chr;
73300+ __u8 wmin, cmin;
73301+ __u8 wsec, csec;
73302+ char cur_tty[64] = { 0 };
73303+ char parent_tty[64] = { 0 };
73304+
73305+ task = va_arg(ap, struct task_struct *);
73306+ wday = va_arg(ap, unsigned int);
73307+ cday = va_arg(ap, unsigned int);
73308+ whr = va_arg(ap, int);
73309+ chr = va_arg(ap, int);
73310+ wmin = va_arg(ap, int);
73311+ cmin = va_arg(ap, int);
73312+ wsec = va_arg(ap, int);
73313+ csec = va_arg(ap, int);
73314+ ulong1 = va_arg(ap, unsigned long);
73315+ cred = __task_cred(task);
73316+ pcred = __task_cred(task->real_parent);
73317+
73318+ gr_log_middle_varargs(audit, msg, gr_task_fullpath(task), task->comm, task_pid_nr(task), &task->signal->curr_ip, tty_name(task->signal->tty, cur_tty), GR_GLOBAL_UID(cred->uid), GR_GLOBAL_UID(cred->euid), GR_GLOBAL_GID(cred->gid), GR_GLOBAL_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_pid_nr(task->real_parent), &task->real_parent->signal->curr_ip, tty_name(task->real_parent->signal->tty, parent_tty), GR_GLOBAL_UID(pcred->uid), GR_GLOBAL_UID(pcred->euid), GR_GLOBAL_GID(pcred->gid), GR_GLOBAL_GID(pcred->egid));
73319+ }
73320+ break;
73321+ default:
73322+ gr_log_middle(audit, msg, ap);
73323+ }
73324+ va_end(ap);
73325+ // these don't need DEFAULTSECARGS printed on the end
73326+ if (argtypes == GR_CRASH1 || argtypes == GR_CRASH2)
73327+ gr_log_end(audit, 0);
73328+ else
73329+ gr_log_end(audit, 1);
73330+ END_LOCKS(audit);
73331+}
73332diff --git a/grsecurity/grsec_mem.c b/grsecurity/grsec_mem.c
73333new file mode 100644
73334index 0000000..f536303
73335--- /dev/null
73336+++ b/grsecurity/grsec_mem.c
73337@@ -0,0 +1,40 @@
73338+#include <linux/kernel.h>
73339+#include <linux/sched.h>
73340+#include <linux/mm.h>
73341+#include <linux/mman.h>
73342+#include <linux/grinternal.h>
73343+
73344+void
73345+gr_handle_ioperm(void)
73346+{
73347+ gr_log_noargs(GR_DONT_AUDIT, GR_IOPERM_MSG);
73348+ return;
73349+}
73350+
73351+void
73352+gr_handle_iopl(void)
73353+{
73354+ gr_log_noargs(GR_DONT_AUDIT, GR_IOPL_MSG);
73355+ return;
73356+}
73357+
73358+void
73359+gr_handle_mem_readwrite(u64 from, u64 to)
73360+{
73361+ gr_log_two_u64(GR_DONT_AUDIT, GR_MEM_READWRITE_MSG, from, to);
73362+ return;
73363+}
73364+
73365+void
73366+gr_handle_vm86(void)
73367+{
73368+ gr_log_noargs(GR_DONT_AUDIT, GR_VM86_MSG);
73369+ return;
73370+}
73371+
73372+void
73373+gr_log_badprocpid(const char *entry)
73374+{
73375+ gr_log_str(GR_DONT_AUDIT, GR_BADPROCPID_MSG, entry);
73376+ return;
73377+}
73378diff --git a/grsecurity/grsec_mount.c b/grsecurity/grsec_mount.c
73379new file mode 100644
73380index 0000000..cd9e124
73381--- /dev/null
73382+++ b/grsecurity/grsec_mount.c
73383@@ -0,0 +1,65 @@
73384+#include <linux/kernel.h>
73385+#include <linux/sched.h>
73386+#include <linux/mount.h>
73387+#include <linux/major.h>
73388+#include <linux/grsecurity.h>
73389+#include <linux/grinternal.h>
73390+
73391+void
73392+gr_log_remount(const char *devname, const int retval)
73393+{
73394+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
73395+ if (grsec_enable_mount && (retval >= 0))
73396+ gr_log_str(GR_DO_AUDIT, GR_REMOUNT_AUDIT_MSG, devname ? devname : "none");
73397+#endif
73398+ return;
73399+}
73400+
73401+void
73402+gr_log_unmount(const char *devname, const int retval)
73403+{
73404+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
73405+ if (grsec_enable_mount && (retval >= 0))
73406+ gr_log_str(GR_DO_AUDIT, GR_UNMOUNT_AUDIT_MSG, devname ? devname : "none");
73407+#endif
73408+ return;
73409+}
73410+
73411+void
73412+gr_log_mount(const char *from, const char *to, const int retval)
73413+{
73414+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
73415+ if (grsec_enable_mount && (retval >= 0))
73416+ gr_log_str_str(GR_DO_AUDIT, GR_MOUNT_AUDIT_MSG, from ? from : "none", to);
73417+#endif
73418+ return;
73419+}
73420+
73421+int
73422+gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags)
73423+{
73424+#ifdef CONFIG_GRKERNSEC_ROFS
73425+ if (grsec_enable_rofs && !(mnt_flags & MNT_READONLY)) {
73426+ gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_MOUNT_MSG, dentry, mnt);
73427+ return -EPERM;
73428+ } else
73429+ return 0;
73430+#endif
73431+ return 0;
73432+}
73433+
73434+int
73435+gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode)
73436+{
73437+#ifdef CONFIG_GRKERNSEC_ROFS
73438+ struct inode *inode = dentry->d_inode;
73439+
73440+ if (grsec_enable_rofs && (acc_mode & MAY_WRITE) &&
73441+ inode && (S_ISBLK(inode->i_mode) || (S_ISCHR(inode->i_mode) && imajor(inode) == RAW_MAJOR))) {
73442+ gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_BLOCKWRITE_MSG, dentry, mnt);
73443+ return -EPERM;
73444+ } else
73445+ return 0;
73446+#endif
73447+ return 0;
73448+}
73449diff --git a/grsecurity/grsec_pax.c b/grsecurity/grsec_pax.c
73450new file mode 100644
73451index 0000000..6ee9d50
73452--- /dev/null
73453+++ b/grsecurity/grsec_pax.c
73454@@ -0,0 +1,45 @@
73455+#include <linux/kernel.h>
73456+#include <linux/sched.h>
73457+#include <linux/mm.h>
73458+#include <linux/file.h>
73459+#include <linux/grinternal.h>
73460+#include <linux/grsecurity.h>
73461+
73462+void
73463+gr_log_textrel(struct vm_area_struct * vma)
73464+{
73465+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
73466+ if (grsec_enable_log_rwxmaps)
73467+ gr_log_textrel_ulong_ulong(GR_DONT_AUDIT, GR_TEXTREL_AUDIT_MSG, vma->vm_file, vma->vm_start, vma->vm_pgoff);
73468+#endif
73469+ return;
73470+}
73471+
73472+void gr_log_ptgnustack(struct file *file)
73473+{
73474+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
73475+ if (grsec_enable_log_rwxmaps)
73476+ gr_log_rwxmap(GR_DONT_AUDIT, GR_PTGNUSTACK_MSG, file);
73477+#endif
73478+ return;
73479+}
73480+
73481+void
73482+gr_log_rwxmmap(struct file *file)
73483+{
73484+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
73485+ if (grsec_enable_log_rwxmaps)
73486+ gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMMAP_MSG, file);
73487+#endif
73488+ return;
73489+}
73490+
73491+void
73492+gr_log_rwxmprotect(struct vm_area_struct *vma)
73493+{
73494+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
73495+ if (grsec_enable_log_rwxmaps)
73496+ gr_log_rwxmap_vma(GR_DONT_AUDIT, GR_RWXMPROTECT_MSG, vma);
73497+#endif
73498+ return;
73499+}
73500diff --git a/grsecurity/grsec_ptrace.c b/grsecurity/grsec_ptrace.c
73501new file mode 100644
73502index 0000000..f7f29aa
73503--- /dev/null
73504+++ b/grsecurity/grsec_ptrace.c
73505@@ -0,0 +1,30 @@
73506+#include <linux/kernel.h>
73507+#include <linux/sched.h>
73508+#include <linux/grinternal.h>
73509+#include <linux/security.h>
73510+
73511+void
73512+gr_audit_ptrace(struct task_struct *task)
73513+{
73514+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
73515+ if (grsec_enable_audit_ptrace)
73516+ gr_log_ptrace(GR_DO_AUDIT, GR_PTRACE_AUDIT_MSG, task);
73517+#endif
73518+ return;
73519+}
73520+
73521+int
73522+gr_ptrace_readexec(struct file *file, int unsafe_flags)
73523+{
73524+#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
73525+ const struct dentry *dentry = file->f_path.dentry;
73526+ const struct vfsmount *mnt = file->f_path.mnt;
73527+
73528+ if (grsec_enable_ptrace_readexec && (unsafe_flags & LSM_UNSAFE_PTRACE) &&
73529+ (inode_permission(dentry->d_inode, MAY_READ) || !gr_acl_handle_open(dentry, mnt, MAY_READ))) {
73530+ gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_READEXEC_MSG, dentry, mnt);
73531+ return -EACCES;
73532+ }
73533+#endif
73534+ return 0;
73535+}
73536diff --git a/grsecurity/grsec_sig.c b/grsecurity/grsec_sig.c
73537new file mode 100644
73538index 0000000..3860c7e
73539--- /dev/null
73540+++ b/grsecurity/grsec_sig.c
73541@@ -0,0 +1,236 @@
73542+#include <linux/kernel.h>
73543+#include <linux/sched.h>
73544+#include <linux/fs.h>
73545+#include <linux/delay.h>
73546+#include <linux/grsecurity.h>
73547+#include <linux/grinternal.h>
73548+#include <linux/hardirq.h>
73549+
73550+char *signames[] = {
73551+ [SIGSEGV] = "Segmentation fault",
73552+ [SIGILL] = "Illegal instruction",
73553+ [SIGABRT] = "Abort",
73554+ [SIGBUS] = "Invalid alignment/Bus error"
73555+};
73556+
73557+void
73558+gr_log_signal(const int sig, const void *addr, const struct task_struct *t)
73559+{
73560+#ifdef CONFIG_GRKERNSEC_SIGNAL
73561+ if (grsec_enable_signal && ((sig == SIGSEGV) || (sig == SIGILL) ||
73562+ (sig == SIGABRT) || (sig == SIGBUS))) {
73563+ if (task_pid_nr(t) == task_pid_nr(current)) {
73564+ gr_log_sig_addr(GR_DONT_AUDIT_GOOD, GR_UNISIGLOG_MSG, signames[sig], addr);
73565+ } else {
73566+ gr_log_sig_task(GR_DONT_AUDIT_GOOD, GR_DUALSIGLOG_MSG, t, sig);
73567+ }
73568+ }
73569+#endif
73570+ return;
73571+}
73572+
73573+int
73574+gr_handle_signal(const struct task_struct *p, const int sig)
73575+{
73576+#ifdef CONFIG_GRKERNSEC
73577+ /* ignore the 0 signal for protected task checks */
73578+ if (task_pid_nr(current) > 1 && sig && gr_check_protected_task(p)) {
73579+ gr_log_sig_task(GR_DONT_AUDIT, GR_SIG_ACL_MSG, p, sig);
73580+ return -EPERM;
73581+ } else if (gr_pid_is_chrooted((struct task_struct *)p)) {
73582+ return -EPERM;
73583+ }
73584+#endif
73585+ return 0;
73586+}
73587+
73588+#ifdef CONFIG_GRKERNSEC
73589+extern int specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t);
73590+
73591+int gr_fake_force_sig(int sig, struct task_struct *t)
73592+{
73593+ unsigned long int flags;
73594+ int ret, blocked, ignored;
73595+ struct k_sigaction *action;
73596+
73597+ spin_lock_irqsave(&t->sighand->siglock, flags);
73598+ action = &t->sighand->action[sig-1];
73599+ ignored = action->sa.sa_handler == SIG_IGN;
73600+ blocked = sigismember(&t->blocked, sig);
73601+ if (blocked || ignored) {
73602+ action->sa.sa_handler = SIG_DFL;
73603+ if (blocked) {
73604+ sigdelset(&t->blocked, sig);
73605+ recalc_sigpending_and_wake(t);
73606+ }
73607+ }
73608+ if (action->sa.sa_handler == SIG_DFL)
73609+ t->signal->flags &= ~SIGNAL_UNKILLABLE;
73610+ ret = specific_send_sig_info(sig, SEND_SIG_PRIV, t);
73611+
73612+ spin_unlock_irqrestore(&t->sighand->siglock, flags);
73613+
73614+ return ret;
73615+}
73616+#endif
73617+
73618+#define GR_USER_BAN_TIME (15 * 60)
73619+#define GR_DAEMON_BRUTE_TIME (30 * 60)
73620+
73621+void gr_handle_brute_attach(int dumpable)
73622+{
73623+#ifdef CONFIG_GRKERNSEC_BRUTE
73624+ struct task_struct *p = current;
73625+ kuid_t uid = GLOBAL_ROOT_UID;
73626+ int daemon = 0;
73627+
73628+ if (!grsec_enable_brute)
73629+ return;
73630+
73631+ rcu_read_lock();
73632+ read_lock(&tasklist_lock);
73633+ read_lock(&grsec_exec_file_lock);
73634+ if (p->real_parent && gr_is_same_file(p->real_parent->exec_file, p->exec_file)) {
73635+ p->real_parent->brute_expires = get_seconds() + GR_DAEMON_BRUTE_TIME;
73636+ p->real_parent->brute = 1;
73637+ daemon = 1;
73638+ } else {
73639+ const struct cred *cred = __task_cred(p), *cred2;
73640+ struct task_struct *tsk, *tsk2;
73641+
73642+ if (dumpable != SUID_DUMP_USER && gr_is_global_nonroot(cred->uid)) {
73643+ struct user_struct *user;
73644+
73645+ uid = cred->uid;
73646+
73647+ /* this is put upon execution past expiration */
73648+ user = find_user(uid);
73649+ if (user == NULL)
73650+ goto unlock;
73651+ user->suid_banned = 1;
73652+ user->suid_ban_expires = get_seconds() + GR_USER_BAN_TIME;
73653+ if (user->suid_ban_expires == ~0UL)
73654+ user->suid_ban_expires--;
73655+
73656+ /* only kill other threads of the same binary, from the same user */
73657+ do_each_thread(tsk2, tsk) {
73658+ cred2 = __task_cred(tsk);
73659+ if (tsk != p && uid_eq(cred2->uid, uid) && gr_is_same_file(tsk->exec_file, p->exec_file))
73660+ gr_fake_force_sig(SIGKILL, tsk);
73661+ } while_each_thread(tsk2, tsk);
73662+ }
73663+ }
73664+unlock:
73665+ read_unlock(&grsec_exec_file_lock);
73666+ read_unlock(&tasklist_lock);
73667+ rcu_read_unlock();
73668+
73669+ if (gr_is_global_nonroot(uid))
73670+ gr_log_fs_int2(GR_DONT_AUDIT, GR_BRUTE_SUID_MSG, p->exec_file->f_path.dentry, p->exec_file->f_path.mnt, GR_GLOBAL_UID(uid), GR_USER_BAN_TIME / 60);
73671+ else if (daemon)
73672+ gr_log_noargs(GR_DONT_AUDIT, GR_BRUTE_DAEMON_MSG);
73673+
73674+#endif
73675+ return;
73676+}
73677+
73678+void gr_handle_brute_check(void)
73679+{
73680+#ifdef CONFIG_GRKERNSEC_BRUTE
73681+ struct task_struct *p = current;
73682+
73683+ if (unlikely(p->brute)) {
73684+ if (!grsec_enable_brute)
73685+ p->brute = 0;
73686+ else if (time_before(get_seconds(), p->brute_expires))
73687+ msleep(30 * 1000);
73688+ }
73689+#endif
73690+ return;
73691+}
73692+
73693+void gr_handle_kernel_exploit(void)
73694+{
73695+#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
73696+ const struct cred *cred;
73697+ struct task_struct *tsk, *tsk2;
73698+ struct user_struct *user;
73699+ kuid_t uid;
73700+
73701+ if (in_irq() || in_serving_softirq() || in_nmi())
73702+ panic("grsec: halting the system due to suspicious kernel crash caused in interrupt context");
73703+
73704+ uid = current_uid();
73705+
73706+ if (gr_is_global_root(uid))
73707+ panic("grsec: halting the system due to suspicious kernel crash caused by root");
73708+ else {
73709+ /* kill all the processes of this user, hold a reference
73710+ to their creds struct, and prevent them from creating
73711+ another process until system reset
73712+ */
73713+ printk(KERN_ALERT "grsec: banning user with uid %u until system restart for suspicious kernel crash\n",
73714+ GR_GLOBAL_UID(uid));
73715+ /* we intentionally leak this ref */
73716+ user = get_uid(current->cred->user);
73717+ if (user)
73718+ user->kernel_banned = 1;
73719+
73720+ /* kill all processes of this user */
73721+ read_lock(&tasklist_lock);
73722+ do_each_thread(tsk2, tsk) {
73723+ cred = __task_cred(tsk);
73724+ if (uid_eq(cred->uid, uid))
73725+ gr_fake_force_sig(SIGKILL, tsk);
73726+ } while_each_thread(tsk2, tsk);
73727+ read_unlock(&tasklist_lock);
73728+ }
73729+#endif
73730+}
73731+
73732+#ifdef CONFIG_GRKERNSEC_BRUTE
73733+static bool suid_ban_expired(struct user_struct *user)
73734+{
73735+ if (user->suid_ban_expires != ~0UL && time_after_eq(get_seconds(), user->suid_ban_expires)) {
73736+ user->suid_banned = 0;
73737+ user->suid_ban_expires = 0;
73738+ free_uid(user);
73739+ return true;
73740+ }
73741+
73742+ return false;
73743+}
73744+#endif
73745+
73746+int gr_process_kernel_exec_ban(void)
73747+{
73748+#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
73749+ if (unlikely(current->cred->user->kernel_banned))
73750+ return -EPERM;
73751+#endif
73752+ return 0;
73753+}
73754+
73755+int gr_process_kernel_setuid_ban(struct user_struct *user)
73756+{
73757+#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
73758+ if (unlikely(user->kernel_banned))
73759+ gr_fake_force_sig(SIGKILL, current);
73760+#endif
73761+ return 0;
73762+}
73763+
73764+int gr_process_suid_exec_ban(const struct linux_binprm *bprm)
73765+{
73766+#ifdef CONFIG_GRKERNSEC_BRUTE
73767+ struct user_struct *user = current->cred->user;
73768+ if (unlikely(user->suid_banned)) {
73769+ if (suid_ban_expired(user))
73770+ return 0;
73771+ /* disallow execution of suid binaries only */
73772+ else if (!uid_eq(bprm->cred->euid, current->cred->uid))
73773+ return -EPERM;
73774+ }
73775+#endif
73776+ return 0;
73777+}
73778diff --git a/grsecurity/grsec_sock.c b/grsecurity/grsec_sock.c
73779new file mode 100644
73780index 0000000..4030d57
73781--- /dev/null
73782+++ b/grsecurity/grsec_sock.c
73783@@ -0,0 +1,244 @@
73784+#include <linux/kernel.h>
73785+#include <linux/module.h>
73786+#include <linux/sched.h>
73787+#include <linux/file.h>
73788+#include <linux/net.h>
73789+#include <linux/in.h>
73790+#include <linux/ip.h>
73791+#include <net/sock.h>
73792+#include <net/inet_sock.h>
73793+#include <linux/grsecurity.h>
73794+#include <linux/grinternal.h>
73795+#include <linux/gracl.h>
73796+
73797+extern int gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb);
73798+extern int gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr);
73799+
73800+EXPORT_SYMBOL(gr_search_udp_recvmsg);
73801+EXPORT_SYMBOL(gr_search_udp_sendmsg);
73802+
73803+#ifdef CONFIG_UNIX_MODULE
73804+EXPORT_SYMBOL(gr_acl_handle_unix);
73805+EXPORT_SYMBOL(gr_acl_handle_mknod);
73806+EXPORT_SYMBOL(gr_handle_chroot_unix);
73807+EXPORT_SYMBOL(gr_handle_create);
73808+#endif
73809+
73810+#ifdef CONFIG_GRKERNSEC
73811+#define gr_conn_table_size 32749
73812+struct conn_table_entry {
73813+ struct conn_table_entry *next;
73814+ struct signal_struct *sig;
73815+};
73816+
73817+struct conn_table_entry *gr_conn_table[gr_conn_table_size];
73818+DEFINE_SPINLOCK(gr_conn_table_lock);
73819+
73820+extern const char * gr_socktype_to_name(unsigned char type);
73821+extern const char * gr_proto_to_name(unsigned char proto);
73822+extern const char * gr_sockfamily_to_name(unsigned char family);
73823+
73824+static __inline__ int
73825+conn_hash(__u32 saddr, __u32 daddr, __u16 sport, __u16 dport, unsigned int size)
73826+{
73827+ return ((daddr + saddr + (sport << 8) + (dport << 16)) % size);
73828+}
73829+
73830+static __inline__ int
73831+conn_match(const struct signal_struct *sig, __u32 saddr, __u32 daddr,
73832+ __u16 sport, __u16 dport)
73833+{
73834+ if (unlikely(sig->gr_saddr == saddr && sig->gr_daddr == daddr &&
73835+ sig->gr_sport == sport && sig->gr_dport == dport))
73836+ return 1;
73837+ else
73838+ return 0;
73839+}
73840+
73841+static void gr_add_to_task_ip_table_nolock(struct signal_struct *sig, struct conn_table_entry *newent)
73842+{
73843+ struct conn_table_entry **match;
73844+ unsigned int index;
73845+
73846+ index = conn_hash(sig->gr_saddr, sig->gr_daddr,
73847+ sig->gr_sport, sig->gr_dport,
73848+ gr_conn_table_size);
73849+
73850+ newent->sig = sig;
73851+
73852+ match = &gr_conn_table[index];
73853+ newent->next = *match;
73854+ *match = newent;
73855+
73856+ return;
73857+}
73858+
73859+static void gr_del_task_from_ip_table_nolock(struct signal_struct *sig)
73860+{
73861+ struct conn_table_entry *match, *last = NULL;
73862+ unsigned int index;
73863+
73864+ index = conn_hash(sig->gr_saddr, sig->gr_daddr,
73865+ sig->gr_sport, sig->gr_dport,
73866+ gr_conn_table_size);
73867+
73868+ match = gr_conn_table[index];
73869+ while (match && !conn_match(match->sig,
73870+ sig->gr_saddr, sig->gr_daddr, sig->gr_sport,
73871+ sig->gr_dport)) {
73872+ last = match;
73873+ match = match->next;
73874+ }
73875+
73876+ if (match) {
73877+ if (last)
73878+ last->next = match->next;
73879+ else
73880+ gr_conn_table[index] = NULL;
73881+ kfree(match);
73882+ }
73883+
73884+ return;
73885+}
73886+
73887+static struct signal_struct * gr_lookup_task_ip_table(__u32 saddr, __u32 daddr,
73888+ __u16 sport, __u16 dport)
73889+{
73890+ struct conn_table_entry *match;
73891+ unsigned int index;
73892+
73893+ index = conn_hash(saddr, daddr, sport, dport, gr_conn_table_size);
73894+
73895+ match = gr_conn_table[index];
73896+ while (match && !conn_match(match->sig, saddr, daddr, sport, dport))
73897+ match = match->next;
73898+
73899+ if (match)
73900+ return match->sig;
73901+ else
73902+ return NULL;
73903+}
73904+
73905+#endif
73906+
73907+void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet)
73908+{
73909+#ifdef CONFIG_GRKERNSEC
73910+ struct signal_struct *sig = task->signal;
73911+ struct conn_table_entry *newent;
73912+
73913+ newent = kmalloc(sizeof(struct conn_table_entry), GFP_ATOMIC);
73914+ if (newent == NULL)
73915+ return;
73916+ /* no bh lock needed since we are called with bh disabled */
73917+ spin_lock(&gr_conn_table_lock);
73918+ gr_del_task_from_ip_table_nolock(sig);
73919+ sig->gr_saddr = inet->inet_rcv_saddr;
73920+ sig->gr_daddr = inet->inet_daddr;
73921+ sig->gr_sport = inet->inet_sport;
73922+ sig->gr_dport = inet->inet_dport;
73923+ gr_add_to_task_ip_table_nolock(sig, newent);
73924+ spin_unlock(&gr_conn_table_lock);
73925+#endif
73926+ return;
73927+}
73928+
73929+void gr_del_task_from_ip_table(struct task_struct *task)
73930+{
73931+#ifdef CONFIG_GRKERNSEC
73932+ spin_lock_bh(&gr_conn_table_lock);
73933+ gr_del_task_from_ip_table_nolock(task->signal);
73934+ spin_unlock_bh(&gr_conn_table_lock);
73935+#endif
73936+ return;
73937+}
73938+
73939+void
73940+gr_attach_curr_ip(const struct sock *sk)
73941+{
73942+#ifdef CONFIG_GRKERNSEC
73943+ struct signal_struct *p, *set;
73944+ const struct inet_sock *inet = inet_sk(sk);
73945+
73946+ if (unlikely(sk->sk_protocol != IPPROTO_TCP))
73947+ return;
73948+
73949+ set = current->signal;
73950+
73951+ spin_lock_bh(&gr_conn_table_lock);
73952+ p = gr_lookup_task_ip_table(inet->inet_daddr, inet->inet_rcv_saddr,
73953+ inet->inet_dport, inet->inet_sport);
73954+ if (unlikely(p != NULL)) {
73955+ set->curr_ip = p->curr_ip;
73956+ set->used_accept = 1;
73957+ gr_del_task_from_ip_table_nolock(p);
73958+ spin_unlock_bh(&gr_conn_table_lock);
73959+ return;
73960+ }
73961+ spin_unlock_bh(&gr_conn_table_lock);
73962+
73963+ set->curr_ip = inet->inet_daddr;
73964+ set->used_accept = 1;
73965+#endif
73966+ return;
73967+}
73968+
73969+int
73970+gr_handle_sock_all(const int family, const int type, const int protocol)
73971+{
73972+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
73973+ if (grsec_enable_socket_all && in_group_p(grsec_socket_all_gid) &&
73974+ (family != AF_UNIX)) {
73975+ if (family == AF_INET)
73976+ gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), gr_proto_to_name(protocol));
73977+ else
73978+ gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), protocol);
73979+ return -EACCES;
73980+ }
73981+#endif
73982+ return 0;
73983+}
73984+
73985+int
73986+gr_handle_sock_server(const struct sockaddr *sck)
73987+{
73988+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
73989+ if (grsec_enable_socket_server &&
73990+ in_group_p(grsec_socket_server_gid) &&
73991+ sck && (sck->sa_family != AF_UNIX) &&
73992+ (sck->sa_family != AF_LOCAL)) {
73993+ gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
73994+ return -EACCES;
73995+ }
73996+#endif
73997+ return 0;
73998+}
73999+
74000+int
74001+gr_handle_sock_server_other(const struct sock *sck)
74002+{
74003+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
74004+ if (grsec_enable_socket_server &&
74005+ in_group_p(grsec_socket_server_gid) &&
74006+ sck && (sck->sk_family != AF_UNIX) &&
74007+ (sck->sk_family != AF_LOCAL)) {
74008+ gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
74009+ return -EACCES;
74010+ }
74011+#endif
74012+ return 0;
74013+}
74014+
74015+int
74016+gr_handle_sock_client(const struct sockaddr *sck)
74017+{
74018+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
74019+ if (grsec_enable_socket_client && in_group_p(grsec_socket_client_gid) &&
74020+ sck && (sck->sa_family != AF_UNIX) &&
74021+ (sck->sa_family != AF_LOCAL)) {
74022+ gr_log_noargs(GR_DONT_AUDIT, GR_CONNECT_MSG);
74023+ return -EACCES;
74024+ }
74025+#endif
74026+ return 0;
74027+}
74028diff --git a/grsecurity/grsec_sysctl.c b/grsecurity/grsec_sysctl.c
74029new file mode 100644
74030index 0000000..8159888
74031--- /dev/null
74032+++ b/grsecurity/grsec_sysctl.c
74033@@ -0,0 +1,479 @@
74034+#include <linux/kernel.h>
74035+#include <linux/sched.h>
74036+#include <linux/sysctl.h>
74037+#include <linux/grsecurity.h>
74038+#include <linux/grinternal.h>
74039+
74040+int
74041+gr_handle_sysctl_mod(const char *dirname, const char *name, const int op)
74042+{
74043+#ifdef CONFIG_GRKERNSEC_SYSCTL
74044+ if (dirname == NULL || name == NULL)
74045+ return 0;
74046+ if (!strcmp(dirname, "grsecurity") && grsec_lock && (op & MAY_WRITE)) {
74047+ gr_log_str(GR_DONT_AUDIT, GR_SYSCTL_MSG, name);
74048+ return -EACCES;
74049+ }
74050+#endif
74051+ return 0;
74052+}
74053+
74054+#if defined(CONFIG_GRKERNSEC_ROFS) || defined(CONFIG_GRKERNSEC_DENYUSB)
74055+static int __maybe_unused __read_only one = 1;
74056+#endif
74057+
74058+#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS) || \
74059+ defined(CONFIG_GRKERNSEC_DENYUSB)
74060+struct ctl_table grsecurity_table[] = {
74061+#ifdef CONFIG_GRKERNSEC_SYSCTL
74062+#ifdef CONFIG_GRKERNSEC_SYSCTL_DISTRO
74063+#ifdef CONFIG_GRKERNSEC_IO
74064+ {
74065+ .procname = "disable_priv_io",
74066+ .data = &grsec_disable_privio,
74067+ .maxlen = sizeof(int),
74068+ .mode = 0600,
74069+ .proc_handler = &proc_dointvec,
74070+ },
74071+#endif
74072+#endif
74073+#ifdef CONFIG_GRKERNSEC_LINK
74074+ {
74075+ .procname = "linking_restrictions",
74076+ .data = &grsec_enable_link,
74077+ .maxlen = sizeof(int),
74078+ .mode = 0600,
74079+ .proc_handler = &proc_dointvec,
74080+ },
74081+#endif
74082+#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
74083+ {
74084+ .procname = "enforce_symlinksifowner",
74085+ .data = &grsec_enable_symlinkown,
74086+ .maxlen = sizeof(int),
74087+ .mode = 0600,
74088+ .proc_handler = &proc_dointvec,
74089+ },
74090+ {
74091+ .procname = "symlinkown_gid",
74092+ .data = &grsec_symlinkown_gid,
74093+ .maxlen = sizeof(int),
74094+ .mode = 0600,
74095+ .proc_handler = &proc_dointvec,
74096+ },
74097+#endif
74098+#ifdef CONFIG_GRKERNSEC_BRUTE
74099+ {
74100+ .procname = "deter_bruteforce",
74101+ .data = &grsec_enable_brute,
74102+ .maxlen = sizeof(int),
74103+ .mode = 0600,
74104+ .proc_handler = &proc_dointvec,
74105+ },
74106+#endif
74107+#ifdef CONFIG_GRKERNSEC_FIFO
74108+ {
74109+ .procname = "fifo_restrictions",
74110+ .data = &grsec_enable_fifo,
74111+ .maxlen = sizeof(int),
74112+ .mode = 0600,
74113+ .proc_handler = &proc_dointvec,
74114+ },
74115+#endif
74116+#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
74117+ {
74118+ .procname = "ptrace_readexec",
74119+ .data = &grsec_enable_ptrace_readexec,
74120+ .maxlen = sizeof(int),
74121+ .mode = 0600,
74122+ .proc_handler = &proc_dointvec,
74123+ },
74124+#endif
74125+#ifdef CONFIG_GRKERNSEC_SETXID
74126+ {
74127+ .procname = "consistent_setxid",
74128+ .data = &grsec_enable_setxid,
74129+ .maxlen = sizeof(int),
74130+ .mode = 0600,
74131+ .proc_handler = &proc_dointvec,
74132+ },
74133+#endif
74134+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
74135+ {
74136+ .procname = "ip_blackhole",
74137+ .data = &grsec_enable_blackhole,
74138+ .maxlen = sizeof(int),
74139+ .mode = 0600,
74140+ .proc_handler = &proc_dointvec,
74141+ },
74142+ {
74143+ .procname = "lastack_retries",
74144+ .data = &grsec_lastack_retries,
74145+ .maxlen = sizeof(int),
74146+ .mode = 0600,
74147+ .proc_handler = &proc_dointvec,
74148+ },
74149+#endif
74150+#ifdef CONFIG_GRKERNSEC_EXECLOG
74151+ {
74152+ .procname = "exec_logging",
74153+ .data = &grsec_enable_execlog,
74154+ .maxlen = sizeof(int),
74155+ .mode = 0600,
74156+ .proc_handler = &proc_dointvec,
74157+ },
74158+#endif
74159+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
74160+ {
74161+ .procname = "rwxmap_logging",
74162+ .data = &grsec_enable_log_rwxmaps,
74163+ .maxlen = sizeof(int),
74164+ .mode = 0600,
74165+ .proc_handler = &proc_dointvec,
74166+ },
74167+#endif
74168+#ifdef CONFIG_GRKERNSEC_SIGNAL
74169+ {
74170+ .procname = "signal_logging",
74171+ .data = &grsec_enable_signal,
74172+ .maxlen = sizeof(int),
74173+ .mode = 0600,
74174+ .proc_handler = &proc_dointvec,
74175+ },
74176+#endif
74177+#ifdef CONFIG_GRKERNSEC_FORKFAIL
74178+ {
74179+ .procname = "forkfail_logging",
74180+ .data = &grsec_enable_forkfail,
74181+ .maxlen = sizeof(int),
74182+ .mode = 0600,
74183+ .proc_handler = &proc_dointvec,
74184+ },
74185+#endif
74186+#ifdef CONFIG_GRKERNSEC_TIME
74187+ {
74188+ .procname = "timechange_logging",
74189+ .data = &grsec_enable_time,
74190+ .maxlen = sizeof(int),
74191+ .mode = 0600,
74192+ .proc_handler = &proc_dointvec,
74193+ },
74194+#endif
74195+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
74196+ {
74197+ .procname = "chroot_deny_shmat",
74198+ .data = &grsec_enable_chroot_shmat,
74199+ .maxlen = sizeof(int),
74200+ .mode = 0600,
74201+ .proc_handler = &proc_dointvec,
74202+ },
74203+#endif
74204+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
74205+ {
74206+ .procname = "chroot_deny_unix",
74207+ .data = &grsec_enable_chroot_unix,
74208+ .maxlen = sizeof(int),
74209+ .mode = 0600,
74210+ .proc_handler = &proc_dointvec,
74211+ },
74212+#endif
74213+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
74214+ {
74215+ .procname = "chroot_deny_mount",
74216+ .data = &grsec_enable_chroot_mount,
74217+ .maxlen = sizeof(int),
74218+ .mode = 0600,
74219+ .proc_handler = &proc_dointvec,
74220+ },
74221+#endif
74222+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
74223+ {
74224+ .procname = "chroot_deny_fchdir",
74225+ .data = &grsec_enable_chroot_fchdir,
74226+ .maxlen = sizeof(int),
74227+ .mode = 0600,
74228+ .proc_handler = &proc_dointvec,
74229+ },
74230+#endif
74231+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
74232+ {
74233+ .procname = "chroot_deny_chroot",
74234+ .data = &grsec_enable_chroot_double,
74235+ .maxlen = sizeof(int),
74236+ .mode = 0600,
74237+ .proc_handler = &proc_dointvec,
74238+ },
74239+#endif
74240+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
74241+ {
74242+ .procname = "chroot_deny_pivot",
74243+ .data = &grsec_enable_chroot_pivot,
74244+ .maxlen = sizeof(int),
74245+ .mode = 0600,
74246+ .proc_handler = &proc_dointvec,
74247+ },
74248+#endif
74249+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
74250+ {
74251+ .procname = "chroot_enforce_chdir",
74252+ .data = &grsec_enable_chroot_chdir,
74253+ .maxlen = sizeof(int),
74254+ .mode = 0600,
74255+ .proc_handler = &proc_dointvec,
74256+ },
74257+#endif
74258+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
74259+ {
74260+ .procname = "chroot_deny_chmod",
74261+ .data = &grsec_enable_chroot_chmod,
74262+ .maxlen = sizeof(int),
74263+ .mode = 0600,
74264+ .proc_handler = &proc_dointvec,
74265+ },
74266+#endif
74267+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
74268+ {
74269+ .procname = "chroot_deny_mknod",
74270+ .data = &grsec_enable_chroot_mknod,
74271+ .maxlen = sizeof(int),
74272+ .mode = 0600,
74273+ .proc_handler = &proc_dointvec,
74274+ },
74275+#endif
74276+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
74277+ {
74278+ .procname = "chroot_restrict_nice",
74279+ .data = &grsec_enable_chroot_nice,
74280+ .maxlen = sizeof(int),
74281+ .mode = 0600,
74282+ .proc_handler = &proc_dointvec,
74283+ },
74284+#endif
74285+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
74286+ {
74287+ .procname = "chroot_execlog",
74288+ .data = &grsec_enable_chroot_execlog,
74289+ .maxlen = sizeof(int),
74290+ .mode = 0600,
74291+ .proc_handler = &proc_dointvec,
74292+ },
74293+#endif
74294+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
74295+ {
74296+ .procname = "chroot_caps",
74297+ .data = &grsec_enable_chroot_caps,
74298+ .maxlen = sizeof(int),
74299+ .mode = 0600,
74300+ .proc_handler = &proc_dointvec,
74301+ },
74302+#endif
74303+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
74304+ {
74305+ .procname = "chroot_deny_sysctl",
74306+ .data = &grsec_enable_chroot_sysctl,
74307+ .maxlen = sizeof(int),
74308+ .mode = 0600,
74309+ .proc_handler = &proc_dointvec,
74310+ },
74311+#endif
74312+#ifdef CONFIG_GRKERNSEC_TPE
74313+ {
74314+ .procname = "tpe",
74315+ .data = &grsec_enable_tpe,
74316+ .maxlen = sizeof(int),
74317+ .mode = 0600,
74318+ .proc_handler = &proc_dointvec,
74319+ },
74320+ {
74321+ .procname = "tpe_gid",
74322+ .data = &grsec_tpe_gid,
74323+ .maxlen = sizeof(int),
74324+ .mode = 0600,
74325+ .proc_handler = &proc_dointvec,
74326+ },
74327+#endif
74328+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
74329+ {
74330+ .procname = "tpe_invert",
74331+ .data = &grsec_enable_tpe_invert,
74332+ .maxlen = sizeof(int),
74333+ .mode = 0600,
74334+ .proc_handler = &proc_dointvec,
74335+ },
74336+#endif
74337+#ifdef CONFIG_GRKERNSEC_TPE_ALL
74338+ {
74339+ .procname = "tpe_restrict_all",
74340+ .data = &grsec_enable_tpe_all,
74341+ .maxlen = sizeof(int),
74342+ .mode = 0600,
74343+ .proc_handler = &proc_dointvec,
74344+ },
74345+#endif
74346+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
74347+ {
74348+ .procname = "socket_all",
74349+ .data = &grsec_enable_socket_all,
74350+ .maxlen = sizeof(int),
74351+ .mode = 0600,
74352+ .proc_handler = &proc_dointvec,
74353+ },
74354+ {
74355+ .procname = "socket_all_gid",
74356+ .data = &grsec_socket_all_gid,
74357+ .maxlen = sizeof(int),
74358+ .mode = 0600,
74359+ .proc_handler = &proc_dointvec,
74360+ },
74361+#endif
74362+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
74363+ {
74364+ .procname = "socket_client",
74365+ .data = &grsec_enable_socket_client,
74366+ .maxlen = sizeof(int),
74367+ .mode = 0600,
74368+ .proc_handler = &proc_dointvec,
74369+ },
74370+ {
74371+ .procname = "socket_client_gid",
74372+ .data = &grsec_socket_client_gid,
74373+ .maxlen = sizeof(int),
74374+ .mode = 0600,
74375+ .proc_handler = &proc_dointvec,
74376+ },
74377+#endif
74378+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
74379+ {
74380+ .procname = "socket_server",
74381+ .data = &grsec_enable_socket_server,
74382+ .maxlen = sizeof(int),
74383+ .mode = 0600,
74384+ .proc_handler = &proc_dointvec,
74385+ },
74386+ {
74387+ .procname = "socket_server_gid",
74388+ .data = &grsec_socket_server_gid,
74389+ .maxlen = sizeof(int),
74390+ .mode = 0600,
74391+ .proc_handler = &proc_dointvec,
74392+ },
74393+#endif
74394+#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
74395+ {
74396+ .procname = "audit_group",
74397+ .data = &grsec_enable_group,
74398+ .maxlen = sizeof(int),
74399+ .mode = 0600,
74400+ .proc_handler = &proc_dointvec,
74401+ },
74402+ {
74403+ .procname = "audit_gid",
74404+ .data = &grsec_audit_gid,
74405+ .maxlen = sizeof(int),
74406+ .mode = 0600,
74407+ .proc_handler = &proc_dointvec,
74408+ },
74409+#endif
74410+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
74411+ {
74412+ .procname = "audit_chdir",
74413+ .data = &grsec_enable_chdir,
74414+ .maxlen = sizeof(int),
74415+ .mode = 0600,
74416+ .proc_handler = &proc_dointvec,
74417+ },
74418+#endif
74419+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
74420+ {
74421+ .procname = "audit_mount",
74422+ .data = &grsec_enable_mount,
74423+ .maxlen = sizeof(int),
74424+ .mode = 0600,
74425+ .proc_handler = &proc_dointvec,
74426+ },
74427+#endif
74428+#ifdef CONFIG_GRKERNSEC_DMESG
74429+ {
74430+ .procname = "dmesg",
74431+ .data = &grsec_enable_dmesg,
74432+ .maxlen = sizeof(int),
74433+ .mode = 0600,
74434+ .proc_handler = &proc_dointvec,
74435+ },
74436+#endif
74437+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
74438+ {
74439+ .procname = "chroot_findtask",
74440+ .data = &grsec_enable_chroot_findtask,
74441+ .maxlen = sizeof(int),
74442+ .mode = 0600,
74443+ .proc_handler = &proc_dointvec,
74444+ },
74445+#endif
74446+#ifdef CONFIG_GRKERNSEC_RESLOG
74447+ {
74448+ .procname = "resource_logging",
74449+ .data = &grsec_resource_logging,
74450+ .maxlen = sizeof(int),
74451+ .mode = 0600,
74452+ .proc_handler = &proc_dointvec,
74453+ },
74454+#endif
74455+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
74456+ {
74457+ .procname = "audit_ptrace",
74458+ .data = &grsec_enable_audit_ptrace,
74459+ .maxlen = sizeof(int),
74460+ .mode = 0600,
74461+ .proc_handler = &proc_dointvec,
74462+ },
74463+#endif
74464+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
74465+ {
74466+ .procname = "harden_ptrace",
74467+ .data = &grsec_enable_harden_ptrace,
74468+ .maxlen = sizeof(int),
74469+ .mode = 0600,
74470+ .proc_handler = &proc_dointvec,
74471+ },
74472+#endif
74473+#ifdef CONFIG_GRKERNSEC_HARDEN_IPC
74474+ {
74475+ .procname = "harden_ipc",
74476+ .data = &grsec_enable_harden_ipc,
74477+ .maxlen = sizeof(int),
74478+ .mode = 0600,
74479+ .proc_handler = &proc_dointvec,
74480+ },
74481+#endif
74482+ {
74483+ .procname = "grsec_lock",
74484+ .data = &grsec_lock,
74485+ .maxlen = sizeof(int),
74486+ .mode = 0600,
74487+ .proc_handler = &proc_dointvec,
74488+ },
74489+#endif
74490+#ifdef CONFIG_GRKERNSEC_ROFS
74491+ {
74492+ .procname = "romount_protect",
74493+ .data = &grsec_enable_rofs,
74494+ .maxlen = sizeof(int),
74495+ .mode = 0600,
74496+ .proc_handler = &proc_dointvec_minmax,
74497+ .extra1 = &one,
74498+ .extra2 = &one,
74499+ },
74500+#endif
74501+#if defined(CONFIG_GRKERNSEC_DENYUSB) && !defined(CONFIG_GRKERNSEC_DENYUSB_FORCE)
74502+ {
74503+ .procname = "deny_new_usb",
74504+ .data = &grsec_deny_new_usb,
74505+ .maxlen = sizeof(int),
74506+ .mode = 0600,
74507+ .proc_handler = &proc_dointvec,
74508+ },
74509+#endif
74510+ { }
74511+};
74512+#endif
74513diff --git a/grsecurity/grsec_time.c b/grsecurity/grsec_time.c
74514new file mode 100644
74515index 0000000..0dc13c3
74516--- /dev/null
74517+++ b/grsecurity/grsec_time.c
74518@@ -0,0 +1,16 @@
74519+#include <linux/kernel.h>
74520+#include <linux/sched.h>
74521+#include <linux/grinternal.h>
74522+#include <linux/module.h>
74523+
74524+void
74525+gr_log_timechange(void)
74526+{
74527+#ifdef CONFIG_GRKERNSEC_TIME
74528+ if (grsec_enable_time)
74529+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_TIME_MSG);
74530+#endif
74531+ return;
74532+}
74533+
74534+EXPORT_SYMBOL(gr_log_timechange);
74535diff --git a/grsecurity/grsec_tpe.c b/grsecurity/grsec_tpe.c
74536new file mode 100644
74537index 0000000..ee57dcf
74538--- /dev/null
74539+++ b/grsecurity/grsec_tpe.c
74540@@ -0,0 +1,73 @@
74541+#include <linux/kernel.h>
74542+#include <linux/sched.h>
74543+#include <linux/file.h>
74544+#include <linux/fs.h>
74545+#include <linux/grinternal.h>
74546+
74547+extern int gr_acl_tpe_check(void);
74548+
74549+int
74550+gr_tpe_allow(const struct file *file)
74551+{
74552+#ifdef CONFIG_GRKERNSEC
74553+ struct inode *inode = file->f_path.dentry->d_parent->d_inode;
74554+ const struct cred *cred = current_cred();
74555+ char *msg = NULL;
74556+ char *msg2 = NULL;
74557+
74558+ // never restrict root
74559+ if (gr_is_global_root(cred->uid))
74560+ return 1;
74561+
74562+ if (grsec_enable_tpe) {
74563+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
74564+ if (grsec_enable_tpe_invert && !in_group_p(grsec_tpe_gid))
74565+ msg = "not being in trusted group";
74566+ else if (!grsec_enable_tpe_invert && in_group_p(grsec_tpe_gid))
74567+ msg = "being in untrusted group";
74568+#else
74569+ if (in_group_p(grsec_tpe_gid))
74570+ msg = "being in untrusted group";
74571+#endif
74572+ }
74573+ if (!msg && gr_acl_tpe_check())
74574+ msg = "being in untrusted role";
74575+
74576+ // not in any affected group/role
74577+ if (!msg)
74578+ goto next_check;
74579+
74580+ if (gr_is_global_nonroot(inode->i_uid))
74581+ msg2 = "file in non-root-owned directory";
74582+ else if (inode->i_mode & S_IWOTH)
74583+ msg2 = "file in world-writable directory";
74584+ else if (inode->i_mode & S_IWGRP)
74585+ msg2 = "file in group-writable directory";
74586+
74587+ if (msg && msg2) {
74588+ char fullmsg[70] = {0};
74589+ snprintf(fullmsg, sizeof(fullmsg)-1, "%s and %s", msg, msg2);
74590+ gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, fullmsg, file->f_path.dentry, file->f_path.mnt);
74591+ return 0;
74592+ }
74593+ msg = NULL;
74594+next_check:
74595+#ifdef CONFIG_GRKERNSEC_TPE_ALL
74596+ if (!grsec_enable_tpe || !grsec_enable_tpe_all)
74597+ return 1;
74598+
74599+ if (gr_is_global_nonroot(inode->i_uid) && !uid_eq(inode->i_uid, cred->uid))
74600+ msg = "directory not owned by user";
74601+ else if (inode->i_mode & S_IWOTH)
74602+ msg = "file in world-writable directory";
74603+ else if (inode->i_mode & S_IWGRP)
74604+ msg = "file in group-writable directory";
74605+
74606+ if (msg) {
74607+ gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, msg, file->f_path.dentry, file->f_path.mnt);
74608+ return 0;
74609+ }
74610+#endif
74611+#endif
74612+ return 1;
74613+}
74614diff --git a/grsecurity/grsec_usb.c b/grsecurity/grsec_usb.c
74615new file mode 100644
74616index 0000000..ae02d8e
74617--- /dev/null
74618+++ b/grsecurity/grsec_usb.c
74619@@ -0,0 +1,15 @@
74620+#include <linux/kernel.h>
74621+#include <linux/grinternal.h>
74622+#include <linux/module.h>
74623+
74624+int gr_handle_new_usb(void)
74625+{
74626+#ifdef CONFIG_GRKERNSEC_DENYUSB
74627+ if (grsec_deny_new_usb) {
74628+ printk(KERN_ALERT "grsec: denied insert of new USB device\n");
74629+ return 1;
74630+ }
74631+#endif
74632+ return 0;
74633+}
74634+EXPORT_SYMBOL_GPL(gr_handle_new_usb);
74635diff --git a/grsecurity/grsum.c b/grsecurity/grsum.c
74636new file mode 100644
74637index 0000000..9f7b1ac
74638--- /dev/null
74639+++ b/grsecurity/grsum.c
74640@@ -0,0 +1,61 @@
74641+#include <linux/err.h>
74642+#include <linux/kernel.h>
74643+#include <linux/sched.h>
74644+#include <linux/mm.h>
74645+#include <linux/scatterlist.h>
74646+#include <linux/crypto.h>
74647+#include <linux/gracl.h>
74648+
74649+
74650+#if !defined(CONFIG_CRYPTO) || defined(CONFIG_CRYPTO_MODULE) || !defined(CONFIG_CRYPTO_SHA256) || defined(CONFIG_CRYPTO_SHA256_MODULE)
74651+#error "crypto and sha256 must be built into the kernel"
74652+#endif
74653+
74654+int
74655+chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum)
74656+{
74657+ char *p;
74658+ struct crypto_hash *tfm;
74659+ struct hash_desc desc;
74660+ struct scatterlist sg;
74661+ unsigned char temp_sum[GR_SHA_LEN];
74662+ volatile int retval = 0;
74663+ volatile int dummy = 0;
74664+ unsigned int i;
74665+
74666+ sg_init_table(&sg, 1);
74667+
74668+ tfm = crypto_alloc_hash("sha256", 0, CRYPTO_ALG_ASYNC);
74669+ if (IS_ERR(tfm)) {
74670+ /* should never happen, since sha256 should be built in */
74671+ return 1;
74672+ }
74673+
74674+ desc.tfm = tfm;
74675+ desc.flags = 0;
74676+
74677+ crypto_hash_init(&desc);
74678+
74679+ p = salt;
74680+ sg_set_buf(&sg, p, GR_SALT_LEN);
74681+ crypto_hash_update(&desc, &sg, sg.length);
74682+
74683+ p = entry->pw;
74684+ sg_set_buf(&sg, p, strlen(p));
74685+
74686+ crypto_hash_update(&desc, &sg, sg.length);
74687+
74688+ crypto_hash_final(&desc, temp_sum);
74689+
74690+ memset(entry->pw, 0, GR_PW_LEN);
74691+
74692+ for (i = 0; i < GR_SHA_LEN; i++)
74693+ if (sum[i] != temp_sum[i])
74694+ retval = 1;
74695+ else
74696+ dummy = 1; // waste a cycle
74697+
74698+ crypto_free_hash(tfm);
74699+
74700+ return retval;
74701+}
74702diff --git a/include/asm-generic/4level-fixup.h b/include/asm-generic/4level-fixup.h
74703index 77ff547..181834f 100644
74704--- a/include/asm-generic/4level-fixup.h
74705+++ b/include/asm-generic/4level-fixup.h
74706@@ -13,8 +13,10 @@
74707 #define pmd_alloc(mm, pud, address) \
74708 ((unlikely(pgd_none(*(pud))) && __pmd_alloc(mm, pud, address))? \
74709 NULL: pmd_offset(pud, address))
74710+#define pmd_alloc_kernel(mm, pud, address) pmd_alloc((mm), (pud), (address))
74711
74712 #define pud_alloc(mm, pgd, address) (pgd)
74713+#define pud_alloc_kernel(mm, pgd, address) pud_alloc((mm), (pgd), (address))
74714 #define pud_offset(pgd, start) (pgd)
74715 #define pud_none(pud) 0
74716 #define pud_bad(pud) 0
74717diff --git a/include/asm-generic/atomic-long.h b/include/asm-generic/atomic-long.h
74718index b7babf0..97f4c4f 100644
74719--- a/include/asm-generic/atomic-long.h
74720+++ b/include/asm-generic/atomic-long.h
74721@@ -22,6 +22,12 @@
74722
74723 typedef atomic64_t atomic_long_t;
74724
74725+#ifdef CONFIG_PAX_REFCOUNT
74726+typedef atomic64_unchecked_t atomic_long_unchecked_t;
74727+#else
74728+typedef atomic64_t atomic_long_unchecked_t;
74729+#endif
74730+
74731 #define ATOMIC_LONG_INIT(i) ATOMIC64_INIT(i)
74732
74733 static inline long atomic_long_read(atomic_long_t *l)
74734@@ -31,6 +37,15 @@ static inline long atomic_long_read(atomic_long_t *l)
74735 return (long)atomic64_read(v);
74736 }
74737
74738+#ifdef CONFIG_PAX_REFCOUNT
74739+static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
74740+{
74741+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
74742+
74743+ return (long)atomic64_read_unchecked(v);
74744+}
74745+#endif
74746+
74747 static inline void atomic_long_set(atomic_long_t *l, long i)
74748 {
74749 atomic64_t *v = (atomic64_t *)l;
74750@@ -38,6 +53,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
74751 atomic64_set(v, i);
74752 }
74753
74754+#ifdef CONFIG_PAX_REFCOUNT
74755+static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
74756+{
74757+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
74758+
74759+ atomic64_set_unchecked(v, i);
74760+}
74761+#endif
74762+
74763 static inline void atomic_long_inc(atomic_long_t *l)
74764 {
74765 atomic64_t *v = (atomic64_t *)l;
74766@@ -45,6 +69,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
74767 atomic64_inc(v);
74768 }
74769
74770+#ifdef CONFIG_PAX_REFCOUNT
74771+static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
74772+{
74773+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
74774+
74775+ atomic64_inc_unchecked(v);
74776+}
74777+#endif
74778+
74779 static inline void atomic_long_dec(atomic_long_t *l)
74780 {
74781 atomic64_t *v = (atomic64_t *)l;
74782@@ -52,6 +85,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
74783 atomic64_dec(v);
74784 }
74785
74786+#ifdef CONFIG_PAX_REFCOUNT
74787+static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
74788+{
74789+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
74790+
74791+ atomic64_dec_unchecked(v);
74792+}
74793+#endif
74794+
74795 static inline void atomic_long_add(long i, atomic_long_t *l)
74796 {
74797 atomic64_t *v = (atomic64_t *)l;
74798@@ -59,6 +101,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
74799 atomic64_add(i, v);
74800 }
74801
74802+#ifdef CONFIG_PAX_REFCOUNT
74803+static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
74804+{
74805+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
74806+
74807+ atomic64_add_unchecked(i, v);
74808+}
74809+#endif
74810+
74811 static inline void atomic_long_sub(long i, atomic_long_t *l)
74812 {
74813 atomic64_t *v = (atomic64_t *)l;
74814@@ -66,6 +117,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
74815 atomic64_sub(i, v);
74816 }
74817
74818+#ifdef CONFIG_PAX_REFCOUNT
74819+static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
74820+{
74821+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
74822+
74823+ atomic64_sub_unchecked(i, v);
74824+}
74825+#endif
74826+
74827 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
74828 {
74829 atomic64_t *v = (atomic64_t *)l;
74830@@ -94,13 +154,22 @@ static inline int atomic_long_add_negative(long i, atomic_long_t *l)
74831 return atomic64_add_negative(i, v);
74832 }
74833
74834-static inline long atomic_long_add_return(long i, atomic_long_t *l)
74835+static inline long __intentional_overflow(-1) atomic_long_add_return(long i, atomic_long_t *l)
74836 {
74837 atomic64_t *v = (atomic64_t *)l;
74838
74839 return (long)atomic64_add_return(i, v);
74840 }
74841
74842+#ifdef CONFIG_PAX_REFCOUNT
74843+static inline long atomic_long_add_return_unchecked(long i, atomic_long_unchecked_t *l)
74844+{
74845+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
74846+
74847+ return (long)atomic64_add_return_unchecked(i, v);
74848+}
74849+#endif
74850+
74851 static inline long atomic_long_sub_return(long i, atomic_long_t *l)
74852 {
74853 atomic64_t *v = (atomic64_t *)l;
74854@@ -115,6 +184,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
74855 return (long)atomic64_inc_return(v);
74856 }
74857
74858+#ifdef CONFIG_PAX_REFCOUNT
74859+static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
74860+{
74861+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
74862+
74863+ return (long)atomic64_inc_return_unchecked(v);
74864+}
74865+#endif
74866+
74867 static inline long atomic_long_dec_return(atomic_long_t *l)
74868 {
74869 atomic64_t *v = (atomic64_t *)l;
74870@@ -140,6 +218,12 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
74871
74872 typedef atomic_t atomic_long_t;
74873
74874+#ifdef CONFIG_PAX_REFCOUNT
74875+typedef atomic_unchecked_t atomic_long_unchecked_t;
74876+#else
74877+typedef atomic_t atomic_long_unchecked_t;
74878+#endif
74879+
74880 #define ATOMIC_LONG_INIT(i) ATOMIC_INIT(i)
74881 static inline long atomic_long_read(atomic_long_t *l)
74882 {
74883@@ -148,6 +232,15 @@ static inline long atomic_long_read(atomic_long_t *l)
74884 return (long)atomic_read(v);
74885 }
74886
74887+#ifdef CONFIG_PAX_REFCOUNT
74888+static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
74889+{
74890+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
74891+
74892+ return (long)atomic_read_unchecked(v);
74893+}
74894+#endif
74895+
74896 static inline void atomic_long_set(atomic_long_t *l, long i)
74897 {
74898 atomic_t *v = (atomic_t *)l;
74899@@ -155,6 +248,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
74900 atomic_set(v, i);
74901 }
74902
74903+#ifdef CONFIG_PAX_REFCOUNT
74904+static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
74905+{
74906+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
74907+
74908+ atomic_set_unchecked(v, i);
74909+}
74910+#endif
74911+
74912 static inline void atomic_long_inc(atomic_long_t *l)
74913 {
74914 atomic_t *v = (atomic_t *)l;
74915@@ -162,6 +264,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
74916 atomic_inc(v);
74917 }
74918
74919+#ifdef CONFIG_PAX_REFCOUNT
74920+static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
74921+{
74922+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
74923+
74924+ atomic_inc_unchecked(v);
74925+}
74926+#endif
74927+
74928 static inline void atomic_long_dec(atomic_long_t *l)
74929 {
74930 atomic_t *v = (atomic_t *)l;
74931@@ -169,6 +280,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
74932 atomic_dec(v);
74933 }
74934
74935+#ifdef CONFIG_PAX_REFCOUNT
74936+static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
74937+{
74938+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
74939+
74940+ atomic_dec_unchecked(v);
74941+}
74942+#endif
74943+
74944 static inline void atomic_long_add(long i, atomic_long_t *l)
74945 {
74946 atomic_t *v = (atomic_t *)l;
74947@@ -176,6 +296,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
74948 atomic_add(i, v);
74949 }
74950
74951+#ifdef CONFIG_PAX_REFCOUNT
74952+static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
74953+{
74954+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
74955+
74956+ atomic_add_unchecked(i, v);
74957+}
74958+#endif
74959+
74960 static inline void atomic_long_sub(long i, atomic_long_t *l)
74961 {
74962 atomic_t *v = (atomic_t *)l;
74963@@ -183,6 +312,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
74964 atomic_sub(i, v);
74965 }
74966
74967+#ifdef CONFIG_PAX_REFCOUNT
74968+static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
74969+{
74970+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
74971+
74972+ atomic_sub_unchecked(i, v);
74973+}
74974+#endif
74975+
74976 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
74977 {
74978 atomic_t *v = (atomic_t *)l;
74979@@ -218,6 +356,16 @@ static inline long atomic_long_add_return(long i, atomic_long_t *l)
74980 return (long)atomic_add_return(i, v);
74981 }
74982
74983+#ifdef CONFIG_PAX_REFCOUNT
74984+static inline long atomic_long_add_return_unchecked(long i, atomic_long_unchecked_t *l)
74985+{
74986+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
74987+
74988+ return (long)atomic_add_return_unchecked(i, v);
74989+}
74990+
74991+#endif
74992+
74993 static inline long atomic_long_sub_return(long i, atomic_long_t *l)
74994 {
74995 atomic_t *v = (atomic_t *)l;
74996@@ -232,6 +380,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
74997 return (long)atomic_inc_return(v);
74998 }
74999
75000+#ifdef CONFIG_PAX_REFCOUNT
75001+static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
75002+{
75003+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
75004+
75005+ return (long)atomic_inc_return_unchecked(v);
75006+}
75007+#endif
75008+
75009 static inline long atomic_long_dec_return(atomic_long_t *l)
75010 {
75011 atomic_t *v = (atomic_t *)l;
75012@@ -255,4 +412,57 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
75013
75014 #endif /* BITS_PER_LONG == 64 */
75015
75016+#ifdef CONFIG_PAX_REFCOUNT
75017+static inline void pax_refcount_needs_these_functions(void)
75018+{
75019+ atomic_read_unchecked((atomic_unchecked_t *)NULL);
75020+ atomic_set_unchecked((atomic_unchecked_t *)NULL, 0);
75021+ atomic_add_unchecked(0, (atomic_unchecked_t *)NULL);
75022+ atomic_sub_unchecked(0, (atomic_unchecked_t *)NULL);
75023+ atomic_inc_unchecked((atomic_unchecked_t *)NULL);
75024+ (void)atomic_inc_and_test_unchecked((atomic_unchecked_t *)NULL);
75025+ atomic_inc_return_unchecked((atomic_unchecked_t *)NULL);
75026+ atomic_add_return_unchecked(0, (atomic_unchecked_t *)NULL);
75027+ atomic_dec_unchecked((atomic_unchecked_t *)NULL);
75028+ atomic_cmpxchg_unchecked((atomic_unchecked_t *)NULL, 0, 0);
75029+ (void)atomic_xchg_unchecked((atomic_unchecked_t *)NULL, 0);
75030+#ifdef CONFIG_X86
75031+ atomic_clear_mask_unchecked(0, NULL);
75032+ atomic_set_mask_unchecked(0, NULL);
75033+#endif
75034+
75035+ atomic_long_read_unchecked((atomic_long_unchecked_t *)NULL);
75036+ atomic_long_set_unchecked((atomic_long_unchecked_t *)NULL, 0);
75037+ atomic_long_add_unchecked(0, (atomic_long_unchecked_t *)NULL);
75038+ atomic_long_sub_unchecked(0, (atomic_long_unchecked_t *)NULL);
75039+ atomic_long_inc_unchecked((atomic_long_unchecked_t *)NULL);
75040+ atomic_long_add_return_unchecked(0, (atomic_long_unchecked_t *)NULL);
75041+ atomic_long_inc_return_unchecked((atomic_long_unchecked_t *)NULL);
75042+ atomic_long_dec_unchecked((atomic_long_unchecked_t *)NULL);
75043+}
75044+#else
75045+#define atomic_read_unchecked(v) atomic_read(v)
75046+#define atomic_set_unchecked(v, i) atomic_set((v), (i))
75047+#define atomic_add_unchecked(i, v) atomic_add((i), (v))
75048+#define atomic_sub_unchecked(i, v) atomic_sub((i), (v))
75049+#define atomic_inc_unchecked(v) atomic_inc(v)
75050+#define atomic_inc_and_test_unchecked(v) atomic_inc_and_test(v)
75051+#define atomic_inc_return_unchecked(v) atomic_inc_return(v)
75052+#define atomic_add_return_unchecked(i, v) atomic_add_return((i), (v))
75053+#define atomic_dec_unchecked(v) atomic_dec(v)
75054+#define atomic_cmpxchg_unchecked(v, o, n) atomic_cmpxchg((v), (o), (n))
75055+#define atomic_xchg_unchecked(v, i) atomic_xchg((v), (i))
75056+#define atomic_clear_mask_unchecked(mask, v) atomic_clear_mask((mask), (v))
75057+#define atomic_set_mask_unchecked(mask, v) atomic_set_mask((mask), (v))
75058+
75059+#define atomic_long_read_unchecked(v) atomic_long_read(v)
75060+#define atomic_long_set_unchecked(v, i) atomic_long_set((v), (i))
75061+#define atomic_long_add_unchecked(i, v) atomic_long_add((i), (v))
75062+#define atomic_long_sub_unchecked(i, v) atomic_long_sub((i), (v))
75063+#define atomic_long_inc_unchecked(v) atomic_long_inc(v)
75064+#define atomic_long_add_return_unchecked(i, v) atomic_long_add_return((i), (v))
75065+#define atomic_long_inc_return_unchecked(v) atomic_long_inc_return(v)
75066+#define atomic_long_dec_unchecked(v) atomic_long_dec(v)
75067+#endif
75068+
75069 #endif /* _ASM_GENERIC_ATOMIC_LONG_H */
75070diff --git a/include/asm-generic/atomic.h b/include/asm-generic/atomic.h
75071index 33bd2de..f31bff97 100644
75072--- a/include/asm-generic/atomic.h
75073+++ b/include/asm-generic/atomic.h
75074@@ -153,7 +153,7 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
75075 * Atomically clears the bits set in @mask from @v
75076 */
75077 #ifndef atomic_clear_mask
75078-static inline void atomic_clear_mask(unsigned long mask, atomic_t *v)
75079+static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
75080 {
75081 unsigned long flags;
75082
75083diff --git a/include/asm-generic/atomic64.h b/include/asm-generic/atomic64.h
75084index b18ce4f..2ee2843 100644
75085--- a/include/asm-generic/atomic64.h
75086+++ b/include/asm-generic/atomic64.h
75087@@ -16,6 +16,8 @@ typedef struct {
75088 long long counter;
75089 } atomic64_t;
75090
75091+typedef atomic64_t atomic64_unchecked_t;
75092+
75093 #define ATOMIC64_INIT(i) { (i) }
75094
75095 extern long long atomic64_read(const atomic64_t *v);
75096@@ -39,4 +41,14 @@ extern int atomic64_add_unless(atomic64_t *v, long long a, long long u);
75097 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
75098 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
75099
75100+#define atomic64_read_unchecked(v) atomic64_read(v)
75101+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
75102+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
75103+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
75104+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
75105+#define atomic64_inc_unchecked(v) atomic64_inc(v)
75106+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
75107+#define atomic64_dec_unchecked(v) atomic64_dec(v)
75108+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
75109+
75110 #endif /* _ASM_GENERIC_ATOMIC64_H */
75111diff --git a/include/asm-generic/bitops/__fls.h b/include/asm-generic/bitops/__fls.h
75112index a60a7cc..0fe12f2 100644
75113--- a/include/asm-generic/bitops/__fls.h
75114+++ b/include/asm-generic/bitops/__fls.h
75115@@ -9,7 +9,7 @@
75116 *
75117 * Undefined if no set bit exists, so code should check against 0 first.
75118 */
75119-static __always_inline unsigned long __fls(unsigned long word)
75120+static __always_inline unsigned long __intentional_overflow(-1) __fls(unsigned long word)
75121 {
75122 int num = BITS_PER_LONG - 1;
75123
75124diff --git a/include/asm-generic/bitops/fls.h b/include/asm-generic/bitops/fls.h
75125index 0576d1f..dad6c71 100644
75126--- a/include/asm-generic/bitops/fls.h
75127+++ b/include/asm-generic/bitops/fls.h
75128@@ -9,7 +9,7 @@
75129 * Note fls(0) = 0, fls(1) = 1, fls(0x80000000) = 32.
75130 */
75131
75132-static __always_inline int fls(int x)
75133+static __always_inline int __intentional_overflow(-1) fls(int x)
75134 {
75135 int r = 32;
75136
75137diff --git a/include/asm-generic/bitops/fls64.h b/include/asm-generic/bitops/fls64.h
75138index b097cf8..3d40e14 100644
75139--- a/include/asm-generic/bitops/fls64.h
75140+++ b/include/asm-generic/bitops/fls64.h
75141@@ -15,7 +15,7 @@
75142 * at position 64.
75143 */
75144 #if BITS_PER_LONG == 32
75145-static __always_inline int fls64(__u64 x)
75146+static __always_inline int __intentional_overflow(-1) fls64(__u64 x)
75147 {
75148 __u32 h = x >> 32;
75149 if (h)
75150@@ -23,7 +23,7 @@ static __always_inline int fls64(__u64 x)
75151 return fls(x);
75152 }
75153 #elif BITS_PER_LONG == 64
75154-static __always_inline int fls64(__u64 x)
75155+static __always_inline int __intentional_overflow(-1) fls64(__u64 x)
75156 {
75157 if (x == 0)
75158 return 0;
75159diff --git a/include/asm-generic/cache.h b/include/asm-generic/cache.h
75160index 1bfcfe5..e04c5c9 100644
75161--- a/include/asm-generic/cache.h
75162+++ b/include/asm-generic/cache.h
75163@@ -6,7 +6,7 @@
75164 * cache lines need to provide their own cache.h.
75165 */
75166
75167-#define L1_CACHE_SHIFT 5
75168-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
75169+#define L1_CACHE_SHIFT 5UL
75170+#define L1_CACHE_BYTES (1UL << L1_CACHE_SHIFT)
75171
75172 #endif /* __ASM_GENERIC_CACHE_H */
75173diff --git a/include/asm-generic/emergency-restart.h b/include/asm-generic/emergency-restart.h
75174index 0d68a1e..b74a761 100644
75175--- a/include/asm-generic/emergency-restart.h
75176+++ b/include/asm-generic/emergency-restart.h
75177@@ -1,7 +1,7 @@
75178 #ifndef _ASM_GENERIC_EMERGENCY_RESTART_H
75179 #define _ASM_GENERIC_EMERGENCY_RESTART_H
75180
75181-static inline void machine_emergency_restart(void)
75182+static inline __noreturn void machine_emergency_restart(void)
75183 {
75184 machine_restart(NULL);
75185 }
75186diff --git a/include/asm-generic/kmap_types.h b/include/asm-generic/kmap_types.h
75187index 90f99c7..00ce236 100644
75188--- a/include/asm-generic/kmap_types.h
75189+++ b/include/asm-generic/kmap_types.h
75190@@ -2,9 +2,9 @@
75191 #define _ASM_GENERIC_KMAP_TYPES_H
75192
75193 #ifdef __WITH_KM_FENCE
75194-# define KM_TYPE_NR 41
75195+# define KM_TYPE_NR 42
75196 #else
75197-# define KM_TYPE_NR 20
75198+# define KM_TYPE_NR 21
75199 #endif
75200
75201 #endif
75202diff --git a/include/asm-generic/local.h b/include/asm-generic/local.h
75203index 9ceb03b..62b0b8f 100644
75204--- a/include/asm-generic/local.h
75205+++ b/include/asm-generic/local.h
75206@@ -23,24 +23,37 @@ typedef struct
75207 atomic_long_t a;
75208 } local_t;
75209
75210+typedef struct {
75211+ atomic_long_unchecked_t a;
75212+} local_unchecked_t;
75213+
75214 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
75215
75216 #define local_read(l) atomic_long_read(&(l)->a)
75217+#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
75218 #define local_set(l,i) atomic_long_set((&(l)->a),(i))
75219+#define local_set_unchecked(l,i) atomic_long_set_unchecked((&(l)->a),(i))
75220 #define local_inc(l) atomic_long_inc(&(l)->a)
75221+#define local_inc_unchecked(l) atomic_long_inc_unchecked(&(l)->a)
75222 #define local_dec(l) atomic_long_dec(&(l)->a)
75223+#define local_dec_unchecked(l) atomic_long_dec_unchecked(&(l)->a)
75224 #define local_add(i,l) atomic_long_add((i),(&(l)->a))
75225+#define local_add_unchecked(i,l) atomic_long_add_unchecked((i),(&(l)->a))
75226 #define local_sub(i,l) atomic_long_sub((i),(&(l)->a))
75227+#define local_sub_unchecked(i,l) atomic_long_sub_unchecked((i),(&(l)->a))
75228
75229 #define local_sub_and_test(i, l) atomic_long_sub_and_test((i), (&(l)->a))
75230 #define local_dec_and_test(l) atomic_long_dec_and_test(&(l)->a)
75231 #define local_inc_and_test(l) atomic_long_inc_and_test(&(l)->a)
75232 #define local_add_negative(i, l) atomic_long_add_negative((i), (&(l)->a))
75233 #define local_add_return(i, l) atomic_long_add_return((i), (&(l)->a))
75234+#define local_add_return_unchecked(i, l) atomic_long_add_return_unchecked((i), (&(l)->a))
75235 #define local_sub_return(i, l) atomic_long_sub_return((i), (&(l)->a))
75236 #define local_inc_return(l) atomic_long_inc_return(&(l)->a)
75237+#define local_dec_return(l) atomic_long_dec_return(&(l)->a)
75238
75239 #define local_cmpxchg(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
75240+#define local_cmpxchg_unchecked(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
75241 #define local_xchg(l, n) atomic_long_xchg((&(l)->a), (n))
75242 #define local_add_unless(l, _a, u) atomic_long_add_unless((&(l)->a), (_a), (u))
75243 #define local_inc_not_zero(l) atomic_long_inc_not_zero(&(l)->a)
75244diff --git a/include/asm-generic/pgtable-nopmd.h b/include/asm-generic/pgtable-nopmd.h
75245index 725612b..9cc513a 100644
75246--- a/include/asm-generic/pgtable-nopmd.h
75247+++ b/include/asm-generic/pgtable-nopmd.h
75248@@ -1,14 +1,19 @@
75249 #ifndef _PGTABLE_NOPMD_H
75250 #define _PGTABLE_NOPMD_H
75251
75252-#ifndef __ASSEMBLY__
75253-
75254 #include <asm-generic/pgtable-nopud.h>
75255
75256-struct mm_struct;
75257-
75258 #define __PAGETABLE_PMD_FOLDED
75259
75260+#define PMD_SHIFT PUD_SHIFT
75261+#define PTRS_PER_PMD 1
75262+#define PMD_SIZE (_AC(1,UL) << PMD_SHIFT)
75263+#define PMD_MASK (~(PMD_SIZE-1))
75264+
75265+#ifndef __ASSEMBLY__
75266+
75267+struct mm_struct;
75268+
75269 /*
75270 * Having the pmd type consist of a pud gets the size right, and allows
75271 * us to conceptually access the pud entry that this pmd is folded into
75272@@ -16,11 +21,6 @@ struct mm_struct;
75273 */
75274 typedef struct { pud_t pud; } pmd_t;
75275
75276-#define PMD_SHIFT PUD_SHIFT
75277-#define PTRS_PER_PMD 1
75278-#define PMD_SIZE (1UL << PMD_SHIFT)
75279-#define PMD_MASK (~(PMD_SIZE-1))
75280-
75281 /*
75282 * The "pud_xxx()" functions here are trivial for a folded two-level
75283 * setup: the pmd is never bad, and a pmd always exists (as it's folded
75284diff --git a/include/asm-generic/pgtable-nopud.h b/include/asm-generic/pgtable-nopud.h
75285index 810431d..0ec4804f 100644
75286--- a/include/asm-generic/pgtable-nopud.h
75287+++ b/include/asm-generic/pgtable-nopud.h
75288@@ -1,10 +1,15 @@
75289 #ifndef _PGTABLE_NOPUD_H
75290 #define _PGTABLE_NOPUD_H
75291
75292-#ifndef __ASSEMBLY__
75293-
75294 #define __PAGETABLE_PUD_FOLDED
75295
75296+#define PUD_SHIFT PGDIR_SHIFT
75297+#define PTRS_PER_PUD 1
75298+#define PUD_SIZE (_AC(1,UL) << PUD_SHIFT)
75299+#define PUD_MASK (~(PUD_SIZE-1))
75300+
75301+#ifndef __ASSEMBLY__
75302+
75303 /*
75304 * Having the pud type consist of a pgd gets the size right, and allows
75305 * us to conceptually access the pgd entry that this pud is folded into
75306@@ -12,11 +17,6 @@
75307 */
75308 typedef struct { pgd_t pgd; } pud_t;
75309
75310-#define PUD_SHIFT PGDIR_SHIFT
75311-#define PTRS_PER_PUD 1
75312-#define PUD_SIZE (1UL << PUD_SHIFT)
75313-#define PUD_MASK (~(PUD_SIZE-1))
75314-
75315 /*
75316 * The "pgd_xxx()" functions here are trivial for a folded two-level
75317 * setup: the pud is never bad, and a pud always exists (as it's folded
75318@@ -29,6 +29,7 @@ static inline void pgd_clear(pgd_t *pgd) { }
75319 #define pud_ERROR(pud) (pgd_ERROR((pud).pgd))
75320
75321 #define pgd_populate(mm, pgd, pud) do { } while (0)
75322+#define pgd_populate_kernel(mm, pgd, pud) do { } while (0)
75323 /*
75324 * (puds are folded into pgds so this doesn't get actually called,
75325 * but the define is needed for a generic inline function.)
75326diff --git a/include/asm-generic/pgtable.h b/include/asm-generic/pgtable.h
75327index b12079a..86683e3 100644
75328--- a/include/asm-generic/pgtable.h
75329+++ b/include/asm-generic/pgtable.h
75330@@ -599,11 +599,10 @@ static inline int pmd_none_or_trans_huge_or_clear_bad(pmd_t *pmd)
75331 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
75332 barrier();
75333 #endif
75334- if (pmd_none(pmdval))
75335+ if (pmd_none(pmdval) || pmd_trans_huge(pmdval))
75336 return 1;
75337 if (unlikely(pmd_bad(pmdval))) {
75338- if (!pmd_trans_huge(pmdval))
75339- pmd_clear_bad(pmd);
75340+ pmd_clear_bad(pmd);
75341 return 1;
75342 }
75343 return 0;
75344@@ -737,6 +736,22 @@ static inline pmd_t pmd_mknuma(pmd_t pmd)
75345 }
75346 #endif /* CONFIG_NUMA_BALANCING */
75347
75348+#ifndef __HAVE_ARCH_PAX_OPEN_KERNEL
75349+#ifdef CONFIG_PAX_KERNEXEC
75350+#error KERNEXEC requires pax_open_kernel
75351+#else
75352+static inline unsigned long pax_open_kernel(void) { return 0; }
75353+#endif
75354+#endif
75355+
75356+#ifndef __HAVE_ARCH_PAX_CLOSE_KERNEL
75357+#ifdef CONFIG_PAX_KERNEXEC
75358+#error KERNEXEC requires pax_close_kernel
75359+#else
75360+static inline unsigned long pax_close_kernel(void) { return 0; }
75361+#endif
75362+#endif
75363+
75364 #endif /* CONFIG_MMU */
75365
75366 #endif /* !__ASSEMBLY__ */
75367diff --git a/include/asm-generic/uaccess.h b/include/asm-generic/uaccess.h
75368index dc1269c..48a4f51 100644
75369--- a/include/asm-generic/uaccess.h
75370+++ b/include/asm-generic/uaccess.h
75371@@ -343,4 +343,20 @@ clear_user(void __user *to, unsigned long n)
75372 return __clear_user(to, n);
75373 }
75374
75375+#ifndef __HAVE_ARCH_PAX_OPEN_USERLAND
75376+#ifdef CONFIG_PAX_MEMORY_UDEREF
75377+#error UDEREF requires pax_open_userland
75378+#else
75379+static inline unsigned long pax_open_userland(void) { return 0; }
75380+#endif
75381+#endif
75382+
75383+#ifndef __HAVE_ARCH_PAX_CLOSE_USERLAND
75384+#ifdef CONFIG_PAX_MEMORY_UDEREF
75385+#error UDEREF requires pax_close_userland
75386+#else
75387+static inline unsigned long pax_close_userland(void) { return 0; }
75388+#endif
75389+#endif
75390+
75391 #endif /* __ASM_GENERIC_UACCESS_H */
75392diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
75393index 83e2c31..eeb4a04 100644
75394--- a/include/asm-generic/vmlinux.lds.h
75395+++ b/include/asm-generic/vmlinux.lds.h
75396@@ -232,6 +232,7 @@
75397 .rodata : AT(ADDR(.rodata) - LOAD_OFFSET) { \
75398 VMLINUX_SYMBOL(__start_rodata) = .; \
75399 *(.rodata) *(.rodata.*) \
75400+ *(.data..read_only) \
75401 *(__vermagic) /* Kernel version magic */ \
75402 . = ALIGN(8); \
75403 VMLINUX_SYMBOL(__start___tracepoints_ptrs) = .; \
75404@@ -715,17 +716,18 @@
75405 * section in the linker script will go there too. @phdr should have
75406 * a leading colon.
75407 *
75408- * Note that this macros defines __per_cpu_load as an absolute symbol.
75409+ * Note that this macros defines per_cpu_load as an absolute symbol.
75410 * If there is no need to put the percpu section at a predetermined
75411 * address, use PERCPU_SECTION.
75412 */
75413 #define PERCPU_VADDR(cacheline, vaddr, phdr) \
75414- VMLINUX_SYMBOL(__per_cpu_load) = .; \
75415- .data..percpu vaddr : AT(VMLINUX_SYMBOL(__per_cpu_load) \
75416+ per_cpu_load = .; \
75417+ .data..percpu vaddr : AT(VMLINUX_SYMBOL(per_cpu_load) \
75418 - LOAD_OFFSET) { \
75419+ VMLINUX_SYMBOL(__per_cpu_load) = . + per_cpu_load; \
75420 PERCPU_INPUT(cacheline) \
75421 } phdr \
75422- . = VMLINUX_SYMBOL(__per_cpu_load) + SIZEOF(.data..percpu);
75423+ . = VMLINUX_SYMBOL(per_cpu_load) + SIZEOF(.data..percpu);
75424
75425 /**
75426 * PERCPU_SECTION - define output section for percpu area, simple version
75427diff --git a/include/crypto/algapi.h b/include/crypto/algapi.h
75428index 418d270..bfd2794 100644
75429--- a/include/crypto/algapi.h
75430+++ b/include/crypto/algapi.h
75431@@ -34,7 +34,7 @@ struct crypto_type {
75432 unsigned int maskclear;
75433 unsigned int maskset;
75434 unsigned int tfmsize;
75435-};
75436+} __do_const;
75437
75438 struct crypto_instance {
75439 struct crypto_alg alg;
75440diff --git a/include/drm/drmP.h b/include/drm/drmP.h
75441index b46fb45..b30d6d5 100644
75442--- a/include/drm/drmP.h
75443+++ b/include/drm/drmP.h
75444@@ -66,6 +66,7 @@
75445 #include <linux/workqueue.h>
75446 #include <linux/poll.h>
75447 #include <asm/pgalloc.h>
75448+#include <asm/local.h>
75449 #include <drm/drm.h>
75450 #include <drm/drm_sarea.h>
75451 #include <drm/drm_vma_manager.h>
75452@@ -277,10 +278,12 @@ do { \
75453 * \param cmd command.
75454 * \param arg argument.
75455 */
75456-typedef int drm_ioctl_t(struct drm_device *dev, void *data,
75457+typedef int (* const drm_ioctl_t)(struct drm_device *dev, void *data,
75458+ struct drm_file *file_priv);
75459+typedef int (* drm_ioctl_no_const_t)(struct drm_device *dev, void *data,
75460 struct drm_file *file_priv);
75461
75462-typedef int drm_ioctl_compat_t(struct file *filp, unsigned int cmd,
75463+typedef int (* const drm_ioctl_compat_t)(struct file *filp, unsigned int cmd,
75464 unsigned long arg);
75465
75466 #define DRM_IOCTL_NR(n) _IOC_NR(n)
75467@@ -296,10 +299,10 @@ typedef int drm_ioctl_compat_t(struct file *filp, unsigned int cmd,
75468 struct drm_ioctl_desc {
75469 unsigned int cmd;
75470 int flags;
75471- drm_ioctl_t *func;
75472+ drm_ioctl_t func;
75473 unsigned int cmd_drv;
75474 const char *name;
75475-};
75476+} __do_const;
75477
75478 /**
75479 * Creates a driver or general drm_ioctl_desc array entry for the given
75480@@ -1027,7 +1030,7 @@ struct drm_info_list {
75481 int (*show)(struct seq_file*, void*); /** show callback */
75482 u32 driver_features; /**< Required driver features for this entry */
75483 void *data;
75484-};
75485+} __do_const;
75486
75487 /**
75488 * debugfs node structure. This structure represents a debugfs file.
75489@@ -1098,7 +1101,7 @@ struct drm_device {
75490
75491 /** \name Usage Counters */
75492 /*@{ */
75493- int open_count; /**< Outstanding files open */
75494+ local_t open_count; /**< Outstanding files open */
75495 atomic_t ioctl_count; /**< Outstanding IOCTLs pending */
75496 atomic_t vma_count; /**< Outstanding vma areas open */
75497 int buf_use; /**< Buffers in use -- cannot alloc */
75498@@ -1109,7 +1112,7 @@ struct drm_device {
75499 /*@{ */
75500 unsigned long counters;
75501 enum drm_stat_type types[15];
75502- atomic_t counts[15];
75503+ atomic_unchecked_t counts[15];
75504 /*@} */
75505
75506 struct list_head filelist;
75507diff --git a/include/drm/drm_crtc_helper.h b/include/drm/drm_crtc_helper.h
75508index f43d556..94d9343 100644
75509--- a/include/drm/drm_crtc_helper.h
75510+++ b/include/drm/drm_crtc_helper.h
75511@@ -109,7 +109,7 @@ struct drm_encoder_helper_funcs {
75512 struct drm_connector *connector);
75513 /* disable encoder when not in use - more explicit than dpms off */
75514 void (*disable)(struct drm_encoder *encoder);
75515-};
75516+} __no_const;
75517
75518 /**
75519 * drm_connector_helper_funcs - helper operations for connectors
75520diff --git a/include/drm/i915_pciids.h b/include/drm/i915_pciids.h
75521index 8a10f5c..5de7f5c 100644
75522--- a/include/drm/i915_pciids.h
75523+++ b/include/drm/i915_pciids.h
75524@@ -37,7 +37,7 @@
75525 */
75526 #define INTEL_VGA_DEVICE(id, info) { \
75527 0x8086, id, \
75528- ~0, ~0, \
75529+ PCI_ANY_ID, PCI_ANY_ID, \
75530 0x030000, 0xff0000, \
75531 (unsigned long) info }
75532
75533diff --git a/include/drm/ttm/ttm_memory.h b/include/drm/ttm/ttm_memory.h
75534index 72dcbe8..8db58d7 100644
75535--- a/include/drm/ttm/ttm_memory.h
75536+++ b/include/drm/ttm/ttm_memory.h
75537@@ -48,7 +48,7 @@
75538
75539 struct ttm_mem_shrink {
75540 int (*do_shrink) (struct ttm_mem_shrink *);
75541-};
75542+} __no_const;
75543
75544 /**
75545 * struct ttm_mem_global - Global memory accounting structure.
75546diff --git a/include/keys/asymmetric-subtype.h b/include/keys/asymmetric-subtype.h
75547index 4b840e8..155d235 100644
75548--- a/include/keys/asymmetric-subtype.h
75549+++ b/include/keys/asymmetric-subtype.h
75550@@ -37,7 +37,7 @@ struct asymmetric_key_subtype {
75551 /* Verify the signature on a key of this subtype (optional) */
75552 int (*verify_signature)(const struct key *key,
75553 const struct public_key_signature *sig);
75554-};
75555+} __do_const;
75556
75557 /**
75558 * asymmetric_key_subtype - Get the subtype from an asymmetric key
75559diff --git a/include/linux/atmdev.h b/include/linux/atmdev.h
75560index c1da539..1dcec55 100644
75561--- a/include/linux/atmdev.h
75562+++ b/include/linux/atmdev.h
75563@@ -28,7 +28,7 @@ struct compat_atm_iobuf {
75564 #endif
75565
75566 struct k_atm_aal_stats {
75567-#define __HANDLE_ITEM(i) atomic_t i
75568+#define __HANDLE_ITEM(i) atomic_unchecked_t i
75569 __AAL_STAT_ITEMS
75570 #undef __HANDLE_ITEM
75571 };
75572@@ -200,7 +200,7 @@ struct atmdev_ops { /* only send is required */
75573 int (*change_qos)(struct atm_vcc *vcc,struct atm_qos *qos,int flags);
75574 int (*proc_read)(struct atm_dev *dev,loff_t *pos,char *page);
75575 struct module *owner;
75576-};
75577+} __do_const ;
75578
75579 struct atmphy_ops {
75580 int (*start)(struct atm_dev *dev);
75581diff --git a/include/linux/audit.h b/include/linux/audit.h
75582index 729a4d1..9b304ae 100644
75583--- a/include/linux/audit.h
75584+++ b/include/linux/audit.h
75585@@ -193,7 +193,7 @@ static inline void audit_ptrace(struct task_struct *t)
75586 extern unsigned int audit_serial(void);
75587 extern int auditsc_get_stamp(struct audit_context *ctx,
75588 struct timespec *t, unsigned int *serial);
75589-extern int audit_set_loginuid(kuid_t loginuid);
75590+extern int __intentional_overflow(-1) audit_set_loginuid(kuid_t loginuid);
75591
75592 static inline kuid_t audit_get_loginuid(struct task_struct *tsk)
75593 {
75594diff --git a/include/linux/binfmts.h b/include/linux/binfmts.h
75595index 7554fd4..0f86379 100644
75596--- a/include/linux/binfmts.h
75597+++ b/include/linux/binfmts.h
75598@@ -73,8 +73,10 @@ struct linux_binfmt {
75599 int (*load_binary)(struct linux_binprm *);
75600 int (*load_shlib)(struct file *);
75601 int (*core_dump)(struct coredump_params *cprm);
75602+ void (*handle_mprotect)(struct vm_area_struct *vma, unsigned long newflags);
75603+ void (*handle_mmap)(struct file *);
75604 unsigned long min_coredump; /* minimal dump size */
75605-};
75606+} __do_const;
75607
75608 extern void __register_binfmt(struct linux_binfmt *fmt, int insert);
75609
75610diff --git a/include/linux/bitops.h b/include/linux/bitops.h
75611index a3b6b82..2a7d758 100644
75612--- a/include/linux/bitops.h
75613+++ b/include/linux/bitops.h
75614@@ -91,7 +91,7 @@ static inline __u64 ror64(__u64 word, unsigned int shift)
75615 * @word: value to rotate
75616 * @shift: bits to roll
75617 */
75618-static inline __u32 rol32(__u32 word, unsigned int shift)
75619+static inline __u32 __intentional_overflow(-1) rol32(__u32 word, unsigned int shift)
75620 {
75621 return (word << shift) | (word >> (32 - shift));
75622 }
75623@@ -101,7 +101,7 @@ static inline __u32 rol32(__u32 word, unsigned int shift)
75624 * @word: value to rotate
75625 * @shift: bits to roll
75626 */
75627-static inline __u32 ror32(__u32 word, unsigned int shift)
75628+static inline __u32 __intentional_overflow(-1) ror32(__u32 word, unsigned int shift)
75629 {
75630 return (word >> shift) | (word << (32 - shift));
75631 }
75632@@ -157,7 +157,7 @@ static inline __s32 sign_extend32(__u32 value, int index)
75633 return (__s32)(value << shift) >> shift;
75634 }
75635
75636-static inline unsigned fls_long(unsigned long l)
75637+static inline unsigned __intentional_overflow(-1) fls_long(unsigned long l)
75638 {
75639 if (sizeof(l) == 4)
75640 return fls(l);
75641diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
75642index 0e6f765..885bb2b 100644
75643--- a/include/linux/blkdev.h
75644+++ b/include/linux/blkdev.h
75645@@ -1537,7 +1537,7 @@ struct block_device_operations {
75646 /* this callback is with swap_lock and sometimes page table lock held */
75647 void (*swap_slot_free_notify) (struct block_device *, unsigned long);
75648 struct module *owner;
75649-};
75650+} __do_const;
75651
75652 extern int __blkdev_driver_ioctl(struct block_device *, fmode_t, unsigned int,
75653 unsigned long);
75654diff --git a/include/linux/blktrace_api.h b/include/linux/blktrace_api.h
75655index 7c2e030..b72475d 100644
75656--- a/include/linux/blktrace_api.h
75657+++ b/include/linux/blktrace_api.h
75658@@ -23,7 +23,7 @@ struct blk_trace {
75659 struct dentry *dir;
75660 struct dentry *dropped_file;
75661 struct dentry *msg_file;
75662- atomic_t dropped;
75663+ atomic_unchecked_t dropped;
75664 };
75665
75666 extern int blk_trace_ioctl(struct block_device *, unsigned, char __user *);
75667diff --git a/include/linux/cache.h b/include/linux/cache.h
75668index 4c57065..40346da 100644
75669--- a/include/linux/cache.h
75670+++ b/include/linux/cache.h
75671@@ -16,6 +16,14 @@
75672 #define __read_mostly
75673 #endif
75674
75675+#ifndef __read_only
75676+#ifdef CONFIG_PAX_KERNEXEC
75677+#error KERNEXEC requires __read_only
75678+#else
75679+#define __read_only __read_mostly
75680+#endif
75681+#endif
75682+
75683 #ifndef ____cacheline_aligned
75684 #define ____cacheline_aligned __attribute__((__aligned__(SMP_CACHE_BYTES)))
75685 #endif
75686diff --git a/include/linux/capability.h b/include/linux/capability.h
75687index a6ee1f9..e1ca49d 100644
75688--- a/include/linux/capability.h
75689+++ b/include/linux/capability.h
75690@@ -212,8 +212,13 @@ extern bool capable(int cap);
75691 extern bool ns_capable(struct user_namespace *ns, int cap);
75692 extern bool inode_capable(const struct inode *inode, int cap);
75693 extern bool file_ns_capable(const struct file *file, struct user_namespace *ns, int cap);
75694+extern bool capable_nolog(int cap);
75695+extern bool ns_capable_nolog(struct user_namespace *ns, int cap);
75696+extern bool inode_capable_nolog(const struct inode *inode, int cap);
75697
75698 /* audit system wants to get cap info from files as well */
75699 extern int get_vfs_caps_from_disk(const struct dentry *dentry, struct cpu_vfs_cap_data *cpu_caps);
75700
75701+extern int is_privileged_binary(const struct dentry *dentry);
75702+
75703 #endif /* !_LINUX_CAPABILITY_H */
75704diff --git a/include/linux/cdrom.h b/include/linux/cdrom.h
75705index 8609d57..86e4d79 100644
75706--- a/include/linux/cdrom.h
75707+++ b/include/linux/cdrom.h
75708@@ -87,7 +87,6 @@ struct cdrom_device_ops {
75709
75710 /* driver specifications */
75711 const int capability; /* capability flags */
75712- int n_minors; /* number of active minor devices */
75713 /* handle uniform packets for scsi type devices (scsi,atapi) */
75714 int (*generic_packet) (struct cdrom_device_info *,
75715 struct packet_command *);
75716diff --git a/include/linux/cleancache.h b/include/linux/cleancache.h
75717index 4ce9056..86caac6 100644
75718--- a/include/linux/cleancache.h
75719+++ b/include/linux/cleancache.h
75720@@ -31,7 +31,7 @@ struct cleancache_ops {
75721 void (*invalidate_page)(int, struct cleancache_filekey, pgoff_t);
75722 void (*invalidate_inode)(int, struct cleancache_filekey);
75723 void (*invalidate_fs)(int);
75724-};
75725+} __no_const;
75726
75727 extern struct cleancache_ops *
75728 cleancache_register_ops(struct cleancache_ops *ops);
75729diff --git a/include/linux/clk-provider.h b/include/linux/clk-provider.h
75730index 73bdb69..d66d47a 100644
75731--- a/include/linux/clk-provider.h
75732+++ b/include/linux/clk-provider.h
75733@@ -141,6 +141,7 @@ struct clk_ops {
75734 unsigned long);
75735 void (*init)(struct clk_hw *hw);
75736 };
75737+typedef struct clk_ops __no_const clk_ops_no_const;
75738
75739 /**
75740 * struct clk_init_data - holds init data that's common to all clocks and is
75741diff --git a/include/linux/compat.h b/include/linux/compat.h
75742index 345da00..b6eff26 100644
75743--- a/include/linux/compat.h
75744+++ b/include/linux/compat.h
75745@@ -313,7 +313,7 @@ compat_sys_get_robust_list(int pid, compat_uptr_t __user *head_ptr,
75746 compat_size_t __user *len_ptr);
75747
75748 asmlinkage long compat_sys_ipc(u32, int, int, u32, compat_uptr_t, u32);
75749-asmlinkage long compat_sys_shmat(int shmid, compat_uptr_t shmaddr, int shmflg);
75750+asmlinkage long compat_sys_shmat(int shmid, compat_uptr_t shmaddr, int shmflg) __intentional_overflow(0);
75751 asmlinkage long compat_sys_semctl(int semid, int semnum, int cmd, int arg);
75752 asmlinkage long compat_sys_msgsnd(int msqid, compat_uptr_t msgp,
75753 compat_ssize_t msgsz, int msgflg);
75754@@ -420,7 +420,7 @@ extern int compat_ptrace_request(struct task_struct *child,
75755 extern long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
75756 compat_ulong_t addr, compat_ulong_t data);
75757 asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
75758- compat_long_t addr, compat_long_t data);
75759+ compat_ulong_t addr, compat_ulong_t data);
75760
75761 asmlinkage long compat_sys_lookup_dcookie(u32, u32, char __user *, size_t);
75762 /*
75763diff --git a/include/linux/compiler-gcc4.h b/include/linux/compiler-gcc4.h
75764index ded4299..ddcbe31 100644
75765--- a/include/linux/compiler-gcc4.h
75766+++ b/include/linux/compiler-gcc4.h
75767@@ -39,9 +39,34 @@
75768 # define __compiletime_warning(message) __attribute__((warning(message)))
75769 # define __compiletime_error(message) __attribute__((error(message)))
75770 #endif /* __CHECKER__ */
75771+
75772+#define __alloc_size(...) __attribute((alloc_size(__VA_ARGS__)))
75773+#define __bos(ptr, arg) __builtin_object_size((ptr), (arg))
75774+#define __bos0(ptr) __bos((ptr), 0)
75775+#define __bos1(ptr) __bos((ptr), 1)
75776 #endif /* GCC_VERSION >= 40300 */
75777
75778 #if GCC_VERSION >= 40500
75779+
75780+#ifdef RANDSTRUCT_PLUGIN
75781+#define __randomize_layout __attribute__((randomize_layout))
75782+#define __no_randomize_layout __attribute__((no_randomize_layout))
75783+#endif
75784+
75785+#ifdef CONSTIFY_PLUGIN
75786+#define __no_const __attribute__((no_const))
75787+#define __do_const __attribute__((do_const))
75788+#endif
75789+
75790+#ifdef SIZE_OVERFLOW_PLUGIN
75791+#define __size_overflow(...) __attribute__((size_overflow(__VA_ARGS__)))
75792+#define __intentional_overflow(...) __attribute__((intentional_overflow(__VA_ARGS__)))
75793+#endif
75794+
75795+#ifdef LATENT_ENTROPY_PLUGIN
75796+#define __latent_entropy __attribute__((latent_entropy))
75797+#endif
75798+
75799 /*
75800 * Mark a position in code as unreachable. This can be used to
75801 * suppress control flow warnings after asm blocks that transfer
75802diff --git a/include/linux/compiler.h b/include/linux/compiler.h
75803index 92669cd..cc564c0 100644
75804--- a/include/linux/compiler.h
75805+++ b/include/linux/compiler.h
75806@@ -5,11 +5,14 @@
75807
75808 #ifdef __CHECKER__
75809 # define __user __attribute__((noderef, address_space(1)))
75810+# define __force_user __force __user
75811 # define __kernel __attribute__((address_space(0)))
75812+# define __force_kernel __force __kernel
75813 # define __safe __attribute__((safe))
75814 # define __force __attribute__((force))
75815 # define __nocast __attribute__((nocast))
75816 # define __iomem __attribute__((noderef, address_space(2)))
75817+# define __force_iomem __force __iomem
75818 # define __must_hold(x) __attribute__((context(x,1,1)))
75819 # define __acquires(x) __attribute__((context(x,0,1)))
75820 # define __releases(x) __attribute__((context(x,1,0)))
75821@@ -17,20 +20,37 @@
75822 # define __release(x) __context__(x,-1)
75823 # define __cond_lock(x,c) ((c) ? ({ __acquire(x); 1; }) : 0)
75824 # define __percpu __attribute__((noderef, address_space(3)))
75825+# define __force_percpu __force __percpu
75826 #ifdef CONFIG_SPARSE_RCU_POINTER
75827 # define __rcu __attribute__((noderef, address_space(4)))
75828+# define __force_rcu __force __rcu
75829 #else
75830 # define __rcu
75831+# define __force_rcu
75832 #endif
75833 extern void __chk_user_ptr(const volatile void __user *);
75834 extern void __chk_io_ptr(const volatile void __iomem *);
75835 #else
75836-# define __user
75837-# define __kernel
75838+# ifdef CHECKER_PLUGIN
75839+//# define __user
75840+//# define __force_user
75841+//# define __kernel
75842+//# define __force_kernel
75843+# else
75844+# ifdef STRUCTLEAK_PLUGIN
75845+# define __user __attribute__((user))
75846+# else
75847+# define __user
75848+# endif
75849+# define __force_user
75850+# define __kernel
75851+# define __force_kernel
75852+# endif
75853 # define __safe
75854 # define __force
75855 # define __nocast
75856 # define __iomem
75857+# define __force_iomem
75858 # define __chk_user_ptr(x) (void)0
75859 # define __chk_io_ptr(x) (void)0
75860 # define __builtin_warning(x, y...) (1)
75861@@ -41,7 +61,9 @@ extern void __chk_io_ptr(const volatile void __iomem *);
75862 # define __release(x) (void)0
75863 # define __cond_lock(x,c) (c)
75864 # define __percpu
75865+# define __force_percpu
75866 # define __rcu
75867+# define __force_rcu
75868 #endif
75869
75870 /* Indirect macros required for expanded argument pasting, eg. __LINE__. */
75871@@ -275,6 +297,34 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
75872 # define __attribute_const__ /* unimplemented */
75873 #endif
75874
75875+#ifndef __randomize_layout
75876+# define __randomize_layout
75877+#endif
75878+
75879+#ifndef __no_randomize_layout
75880+# define __no_randomize_layout
75881+#endif
75882+
75883+#ifndef __no_const
75884+# define __no_const
75885+#endif
75886+
75887+#ifndef __do_const
75888+# define __do_const
75889+#endif
75890+
75891+#ifndef __size_overflow
75892+# define __size_overflow(...)
75893+#endif
75894+
75895+#ifndef __intentional_overflow
75896+# define __intentional_overflow(...)
75897+#endif
75898+
75899+#ifndef __latent_entropy
75900+# define __latent_entropy
75901+#endif
75902+
75903 /*
75904 * Tell gcc if a function is cold. The compiler will assume any path
75905 * directly leading to the call is unlikely.
75906@@ -284,6 +334,22 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
75907 #define __cold
75908 #endif
75909
75910+#ifndef __alloc_size
75911+#define __alloc_size(...)
75912+#endif
75913+
75914+#ifndef __bos
75915+#define __bos(ptr, arg)
75916+#endif
75917+
75918+#ifndef __bos0
75919+#define __bos0(ptr)
75920+#endif
75921+
75922+#ifndef __bos1
75923+#define __bos1(ptr)
75924+#endif
75925+
75926 /* Simple shorthand for a section definition */
75927 #ifndef __section
75928 # define __section(S) __attribute__ ((__section__(#S)))
75929@@ -349,7 +415,8 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
75930 * use is to mediate communication between process-level code and irq/NMI
75931 * handlers, all running on the same CPU.
75932 */
75933-#define ACCESS_ONCE(x) (*(volatile typeof(x) *)&(x))
75934+#define ACCESS_ONCE(x) (*(volatile const typeof(x) *)&(x))
75935+#define ACCESS_ONCE_RW(x) (*(volatile typeof(x) *)&(x))
75936
75937 /* Ignore/forbid kprobes attach on very low level functions marked by this attribute: */
75938 #ifdef CONFIG_KPROBES
75939diff --git a/include/linux/completion.h b/include/linux/completion.h
75940index 3cd574d..240dcb0 100644
75941--- a/include/linux/completion.h
75942+++ b/include/linux/completion.h
75943@@ -78,16 +78,16 @@ static inline void init_completion(struct completion *x)
75944
75945 extern void wait_for_completion(struct completion *);
75946 extern void wait_for_completion_io(struct completion *);
75947-extern int wait_for_completion_interruptible(struct completion *x);
75948-extern int wait_for_completion_killable(struct completion *x);
75949+extern int wait_for_completion_interruptible(struct completion *x) __intentional_overflow(-1);
75950+extern int wait_for_completion_killable(struct completion *x) __intentional_overflow(-1);
75951 extern unsigned long wait_for_completion_timeout(struct completion *x,
75952- unsigned long timeout);
75953+ unsigned long timeout) __intentional_overflow(-1);
75954 extern unsigned long wait_for_completion_io_timeout(struct completion *x,
75955- unsigned long timeout);
75956+ unsigned long timeout) __intentional_overflow(-1);
75957 extern long wait_for_completion_interruptible_timeout(
75958- struct completion *x, unsigned long timeout);
75959+ struct completion *x, unsigned long timeout) __intentional_overflow(-1);
75960 extern long wait_for_completion_killable_timeout(
75961- struct completion *x, unsigned long timeout);
75962+ struct completion *x, unsigned long timeout) __intentional_overflow(-1);
75963 extern bool try_wait_for_completion(struct completion *x);
75964 extern bool completion_done(struct completion *x);
75965
75966diff --git a/include/linux/configfs.h b/include/linux/configfs.h
75967index 34025df..d94bbbc 100644
75968--- a/include/linux/configfs.h
75969+++ b/include/linux/configfs.h
75970@@ -125,7 +125,7 @@ struct configfs_attribute {
75971 const char *ca_name;
75972 struct module *ca_owner;
75973 umode_t ca_mode;
75974-};
75975+} __do_const;
75976
75977 /*
75978 * Users often need to create attribute structures for their configurable
75979diff --git a/include/linux/cpufreq.h b/include/linux/cpufreq.h
75980index fcabc42..cba5d93 100644
75981--- a/include/linux/cpufreq.h
75982+++ b/include/linux/cpufreq.h
75983@@ -167,6 +167,7 @@ struct global_attr {
75984 ssize_t (*store)(struct kobject *a, struct attribute *b,
75985 const char *c, size_t count);
75986 };
75987+typedef struct global_attr __no_const global_attr_no_const;
75988
75989 #define define_one_global_ro(_name) \
75990 static struct global_attr _name = \
75991@@ -208,7 +209,7 @@ struct cpufreq_driver {
75992 int (*suspend) (struct cpufreq_policy *policy);
75993 int (*resume) (struct cpufreq_policy *policy);
75994 struct freq_attr **attr;
75995-};
75996+} __do_const;
75997
75998 /* flags */
75999 #define CPUFREQ_STICKY 0x01 /* the driver isn't removed even if
76000diff --git a/include/linux/cpuidle.h b/include/linux/cpuidle.h
76001index 781addc..d1e1fe6 100644
76002--- a/include/linux/cpuidle.h
76003+++ b/include/linux/cpuidle.h
76004@@ -50,7 +50,8 @@ struct cpuidle_state {
76005 int index);
76006
76007 int (*enter_dead) (struct cpuidle_device *dev, int index);
76008-};
76009+} __do_const;
76010+typedef struct cpuidle_state __no_const cpuidle_state_no_const;
76011
76012 /* Idle State Flags */
76013 #define CPUIDLE_FLAG_TIME_VALID (0x01) /* is residency time measurable? */
76014@@ -192,7 +193,7 @@ struct cpuidle_governor {
76015 void (*reflect) (struct cpuidle_device *dev, int index);
76016
76017 struct module *owner;
76018-};
76019+} __do_const;
76020
76021 #ifdef CONFIG_CPU_IDLE
76022
76023diff --git a/include/linux/cpumask.h b/include/linux/cpumask.h
76024index d08e4d2..95fad61 100644
76025--- a/include/linux/cpumask.h
76026+++ b/include/linux/cpumask.h
76027@@ -118,17 +118,17 @@ static inline unsigned int cpumask_first(const struct cpumask *srcp)
76028 }
76029
76030 /* Valid inputs for n are -1 and 0. */
76031-static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
76032+static inline unsigned int __intentional_overflow(-1) cpumask_next(int n, const struct cpumask *srcp)
76033 {
76034 return n+1;
76035 }
76036
76037-static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
76038+static inline unsigned int __intentional_overflow(-1) cpumask_next_zero(int n, const struct cpumask *srcp)
76039 {
76040 return n+1;
76041 }
76042
76043-static inline unsigned int cpumask_next_and(int n,
76044+static inline unsigned int __intentional_overflow(-1) cpumask_next_and(int n,
76045 const struct cpumask *srcp,
76046 const struct cpumask *andp)
76047 {
76048@@ -167,7 +167,7 @@ static inline unsigned int cpumask_first(const struct cpumask *srcp)
76049 *
76050 * Returns >= nr_cpu_ids if no further cpus set.
76051 */
76052-static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
76053+static inline unsigned int __intentional_overflow(-1) cpumask_next(int n, const struct cpumask *srcp)
76054 {
76055 /* -1 is a legal arg here. */
76056 if (n != -1)
76057@@ -182,7 +182,7 @@ static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
76058 *
76059 * Returns >= nr_cpu_ids if no further cpus unset.
76060 */
76061-static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
76062+static inline unsigned int __intentional_overflow(-1) cpumask_next_zero(int n, const struct cpumask *srcp)
76063 {
76064 /* -1 is a legal arg here. */
76065 if (n != -1)
76066@@ -190,7 +190,7 @@ static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
76067 return find_next_zero_bit(cpumask_bits(srcp), nr_cpumask_bits, n+1);
76068 }
76069
76070-int cpumask_next_and(int n, const struct cpumask *, const struct cpumask *);
76071+int cpumask_next_and(int n, const struct cpumask *, const struct cpumask *) __intentional_overflow(-1);
76072 int cpumask_any_but(const struct cpumask *mask, unsigned int cpu);
76073
76074 /**
76075diff --git a/include/linux/cred.h b/include/linux/cred.h
76076index 04421e8..117e17a 100644
76077--- a/include/linux/cred.h
76078+++ b/include/linux/cred.h
76079@@ -35,7 +35,7 @@ struct group_info {
76080 int nblocks;
76081 kgid_t small_block[NGROUPS_SMALL];
76082 kgid_t *blocks[0];
76083-};
76084+} __randomize_layout;
76085
76086 /**
76087 * get_group_info - Get a reference to a group info structure
76088@@ -136,7 +136,7 @@ struct cred {
76089 struct user_namespace *user_ns; /* user_ns the caps and keyrings are relative to. */
76090 struct group_info *group_info; /* supplementary groups for euid/fsgid */
76091 struct rcu_head rcu; /* RCU deletion hook */
76092-};
76093+} __randomize_layout;
76094
76095 extern void __put_cred(struct cred *);
76096 extern void exit_creds(struct task_struct *);
76097@@ -194,6 +194,9 @@ static inline void validate_creds_for_do_exit(struct task_struct *tsk)
76098 static inline void validate_process_creds(void)
76099 {
76100 }
76101+static inline void validate_task_creds(struct task_struct *task)
76102+{
76103+}
76104 #endif
76105
76106 /**
76107diff --git a/include/linux/crypto.h b/include/linux/crypto.h
76108index b92eadf..b4ecdc1 100644
76109--- a/include/linux/crypto.h
76110+++ b/include/linux/crypto.h
76111@@ -373,7 +373,7 @@ struct cipher_tfm {
76112 const u8 *key, unsigned int keylen);
76113 void (*cit_encrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
76114 void (*cit_decrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
76115-};
76116+} __no_const;
76117
76118 struct hash_tfm {
76119 int (*init)(struct hash_desc *desc);
76120@@ -394,13 +394,13 @@ struct compress_tfm {
76121 int (*cot_decompress)(struct crypto_tfm *tfm,
76122 const u8 *src, unsigned int slen,
76123 u8 *dst, unsigned int *dlen);
76124-};
76125+} __no_const;
76126
76127 struct rng_tfm {
76128 int (*rng_gen_random)(struct crypto_rng *tfm, u8 *rdata,
76129 unsigned int dlen);
76130 int (*rng_reset)(struct crypto_rng *tfm, u8 *seed, unsigned int slen);
76131-};
76132+} __no_const;
76133
76134 #define crt_ablkcipher crt_u.ablkcipher
76135 #define crt_aead crt_u.aead
76136diff --git a/include/linux/ctype.h b/include/linux/ctype.h
76137index 653589e..4ef254a 100644
76138--- a/include/linux/ctype.h
76139+++ b/include/linux/ctype.h
76140@@ -56,7 +56,7 @@ static inline unsigned char __toupper(unsigned char c)
76141 * Fast implementation of tolower() for internal usage. Do not use in your
76142 * code.
76143 */
76144-static inline char _tolower(const char c)
76145+static inline unsigned char _tolower(const unsigned char c)
76146 {
76147 return c | 0x20;
76148 }
76149diff --git a/include/linux/dcache.h b/include/linux/dcache.h
76150index 59066e0..5a22494 100644
76151--- a/include/linux/dcache.h
76152+++ b/include/linux/dcache.h
76153@@ -131,7 +131,7 @@ struct dentry {
76154 } d_u;
76155 struct list_head d_subdirs; /* our children */
76156 struct hlist_node d_alias; /* inode alias list */
76157-};
76158+} __randomize_layout;
76159
76160 /*
76161 * dentry->d_lock spinlock nesting subclasses:
76162diff --git a/include/linux/decompress/mm.h b/include/linux/decompress/mm.h
76163index 7925bf0..d5143d2 100644
76164--- a/include/linux/decompress/mm.h
76165+++ b/include/linux/decompress/mm.h
76166@@ -77,7 +77,7 @@ static void free(void *where)
76167 * warnings when not needed (indeed large_malloc / large_free are not
76168 * needed by inflate */
76169
76170-#define malloc(a) kmalloc(a, GFP_KERNEL)
76171+#define malloc(a) kmalloc((a), GFP_KERNEL)
76172 #define free(a) kfree(a)
76173
76174 #define large_malloc(a) vmalloc(a)
76175diff --git a/include/linux/devfreq.h b/include/linux/devfreq.h
76176index 5f1ab92..39c35ae 100644
76177--- a/include/linux/devfreq.h
76178+++ b/include/linux/devfreq.h
76179@@ -114,7 +114,7 @@ struct devfreq_governor {
76180 int (*get_target_freq)(struct devfreq *this, unsigned long *freq);
76181 int (*event_handler)(struct devfreq *devfreq,
76182 unsigned int event, void *data);
76183-};
76184+} __do_const;
76185
76186 /**
76187 * struct devfreq - Device devfreq structure
76188diff --git a/include/linux/device.h b/include/linux/device.h
76189index 2a9d6ed..d14551e3 100644
76190--- a/include/linux/device.h
76191+++ b/include/linux/device.h
76192@@ -313,7 +313,7 @@ struct subsys_interface {
76193 struct list_head node;
76194 int (*add_dev)(struct device *dev, struct subsys_interface *sif);
76195 int (*remove_dev)(struct device *dev, struct subsys_interface *sif);
76196-};
76197+} __do_const;
76198
76199 int subsys_interface_register(struct subsys_interface *sif);
76200 void subsys_interface_unregister(struct subsys_interface *sif);
76201@@ -501,7 +501,7 @@ struct device_type {
76202 void (*release)(struct device *dev);
76203
76204 const struct dev_pm_ops *pm;
76205-};
76206+} __do_const;
76207
76208 /* interface for exporting device attributes */
76209 struct device_attribute {
76210@@ -511,11 +511,12 @@ struct device_attribute {
76211 ssize_t (*store)(struct device *dev, struct device_attribute *attr,
76212 const char *buf, size_t count);
76213 };
76214+typedef struct device_attribute __no_const device_attribute_no_const;
76215
76216 struct dev_ext_attribute {
76217 struct device_attribute attr;
76218 void *var;
76219-};
76220+} __do_const;
76221
76222 ssize_t device_show_ulong(struct device *dev, struct device_attribute *attr,
76223 char *buf);
76224diff --git a/include/linux/dma-mapping.h b/include/linux/dma-mapping.h
76225index 3a8d0a2..c762be2 100644
76226--- a/include/linux/dma-mapping.h
76227+++ b/include/linux/dma-mapping.h
76228@@ -54,7 +54,7 @@ struct dma_map_ops {
76229 u64 (*get_required_mask)(struct device *dev);
76230 #endif
76231 int is_phys;
76232-};
76233+} __do_const;
76234
76235 #define DMA_BIT_MASK(n) (((n) == 64) ? ~0ULL : ((1ULL<<(n))-1))
76236
76237diff --git a/include/linux/dmaengine.h b/include/linux/dmaengine.h
76238index 0bc7275..4ccbf11 100644
76239--- a/include/linux/dmaengine.h
76240+++ b/include/linux/dmaengine.h
76241@@ -1078,9 +1078,9 @@ struct dma_pinned_list {
76242 struct dma_pinned_list *dma_pin_iovec_pages(struct iovec *iov, size_t len);
76243 void dma_unpin_iovec_pages(struct dma_pinned_list* pinned_list);
76244
76245-dma_cookie_t dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
76246+dma_cookie_t __intentional_overflow(0) dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
76247 struct dma_pinned_list *pinned_list, unsigned char *kdata, size_t len);
76248-dma_cookie_t dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
76249+dma_cookie_t __intentional_overflow(0) dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
76250 struct dma_pinned_list *pinned_list, struct page *page,
76251 unsigned int offset, size_t len);
76252
76253diff --git a/include/linux/efi.h b/include/linux/efi.h
76254index 094ddd0..f1dfcd3 100644
76255--- a/include/linux/efi.h
76256+++ b/include/linux/efi.h
76257@@ -745,6 +745,7 @@ struct efivar_operations {
76258 efi_set_variable_t *set_variable;
76259 efi_query_variable_store_t *query_variable_store;
76260 };
76261+typedef struct efivar_operations __no_const efivar_operations_no_const;
76262
76263 struct efivars {
76264 /*
76265diff --git a/include/linux/elf.h b/include/linux/elf.h
76266index 40a3c0e0..4c45a38 100644
76267--- a/include/linux/elf.h
76268+++ b/include/linux/elf.h
76269@@ -24,6 +24,7 @@ extern Elf32_Dyn _DYNAMIC [];
76270 #define elf_note elf32_note
76271 #define elf_addr_t Elf32_Off
76272 #define Elf_Half Elf32_Half
76273+#define elf_dyn Elf32_Dyn
76274
76275 #else
76276
76277@@ -34,6 +35,7 @@ extern Elf64_Dyn _DYNAMIC [];
76278 #define elf_note elf64_note
76279 #define elf_addr_t Elf64_Off
76280 #define Elf_Half Elf64_Half
76281+#define elf_dyn Elf64_Dyn
76282
76283 #endif
76284
76285diff --git a/include/linux/err.h b/include/linux/err.h
76286index 15f92e0..e825a8e 100644
76287--- a/include/linux/err.h
76288+++ b/include/linux/err.h
76289@@ -19,12 +19,12 @@
76290
76291 #define IS_ERR_VALUE(x) unlikely((x) >= (unsigned long)-MAX_ERRNO)
76292
76293-static inline void * __must_check ERR_PTR(long error)
76294+static inline void * __must_check __intentional_overflow(-1) ERR_PTR(long error)
76295 {
76296 return (void *) error;
76297 }
76298
76299-static inline long __must_check PTR_ERR(__force const void *ptr)
76300+static inline long __must_check __intentional_overflow(-1) PTR_ERR(__force const void *ptr)
76301 {
76302 return (long) ptr;
76303 }
76304diff --git a/include/linux/extcon.h b/include/linux/extcon.h
76305index fcb51c8..bdafcf6 100644
76306--- a/include/linux/extcon.h
76307+++ b/include/linux/extcon.h
76308@@ -134,7 +134,7 @@ struct extcon_dev {
76309 /* /sys/class/extcon/.../mutually_exclusive/... */
76310 struct attribute_group attr_g_muex;
76311 struct attribute **attrs_muex;
76312- struct device_attribute *d_attrs_muex;
76313+ device_attribute_no_const *d_attrs_muex;
76314 };
76315
76316 /**
76317diff --git a/include/linux/fb.h b/include/linux/fb.h
76318index ffac70a..ca3e711 100644
76319--- a/include/linux/fb.h
76320+++ b/include/linux/fb.h
76321@@ -304,7 +304,7 @@ struct fb_ops {
76322 /* called at KDB enter and leave time to prepare the console */
76323 int (*fb_debug_enter)(struct fb_info *info);
76324 int (*fb_debug_leave)(struct fb_info *info);
76325-};
76326+} __do_const;
76327
76328 #ifdef CONFIG_FB_TILEBLITTING
76329 #define FB_TILE_CURSOR_NONE 0
76330diff --git a/include/linux/fdtable.h b/include/linux/fdtable.h
76331index 085197b..0fa6f0b 100644
76332--- a/include/linux/fdtable.h
76333+++ b/include/linux/fdtable.h
76334@@ -95,7 +95,7 @@ struct files_struct *get_files_struct(struct task_struct *);
76335 void put_files_struct(struct files_struct *fs);
76336 void reset_files_struct(struct files_struct *);
76337 int unshare_files(struct files_struct **);
76338-struct files_struct *dup_fd(struct files_struct *, int *);
76339+struct files_struct *dup_fd(struct files_struct *, int *) __latent_entropy;
76340 void do_close_on_exec(struct files_struct *);
76341 int iterate_fd(struct files_struct *, unsigned,
76342 int (*)(const void *, struct file *, unsigned),
76343diff --git a/include/linux/frontswap.h b/include/linux/frontswap.h
76344index 8293262..2b3b8bd 100644
76345--- a/include/linux/frontswap.h
76346+++ b/include/linux/frontswap.h
76347@@ -11,7 +11,7 @@ struct frontswap_ops {
76348 int (*load)(unsigned, pgoff_t, struct page *);
76349 void (*invalidate_page)(unsigned, pgoff_t);
76350 void (*invalidate_area)(unsigned);
76351-};
76352+} __no_const;
76353
76354 extern bool frontswap_enabled;
76355 extern struct frontswap_ops *
76356diff --git a/include/linux/fs.h b/include/linux/fs.h
76357index 164d2a9..631465c 100644
76358--- a/include/linux/fs.h
76359+++ b/include/linux/fs.h
76360@@ -423,7 +423,7 @@ struct address_space {
76361 spinlock_t private_lock; /* for use by the address_space */
76362 struct list_head private_list; /* ditto */
76363 void *private_data; /* ditto */
76364-} __attribute__((aligned(sizeof(long))));
76365+} __attribute__((aligned(sizeof(long)))) __randomize_layout;
76366 /*
76367 * On most architectures that alignment is already the case; but
76368 * must be enforced here for CRIS, to let the least significant bit
76369@@ -466,7 +466,7 @@ struct block_device {
76370 int bd_fsfreeze_count;
76371 /* Mutex for freeze */
76372 struct mutex bd_fsfreeze_mutex;
76373-};
76374+} __randomize_layout;
76375
76376 /*
76377 * Radix-tree tags, for tagging dirty and writeback pages within the pagecache
76378@@ -610,7 +610,7 @@ struct inode {
76379 atomic_t i_readcount; /* struct files open RO */
76380 #endif
76381 void *i_private; /* fs or device private pointer */
76382-};
76383+} __randomize_layout;
76384
76385 static inline int inode_unhashed(struct inode *inode)
76386 {
76387@@ -810,7 +810,7 @@ struct file {
76388 #ifdef CONFIG_DEBUG_WRITECOUNT
76389 unsigned long f_mnt_write_state;
76390 #endif
76391-};
76392+} __randomize_layout;
76393
76394 struct file_handle {
76395 __u32 handle_bytes;
76396@@ -979,7 +979,7 @@ struct file_lock {
76397 int state; /* state of grant or error if -ve */
76398 } afs;
76399 } fl_u;
76400-};
76401+} __randomize_layout;
76402
76403 /* The following constant reflects the upper bound of the file/locking space */
76404 #ifndef OFFSET_MAX
76405@@ -1330,7 +1330,7 @@ struct super_block {
76406 */
76407 struct list_lru s_dentry_lru ____cacheline_aligned_in_smp;
76408 struct list_lru s_inode_lru ____cacheline_aligned_in_smp;
76409-};
76410+} __randomize_layout;
76411
76412 extern struct timespec current_fs_time(struct super_block *sb);
76413
76414@@ -1552,7 +1552,8 @@ struct file_operations {
76415 long (*fallocate)(struct file *file, int mode, loff_t offset,
76416 loff_t len);
76417 int (*show_fdinfo)(struct seq_file *m, struct file *f);
76418-};
76419+} __do_const __randomize_layout;
76420+typedef struct file_operations __no_const file_operations_no_const;
76421
76422 struct inode_operations {
76423 struct dentry * (*lookup) (struct inode *,struct dentry *, unsigned int);
76424@@ -2747,4 +2748,14 @@ static inline bool dir_relax(struct inode *inode)
76425 return !IS_DEADDIR(inode);
76426 }
76427
76428+static inline bool is_sidechannel_device(const struct inode *inode)
76429+{
76430+#ifdef CONFIG_GRKERNSEC_DEVICE_SIDECHANNEL
76431+ umode_t mode = inode->i_mode;
76432+ return ((S_ISCHR(mode) || S_ISBLK(mode)) && (mode & (S_IROTH | S_IWOTH)));
76433+#else
76434+ return false;
76435+#endif
76436+}
76437+
76438 #endif /* _LINUX_FS_H */
76439diff --git a/include/linux/fs_struct.h b/include/linux/fs_struct.h
76440index 0efc3e6..fd23610 100644
76441--- a/include/linux/fs_struct.h
76442+++ b/include/linux/fs_struct.h
76443@@ -6,13 +6,13 @@
76444 #include <linux/seqlock.h>
76445
76446 struct fs_struct {
76447- int users;
76448+ atomic_t users;
76449 spinlock_t lock;
76450 seqcount_t seq;
76451 int umask;
76452 int in_exec;
76453 struct path root, pwd;
76454-};
76455+} __randomize_layout;
76456
76457 extern struct kmem_cache *fs_cachep;
76458
76459diff --git a/include/linux/fscache-cache.h b/include/linux/fscache-cache.h
76460index 7823e9e..56b6f2f 100644
76461--- a/include/linux/fscache-cache.h
76462+++ b/include/linux/fscache-cache.h
76463@@ -113,7 +113,7 @@ struct fscache_operation {
76464 fscache_operation_release_t release;
76465 };
76466
76467-extern atomic_t fscache_op_debug_id;
76468+extern atomic_unchecked_t fscache_op_debug_id;
76469 extern void fscache_op_work_func(struct work_struct *work);
76470
76471 extern void fscache_enqueue_operation(struct fscache_operation *);
76472@@ -135,7 +135,7 @@ static inline void fscache_operation_init(struct fscache_operation *op,
76473 INIT_WORK(&op->work, fscache_op_work_func);
76474 atomic_set(&op->usage, 1);
76475 op->state = FSCACHE_OP_ST_INITIALISED;
76476- op->debug_id = atomic_inc_return(&fscache_op_debug_id);
76477+ op->debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
76478 op->processor = processor;
76479 op->release = release;
76480 INIT_LIST_HEAD(&op->pend_link);
76481diff --git a/include/linux/fscache.h b/include/linux/fscache.h
76482index 19b4645..3b73dfc 100644
76483--- a/include/linux/fscache.h
76484+++ b/include/linux/fscache.h
76485@@ -152,7 +152,7 @@ struct fscache_cookie_def {
76486 * - this is mandatory for any object that may have data
76487 */
76488 void (*now_uncached)(void *cookie_netfs_data);
76489-};
76490+} __do_const;
76491
76492 /*
76493 * fscache cached network filesystem type
76494diff --git a/include/linux/fsnotify.h b/include/linux/fsnotify.h
76495index 1c804b0..1432c2b 100644
76496--- a/include/linux/fsnotify.h
76497+++ b/include/linux/fsnotify.h
76498@@ -195,6 +195,9 @@ static inline void fsnotify_access(struct file *file)
76499 struct inode *inode = file_inode(file);
76500 __u32 mask = FS_ACCESS;
76501
76502+ if (is_sidechannel_device(inode))
76503+ return;
76504+
76505 if (S_ISDIR(inode->i_mode))
76506 mask |= FS_ISDIR;
76507
76508@@ -213,6 +216,9 @@ static inline void fsnotify_modify(struct file *file)
76509 struct inode *inode = file_inode(file);
76510 __u32 mask = FS_MODIFY;
76511
76512+ if (is_sidechannel_device(inode))
76513+ return;
76514+
76515 if (S_ISDIR(inode->i_mode))
76516 mask |= FS_ISDIR;
76517
76518@@ -315,7 +321,7 @@ static inline void fsnotify_change(struct dentry *dentry, unsigned int ia_valid)
76519 */
76520 static inline const unsigned char *fsnotify_oldname_init(const unsigned char *name)
76521 {
76522- return kstrdup(name, GFP_KERNEL);
76523+ return (const unsigned char *)kstrdup((const char *)name, GFP_KERNEL);
76524 }
76525
76526 /*
76527diff --git a/include/linux/genhd.h b/include/linux/genhd.h
76528index 9f3c275..8bdff5d 100644
76529--- a/include/linux/genhd.h
76530+++ b/include/linux/genhd.h
76531@@ -194,7 +194,7 @@ struct gendisk {
76532 struct kobject *slave_dir;
76533
76534 struct timer_rand_state *random;
76535- atomic_t sync_io; /* RAID */
76536+ atomic_unchecked_t sync_io; /* RAID */
76537 struct disk_events *ev;
76538 #ifdef CONFIG_BLK_DEV_INTEGRITY
76539 struct blk_integrity *integrity;
76540@@ -435,7 +435,7 @@ extern void disk_flush_events(struct gendisk *disk, unsigned int mask);
76541 extern unsigned int disk_clear_events(struct gendisk *disk, unsigned int mask);
76542
76543 /* drivers/char/random.c */
76544-extern void add_disk_randomness(struct gendisk *disk);
76545+extern void add_disk_randomness(struct gendisk *disk) __latent_entropy;
76546 extern void rand_initialize_disk(struct gendisk *disk);
76547
76548 static inline sector_t get_start_sect(struct block_device *bdev)
76549diff --git a/include/linux/genl_magic_func.h b/include/linux/genl_magic_func.h
76550index 023bc34..b02b46a 100644
76551--- a/include/linux/genl_magic_func.h
76552+++ b/include/linux/genl_magic_func.h
76553@@ -246,7 +246,7 @@ const char *CONCAT_(GENL_MAGIC_FAMILY, _genl_cmd_to_str)(__u8 cmd)
76554 },
76555
76556 #define ZZZ_genl_ops CONCAT_(GENL_MAGIC_FAMILY, _genl_ops)
76557-static struct genl_ops ZZZ_genl_ops[] __read_mostly = {
76558+static struct genl_ops ZZZ_genl_ops[] = {
76559 #include GENL_MAGIC_INCLUDE_FILE
76560 };
76561
76562diff --git a/include/linux/gfp.h b/include/linux/gfp.h
76563index 9b4dd49..61fd41d 100644
76564--- a/include/linux/gfp.h
76565+++ b/include/linux/gfp.h
76566@@ -35,6 +35,13 @@ struct vm_area_struct;
76567 #define ___GFP_NO_KSWAPD 0x400000u
76568 #define ___GFP_OTHER_NODE 0x800000u
76569 #define ___GFP_WRITE 0x1000000u
76570+
76571+#ifdef CONFIG_PAX_USERCOPY_SLABS
76572+#define ___GFP_USERCOPY 0x2000000u
76573+#else
76574+#define ___GFP_USERCOPY 0
76575+#endif
76576+
76577 /* If the above are modified, __GFP_BITS_SHIFT may need updating */
76578
76579 /*
76580@@ -92,6 +99,7 @@ struct vm_area_struct;
76581 #define __GFP_OTHER_NODE ((__force gfp_t)___GFP_OTHER_NODE) /* On behalf of other node */
76582 #define __GFP_KMEMCG ((__force gfp_t)___GFP_KMEMCG) /* Allocation comes from a memcg-accounted resource */
76583 #define __GFP_WRITE ((__force gfp_t)___GFP_WRITE) /* Allocator intends to dirty page */
76584+#define __GFP_USERCOPY ((__force gfp_t)___GFP_USERCOPY)/* Allocator intends to copy page to/from userland */
76585
76586 /*
76587 * This may seem redundant, but it's a way of annotating false positives vs.
76588@@ -99,7 +107,7 @@ struct vm_area_struct;
76589 */
76590 #define __GFP_NOTRACK_FALSE_POSITIVE (__GFP_NOTRACK)
76591
76592-#define __GFP_BITS_SHIFT 25 /* Room for N __GFP_FOO bits */
76593+#define __GFP_BITS_SHIFT 26 /* Room for N __GFP_FOO bits */
76594 #define __GFP_BITS_MASK ((__force gfp_t)((1 << __GFP_BITS_SHIFT) - 1))
76595
76596 /* This equals 0, but use constants in case they ever change */
76597@@ -153,6 +161,8 @@ struct vm_area_struct;
76598 /* 4GB DMA on some platforms */
76599 #define GFP_DMA32 __GFP_DMA32
76600
76601+#define GFP_USERCOPY __GFP_USERCOPY
76602+
76603 /* Convert GFP flags to their corresponding migrate type */
76604 static inline int allocflags_to_migratetype(gfp_t gfp_flags)
76605 {
76606diff --git a/include/linux/gracl.h b/include/linux/gracl.h
76607new file mode 100644
76608index 0000000..edb2cb6
76609--- /dev/null
76610+++ b/include/linux/gracl.h
76611@@ -0,0 +1,340 @@
76612+#ifndef GR_ACL_H
76613+#define GR_ACL_H
76614+
76615+#include <linux/grdefs.h>
76616+#include <linux/resource.h>
76617+#include <linux/capability.h>
76618+#include <linux/dcache.h>
76619+#include <asm/resource.h>
76620+
76621+/* Major status information */
76622+
76623+#define GR_VERSION "grsecurity 3.0"
76624+#define GRSECURITY_VERSION 0x3000
76625+
76626+enum {
76627+ GR_SHUTDOWN = 0,
76628+ GR_ENABLE = 1,
76629+ GR_SPROLE = 2,
76630+ GR_OLDRELOAD = 3,
76631+ GR_SEGVMOD = 4,
76632+ GR_STATUS = 5,
76633+ GR_UNSPROLE = 6,
76634+ GR_PASSSET = 7,
76635+ GR_SPROLEPAM = 8,
76636+ GR_RELOAD = 9,
76637+};
76638+
76639+/* Password setup definitions
76640+ * kernel/grhash.c */
76641+enum {
76642+ GR_PW_LEN = 128,
76643+ GR_SALT_LEN = 16,
76644+ GR_SHA_LEN = 32,
76645+};
76646+
76647+enum {
76648+ GR_SPROLE_LEN = 64,
76649+};
76650+
76651+enum {
76652+ GR_NO_GLOB = 0,
76653+ GR_REG_GLOB,
76654+ GR_CREATE_GLOB
76655+};
76656+
76657+#define GR_NLIMITS 32
76658+
76659+/* Begin Data Structures */
76660+
76661+struct sprole_pw {
76662+ unsigned char *rolename;
76663+ unsigned char salt[GR_SALT_LEN];
76664+ unsigned char sum[GR_SHA_LEN]; /* 256-bit SHA hash of the password */
76665+};
76666+
76667+struct name_entry {
76668+ __u32 key;
76669+ ino_t inode;
76670+ dev_t device;
76671+ char *name;
76672+ __u16 len;
76673+ __u8 deleted;
76674+ struct name_entry *prev;
76675+ struct name_entry *next;
76676+};
76677+
76678+struct inodev_entry {
76679+ struct name_entry *nentry;
76680+ struct inodev_entry *prev;
76681+ struct inodev_entry *next;
76682+};
76683+
76684+struct acl_role_db {
76685+ struct acl_role_label **r_hash;
76686+ __u32 r_size;
76687+};
76688+
76689+struct inodev_db {
76690+ struct inodev_entry **i_hash;
76691+ __u32 i_size;
76692+};
76693+
76694+struct name_db {
76695+ struct name_entry **n_hash;
76696+ __u32 n_size;
76697+};
76698+
76699+struct crash_uid {
76700+ uid_t uid;
76701+ unsigned long expires;
76702+};
76703+
76704+struct gr_hash_struct {
76705+ void **table;
76706+ void **nametable;
76707+ void *first;
76708+ __u32 table_size;
76709+ __u32 used_size;
76710+ int type;
76711+};
76712+
76713+/* Userspace Grsecurity ACL data structures */
76714+
76715+struct acl_subject_label {
76716+ char *filename;
76717+ ino_t inode;
76718+ dev_t device;
76719+ __u32 mode;
76720+ kernel_cap_t cap_mask;
76721+ kernel_cap_t cap_lower;
76722+ kernel_cap_t cap_invert_audit;
76723+
76724+ struct rlimit res[GR_NLIMITS];
76725+ __u32 resmask;
76726+
76727+ __u8 user_trans_type;
76728+ __u8 group_trans_type;
76729+ uid_t *user_transitions;
76730+ gid_t *group_transitions;
76731+ __u16 user_trans_num;
76732+ __u16 group_trans_num;
76733+
76734+ __u32 sock_families[2];
76735+ __u32 ip_proto[8];
76736+ __u32 ip_type;
76737+ struct acl_ip_label **ips;
76738+ __u32 ip_num;
76739+ __u32 inaddr_any_override;
76740+
76741+ __u32 crashes;
76742+ unsigned long expires;
76743+
76744+ struct acl_subject_label *parent_subject;
76745+ struct gr_hash_struct *hash;
76746+ struct acl_subject_label *prev;
76747+ struct acl_subject_label *next;
76748+
76749+ struct acl_object_label **obj_hash;
76750+ __u32 obj_hash_size;
76751+ __u16 pax_flags;
76752+};
76753+
76754+struct role_allowed_ip {
76755+ __u32 addr;
76756+ __u32 netmask;
76757+
76758+ struct role_allowed_ip *prev;
76759+ struct role_allowed_ip *next;
76760+};
76761+
76762+struct role_transition {
76763+ char *rolename;
76764+
76765+ struct role_transition *prev;
76766+ struct role_transition *next;
76767+};
76768+
76769+struct acl_role_label {
76770+ char *rolename;
76771+ uid_t uidgid;
76772+ __u16 roletype;
76773+
76774+ __u16 auth_attempts;
76775+ unsigned long expires;
76776+
76777+ struct acl_subject_label *root_label;
76778+ struct gr_hash_struct *hash;
76779+
76780+ struct acl_role_label *prev;
76781+ struct acl_role_label *next;
76782+
76783+ struct role_transition *transitions;
76784+ struct role_allowed_ip *allowed_ips;
76785+ uid_t *domain_children;
76786+ __u16 domain_child_num;
76787+
76788+ umode_t umask;
76789+
76790+ struct acl_subject_label **subj_hash;
76791+ __u32 subj_hash_size;
76792+};
76793+
76794+struct user_acl_role_db {
76795+ struct acl_role_label **r_table;
76796+ __u32 num_pointers; /* Number of allocations to track */
76797+ __u32 num_roles; /* Number of roles */
76798+ __u32 num_domain_children; /* Number of domain children */
76799+ __u32 num_subjects; /* Number of subjects */
76800+ __u32 num_objects; /* Number of objects */
76801+};
76802+
76803+struct acl_object_label {
76804+ char *filename;
76805+ ino_t inode;
76806+ dev_t device;
76807+ __u32 mode;
76808+
76809+ struct acl_subject_label *nested;
76810+ struct acl_object_label *globbed;
76811+
76812+ /* next two structures not used */
76813+
76814+ struct acl_object_label *prev;
76815+ struct acl_object_label *next;
76816+};
76817+
76818+struct acl_ip_label {
76819+ char *iface;
76820+ __u32 addr;
76821+ __u32 netmask;
76822+ __u16 low, high;
76823+ __u8 mode;
76824+ __u32 type;
76825+ __u32 proto[8];
76826+
76827+ /* next two structures not used */
76828+
76829+ struct acl_ip_label *prev;
76830+ struct acl_ip_label *next;
76831+};
76832+
76833+struct gr_arg {
76834+ struct user_acl_role_db role_db;
76835+ unsigned char pw[GR_PW_LEN];
76836+ unsigned char salt[GR_SALT_LEN];
76837+ unsigned char sum[GR_SHA_LEN];
76838+ unsigned char sp_role[GR_SPROLE_LEN];
76839+ struct sprole_pw *sprole_pws;
76840+ dev_t segv_device;
76841+ ino_t segv_inode;
76842+ uid_t segv_uid;
76843+ __u16 num_sprole_pws;
76844+ __u16 mode;
76845+};
76846+
76847+struct gr_arg_wrapper {
76848+ struct gr_arg *arg;
76849+ __u32 version;
76850+ __u32 size;
76851+};
76852+
76853+struct subject_map {
76854+ struct acl_subject_label *user;
76855+ struct acl_subject_label *kernel;
76856+ struct subject_map *prev;
76857+ struct subject_map *next;
76858+};
76859+
76860+struct acl_subj_map_db {
76861+ struct subject_map **s_hash;
76862+ __u32 s_size;
76863+};
76864+
76865+struct gr_policy_state {
76866+ struct sprole_pw **acl_special_roles;
76867+ __u16 num_sprole_pws;
76868+ struct acl_role_label *kernel_role;
76869+ struct acl_role_label *role_list;
76870+ struct acl_role_label *default_role;
76871+ struct acl_role_db acl_role_set;
76872+ struct acl_subj_map_db subj_map_set;
76873+ struct name_db name_set;
76874+ struct inodev_db inodev_set;
76875+};
76876+
76877+struct gr_alloc_state {
76878+ unsigned long alloc_stack_next;
76879+ unsigned long alloc_stack_size;
76880+ void **alloc_stack;
76881+};
76882+
76883+struct gr_reload_state {
76884+ struct gr_policy_state oldpolicy;
76885+ struct gr_alloc_state oldalloc;
76886+ struct gr_policy_state newpolicy;
76887+ struct gr_alloc_state newalloc;
76888+ struct gr_policy_state *oldpolicy_ptr;
76889+ struct gr_alloc_state *oldalloc_ptr;
76890+ unsigned char oldmode;
76891+};
76892+
76893+/* End Data Structures Section */
76894+
76895+/* Hash functions generated by empirical testing by Brad Spengler
76896+ Makes good use of the low bits of the inode. Generally 0-1 times
76897+ in loop for successful match. 0-3 for unsuccessful match.
76898+ Shift/add algorithm with modulus of table size and an XOR*/
76899+
76900+static __inline__ unsigned int
76901+gr_rhash(const uid_t uid, const __u16 type, const unsigned int sz)
76902+{
76903+ return ((((uid + type) << (16 + type)) ^ uid) % sz);
76904+}
76905+
76906+ static __inline__ unsigned int
76907+gr_shash(const struct acl_subject_label *userp, const unsigned int sz)
76908+{
76909+ return ((const unsigned long)userp % sz);
76910+}
76911+
76912+static __inline__ unsigned int
76913+gr_fhash(const ino_t ino, const dev_t dev, const unsigned int sz)
76914+{
76915+ return (((ino + dev) ^ ((ino << 13) + (ino << 23) + (dev << 9))) % sz);
76916+}
76917+
76918+static __inline__ unsigned int
76919+gr_nhash(const char *name, const __u16 len, const unsigned int sz)
76920+{
76921+ return full_name_hash((const unsigned char *)name, len) % sz;
76922+}
76923+
76924+#define FOR_EACH_SUBJECT_START(role,subj,iter) \
76925+ subj = NULL; \
76926+ iter = 0; \
76927+ while (iter < role->subj_hash_size) { \
76928+ if (subj == NULL) \
76929+ subj = role->subj_hash[iter]; \
76930+ if (subj == NULL) { \
76931+ iter++; \
76932+ continue; \
76933+ }
76934+
76935+#define FOR_EACH_SUBJECT_END(subj,iter) \
76936+ subj = subj->next; \
76937+ if (subj == NULL) \
76938+ iter++; \
76939+ }
76940+
76941+
76942+#define FOR_EACH_NESTED_SUBJECT_START(role,subj) \
76943+ subj = role->hash->first; \
76944+ while (subj != NULL) {
76945+
76946+#define FOR_EACH_NESTED_SUBJECT_END(subj) \
76947+ subj = subj->next; \
76948+ }
76949+
76950+#endif
76951+
76952diff --git a/include/linux/gracl_compat.h b/include/linux/gracl_compat.h
76953new file mode 100644
76954index 0000000..33ebd1f
76955--- /dev/null
76956+++ b/include/linux/gracl_compat.h
76957@@ -0,0 +1,156 @@
76958+#ifndef GR_ACL_COMPAT_H
76959+#define GR_ACL_COMPAT_H
76960+
76961+#include <linux/resource.h>
76962+#include <asm/resource.h>
76963+
76964+struct sprole_pw_compat {
76965+ compat_uptr_t rolename;
76966+ unsigned char salt[GR_SALT_LEN];
76967+ unsigned char sum[GR_SHA_LEN];
76968+};
76969+
76970+struct gr_hash_struct_compat {
76971+ compat_uptr_t table;
76972+ compat_uptr_t nametable;
76973+ compat_uptr_t first;
76974+ __u32 table_size;
76975+ __u32 used_size;
76976+ int type;
76977+};
76978+
76979+struct acl_subject_label_compat {
76980+ compat_uptr_t filename;
76981+ compat_ino_t inode;
76982+ __u32 device;
76983+ __u32 mode;
76984+ kernel_cap_t cap_mask;
76985+ kernel_cap_t cap_lower;
76986+ kernel_cap_t cap_invert_audit;
76987+
76988+ struct compat_rlimit res[GR_NLIMITS];
76989+ __u32 resmask;
76990+
76991+ __u8 user_trans_type;
76992+ __u8 group_trans_type;
76993+ compat_uptr_t user_transitions;
76994+ compat_uptr_t group_transitions;
76995+ __u16 user_trans_num;
76996+ __u16 group_trans_num;
76997+
76998+ __u32 sock_families[2];
76999+ __u32 ip_proto[8];
77000+ __u32 ip_type;
77001+ compat_uptr_t ips;
77002+ __u32 ip_num;
77003+ __u32 inaddr_any_override;
77004+
77005+ __u32 crashes;
77006+ compat_ulong_t expires;
77007+
77008+ compat_uptr_t parent_subject;
77009+ compat_uptr_t hash;
77010+ compat_uptr_t prev;
77011+ compat_uptr_t next;
77012+
77013+ compat_uptr_t obj_hash;
77014+ __u32 obj_hash_size;
77015+ __u16 pax_flags;
77016+};
77017+
77018+struct role_allowed_ip_compat {
77019+ __u32 addr;
77020+ __u32 netmask;
77021+
77022+ compat_uptr_t prev;
77023+ compat_uptr_t next;
77024+};
77025+
77026+struct role_transition_compat {
77027+ compat_uptr_t rolename;
77028+
77029+ compat_uptr_t prev;
77030+ compat_uptr_t next;
77031+};
77032+
77033+struct acl_role_label_compat {
77034+ compat_uptr_t rolename;
77035+ uid_t uidgid;
77036+ __u16 roletype;
77037+
77038+ __u16 auth_attempts;
77039+ compat_ulong_t expires;
77040+
77041+ compat_uptr_t root_label;
77042+ compat_uptr_t hash;
77043+
77044+ compat_uptr_t prev;
77045+ compat_uptr_t next;
77046+
77047+ compat_uptr_t transitions;
77048+ compat_uptr_t allowed_ips;
77049+ compat_uptr_t domain_children;
77050+ __u16 domain_child_num;
77051+
77052+ umode_t umask;
77053+
77054+ compat_uptr_t subj_hash;
77055+ __u32 subj_hash_size;
77056+};
77057+
77058+struct user_acl_role_db_compat {
77059+ compat_uptr_t r_table;
77060+ __u32 num_pointers;
77061+ __u32 num_roles;
77062+ __u32 num_domain_children;
77063+ __u32 num_subjects;
77064+ __u32 num_objects;
77065+};
77066+
77067+struct acl_object_label_compat {
77068+ compat_uptr_t filename;
77069+ compat_ino_t inode;
77070+ __u32 device;
77071+ __u32 mode;
77072+
77073+ compat_uptr_t nested;
77074+ compat_uptr_t globbed;
77075+
77076+ compat_uptr_t prev;
77077+ compat_uptr_t next;
77078+};
77079+
77080+struct acl_ip_label_compat {
77081+ compat_uptr_t iface;
77082+ __u32 addr;
77083+ __u32 netmask;
77084+ __u16 low, high;
77085+ __u8 mode;
77086+ __u32 type;
77087+ __u32 proto[8];
77088+
77089+ compat_uptr_t prev;
77090+ compat_uptr_t next;
77091+};
77092+
77093+struct gr_arg_compat {
77094+ struct user_acl_role_db_compat role_db;
77095+ unsigned char pw[GR_PW_LEN];
77096+ unsigned char salt[GR_SALT_LEN];
77097+ unsigned char sum[GR_SHA_LEN];
77098+ unsigned char sp_role[GR_SPROLE_LEN];
77099+ compat_uptr_t sprole_pws;
77100+ __u32 segv_device;
77101+ compat_ino_t segv_inode;
77102+ uid_t segv_uid;
77103+ __u16 num_sprole_pws;
77104+ __u16 mode;
77105+};
77106+
77107+struct gr_arg_wrapper_compat {
77108+ compat_uptr_t arg;
77109+ __u32 version;
77110+ __u32 size;
77111+};
77112+
77113+#endif
77114diff --git a/include/linux/gralloc.h b/include/linux/gralloc.h
77115new file mode 100644
77116index 0000000..323ecf2
77117--- /dev/null
77118+++ b/include/linux/gralloc.h
77119@@ -0,0 +1,9 @@
77120+#ifndef __GRALLOC_H
77121+#define __GRALLOC_H
77122+
77123+void acl_free_all(void);
77124+int acl_alloc_stack_init(unsigned long size);
77125+void *acl_alloc(unsigned long len);
77126+void *acl_alloc_num(unsigned long num, unsigned long len);
77127+
77128+#endif
77129diff --git a/include/linux/grdefs.h b/include/linux/grdefs.h
77130new file mode 100644
77131index 0000000..be66033
77132--- /dev/null
77133+++ b/include/linux/grdefs.h
77134@@ -0,0 +1,140 @@
77135+#ifndef GRDEFS_H
77136+#define GRDEFS_H
77137+
77138+/* Begin grsecurity status declarations */
77139+
77140+enum {
77141+ GR_READY = 0x01,
77142+ GR_STATUS_INIT = 0x00 // disabled state
77143+};
77144+
77145+/* Begin ACL declarations */
77146+
77147+/* Role flags */
77148+
77149+enum {
77150+ GR_ROLE_USER = 0x0001,
77151+ GR_ROLE_GROUP = 0x0002,
77152+ GR_ROLE_DEFAULT = 0x0004,
77153+ GR_ROLE_SPECIAL = 0x0008,
77154+ GR_ROLE_AUTH = 0x0010,
77155+ GR_ROLE_NOPW = 0x0020,
77156+ GR_ROLE_GOD = 0x0040,
77157+ GR_ROLE_LEARN = 0x0080,
77158+ GR_ROLE_TPE = 0x0100,
77159+ GR_ROLE_DOMAIN = 0x0200,
77160+ GR_ROLE_PAM = 0x0400,
77161+ GR_ROLE_PERSIST = 0x0800
77162+};
77163+
77164+/* ACL Subject and Object mode flags */
77165+enum {
77166+ GR_DELETED = 0x80000000
77167+};
77168+
77169+/* ACL Object-only mode flags */
77170+enum {
77171+ GR_READ = 0x00000001,
77172+ GR_APPEND = 0x00000002,
77173+ GR_WRITE = 0x00000004,
77174+ GR_EXEC = 0x00000008,
77175+ GR_FIND = 0x00000010,
77176+ GR_INHERIT = 0x00000020,
77177+ GR_SETID = 0x00000040,
77178+ GR_CREATE = 0x00000080,
77179+ GR_DELETE = 0x00000100,
77180+ GR_LINK = 0x00000200,
77181+ GR_AUDIT_READ = 0x00000400,
77182+ GR_AUDIT_APPEND = 0x00000800,
77183+ GR_AUDIT_WRITE = 0x00001000,
77184+ GR_AUDIT_EXEC = 0x00002000,
77185+ GR_AUDIT_FIND = 0x00004000,
77186+ GR_AUDIT_INHERIT= 0x00008000,
77187+ GR_AUDIT_SETID = 0x00010000,
77188+ GR_AUDIT_CREATE = 0x00020000,
77189+ GR_AUDIT_DELETE = 0x00040000,
77190+ GR_AUDIT_LINK = 0x00080000,
77191+ GR_PTRACERD = 0x00100000,
77192+ GR_NOPTRACE = 0x00200000,
77193+ GR_SUPPRESS = 0x00400000,
77194+ GR_NOLEARN = 0x00800000,
77195+ GR_INIT_TRANSFER= 0x01000000
77196+};
77197+
77198+#define GR_AUDITS (GR_AUDIT_READ | GR_AUDIT_WRITE | GR_AUDIT_APPEND | GR_AUDIT_EXEC | \
77199+ GR_AUDIT_FIND | GR_AUDIT_INHERIT | GR_AUDIT_SETID | \
77200+ GR_AUDIT_CREATE | GR_AUDIT_DELETE | GR_AUDIT_LINK)
77201+
77202+/* ACL subject-only mode flags */
77203+enum {
77204+ GR_KILL = 0x00000001,
77205+ GR_VIEW = 0x00000002,
77206+ GR_PROTECTED = 0x00000004,
77207+ GR_LEARN = 0x00000008,
77208+ GR_OVERRIDE = 0x00000010,
77209+ /* just a placeholder, this mode is only used in userspace */
77210+ GR_DUMMY = 0x00000020,
77211+ GR_PROTSHM = 0x00000040,
77212+ GR_KILLPROC = 0x00000080,
77213+ GR_KILLIPPROC = 0x00000100,
77214+ /* just a placeholder, this mode is only used in userspace */
77215+ GR_NOTROJAN = 0x00000200,
77216+ GR_PROTPROCFD = 0x00000400,
77217+ GR_PROCACCT = 0x00000800,
77218+ GR_RELAXPTRACE = 0x00001000,
77219+ //GR_NESTED = 0x00002000,
77220+ GR_INHERITLEARN = 0x00004000,
77221+ GR_PROCFIND = 0x00008000,
77222+ GR_POVERRIDE = 0x00010000,
77223+ GR_KERNELAUTH = 0x00020000,
77224+ GR_ATSECURE = 0x00040000,
77225+ GR_SHMEXEC = 0x00080000
77226+};
77227+
77228+enum {
77229+ GR_PAX_ENABLE_SEGMEXEC = 0x0001,
77230+ GR_PAX_ENABLE_PAGEEXEC = 0x0002,
77231+ GR_PAX_ENABLE_MPROTECT = 0x0004,
77232+ GR_PAX_ENABLE_RANDMMAP = 0x0008,
77233+ GR_PAX_ENABLE_EMUTRAMP = 0x0010,
77234+ GR_PAX_DISABLE_SEGMEXEC = 0x0100,
77235+ GR_PAX_DISABLE_PAGEEXEC = 0x0200,
77236+ GR_PAX_DISABLE_MPROTECT = 0x0400,
77237+ GR_PAX_DISABLE_RANDMMAP = 0x0800,
77238+ GR_PAX_DISABLE_EMUTRAMP = 0x1000,
77239+};
77240+
77241+enum {
77242+ GR_ID_USER = 0x01,
77243+ GR_ID_GROUP = 0x02,
77244+};
77245+
77246+enum {
77247+ GR_ID_ALLOW = 0x01,
77248+ GR_ID_DENY = 0x02,
77249+};
77250+
77251+#define GR_CRASH_RES 31
77252+#define GR_UIDTABLE_MAX 500
77253+
77254+/* begin resource learning section */
77255+enum {
77256+ GR_RLIM_CPU_BUMP = 60,
77257+ GR_RLIM_FSIZE_BUMP = 50000,
77258+ GR_RLIM_DATA_BUMP = 10000,
77259+ GR_RLIM_STACK_BUMP = 1000,
77260+ GR_RLIM_CORE_BUMP = 10000,
77261+ GR_RLIM_RSS_BUMP = 500000,
77262+ GR_RLIM_NPROC_BUMP = 1,
77263+ GR_RLIM_NOFILE_BUMP = 5,
77264+ GR_RLIM_MEMLOCK_BUMP = 50000,
77265+ GR_RLIM_AS_BUMP = 500000,
77266+ GR_RLIM_LOCKS_BUMP = 2,
77267+ GR_RLIM_SIGPENDING_BUMP = 5,
77268+ GR_RLIM_MSGQUEUE_BUMP = 10000,
77269+ GR_RLIM_NICE_BUMP = 1,
77270+ GR_RLIM_RTPRIO_BUMP = 1,
77271+ GR_RLIM_RTTIME_BUMP = 1000000
77272+};
77273+
77274+#endif
77275diff --git a/include/linux/grinternal.h b/include/linux/grinternal.h
77276new file mode 100644
77277index 0000000..d25522e
77278--- /dev/null
77279+++ b/include/linux/grinternal.h
77280@@ -0,0 +1,229 @@
77281+#ifndef __GRINTERNAL_H
77282+#define __GRINTERNAL_H
77283+
77284+#ifdef CONFIG_GRKERNSEC
77285+
77286+#include <linux/fs.h>
77287+#include <linux/mnt_namespace.h>
77288+#include <linux/nsproxy.h>
77289+#include <linux/gracl.h>
77290+#include <linux/grdefs.h>
77291+#include <linux/grmsg.h>
77292+
77293+void gr_add_learn_entry(const char *fmt, ...)
77294+ __attribute__ ((format (printf, 1, 2)));
77295+__u32 gr_search_file(const struct dentry *dentry, const __u32 mode,
77296+ const struct vfsmount *mnt);
77297+__u32 gr_check_create(const struct dentry *new_dentry,
77298+ const struct dentry *parent,
77299+ const struct vfsmount *mnt, const __u32 mode);
77300+int gr_check_protected_task(const struct task_struct *task);
77301+__u32 to_gr_audit(const __u32 reqmode);
77302+int gr_set_acls(const int type);
77303+int gr_acl_is_enabled(void);
77304+char gr_roletype_to_char(void);
77305+
77306+void gr_handle_alertkill(struct task_struct *task);
77307+char *gr_to_filename(const struct dentry *dentry,
77308+ const struct vfsmount *mnt);
77309+char *gr_to_filename1(const struct dentry *dentry,
77310+ const struct vfsmount *mnt);
77311+char *gr_to_filename2(const struct dentry *dentry,
77312+ const struct vfsmount *mnt);
77313+char *gr_to_filename3(const struct dentry *dentry,
77314+ const struct vfsmount *mnt);
77315+
77316+extern int grsec_enable_ptrace_readexec;
77317+extern int grsec_enable_harden_ptrace;
77318+extern int grsec_enable_link;
77319+extern int grsec_enable_fifo;
77320+extern int grsec_enable_execve;
77321+extern int grsec_enable_shm;
77322+extern int grsec_enable_execlog;
77323+extern int grsec_enable_signal;
77324+extern int grsec_enable_audit_ptrace;
77325+extern int grsec_enable_forkfail;
77326+extern int grsec_enable_time;
77327+extern int grsec_enable_rofs;
77328+extern int grsec_deny_new_usb;
77329+extern int grsec_enable_chroot_shmat;
77330+extern int grsec_enable_chroot_mount;
77331+extern int grsec_enable_chroot_double;
77332+extern int grsec_enable_chroot_pivot;
77333+extern int grsec_enable_chroot_chdir;
77334+extern int grsec_enable_chroot_chmod;
77335+extern int grsec_enable_chroot_mknod;
77336+extern int grsec_enable_chroot_fchdir;
77337+extern int grsec_enable_chroot_nice;
77338+extern int grsec_enable_chroot_execlog;
77339+extern int grsec_enable_chroot_caps;
77340+extern int grsec_enable_chroot_sysctl;
77341+extern int grsec_enable_chroot_unix;
77342+extern int grsec_enable_symlinkown;
77343+extern kgid_t grsec_symlinkown_gid;
77344+extern int grsec_enable_tpe;
77345+extern kgid_t grsec_tpe_gid;
77346+extern int grsec_enable_tpe_all;
77347+extern int grsec_enable_tpe_invert;
77348+extern int grsec_enable_socket_all;
77349+extern kgid_t grsec_socket_all_gid;
77350+extern int grsec_enable_socket_client;
77351+extern kgid_t grsec_socket_client_gid;
77352+extern int grsec_enable_socket_server;
77353+extern kgid_t grsec_socket_server_gid;
77354+extern kgid_t grsec_audit_gid;
77355+extern int grsec_enable_group;
77356+extern int grsec_enable_log_rwxmaps;
77357+extern int grsec_enable_mount;
77358+extern int grsec_enable_chdir;
77359+extern int grsec_resource_logging;
77360+extern int grsec_enable_blackhole;
77361+extern int grsec_lastack_retries;
77362+extern int grsec_enable_brute;
77363+extern int grsec_enable_harden_ipc;
77364+extern int grsec_lock;
77365+
77366+extern spinlock_t grsec_alert_lock;
77367+extern unsigned long grsec_alert_wtime;
77368+extern unsigned long grsec_alert_fyet;
77369+
77370+extern spinlock_t grsec_audit_lock;
77371+
77372+extern rwlock_t grsec_exec_file_lock;
77373+
77374+#define gr_task_fullpath(tsk) ((tsk)->exec_file ? \
77375+ gr_to_filename2((tsk)->exec_file->f_path.dentry, \
77376+ (tsk)->exec_file->f_path.mnt) : "/")
77377+
77378+#define gr_parent_task_fullpath(tsk) ((tsk)->real_parent->exec_file ? \
77379+ gr_to_filename3((tsk)->real_parent->exec_file->f_path.dentry, \
77380+ (tsk)->real_parent->exec_file->f_path.mnt) : "/")
77381+
77382+#define gr_task_fullpath0(tsk) ((tsk)->exec_file ? \
77383+ gr_to_filename((tsk)->exec_file->f_path.dentry, \
77384+ (tsk)->exec_file->f_path.mnt) : "/")
77385+
77386+#define gr_parent_task_fullpath0(tsk) ((tsk)->real_parent->exec_file ? \
77387+ gr_to_filename1((tsk)->real_parent->exec_file->f_path.dentry, \
77388+ (tsk)->real_parent->exec_file->f_path.mnt) : "/")
77389+
77390+#define proc_is_chrooted(tsk_a) ((tsk_a)->gr_is_chrooted)
77391+
77392+#define have_same_root(tsk_a,tsk_b) ((tsk_a)->gr_chroot_dentry == (tsk_b)->gr_chroot_dentry)
77393+
77394+static inline bool gr_is_same_file(const struct file *file1, const struct file *file2)
77395+{
77396+ if (file1 && file2) {
77397+ const struct inode *inode1 = file1->f_path.dentry->d_inode;
77398+ const struct inode *inode2 = file2->f_path.dentry->d_inode;
77399+ if (inode1->i_ino == inode2->i_ino && inode1->i_sb->s_dev == inode2->i_sb->s_dev)
77400+ return true;
77401+ }
77402+
77403+ return false;
77404+}
77405+
77406+#define GR_CHROOT_CAPS {{ \
77407+ CAP_TO_MASK(CAP_LINUX_IMMUTABLE) | CAP_TO_MASK(CAP_NET_ADMIN) | \
77408+ CAP_TO_MASK(CAP_SYS_MODULE) | CAP_TO_MASK(CAP_SYS_RAWIO) | \
77409+ CAP_TO_MASK(CAP_SYS_PACCT) | CAP_TO_MASK(CAP_SYS_ADMIN) | \
77410+ CAP_TO_MASK(CAP_SYS_BOOT) | CAP_TO_MASK(CAP_SYS_TIME) | \
77411+ CAP_TO_MASK(CAP_NET_RAW) | CAP_TO_MASK(CAP_SYS_TTY_CONFIG) | \
77412+ CAP_TO_MASK(CAP_IPC_OWNER) | CAP_TO_MASK(CAP_SETFCAP), \
77413+ CAP_TO_MASK(CAP_SYSLOG) | CAP_TO_MASK(CAP_MAC_ADMIN) }}
77414+
77415+#define security_learn(normal_msg,args...) \
77416+({ \
77417+ read_lock(&grsec_exec_file_lock); \
77418+ gr_add_learn_entry(normal_msg "\n", ## args); \
77419+ read_unlock(&grsec_exec_file_lock); \
77420+})
77421+
77422+enum {
77423+ GR_DO_AUDIT,
77424+ GR_DONT_AUDIT,
77425+ /* used for non-audit messages that we shouldn't kill the task on */
77426+ GR_DONT_AUDIT_GOOD
77427+};
77428+
77429+enum {
77430+ GR_TTYSNIFF,
77431+ GR_RBAC,
77432+ GR_RBAC_STR,
77433+ GR_STR_RBAC,
77434+ GR_RBAC_MODE2,
77435+ GR_RBAC_MODE3,
77436+ GR_FILENAME,
77437+ GR_SYSCTL_HIDDEN,
77438+ GR_NOARGS,
77439+ GR_ONE_INT,
77440+ GR_ONE_INT_TWO_STR,
77441+ GR_ONE_STR,
77442+ GR_STR_INT,
77443+ GR_TWO_STR_INT,
77444+ GR_TWO_INT,
77445+ GR_TWO_U64,
77446+ GR_THREE_INT,
77447+ GR_FIVE_INT_TWO_STR,
77448+ GR_TWO_STR,
77449+ GR_THREE_STR,
77450+ GR_FOUR_STR,
77451+ GR_STR_FILENAME,
77452+ GR_FILENAME_STR,
77453+ GR_FILENAME_TWO_INT,
77454+ GR_FILENAME_TWO_INT_STR,
77455+ GR_TEXTREL,
77456+ GR_PTRACE,
77457+ GR_RESOURCE,
77458+ GR_CAP,
77459+ GR_SIG,
77460+ GR_SIG2,
77461+ GR_CRASH1,
77462+ GR_CRASH2,
77463+ GR_PSACCT,
77464+ GR_RWXMAP,
77465+ GR_RWXMAPVMA
77466+};
77467+
77468+#define gr_log_hidden_sysctl(audit, msg, str) gr_log_varargs(audit, msg, GR_SYSCTL_HIDDEN, str)
77469+#define gr_log_ttysniff(audit, msg, task) gr_log_varargs(audit, msg, GR_TTYSNIFF, task)
77470+#define gr_log_fs_rbac_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_RBAC, dentry, mnt)
77471+#define gr_log_fs_rbac_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_RBAC_STR, dentry, mnt, str)
77472+#define gr_log_fs_str_rbac(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_RBAC, str, dentry, mnt)
77473+#define gr_log_fs_rbac_mode2(audit, msg, dentry, mnt, str1, str2) gr_log_varargs(audit, msg, GR_RBAC_MODE2, dentry, mnt, str1, str2)
77474+#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)
77475+#define gr_log_fs_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_FILENAME, dentry, mnt)
77476+#define gr_log_noargs(audit, msg) gr_log_varargs(audit, msg, GR_NOARGS)
77477+#define gr_log_int(audit, msg, num) gr_log_varargs(audit, msg, GR_ONE_INT, num)
77478+#define gr_log_int_str2(audit, msg, num, str1, str2) gr_log_varargs(audit, msg, GR_ONE_INT_TWO_STR, num, str1, str2)
77479+#define gr_log_str(audit, msg, str) gr_log_varargs(audit, msg, GR_ONE_STR, str)
77480+#define gr_log_str_int(audit, msg, str, num) gr_log_varargs(audit, msg, GR_STR_INT, str, num)
77481+#define gr_log_int_int(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_INT, num1, num2)
77482+#define gr_log_two_u64(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_U64, num1, num2)
77483+#define gr_log_int3(audit, msg, num1, num2, num3) gr_log_varargs(audit, msg, GR_THREE_INT, num1, num2, num3)
77484+#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)
77485+#define gr_log_str_str(audit, msg, str1, str2) gr_log_varargs(audit, msg, GR_TWO_STR, str1, str2)
77486+#define gr_log_str2_int(audit, msg, str1, str2, num) gr_log_varargs(audit, msg, GR_TWO_STR_INT, str1, str2, num)
77487+#define gr_log_str3(audit, msg, str1, str2, str3) gr_log_varargs(audit, msg, GR_THREE_STR, str1, str2, str3)
77488+#define gr_log_str4(audit, msg, str1, str2, str3, str4) gr_log_varargs(audit, msg, GR_FOUR_STR, str1, str2, str3, str4)
77489+#define gr_log_str_fs(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_FILENAME, str, dentry, mnt)
77490+#define gr_log_fs_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_FILENAME_STR, dentry, mnt, str)
77491+#define gr_log_fs_int2(audit, msg, dentry, mnt, num1, num2) gr_log_varargs(audit, msg, GR_FILENAME_TWO_INT, dentry, mnt, num1, num2)
77492+#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)
77493+#define gr_log_textrel_ulong_ulong(audit, msg, file, ulong1, ulong2) gr_log_varargs(audit, msg, GR_TEXTREL, file, ulong1, ulong2)
77494+#define gr_log_ptrace(audit, msg, task) gr_log_varargs(audit, msg, GR_PTRACE, task)
77495+#define gr_log_res_ulong2_str(audit, msg, task, ulong1, str, ulong2) gr_log_varargs(audit, msg, GR_RESOURCE, task, ulong1, str, ulong2)
77496+#define gr_log_cap(audit, msg, task, str) gr_log_varargs(audit, msg, GR_CAP, task, str)
77497+#define gr_log_sig_addr(audit, msg, str, addr) gr_log_varargs(audit, msg, GR_SIG, str, addr)
77498+#define gr_log_sig_task(audit, msg, task, num) gr_log_varargs(audit, msg, GR_SIG2, task, num)
77499+#define gr_log_crash1(audit, msg, task, ulong) gr_log_varargs(audit, msg, GR_CRASH1, task, ulong)
77500+#define gr_log_crash2(audit, msg, task, ulong1) gr_log_varargs(audit, msg, GR_CRASH2, task, ulong1)
77501+#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)
77502+#define gr_log_rwxmap(audit, msg, str) gr_log_varargs(audit, msg, GR_RWXMAP, str)
77503+#define gr_log_rwxmap_vma(audit, msg, str) gr_log_varargs(audit, msg, GR_RWXMAPVMA, str)
77504+
77505+void gr_log_varargs(int audit, const char *msg, int argtypes, ...);
77506+
77507+#endif
77508+
77509+#endif
77510diff --git a/include/linux/grmsg.h b/include/linux/grmsg.h
77511new file mode 100644
77512index 0000000..195cbe4
77513--- /dev/null
77514+++ b/include/linux/grmsg.h
77515@@ -0,0 +1,115 @@
77516+#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"
77517+#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"
77518+#define GR_PTRACE_ACL_MSG "denied ptrace of %.950s(%.16s:%d) by "
77519+#define GR_STOPMOD_MSG "denied modification of module state by "
77520+#define GR_ROFS_BLOCKWRITE_MSG "denied write to block device %.950s by "
77521+#define GR_ROFS_MOUNT_MSG "denied writable mount of %.950s by "
77522+#define GR_IOPERM_MSG "denied use of ioperm() by "
77523+#define GR_IOPL_MSG "denied use of iopl() by "
77524+#define GR_SHMAT_ACL_MSG "denied attach of shared memory of UID %u, PID %d, ID %u by "
77525+#define GR_UNIX_CHROOT_MSG "denied connect() to abstract AF_UNIX socket outside of chroot by "
77526+#define GR_SHMAT_CHROOT_MSG "denied attach of shared memory outside of chroot by "
77527+#define GR_MEM_READWRITE_MSG "denied access of range %Lx -> %Lx in /dev/mem by "
77528+#define GR_SYMLINK_MSG "not following symlink %.950s owned by %d.%d by "
77529+#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"
77530+#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"
77531+#define GR_HIDDEN_ACL_MSG "%s access to hidden file %.950s by "
77532+#define GR_OPEN_ACL_MSG "%s open of %.950s for%s%s by "
77533+#define GR_CREATE_ACL_MSG "%s create of %.950s for%s%s by "
77534+#define GR_FIFO_MSG "denied writing FIFO %.950s of %d.%d by "
77535+#define GR_MKNOD_CHROOT_MSG "denied mknod of %.950s from chroot by "
77536+#define GR_MKNOD_ACL_MSG "%s mknod of %.950s by "
77537+#define GR_UNIXCONNECT_ACL_MSG "%s connect() to the unix domain socket %.950s by "
77538+#define GR_TTYSNIFF_ACL_MSG "terminal being sniffed by IP:%pI4 %.480s[%.16s:%d], parent %.480s[%.16s:%d] against "
77539+#define GR_MKDIR_ACL_MSG "%s mkdir of %.950s by "
77540+#define GR_RMDIR_ACL_MSG "%s rmdir of %.950s by "
77541+#define GR_UNLINK_ACL_MSG "%s unlink of %.950s by "
77542+#define GR_SYMLINK_ACL_MSG "%s symlink from %.480s to %.480s by "
77543+#define GR_HARDLINK_MSG "denied hardlink of %.930s (owned by %d.%d) to %.30s for "
77544+#define GR_LINK_ACL_MSG "%s link of %.480s to %.480s by "
77545+#define GR_INHERIT_ACL_MSG "successful inherit of %.480s's ACL for %.480s by "
77546+#define GR_RENAME_ACL_MSG "%s rename of %.480s to %.480s by "
77547+#define GR_UNSAFESHARE_EXEC_ACL_MSG "denied exec with cloned fs of %.950s by "
77548+#define GR_PTRACE_EXEC_ACL_MSG "denied ptrace of %.950s by "
77549+#define GR_EXEC_ACL_MSG "%s execution of %.950s by "
77550+#define GR_EXEC_TPE_MSG "denied untrusted exec (due to %.70s) of %.950s by "
77551+#define GR_SEGVSTART_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning uid %u from login for %lu seconds"
77552+#define GR_SEGVNOSUID_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning execution for %lu seconds"
77553+#define GR_MOUNT_CHROOT_MSG "denied mount of %.256s as %.930s from chroot by "
77554+#define GR_PIVOT_CHROOT_MSG "denied pivot_root from chroot by "
77555+#define GR_TRUNCATE_ACL_MSG "%s truncate of %.950s by "
77556+#define GR_ATIME_ACL_MSG "%s access time change of %.950s by "
77557+#define GR_ACCESS_ACL_MSG "%s access of %.950s for%s%s%s by "
77558+#define GR_CHROOT_CHROOT_MSG "denied double chroot to %.950s by "
77559+#define GR_CHMOD_CHROOT_MSG "denied chmod +s of %.950s by "
77560+#define GR_CHMOD_ACL_MSG "%s chmod of %.950s by "
77561+#define GR_CHROOT_FCHDIR_MSG "denied fchdir outside of chroot to %.950s by "
77562+#define GR_CHOWN_ACL_MSG "%s chown of %.950s by "
77563+#define GR_SETXATTR_ACL_MSG "%s setting extended attribute of %.950s by "
77564+#define GR_REMOVEXATTR_ACL_MSG "%s removing extended attribute of %.950s by "
77565+#define GR_WRITLIB_ACL_MSG "denied load of writable library %.950s by "
77566+#define GR_INITF_ACL_MSG "init_variables() failed %s by "
77567+#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"
77568+#define GR_DEV_ACL_MSG "/dev/grsec: %d bytes sent %d required, being fed garbage by "
77569+#define GR_SHUTS_ACL_MSG "shutdown auth success for "
77570+#define GR_SHUTF_ACL_MSG "shutdown auth failure for "
77571+#define GR_SHUTI_ACL_MSG "ignoring shutdown for disabled RBAC system for "
77572+#define GR_SEGVMODS_ACL_MSG "segvmod auth success for "
77573+#define GR_SEGVMODF_ACL_MSG "segvmod auth failure for "
77574+#define GR_SEGVMODI_ACL_MSG "ignoring segvmod for disabled RBAC system for "
77575+#define GR_ENABLE_ACL_MSG "%s RBAC system loaded by "
77576+#define GR_ENABLEF_ACL_MSG "unable to load %s for "
77577+#define GR_RELOADI_ACL_MSG "ignoring reload request for disabled RBAC system"
77578+#define GR_RELOAD_ACL_MSG "%s RBAC system reloaded by "
77579+#define GR_RELOADF_ACL_MSG "failed reload of %s for "
77580+#define GR_SPROLEI_ACL_MSG "ignoring change to special role for disabled RBAC system for "
77581+#define GR_SPROLES_ACL_MSG "successful change to special role %s (id %d) by "
77582+#define GR_SPROLEL_ACL_MSG "special role %s (id %d) exited by "
77583+#define GR_SPROLEF_ACL_MSG "special role %s failure for "
77584+#define GR_UNSPROLEI_ACL_MSG "ignoring unauth of special role for disabled RBAC system for "
77585+#define GR_UNSPROLES_ACL_MSG "successful unauth of special role %s (id %d) by "
77586+#define GR_INVMODE_ACL_MSG "invalid mode %d by "
77587+#define GR_PRIORITY_CHROOT_MSG "denied priority change of process (%.16s:%d) by "
77588+#define GR_FAILFORK_MSG "failed fork with errno %s by "
77589+#define GR_NICE_CHROOT_MSG "denied priority change by "
77590+#define GR_UNISIGLOG_MSG "%.32s occurred at %p in "
77591+#define GR_DUALSIGLOG_MSG "signal %d sent to " DEFAULTSECMSG " by "
77592+#define GR_SIG_ACL_MSG "denied send of signal %d to protected task " DEFAULTSECMSG " by "
77593+#define GR_SYSCTL_MSG "denied modification of grsecurity sysctl value : %.32s by "
77594+#define GR_SYSCTL_ACL_MSG "%s sysctl of %.950s for%s%s by "
77595+#define GR_TIME_MSG "time set by "
77596+#define GR_DEFACL_MSG "fatal: unable to find subject for (%.16s:%d), loaded by "
77597+#define GR_MMAP_ACL_MSG "%s executable mmap of %.950s by "
77598+#define GR_MPROTECT_ACL_MSG "%s executable mprotect of %.950s by "
77599+#define GR_SOCK_MSG "denied socket(%.16s,%.16s,%.16s) by "
77600+#define GR_SOCK_NOINET_MSG "denied socket(%.16s,%.16s,%d) by "
77601+#define GR_BIND_MSG "denied bind() by "
77602+#define GR_CONNECT_MSG "denied connect() by "
77603+#define GR_BIND_ACL_MSG "denied bind() to %pI4 port %u sock type %.16s protocol %.16s by "
77604+#define GR_CONNECT_ACL_MSG "denied connect() to %pI4 port %u sock type %.16s protocol %.16s by "
77605+#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"
77606+#define GR_EXEC_CHROOT_MSG "exec of %.980s within chroot by process "
77607+#define GR_CAP_ACL_MSG "use of %s denied for "
77608+#define GR_CAP_CHROOT_MSG "use of %s in chroot denied for "
77609+#define GR_CAP_ACL_MSG2 "use of %s permitted for "
77610+#define GR_USRCHANGE_ACL_MSG "change to uid %u denied for "
77611+#define GR_GRPCHANGE_ACL_MSG "change to gid %u denied for "
77612+#define GR_REMOUNT_AUDIT_MSG "remount of %.256s by "
77613+#define GR_UNMOUNT_AUDIT_MSG "unmount of %.256s by "
77614+#define GR_MOUNT_AUDIT_MSG "mount of %.256s to %.256s by "
77615+#define GR_CHDIR_AUDIT_MSG "chdir to %.980s by "
77616+#define GR_EXEC_AUDIT_MSG "exec of %.930s (%.128s) by "
77617+#define GR_RESOURCE_MSG "denied resource overstep by requesting %lu for %.16s against limit %lu for "
77618+#define GR_RWXMMAP_MSG "denied RWX mmap of %.950s by "
77619+#define GR_RWXMPROTECT_MSG "denied RWX mprotect of %.950s by "
77620+#define GR_TEXTREL_AUDIT_MSG "denied text relocation in %.950s, VMA:0x%08lx 0x%08lx by "
77621+#define GR_PTGNUSTACK_MSG "denied marking stack executable as requested by PT_GNU_STACK marking in %.950s by "
77622+#define GR_VM86_MSG "denied use of vm86 by "
77623+#define GR_PTRACE_AUDIT_MSG "process %.950s(%.16s:%d) attached to via ptrace by "
77624+#define GR_PTRACE_READEXEC_MSG "denied ptrace of unreadable binary %.950s by "
77625+#define GR_INIT_TRANSFER_MSG "persistent special role transferred privilege to init by "
77626+#define GR_BADPROCPID_MSG "denied read of sensitive /proc/pid/%s entry via fd passed across exec by "
77627+#define GR_SYMLINKOWNER_MSG "denied following symlink %.950s since symlink owner %u does not match target owner %u, by "
77628+#define GR_BRUTE_DAEMON_MSG "bruteforce prevention initiated for the next 30 minutes or until service restarted, stalling each fork 30 seconds. Please investigate the crash report for "
77629+#define GR_BRUTE_SUID_MSG "bruteforce prevention initiated due to crash of %.950s against uid %u, banning suid/sgid execs for %u minutes. Please investigate the crash report for "
77630+#define GR_IPC_DENIED_MSG "denied %s of overly-permissive IPC object with creator uid %u by "
77631diff --git a/include/linux/grsecurity.h b/include/linux/grsecurity.h
77632new file mode 100644
77633index 0000000..d8b5b48
77634--- /dev/null
77635+++ b/include/linux/grsecurity.h
77636@@ -0,0 +1,245 @@
77637+#ifndef GR_SECURITY_H
77638+#define GR_SECURITY_H
77639+#include <linux/fs.h>
77640+#include <linux/fs_struct.h>
77641+#include <linux/binfmts.h>
77642+#include <linux/gracl.h>
77643+
77644+/* notify of brain-dead configs */
77645+#if defined(CONFIG_GRKERNSEC_PROC_USER) && defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
77646+#error "CONFIG_GRKERNSEC_PROC_USER and CONFIG_GRKERNSEC_PROC_USERGROUP cannot both be enabled."
77647+#endif
77648+#if defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_PAGEEXEC) && !defined(CONFIG_PAX_SEGMEXEC) && !defined(CONFIG_PAX_KERNEXEC)
77649+#error "CONFIG_PAX_NOEXEC enabled, but PAGEEXEC, SEGMEXEC, and KERNEXEC are disabled."
77650+#endif
77651+#if defined(CONFIG_PAX_ASLR) && !defined(CONFIG_PAX_RANDKSTACK) && !defined(CONFIG_PAX_RANDUSTACK) && !defined(CONFIG_PAX_RANDMMAP)
77652+#error "CONFIG_PAX_ASLR enabled, but RANDKSTACK, RANDUSTACK, and RANDMMAP are disabled."
77653+#endif
77654+#if defined(CONFIG_PAX) && !defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_ASLR)
77655+#error "CONFIG_PAX enabled, but no PaX options are enabled."
77656+#endif
77657+
77658+int gr_handle_new_usb(void);
77659+
77660+void gr_handle_brute_attach(int dumpable);
77661+void gr_handle_brute_check(void);
77662+void gr_handle_kernel_exploit(void);
77663+
77664+char gr_roletype_to_char(void);
77665+
77666+int gr_acl_enable_at_secure(void);
77667+
77668+int gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs);
77669+int gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs);
77670+
77671+void gr_del_task_from_ip_table(struct task_struct *p);
77672+
77673+int gr_pid_is_chrooted(struct task_struct *p);
77674+int gr_handle_chroot_fowner(struct pid *pid, enum pid_type type);
77675+int gr_handle_chroot_nice(void);
77676+int gr_handle_chroot_sysctl(const int op);
77677+int gr_handle_chroot_setpriority(struct task_struct *p,
77678+ const int niceval);
77679+int gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt);
77680+int gr_handle_chroot_chroot(const struct dentry *dentry,
77681+ const struct vfsmount *mnt);
77682+void gr_handle_chroot_chdir(const struct path *path);
77683+int gr_handle_chroot_chmod(const struct dentry *dentry,
77684+ const struct vfsmount *mnt, const int mode);
77685+int gr_handle_chroot_mknod(const struct dentry *dentry,
77686+ const struct vfsmount *mnt, const int mode);
77687+int gr_handle_chroot_mount(const struct dentry *dentry,
77688+ const struct vfsmount *mnt,
77689+ const char *dev_name);
77690+int gr_handle_chroot_pivot(void);
77691+int gr_handle_chroot_unix(const pid_t pid);
77692+
77693+int gr_handle_rawio(const struct inode *inode);
77694+
77695+void gr_handle_ioperm(void);
77696+void gr_handle_iopl(void);
77697+
77698+umode_t gr_acl_umask(void);
77699+
77700+int gr_tpe_allow(const struct file *file);
77701+
77702+void gr_set_chroot_entries(struct task_struct *task, const struct path *path);
77703+void gr_clear_chroot_entries(struct task_struct *task);
77704+
77705+void gr_log_forkfail(const int retval);
77706+void gr_log_timechange(void);
77707+void gr_log_signal(const int sig, const void *addr, const struct task_struct *t);
77708+void gr_log_chdir(const struct dentry *dentry,
77709+ const struct vfsmount *mnt);
77710+void gr_log_chroot_exec(const struct dentry *dentry,
77711+ const struct vfsmount *mnt);
77712+void gr_log_remount(const char *devname, const int retval);
77713+void gr_log_unmount(const char *devname, const int retval);
77714+void gr_log_mount(const char *from, const char *to, const int retval);
77715+void gr_log_textrel(struct vm_area_struct *vma);
77716+void gr_log_ptgnustack(struct file *file);
77717+void gr_log_rwxmmap(struct file *file);
77718+void gr_log_rwxmprotect(struct vm_area_struct *vma);
77719+
77720+int gr_handle_follow_link(const struct inode *parent,
77721+ const struct inode *inode,
77722+ const struct dentry *dentry,
77723+ const struct vfsmount *mnt);
77724+int gr_handle_fifo(const struct dentry *dentry,
77725+ const struct vfsmount *mnt,
77726+ const struct dentry *dir, const int flag,
77727+ const int acc_mode);
77728+int gr_handle_hardlink(const struct dentry *dentry,
77729+ const struct vfsmount *mnt,
77730+ struct inode *inode,
77731+ const int mode, const struct filename *to);
77732+
77733+int gr_is_capable(const int cap);
77734+int gr_is_capable_nolog(const int cap);
77735+int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
77736+int gr_task_is_capable_nolog(const struct task_struct *task, const int cap);
77737+
77738+void gr_copy_label(struct task_struct *tsk);
77739+void gr_handle_crash(struct task_struct *task, const int sig);
77740+int gr_handle_signal(const struct task_struct *p, const int sig);
77741+int gr_check_crash_uid(const kuid_t uid);
77742+int gr_check_protected_task(const struct task_struct *task);
77743+int gr_check_protected_task_fowner(struct pid *pid, enum pid_type type);
77744+int gr_acl_handle_mmap(const struct file *file,
77745+ const unsigned long prot);
77746+int gr_acl_handle_mprotect(const struct file *file,
77747+ const unsigned long prot);
77748+int gr_check_hidden_task(const struct task_struct *tsk);
77749+__u32 gr_acl_handle_truncate(const struct dentry *dentry,
77750+ const struct vfsmount *mnt);
77751+__u32 gr_acl_handle_utime(const struct dentry *dentry,
77752+ const struct vfsmount *mnt);
77753+__u32 gr_acl_handle_access(const struct dentry *dentry,
77754+ const struct vfsmount *mnt, const int fmode);
77755+__u32 gr_acl_handle_chmod(const struct dentry *dentry,
77756+ const struct vfsmount *mnt, umode_t *mode);
77757+__u32 gr_acl_handle_chown(const struct dentry *dentry,
77758+ const struct vfsmount *mnt);
77759+__u32 gr_acl_handle_setxattr(const struct dentry *dentry,
77760+ const struct vfsmount *mnt);
77761+__u32 gr_acl_handle_removexattr(const struct dentry *dentry,
77762+ const struct vfsmount *mnt);
77763+int gr_handle_ptrace(struct task_struct *task, const long request);
77764+int gr_handle_proc_ptrace(struct task_struct *task);
77765+__u32 gr_acl_handle_execve(const struct dentry *dentry,
77766+ const struct vfsmount *mnt);
77767+int gr_check_crash_exec(const struct file *filp);
77768+int gr_acl_is_enabled(void);
77769+void gr_set_role_label(struct task_struct *task, const kuid_t uid,
77770+ const kgid_t gid);
77771+int gr_set_proc_label(const struct dentry *dentry,
77772+ const struct vfsmount *mnt,
77773+ const int unsafe_flags);
77774+__u32 gr_acl_handle_hidden_file(const struct dentry *dentry,
77775+ const struct vfsmount *mnt);
77776+__u32 gr_acl_handle_open(const struct dentry *dentry,
77777+ const struct vfsmount *mnt, int acc_mode);
77778+__u32 gr_acl_handle_creat(const struct dentry *dentry,
77779+ const struct dentry *p_dentry,
77780+ const struct vfsmount *p_mnt,
77781+ int open_flags, int acc_mode, const int imode);
77782+void gr_handle_create(const struct dentry *dentry,
77783+ const struct vfsmount *mnt);
77784+void gr_handle_proc_create(const struct dentry *dentry,
77785+ const struct inode *inode);
77786+__u32 gr_acl_handle_mknod(const struct dentry *new_dentry,
77787+ const struct dentry *parent_dentry,
77788+ const struct vfsmount *parent_mnt,
77789+ const int mode);
77790+__u32 gr_acl_handle_mkdir(const struct dentry *new_dentry,
77791+ const struct dentry *parent_dentry,
77792+ const struct vfsmount *parent_mnt);
77793+__u32 gr_acl_handle_rmdir(const struct dentry *dentry,
77794+ const struct vfsmount *mnt);
77795+void gr_handle_delete(const ino_t ino, const dev_t dev);
77796+__u32 gr_acl_handle_unlink(const struct dentry *dentry,
77797+ const struct vfsmount *mnt);
77798+__u32 gr_acl_handle_symlink(const struct dentry *new_dentry,
77799+ const struct dentry *parent_dentry,
77800+ const struct vfsmount *parent_mnt,
77801+ const struct filename *from);
77802+__u32 gr_acl_handle_link(const struct dentry *new_dentry,
77803+ const struct dentry *parent_dentry,
77804+ const struct vfsmount *parent_mnt,
77805+ const struct dentry *old_dentry,
77806+ const struct vfsmount *old_mnt, const struct filename *to);
77807+int gr_handle_symlink_owner(const struct path *link, const struct inode *target);
77808+int gr_acl_handle_rename(struct dentry *new_dentry,
77809+ struct dentry *parent_dentry,
77810+ const struct vfsmount *parent_mnt,
77811+ struct dentry *old_dentry,
77812+ struct inode *old_parent_inode,
77813+ struct vfsmount *old_mnt, const struct filename *newname);
77814+void gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
77815+ struct dentry *old_dentry,
77816+ struct dentry *new_dentry,
77817+ struct vfsmount *mnt, const __u8 replace);
77818+__u32 gr_check_link(const struct dentry *new_dentry,
77819+ const struct dentry *parent_dentry,
77820+ const struct vfsmount *parent_mnt,
77821+ const struct dentry *old_dentry,
77822+ const struct vfsmount *old_mnt);
77823+int gr_acl_handle_filldir(const struct file *file, const char *name,
77824+ const unsigned int namelen, const ino_t ino);
77825+
77826+__u32 gr_acl_handle_unix(const struct dentry *dentry,
77827+ const struct vfsmount *mnt);
77828+void gr_acl_handle_exit(void);
77829+void gr_acl_handle_psacct(struct task_struct *task, const long code);
77830+int gr_acl_handle_procpidmem(const struct task_struct *task);
77831+int gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags);
77832+int gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode);
77833+void gr_audit_ptrace(struct task_struct *task);
77834+dev_t gr_get_dev_from_dentry(struct dentry *dentry);
77835+void gr_put_exec_file(struct task_struct *task);
77836+
77837+int gr_ptrace_readexec(struct file *file, int unsafe_flags);
77838+
77839+#if defined(CONFIG_GRKERNSEC) && (defined(CONFIG_GRKERNSEC_RESLOG) || !defined(CONFIG_GRKERNSEC_NO_RBAC))
77840+extern void gr_learn_resource(const struct task_struct *task, const int res,
77841+ const unsigned long wanted, const int gt);
77842+#else
77843+static inline void gr_learn_resource(const struct task_struct *task, const int res,
77844+ const unsigned long wanted, const int gt)
77845+{
77846+}
77847+#endif
77848+
77849+#ifdef CONFIG_GRKERNSEC_RESLOG
77850+extern void gr_log_resource(const struct task_struct *task, const int res,
77851+ const unsigned long wanted, const int gt);
77852+#else
77853+static inline void gr_log_resource(const struct task_struct *task, const int res,
77854+ const unsigned long wanted, const int gt)
77855+{
77856+}
77857+#endif
77858+
77859+#ifdef CONFIG_GRKERNSEC
77860+void task_grsec_rbac(struct seq_file *m, struct task_struct *p);
77861+void gr_handle_vm86(void);
77862+void gr_handle_mem_readwrite(u64 from, u64 to);
77863+
77864+void gr_log_badprocpid(const char *entry);
77865+
77866+extern int grsec_enable_dmesg;
77867+extern int grsec_disable_privio;
77868+
77869+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
77870+extern kgid_t grsec_proc_gid;
77871+#endif
77872+
77873+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
77874+extern int grsec_enable_chroot_findtask;
77875+#endif
77876+#ifdef CONFIG_GRKERNSEC_SETXID
77877+extern int grsec_enable_setxid;
77878+#endif
77879+#endif
77880+
77881+#endif
77882diff --git a/include/linux/grsock.h b/include/linux/grsock.h
77883new file mode 100644
77884index 0000000..e7ffaaf
77885--- /dev/null
77886+++ b/include/linux/grsock.h
77887@@ -0,0 +1,19 @@
77888+#ifndef __GRSOCK_H
77889+#define __GRSOCK_H
77890+
77891+extern void gr_attach_curr_ip(const struct sock *sk);
77892+extern int gr_handle_sock_all(const int family, const int type,
77893+ const int protocol);
77894+extern int gr_handle_sock_server(const struct sockaddr *sck);
77895+extern int gr_handle_sock_server_other(const struct sock *sck);
77896+extern int gr_handle_sock_client(const struct sockaddr *sck);
77897+extern int gr_search_connect(struct socket * sock,
77898+ struct sockaddr_in * addr);
77899+extern int gr_search_bind(struct socket * sock,
77900+ struct sockaddr_in * addr);
77901+extern int gr_search_listen(struct socket * sock);
77902+extern int gr_search_accept(struct socket * sock);
77903+extern int gr_search_socket(const int domain, const int type,
77904+ const int protocol);
77905+
77906+#endif
77907diff --git a/include/linux/highmem.h b/include/linux/highmem.h
77908index 7fb31da..08b5114 100644
77909--- a/include/linux/highmem.h
77910+++ b/include/linux/highmem.h
77911@@ -189,6 +189,18 @@ static inline void clear_highpage(struct page *page)
77912 kunmap_atomic(kaddr);
77913 }
77914
77915+static inline void sanitize_highpage(struct page *page)
77916+{
77917+ void *kaddr;
77918+ unsigned long flags;
77919+
77920+ local_irq_save(flags);
77921+ kaddr = kmap_atomic(page);
77922+ clear_page(kaddr);
77923+ kunmap_atomic(kaddr);
77924+ local_irq_restore(flags);
77925+}
77926+
77927 static inline void zero_user_segments(struct page *page,
77928 unsigned start1, unsigned end1,
77929 unsigned start2, unsigned end2)
77930diff --git a/include/linux/hwmon-sysfs.h b/include/linux/hwmon-sysfs.h
77931index 1c7b89a..7dda400 100644
77932--- a/include/linux/hwmon-sysfs.h
77933+++ b/include/linux/hwmon-sysfs.h
77934@@ -25,7 +25,8 @@
77935 struct sensor_device_attribute{
77936 struct device_attribute dev_attr;
77937 int index;
77938-};
77939+} __do_const;
77940+typedef struct sensor_device_attribute __no_const sensor_device_attribute_no_const;
77941 #define to_sensor_dev_attr(_dev_attr) \
77942 container_of(_dev_attr, struct sensor_device_attribute, dev_attr)
77943
77944@@ -41,7 +42,8 @@ struct sensor_device_attribute_2 {
77945 struct device_attribute dev_attr;
77946 u8 index;
77947 u8 nr;
77948-};
77949+} __do_const;
77950+typedef struct sensor_device_attribute_2 __no_const sensor_device_attribute_2_no_const;
77951 #define to_sensor_dev_attr_2(_dev_attr) \
77952 container_of(_dev_attr, struct sensor_device_attribute_2, dev_attr)
77953
77954diff --git a/include/linux/i2c.h b/include/linux/i2c.h
77955index 2ab11dc..663a3f2 100644
77956--- a/include/linux/i2c.h
77957+++ b/include/linux/i2c.h
77958@@ -366,6 +366,7 @@ struct i2c_algorithm {
77959 /* To determine what the adapter supports */
77960 u32 (*functionality) (struct i2c_adapter *);
77961 };
77962+typedef struct i2c_algorithm __no_const i2c_algorithm_no_const;
77963
77964 /**
77965 * struct i2c_bus_recovery_info - I2C bus recovery information
77966diff --git a/include/linux/i2o.h b/include/linux/i2o.h
77967index d23c3c2..eb63c81 100644
77968--- a/include/linux/i2o.h
77969+++ b/include/linux/i2o.h
77970@@ -565,7 +565,7 @@ struct i2o_controller {
77971 struct i2o_device *exec; /* Executive */
77972 #if BITS_PER_LONG == 64
77973 spinlock_t context_list_lock; /* lock for context_list */
77974- atomic_t context_list_counter; /* needed for unique contexts */
77975+ atomic_unchecked_t context_list_counter; /* needed for unique contexts */
77976 struct list_head context_list; /* list of context id's
77977 and pointers */
77978 #endif
77979diff --git a/include/linux/if_pppox.h b/include/linux/if_pppox.h
77980index aff7ad8..3942bbd 100644
77981--- a/include/linux/if_pppox.h
77982+++ b/include/linux/if_pppox.h
77983@@ -76,7 +76,7 @@ struct pppox_proto {
77984 int (*ioctl)(struct socket *sock, unsigned int cmd,
77985 unsigned long arg);
77986 struct module *owner;
77987-};
77988+} __do_const;
77989
77990 extern int register_pppox_proto(int proto_num, const struct pppox_proto *pp);
77991 extern void unregister_pppox_proto(int proto_num);
77992diff --git a/include/linux/init.h b/include/linux/init.h
77993index f1c27a71..7d6010e 100644
77994--- a/include/linux/init.h
77995+++ b/include/linux/init.h
77996@@ -39,9 +39,17 @@
77997 * Also note, that this data cannot be "const".
77998 */
77999
78000+#define add_init_latent_entropy __latent_entropy
78001+
78002+#ifdef CONFIG_MEMORY_HOTPLUG
78003+#define add_meminit_latent_entropy
78004+#else
78005+#define add_meminit_latent_entropy __latent_entropy
78006+#endif
78007+
78008 /* These are for everybody (although not all archs will actually
78009 discard it in modules) */
78010-#define __init __section(.init.text) __cold notrace
78011+#define __init __section(.init.text) __cold notrace add_init_latent_entropy
78012 #define __initdata __section(.init.data)
78013 #define __initconst __constsection(.init.rodata)
78014 #define __exitdata __section(.exit.data)
78015@@ -102,7 +110,7 @@
78016 #define __cpuexitconst
78017
78018 /* Used for MEMORY_HOTPLUG */
78019-#define __meminit __section(.meminit.text) __cold notrace
78020+#define __meminit __section(.meminit.text) __cold notrace add_meminit_latent_entropy
78021 #define __meminitdata __section(.meminit.data)
78022 #define __meminitconst __constsection(.meminit.rodata)
78023 #define __memexit __section(.memexit.text) __exitused __cold notrace
78024diff --git a/include/linux/init_task.h b/include/linux/init_task.h
78025index 5cd0f09..c9f67cc 100644
78026--- a/include/linux/init_task.h
78027+++ b/include/linux/init_task.h
78028@@ -154,6 +154,12 @@ extern struct task_group root_task_group;
78029
78030 #define INIT_TASK_COMM "swapper"
78031
78032+#ifdef CONFIG_X86
78033+#define INIT_TASK_THREAD_INFO .tinfo = INIT_THREAD_INFO,
78034+#else
78035+#define INIT_TASK_THREAD_INFO
78036+#endif
78037+
78038 /*
78039 * INIT_TASK is used to set up the first task table, touch at
78040 * your own risk!. Base=0, limit=0x1fffff (=2MB)
78041@@ -193,6 +199,7 @@ extern struct task_group root_task_group;
78042 RCU_POINTER_INITIALIZER(cred, &init_cred), \
78043 .comm = INIT_TASK_COMM, \
78044 .thread = INIT_THREAD, \
78045+ INIT_TASK_THREAD_INFO \
78046 .fs = &init_fs, \
78047 .files = &init_files, \
78048 .signal = &init_signals, \
78049diff --git a/include/linux/interrupt.h b/include/linux/interrupt.h
78050index 5e865b5..71bd258 100644
78051--- a/include/linux/interrupt.h
78052+++ b/include/linux/interrupt.h
78053@@ -361,7 +361,7 @@ enum
78054 /* map softirq index to softirq name. update 'softirq_to_name' in
78055 * kernel/softirq.c when adding a new softirq.
78056 */
78057-extern char *softirq_to_name[NR_SOFTIRQS];
78058+extern const char * const softirq_to_name[NR_SOFTIRQS];
78059
78060 /* softirq mask and active fields moved to irq_cpustat_t in
78061 * asm/hardirq.h to get better cache usage. KAO
78062@@ -369,12 +369,12 @@ extern char *softirq_to_name[NR_SOFTIRQS];
78063
78064 struct softirq_action
78065 {
78066- void (*action)(struct softirq_action *);
78067-};
78068+ void (*action)(void);
78069+} __no_const;
78070
78071 asmlinkage void do_softirq(void);
78072 asmlinkage void __do_softirq(void);
78073-extern void open_softirq(int nr, void (*action)(struct softirq_action *));
78074+extern void open_softirq(int nr, void (*action)(void));
78075 extern void softirq_init(void);
78076 extern void __raise_softirq_irqoff(unsigned int nr);
78077
78078diff --git a/include/linux/iommu.h b/include/linux/iommu.h
78079index 7ea319e..f9e971d 100644
78080--- a/include/linux/iommu.h
78081+++ b/include/linux/iommu.h
78082@@ -129,7 +129,7 @@ struct iommu_ops {
78083 u32 (*domain_get_windows)(struct iommu_domain *domain);
78084
78085 unsigned long pgsize_bitmap;
78086-};
78087+} __do_const;
78088
78089 #define IOMMU_GROUP_NOTIFY_ADD_DEVICE 1 /* Device added */
78090 #define IOMMU_GROUP_NOTIFY_DEL_DEVICE 2 /* Pre Device removed */
78091diff --git a/include/linux/ioport.h b/include/linux/ioport.h
78092index 89b7c24..382af74 100644
78093--- a/include/linux/ioport.h
78094+++ b/include/linux/ioport.h
78095@@ -161,7 +161,7 @@ struct resource *lookup_resource(struct resource *root, resource_size_t start);
78096 int adjust_resource(struct resource *res, resource_size_t start,
78097 resource_size_t size);
78098 resource_size_t resource_alignment(struct resource *res);
78099-static inline resource_size_t resource_size(const struct resource *res)
78100+static inline resource_size_t __intentional_overflow(-1) resource_size(const struct resource *res)
78101 {
78102 return res->end - res->start + 1;
78103 }
78104diff --git a/include/linux/ipc_namespace.h b/include/linux/ipc_namespace.h
78105index f6c82de..de8619e 100644
78106--- a/include/linux/ipc_namespace.h
78107+++ b/include/linux/ipc_namespace.h
78108@@ -70,7 +70,7 @@ struct ipc_namespace {
78109 struct user_namespace *user_ns;
78110
78111 unsigned int proc_inum;
78112-};
78113+} __randomize_layout;
78114
78115 extern struct ipc_namespace init_ipc_ns;
78116 extern atomic_t nr_ipc_ns;
78117diff --git a/include/linux/irq.h b/include/linux/irq.h
78118index 56bb0dc..8ae94d62 100644
78119--- a/include/linux/irq.h
78120+++ b/include/linux/irq.h
78121@@ -333,7 +333,8 @@ struct irq_chip {
78122 void (*irq_print_chip)(struct irq_data *data, struct seq_file *p);
78123
78124 unsigned long flags;
78125-};
78126+} __do_const;
78127+typedef struct irq_chip __no_const irq_chip_no_const;
78128
78129 /*
78130 * irq_chip specific flags
78131diff --git a/include/linux/irqchip/arm-gic.h b/include/linux/irqchip/arm-gic.h
78132index 0e5d9ec..46acb3a 100644
78133--- a/include/linux/irqchip/arm-gic.h
78134+++ b/include/linux/irqchip/arm-gic.h
78135@@ -59,9 +59,11 @@
78136
78137 #ifndef __ASSEMBLY__
78138
78139+#include <linux/irq.h>
78140+
78141 struct device_node;
78142
78143-extern struct irq_chip gic_arch_extn;
78144+extern irq_chip_no_const gic_arch_extn;
78145
78146 void gic_init_bases(unsigned int, int, void __iomem *, void __iomem *,
78147 u32 offset, struct device_node *);
78148diff --git a/include/linux/jiffies.h b/include/linux/jiffies.h
78149index d235e88..8ccbe74 100644
78150--- a/include/linux/jiffies.h
78151+++ b/include/linux/jiffies.h
78152@@ -292,14 +292,14 @@ extern unsigned long preset_lpj;
78153 /*
78154 * Convert various time units to each other:
78155 */
78156-extern unsigned int jiffies_to_msecs(const unsigned long j);
78157-extern unsigned int jiffies_to_usecs(const unsigned long j);
78158-extern unsigned long msecs_to_jiffies(const unsigned int m);
78159-extern unsigned long usecs_to_jiffies(const unsigned int u);
78160-extern unsigned long timespec_to_jiffies(const struct timespec *value);
78161+extern unsigned int jiffies_to_msecs(const unsigned long j) __intentional_overflow(-1);
78162+extern unsigned int jiffies_to_usecs(const unsigned long j) __intentional_overflow(-1);
78163+extern unsigned long msecs_to_jiffies(const unsigned int m) __intentional_overflow(-1);
78164+extern unsigned long usecs_to_jiffies(const unsigned int u) __intentional_overflow(-1);
78165+extern unsigned long timespec_to_jiffies(const struct timespec *value) __intentional_overflow(-1);
78166 extern void jiffies_to_timespec(const unsigned long jiffies,
78167 struct timespec *value);
78168-extern unsigned long timeval_to_jiffies(const struct timeval *value);
78169+extern unsigned long timeval_to_jiffies(const struct timeval *value) __intentional_overflow(-1);
78170 extern void jiffies_to_timeval(const unsigned long jiffies,
78171 struct timeval *value);
78172
78173diff --git a/include/linux/kallsyms.h b/include/linux/kallsyms.h
78174index 6883e19..e854fcb 100644
78175--- a/include/linux/kallsyms.h
78176+++ b/include/linux/kallsyms.h
78177@@ -15,7 +15,8 @@
78178
78179 struct module;
78180
78181-#ifdef CONFIG_KALLSYMS
78182+#if !defined(__INCLUDED_BY_HIDESYM) || !defined(CONFIG_KALLSYMS)
78183+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
78184 /* Lookup the address for a symbol. Returns 0 if not found. */
78185 unsigned long kallsyms_lookup_name(const char *name);
78186
78187@@ -106,6 +107,21 @@ static inline int lookup_symbol_attrs(unsigned long addr, unsigned long *size, u
78188 /* Stupid that this does nothing, but I didn't create this mess. */
78189 #define __print_symbol(fmt, addr)
78190 #endif /*CONFIG_KALLSYMS*/
78191+#else /* when included by kallsyms.c, vsnprintf.c, kprobes.c, or
78192+ arch/x86/kernel/dumpstack.c, with HIDESYM enabled */
78193+extern unsigned long kallsyms_lookup_name(const char *name);
78194+extern void __print_symbol(const char *fmt, unsigned long address);
78195+extern int sprint_backtrace(char *buffer, unsigned long address);
78196+extern int sprint_symbol(char *buffer, unsigned long address);
78197+extern int sprint_symbol_no_offset(char *buffer, unsigned long address);
78198+const char *kallsyms_lookup(unsigned long addr,
78199+ unsigned long *symbolsize,
78200+ unsigned long *offset,
78201+ char **modname, char *namebuf);
78202+extern int kallsyms_lookup_size_offset(unsigned long addr,
78203+ unsigned long *symbolsize,
78204+ unsigned long *offset);
78205+#endif
78206
78207 /* This macro allows us to keep printk typechecking */
78208 static __printf(1, 2)
78209diff --git a/include/linux/key-type.h b/include/linux/key-type.h
78210index 518a53a..5e28358 100644
78211--- a/include/linux/key-type.h
78212+++ b/include/linux/key-type.h
78213@@ -125,7 +125,7 @@ struct key_type {
78214 /* internal fields */
78215 struct list_head link; /* link in types list */
78216 struct lock_class_key lock_class; /* key->sem lock class */
78217-};
78218+} __do_const;
78219
78220 extern struct key_type key_type_keyring;
78221
78222diff --git a/include/linux/kgdb.h b/include/linux/kgdb.h
78223index c6e091b..a940adf 100644
78224--- a/include/linux/kgdb.h
78225+++ b/include/linux/kgdb.h
78226@@ -52,7 +52,7 @@ extern int kgdb_connected;
78227 extern int kgdb_io_module_registered;
78228
78229 extern atomic_t kgdb_setting_breakpoint;
78230-extern atomic_t kgdb_cpu_doing_single_step;
78231+extern atomic_unchecked_t kgdb_cpu_doing_single_step;
78232
78233 extern struct task_struct *kgdb_usethread;
78234 extern struct task_struct *kgdb_contthread;
78235@@ -254,7 +254,7 @@ struct kgdb_arch {
78236 void (*correct_hw_break)(void);
78237
78238 void (*enable_nmi)(bool on);
78239-};
78240+} __do_const;
78241
78242 /**
78243 * struct kgdb_io - Describe the interface for an I/O driver to talk with KGDB.
78244@@ -279,7 +279,7 @@ struct kgdb_io {
78245 void (*pre_exception) (void);
78246 void (*post_exception) (void);
78247 int is_console;
78248-};
78249+} __do_const;
78250
78251 extern struct kgdb_arch arch_kgdb_ops;
78252
78253diff --git a/include/linux/kmod.h b/include/linux/kmod.h
78254index 0555cc6..40116ce 100644
78255--- a/include/linux/kmod.h
78256+++ b/include/linux/kmod.h
78257@@ -34,6 +34,8 @@ extern char modprobe_path[]; /* for sysctl */
78258 * usually useless though. */
78259 extern __printf(2, 3)
78260 int __request_module(bool wait, const char *name, ...);
78261+extern __printf(3, 4)
78262+int ___request_module(bool wait, char *param_name, const char *name, ...);
78263 #define request_module(mod...) __request_module(true, mod)
78264 #define request_module_nowait(mod...) __request_module(false, mod)
78265 #define try_then_request_module(x, mod...) \
78266@@ -57,6 +59,9 @@ struct subprocess_info {
78267 struct work_struct work;
78268 struct completion *complete;
78269 char *path;
78270+#ifdef CONFIG_GRKERNSEC
78271+ char *origpath;
78272+#endif
78273 char **argv;
78274 char **envp;
78275 int wait;
78276diff --git a/include/linux/kobject.h b/include/linux/kobject.h
78277index de6dcbcc..2b31538 100644
78278--- a/include/linux/kobject.h
78279+++ b/include/linux/kobject.h
78280@@ -115,7 +115,7 @@ struct kobj_type {
78281 struct attribute **default_attrs;
78282 const struct kobj_ns_type_operations *(*child_ns_type)(struct kobject *kobj);
78283 const void *(*namespace)(struct kobject *kobj);
78284-};
78285+} __do_const;
78286
78287 struct kobj_uevent_env {
78288 char *envp[UEVENT_NUM_ENVP];
78289@@ -138,6 +138,7 @@ struct kobj_attribute {
78290 ssize_t (*store)(struct kobject *kobj, struct kobj_attribute *attr,
78291 const char *buf, size_t count);
78292 };
78293+typedef struct kobj_attribute __no_const kobj_attribute_no_const;
78294
78295 extern const struct sysfs_ops kobj_sysfs_ops;
78296
78297@@ -165,7 +166,7 @@ struct kset {
78298 spinlock_t list_lock;
78299 struct kobject kobj;
78300 const struct kset_uevent_ops *uevent_ops;
78301-};
78302+} __randomize_layout;
78303
78304 extern void kset_init(struct kset *kset);
78305 extern int __must_check kset_register(struct kset *kset);
78306diff --git a/include/linux/kobject_ns.h b/include/linux/kobject_ns.h
78307index df32d25..fb52e27 100644
78308--- a/include/linux/kobject_ns.h
78309+++ b/include/linux/kobject_ns.h
78310@@ -44,7 +44,7 @@ struct kobj_ns_type_operations {
78311 const void *(*netlink_ns)(struct sock *sk);
78312 const void *(*initial_ns)(void);
78313 void (*drop_ns)(void *);
78314-};
78315+} __do_const;
78316
78317 int kobj_ns_type_register(const struct kobj_ns_type_operations *ops);
78318 int kobj_ns_type_registered(enum kobj_ns_type type);
78319diff --git a/include/linux/kref.h b/include/linux/kref.h
78320index 484604d..0f6c5b6 100644
78321--- a/include/linux/kref.h
78322+++ b/include/linux/kref.h
78323@@ -68,7 +68,7 @@ static inline void kref_get(struct kref *kref)
78324 static inline int kref_sub(struct kref *kref, unsigned int count,
78325 void (*release)(struct kref *kref))
78326 {
78327- WARN_ON(release == NULL);
78328+ BUG_ON(release == NULL);
78329
78330 if (atomic_sub_and_test((int) count, &kref->refcount)) {
78331 release(kref);
78332diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
78333index 0fbbc7a..db081e3 100644
78334--- a/include/linux/kvm_host.h
78335+++ b/include/linux/kvm_host.h
78336@@ -458,7 +458,7 @@ static inline void kvm_irqfd_exit(void)
78337 {
78338 }
78339 #endif
78340-int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
78341+int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
78342 struct module *module);
78343 void kvm_exit(void);
78344
78345@@ -632,7 +632,7 @@ int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu,
78346 struct kvm_guest_debug *dbg);
78347 int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run);
78348
78349-int kvm_arch_init(void *opaque);
78350+int kvm_arch_init(const void *opaque);
78351 void kvm_arch_exit(void);
78352
78353 int kvm_arch_vcpu_init(struct kvm_vcpu *vcpu);
78354diff --git a/include/linux/libata.h b/include/linux/libata.h
78355index 9b50337..712d748 100644
78356--- a/include/linux/libata.h
78357+++ b/include/linux/libata.h
78358@@ -973,7 +973,7 @@ struct ata_port_operations {
78359 * fields must be pointers.
78360 */
78361 const struct ata_port_operations *inherits;
78362-};
78363+} __do_const;
78364
78365 struct ata_port_info {
78366 unsigned long flags;
78367diff --git a/include/linux/linkage.h b/include/linux/linkage.h
78368index d3e8ad2..a949f68 100644
78369--- a/include/linux/linkage.h
78370+++ b/include/linux/linkage.h
78371@@ -31,6 +31,7 @@
78372 #endif
78373
78374 #define __page_aligned_data __section(.data..page_aligned) __aligned(PAGE_SIZE)
78375+#define __page_aligned_rodata __read_only __aligned(PAGE_SIZE)
78376 #define __page_aligned_bss __section(.bss..page_aligned) __aligned(PAGE_SIZE)
78377
78378 /*
78379diff --git a/include/linux/list.h b/include/linux/list.h
78380index f4d8a2f..38e6e46 100644
78381--- a/include/linux/list.h
78382+++ b/include/linux/list.h
78383@@ -112,6 +112,19 @@ extern void __list_del_entry(struct list_head *entry);
78384 extern void list_del(struct list_head *entry);
78385 #endif
78386
78387+extern void __pax_list_add(struct list_head *new,
78388+ struct list_head *prev,
78389+ struct list_head *next);
78390+static inline void pax_list_add(struct list_head *new, struct list_head *head)
78391+{
78392+ __pax_list_add(new, head, head->next);
78393+}
78394+static inline void pax_list_add_tail(struct list_head *new, struct list_head *head)
78395+{
78396+ __pax_list_add(new, head->prev, head);
78397+}
78398+extern void pax_list_del(struct list_head *entry);
78399+
78400 /**
78401 * list_replace - replace old entry by new one
78402 * @old : the element to be replaced
78403@@ -145,6 +158,8 @@ static inline void list_del_init(struct list_head *entry)
78404 INIT_LIST_HEAD(entry);
78405 }
78406
78407+extern void pax_list_del_init(struct list_head *entry);
78408+
78409 /**
78410 * list_move - delete from one list and add as another's head
78411 * @list: the entry to move
78412diff --git a/include/linux/math64.h b/include/linux/math64.h
78413index 69ed5f5..243ed51 100644
78414--- a/include/linux/math64.h
78415+++ b/include/linux/math64.h
78416@@ -15,7 +15,7 @@
78417 * This is commonly provided by 32bit archs to provide an optimized 64bit
78418 * divide.
78419 */
78420-static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
78421+static inline u64 __intentional_overflow(-1) div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
78422 {
78423 *remainder = dividend % divisor;
78424 return dividend / divisor;
78425@@ -42,7 +42,7 @@ static inline u64 div64_u64_rem(u64 dividend, u64 divisor, u64 *remainder)
78426 /**
78427 * div64_u64 - unsigned 64bit divide with 64bit divisor
78428 */
78429-static inline u64 div64_u64(u64 dividend, u64 divisor)
78430+static inline u64 __intentional_overflow(-1) div64_u64(u64 dividend, u64 divisor)
78431 {
78432 return dividend / divisor;
78433 }
78434@@ -61,7 +61,7 @@ static inline s64 div64_s64(s64 dividend, s64 divisor)
78435 #define div64_ul(x, y) div_u64((x), (y))
78436
78437 #ifndef div_u64_rem
78438-static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
78439+static inline u64 __intentional_overflow(-1) div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
78440 {
78441 *remainder = do_div(dividend, divisor);
78442 return dividend;
78443@@ -77,7 +77,7 @@ extern u64 div64_u64_rem(u64 dividend, u64 divisor, u64 *remainder);
78444 #endif
78445
78446 #ifndef div64_u64
78447-extern u64 div64_u64(u64 dividend, u64 divisor);
78448+extern u64 __intentional_overflow(-1) div64_u64(u64 dividend, u64 divisor);
78449 #endif
78450
78451 #ifndef div64_s64
78452@@ -94,7 +94,7 @@ extern s64 div64_s64(s64 dividend, s64 divisor);
78453 * divide.
78454 */
78455 #ifndef div_u64
78456-static inline u64 div_u64(u64 dividend, u32 divisor)
78457+static inline u64 __intentional_overflow(-1) div_u64(u64 dividend, u32 divisor)
78458 {
78459 u32 remainder;
78460 return div_u64_rem(dividend, divisor, &remainder);
78461diff --git a/include/linux/mempolicy.h b/include/linux/mempolicy.h
78462index da6716b..2e31db3 100644
78463--- a/include/linux/mempolicy.h
78464+++ b/include/linux/mempolicy.h
78465@@ -91,6 +91,10 @@ static inline struct mempolicy *mpol_dup(struct mempolicy *pol)
78466 }
78467
78468 #define vma_policy(vma) ((vma)->vm_policy)
78469+static inline void set_vma_policy(struct vm_area_struct *vma, struct mempolicy *pol)
78470+{
78471+ vma->vm_policy = pol;
78472+}
78473
78474 static inline void mpol_get(struct mempolicy *pol)
78475 {
78476@@ -240,6 +244,9 @@ mpol_shared_policy_lookup(struct shared_policy *sp, unsigned long idx)
78477 }
78478
78479 #define vma_policy(vma) NULL
78480+static inline void set_vma_policy(struct vm_area_struct *vma, struct mempolicy *pol)
78481+{
78482+}
78483
78484 static inline int
78485 vma_dup_policy(struct vm_area_struct *src, struct vm_area_struct *dst)
78486diff --git a/include/linux/mm.h b/include/linux/mm.h
78487index 8b6e55e..c4edf39 100644
78488--- a/include/linux/mm.h
78489+++ b/include/linux/mm.h
78490@@ -113,6 +113,11 @@ extern unsigned int kobjsize(const void *objp);
78491 #define VM_HUGETLB 0x00400000 /* Huge TLB Page VM */
78492 #define VM_NONLINEAR 0x00800000 /* Is non-linear (remap_file_pages) */
78493 #define VM_ARCH_1 0x01000000 /* Architecture-specific flag */
78494+
78495+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
78496+#define VM_PAGEEXEC 0x02000000 /* vma->vm_page_prot needs special handling */
78497+#endif
78498+
78499 #define VM_DONTDUMP 0x04000000 /* Do not include in the core dump */
78500
78501 #ifdef CONFIG_MEM_SOFT_DIRTY
78502@@ -215,8 +220,8 @@ struct vm_operations_struct {
78503 /* called by access_process_vm when get_user_pages() fails, typically
78504 * for use by special VMAs that can switch between memory and hardware
78505 */
78506- int (*access)(struct vm_area_struct *vma, unsigned long addr,
78507- void *buf, int len, int write);
78508+ ssize_t (*access)(struct vm_area_struct *vma, unsigned long addr,
78509+ void *buf, size_t len, int write);
78510 #ifdef CONFIG_NUMA
78511 /*
78512 * set_policy() op must add a reference to any non-NULL @new mempolicy
78513@@ -246,6 +251,7 @@ struct vm_operations_struct {
78514 int (*remap_pages)(struct vm_area_struct *vma, unsigned long addr,
78515 unsigned long size, pgoff_t pgoff);
78516 };
78517+typedef struct vm_operations_struct __no_const vm_operations_struct_no_const;
78518
78519 struct mmu_gather;
78520 struct inode;
78521@@ -977,8 +983,8 @@ int follow_pfn(struct vm_area_struct *vma, unsigned long address,
78522 unsigned long *pfn);
78523 int follow_phys(struct vm_area_struct *vma, unsigned long address,
78524 unsigned int flags, unsigned long *prot, resource_size_t *phys);
78525-int generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
78526- void *buf, int len, int write);
78527+ssize_t generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
78528+ void *buf, size_t len, int write);
78529
78530 static inline void unmap_shared_mapping_range(struct address_space *mapping,
78531 loff_t const holebegin, loff_t const holelen)
78532@@ -1017,9 +1023,9 @@ static inline int fixup_user_fault(struct task_struct *tsk,
78533 }
78534 #endif
78535
78536-extern int access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, int len, int write);
78537-extern int access_remote_vm(struct mm_struct *mm, unsigned long addr,
78538- void *buf, int len, int write);
78539+extern ssize_t access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, size_t len, int write);
78540+extern ssize_t access_remote_vm(struct mm_struct *mm, unsigned long addr,
78541+ void *buf, size_t len, int write);
78542
78543 long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
78544 unsigned long start, unsigned long nr_pages,
78545@@ -1051,34 +1057,6 @@ int set_page_dirty(struct page *page);
78546 int set_page_dirty_lock(struct page *page);
78547 int clear_page_dirty_for_io(struct page *page);
78548
78549-/* Is the vma a continuation of the stack vma above it? */
78550-static inline int vma_growsdown(struct vm_area_struct *vma, unsigned long addr)
78551-{
78552- return vma && (vma->vm_end == addr) && (vma->vm_flags & VM_GROWSDOWN);
78553-}
78554-
78555-static inline int stack_guard_page_start(struct vm_area_struct *vma,
78556- unsigned long addr)
78557-{
78558- return (vma->vm_flags & VM_GROWSDOWN) &&
78559- (vma->vm_start == addr) &&
78560- !vma_growsdown(vma->vm_prev, addr);
78561-}
78562-
78563-/* Is the vma a continuation of the stack vma below it? */
78564-static inline int vma_growsup(struct vm_area_struct *vma, unsigned long addr)
78565-{
78566- return vma && (vma->vm_start == addr) && (vma->vm_flags & VM_GROWSUP);
78567-}
78568-
78569-static inline int stack_guard_page_end(struct vm_area_struct *vma,
78570- unsigned long addr)
78571-{
78572- return (vma->vm_flags & VM_GROWSUP) &&
78573- (vma->vm_end == addr) &&
78574- !vma_growsup(vma->vm_next, addr);
78575-}
78576-
78577 extern pid_t
78578 vm_is_stack(struct task_struct *task, struct vm_area_struct *vma, int in_group);
78579
78580@@ -1178,6 +1156,15 @@ static inline void sync_mm_rss(struct mm_struct *mm)
78581 }
78582 #endif
78583
78584+#ifdef CONFIG_MMU
78585+pgprot_t vm_get_page_prot(vm_flags_t vm_flags);
78586+#else
78587+static inline pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
78588+{
78589+ return __pgprot(0);
78590+}
78591+#endif
78592+
78593 int vma_wants_writenotify(struct vm_area_struct *vma);
78594
78595 extern pte_t *__get_locked_pte(struct mm_struct *mm, unsigned long addr,
78596@@ -1196,8 +1183,15 @@ static inline int __pud_alloc(struct mm_struct *mm, pgd_t *pgd,
78597 {
78598 return 0;
78599 }
78600+
78601+static inline int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd,
78602+ unsigned long address)
78603+{
78604+ return 0;
78605+}
78606 #else
78607 int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
78608+int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
78609 #endif
78610
78611 #ifdef __PAGETABLE_PMD_FOLDED
78612@@ -1206,8 +1200,15 @@ static inline int __pmd_alloc(struct mm_struct *mm, pud_t *pud,
78613 {
78614 return 0;
78615 }
78616+
78617+static inline int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud,
78618+ unsigned long address)
78619+{
78620+ return 0;
78621+}
78622 #else
78623 int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address);
78624+int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address);
78625 #endif
78626
78627 int __pte_alloc(struct mm_struct *mm, struct vm_area_struct *vma,
78628@@ -1225,11 +1226,23 @@ static inline pud_t *pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long a
78629 NULL: pud_offset(pgd, address);
78630 }
78631
78632+static inline pud_t *pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
78633+{
78634+ return (unlikely(pgd_none(*pgd)) && __pud_alloc_kernel(mm, pgd, address))?
78635+ NULL: pud_offset(pgd, address);
78636+}
78637+
78638 static inline pmd_t *pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
78639 {
78640 return (unlikely(pud_none(*pud)) && __pmd_alloc(mm, pud, address))?
78641 NULL: pmd_offset(pud, address);
78642 }
78643+
78644+static inline pmd_t *pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
78645+{
78646+ return (unlikely(pud_none(*pud)) && __pmd_alloc_kernel(mm, pud, address))?
78647+ NULL: pmd_offset(pud, address);
78648+}
78649 #endif /* CONFIG_MMU && !__ARCH_HAS_4LEVEL_HACK */
78650
78651 #if USE_SPLIT_PTLOCKS
78652@@ -1517,7 +1530,7 @@ extern int install_special_mapping(struct mm_struct *mm,
78653 unsigned long addr, unsigned long len,
78654 unsigned long flags, struct page **pages);
78655
78656-extern unsigned long get_unmapped_area(struct file *, unsigned long, unsigned long, unsigned long, unsigned long);
78657+extern unsigned long get_unmapped_area(struct file *, unsigned long, unsigned long, unsigned long, unsigned long) __intentional_overflow(-1);
78658
78659 extern unsigned long mmap_region(struct file *file, unsigned long addr,
78660 unsigned long len, vm_flags_t vm_flags, unsigned long pgoff);
78661@@ -1525,6 +1538,7 @@ extern unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
78662 unsigned long len, unsigned long prot, unsigned long flags,
78663 unsigned long pgoff, unsigned long *populate);
78664 extern int do_munmap(struct mm_struct *, unsigned long, size_t);
78665+extern int __do_munmap(struct mm_struct *, unsigned long, size_t);
78666
78667 #ifdef CONFIG_MMU
78668 extern int __mm_populate(unsigned long addr, unsigned long len,
78669@@ -1553,10 +1567,11 @@ struct vm_unmapped_area_info {
78670 unsigned long high_limit;
78671 unsigned long align_mask;
78672 unsigned long align_offset;
78673+ unsigned long threadstack_offset;
78674 };
78675
78676-extern unsigned long unmapped_area(struct vm_unmapped_area_info *info);
78677-extern unsigned long unmapped_area_topdown(struct vm_unmapped_area_info *info);
78678+extern unsigned long unmapped_area(const struct vm_unmapped_area_info *info);
78679+extern unsigned long unmapped_area_topdown(const struct vm_unmapped_area_info *info);
78680
78681 /*
78682 * Search for an unmapped address range.
78683@@ -1568,7 +1583,7 @@ extern unsigned long unmapped_area_topdown(struct vm_unmapped_area_info *info);
78684 * - satisfies (begin_addr & align_mask) == (align_offset & align_mask)
78685 */
78686 static inline unsigned long
78687-vm_unmapped_area(struct vm_unmapped_area_info *info)
78688+vm_unmapped_area(const struct vm_unmapped_area_info *info)
78689 {
78690 if (!(info->flags & VM_UNMAPPED_AREA_TOPDOWN))
78691 return unmapped_area(info);
78692@@ -1631,6 +1646,10 @@ extern struct vm_area_struct * find_vma(struct mm_struct * mm, unsigned long add
78693 extern struct vm_area_struct * find_vma_prev(struct mm_struct * mm, unsigned long addr,
78694 struct vm_area_struct **pprev);
78695
78696+extern struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma);
78697+extern __must_check long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma);
78698+extern void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl);
78699+
78700 /* Look up the first VMA which intersects the interval start_addr..end_addr-1,
78701 NULL if none. Assume start_addr < end_addr. */
78702 static inline struct vm_area_struct * find_vma_intersection(struct mm_struct * mm, unsigned long start_addr, unsigned long end_addr)
78703@@ -1659,15 +1678,6 @@ static inline struct vm_area_struct *find_exact_vma(struct mm_struct *mm,
78704 return vma;
78705 }
78706
78707-#ifdef CONFIG_MMU
78708-pgprot_t vm_get_page_prot(unsigned long vm_flags);
78709-#else
78710-static inline pgprot_t vm_get_page_prot(unsigned long vm_flags)
78711-{
78712- return __pgprot(0);
78713-}
78714-#endif
78715-
78716 #ifdef CONFIG_ARCH_USES_NUMA_PROT_NONE
78717 unsigned long change_prot_numa(struct vm_area_struct *vma,
78718 unsigned long start, unsigned long end);
78719@@ -1719,6 +1729,11 @@ void vm_stat_account(struct mm_struct *, unsigned long, struct file *, long);
78720 static inline void vm_stat_account(struct mm_struct *mm,
78721 unsigned long flags, struct file *file, long pages)
78722 {
78723+
78724+#ifdef CONFIG_PAX_RANDMMAP
78725+ if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
78726+#endif
78727+
78728 mm->total_vm += pages;
78729 }
78730 #endif /* CONFIG_PROC_FS */
78731@@ -1800,7 +1815,7 @@ extern int unpoison_memory(unsigned long pfn);
78732 extern int sysctl_memory_failure_early_kill;
78733 extern int sysctl_memory_failure_recovery;
78734 extern void shake_page(struct page *p, int access);
78735-extern atomic_long_t num_poisoned_pages;
78736+extern atomic_long_unchecked_t num_poisoned_pages;
78737 extern int soft_offline_page(struct page *page, int flags);
78738
78739 extern void dump_page(struct page *page);
78740@@ -1837,5 +1852,11 @@ void __init setup_nr_node_ids(void);
78741 static inline void setup_nr_node_ids(void) {}
78742 #endif
78743
78744+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
78745+extern void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot);
78746+#else
78747+static inline void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot) {}
78748+#endif
78749+
78750 #endif /* __KERNEL__ */
78751 #endif /* _LINUX_MM_H */
78752diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
78753index 8e082f1..f444f6e 100644
78754--- a/include/linux/mm_types.h
78755+++ b/include/linux/mm_types.h
78756@@ -289,7 +289,9 @@ struct vm_area_struct {
78757 #ifdef CONFIG_NUMA
78758 struct mempolicy *vm_policy; /* NUMA policy for the VMA */
78759 #endif
78760-};
78761+
78762+ struct vm_area_struct *vm_mirror;/* PaX: mirror vma or NULL */
78763+} __randomize_layout;
78764
78765 struct core_thread {
78766 struct task_struct *task;
78767@@ -444,7 +446,25 @@ struct mm_struct {
78768 bool tlb_flush_pending;
78769 #endif
78770 struct uprobes_state uprobes_state;
78771-};
78772+
78773+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
78774+ unsigned long pax_flags;
78775+#endif
78776+
78777+#ifdef CONFIG_PAX_DLRESOLVE
78778+ unsigned long call_dl_resolve;
78779+#endif
78780+
78781+#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
78782+ unsigned long call_syscall;
78783+#endif
78784+
78785+#ifdef CONFIG_PAX_ASLR
78786+ unsigned long delta_mmap; /* randomized offset */
78787+ unsigned long delta_stack; /* randomized offset */
78788+#endif
78789+
78790+} __randomize_layout;
78791
78792 /* first nid will either be a valid NID or one of these values */
78793 #define NUMA_PTE_SCAN_INIT -1
78794diff --git a/include/linux/mmiotrace.h b/include/linux/mmiotrace.h
78795index c5d5278..f0b68c8 100644
78796--- a/include/linux/mmiotrace.h
78797+++ b/include/linux/mmiotrace.h
78798@@ -46,7 +46,7 @@ extern int kmmio_handler(struct pt_regs *regs, unsigned long addr);
78799 /* Called from ioremap.c */
78800 extern void mmiotrace_ioremap(resource_size_t offset, unsigned long size,
78801 void __iomem *addr);
78802-extern void mmiotrace_iounmap(volatile void __iomem *addr);
78803+extern void mmiotrace_iounmap(const volatile void __iomem *addr);
78804
78805 /* For anyone to insert markers. Remember trailing newline. */
78806 extern __printf(1, 2) int mmiotrace_printk(const char *fmt, ...);
78807@@ -66,7 +66,7 @@ static inline void mmiotrace_ioremap(resource_size_t offset,
78808 {
78809 }
78810
78811-static inline void mmiotrace_iounmap(volatile void __iomem *addr)
78812+static inline void mmiotrace_iounmap(const volatile void __iomem *addr)
78813 {
78814 }
78815
78816diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
78817index bd791e4..8617c34f 100644
78818--- a/include/linux/mmzone.h
78819+++ b/include/linux/mmzone.h
78820@@ -396,7 +396,7 @@ struct zone {
78821 unsigned long flags; /* zone flags, see below */
78822
78823 /* Zone statistics */
78824- atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
78825+ atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
78826
78827 /*
78828 * The target ratio of ACTIVE_ANON to INACTIVE_ANON pages on
78829diff --git a/include/linux/mod_devicetable.h b/include/linux/mod_devicetable.h
78830index 45e9214..a7227d6 100644
78831--- a/include/linux/mod_devicetable.h
78832+++ b/include/linux/mod_devicetable.h
78833@@ -13,7 +13,7 @@
78834 typedef unsigned long kernel_ulong_t;
78835 #endif
78836
78837-#define PCI_ANY_ID (~0)
78838+#define PCI_ANY_ID ((__u16)~0)
78839
78840 struct pci_device_id {
78841 __u32 vendor, device; /* Vendor and device ID or PCI_ANY_ID*/
78842@@ -139,7 +139,7 @@ struct usb_device_id {
78843 #define USB_DEVICE_ID_MATCH_INT_PROTOCOL 0x0200
78844 #define USB_DEVICE_ID_MATCH_INT_NUMBER 0x0400
78845
78846-#define HID_ANY_ID (~0)
78847+#define HID_ANY_ID (~0U)
78848 #define HID_BUS_ANY 0xffff
78849 #define HID_GROUP_ANY 0x0000
78850
78851@@ -467,7 +467,7 @@ struct dmi_system_id {
78852 const char *ident;
78853 struct dmi_strmatch matches[4];
78854 void *driver_data;
78855-};
78856+} __do_const;
78857 /*
78858 * struct dmi_device_id appears during expansion of
78859 * "MODULE_DEVICE_TABLE(dmi, x)". Compiler doesn't look inside it
78860diff --git a/include/linux/module.h b/include/linux/module.h
78861index 05f2447..bcb0add 100644
78862--- a/include/linux/module.h
78863+++ b/include/linux/module.h
78864@@ -17,9 +17,11 @@
78865 #include <linux/moduleparam.h>
78866 #include <linux/tracepoint.h>
78867 #include <linux/export.h>
78868+#include <linux/fs.h>
78869
78870 #include <linux/percpu.h>
78871 #include <asm/module.h>
78872+#include <asm/pgtable.h>
78873
78874 /* In stripped ARM and x86-64 modules, ~ is surprisingly rare. */
78875 #define MODULE_SIG_STRING "~Module signature appended~\n"
78876@@ -43,7 +45,7 @@ struct module_kobject {
78877 struct kobject *drivers_dir;
78878 struct module_param_attrs *mp;
78879 struct completion *kobj_completion;
78880-};
78881+} __randomize_layout;
78882
78883 struct module_attribute {
78884 struct attribute attr;
78885@@ -55,12 +57,13 @@ struct module_attribute {
78886 int (*test)(struct module *);
78887 void (*free)(struct module *);
78888 };
78889+typedef struct module_attribute __no_const module_attribute_no_const;
78890
78891 struct module_version_attribute {
78892 struct module_attribute mattr;
78893 const char *module_name;
78894 const char *version;
78895-} __attribute__ ((__aligned__(sizeof(void *))));
78896+} __do_const __attribute__ ((__aligned__(sizeof(void *))));
78897
78898 extern ssize_t __modver_version_show(struct module_attribute *,
78899 struct module_kobject *, char *);
78900@@ -238,7 +241,7 @@ struct module
78901
78902 /* Sysfs stuff. */
78903 struct module_kobject mkobj;
78904- struct module_attribute *modinfo_attrs;
78905+ module_attribute_no_const *modinfo_attrs;
78906 const char *version;
78907 const char *srcversion;
78908 struct kobject *holders_dir;
78909@@ -287,19 +290,16 @@ struct module
78910 int (*init)(void);
78911
78912 /* If this is non-NULL, vfree after init() returns */
78913- void *module_init;
78914+ void *module_init_rx, *module_init_rw;
78915
78916 /* Here is the actual code + data, vfree'd on unload. */
78917- void *module_core;
78918+ void *module_core_rx, *module_core_rw;
78919
78920 /* Here are the sizes of the init and core sections */
78921- unsigned int init_size, core_size;
78922+ unsigned int init_size_rw, core_size_rw;
78923
78924 /* The size of the executable code in each section. */
78925- unsigned int init_text_size, core_text_size;
78926-
78927- /* Size of RO sections of the module (text+rodata) */
78928- unsigned int init_ro_size, core_ro_size;
78929+ unsigned int init_size_rx, core_size_rx;
78930
78931 /* Arch-specific module values */
78932 struct mod_arch_specific arch;
78933@@ -355,6 +355,10 @@ struct module
78934 #ifdef CONFIG_EVENT_TRACING
78935 struct ftrace_event_call **trace_events;
78936 unsigned int num_trace_events;
78937+ struct file_operations trace_id;
78938+ struct file_operations trace_enable;
78939+ struct file_operations trace_format;
78940+ struct file_operations trace_filter;
78941 #endif
78942 #ifdef CONFIG_FTRACE_MCOUNT_RECORD
78943 unsigned int num_ftrace_callsites;
78944@@ -381,7 +385,7 @@ struct module
78945 ctor_fn_t *ctors;
78946 unsigned int num_ctors;
78947 #endif
78948-};
78949+} __randomize_layout;
78950 #ifndef MODULE_ARCH_INIT
78951 #define MODULE_ARCH_INIT {}
78952 #endif
78953@@ -402,16 +406,46 @@ bool is_module_address(unsigned long addr);
78954 bool is_module_percpu_address(unsigned long addr);
78955 bool is_module_text_address(unsigned long addr);
78956
78957+static inline int within_module_range(unsigned long addr, void *start, unsigned long size)
78958+{
78959+
78960+#ifdef CONFIG_PAX_KERNEXEC
78961+ if (ktla_ktva(addr) >= (unsigned long)start &&
78962+ ktla_ktva(addr) < (unsigned long)start + size)
78963+ return 1;
78964+#endif
78965+
78966+ return ((void *)addr >= start && (void *)addr < start + size);
78967+}
78968+
78969+static inline int within_module_core_rx(unsigned long addr, const struct module *mod)
78970+{
78971+ return within_module_range(addr, mod->module_core_rx, mod->core_size_rx);
78972+}
78973+
78974+static inline int within_module_core_rw(unsigned long addr, const struct module *mod)
78975+{
78976+ return within_module_range(addr, mod->module_core_rw, mod->core_size_rw);
78977+}
78978+
78979+static inline int within_module_init_rx(unsigned long addr, const struct module *mod)
78980+{
78981+ return within_module_range(addr, mod->module_init_rx, mod->init_size_rx);
78982+}
78983+
78984+static inline int within_module_init_rw(unsigned long addr, const struct module *mod)
78985+{
78986+ return within_module_range(addr, mod->module_init_rw, mod->init_size_rw);
78987+}
78988+
78989 static inline int within_module_core(unsigned long addr, const struct module *mod)
78990 {
78991- return (unsigned long)mod->module_core <= addr &&
78992- addr < (unsigned long)mod->module_core + mod->core_size;
78993+ return within_module_core_rx(addr, mod) || within_module_core_rw(addr, mod);
78994 }
78995
78996 static inline int within_module_init(unsigned long addr, const struct module *mod)
78997 {
78998- return (unsigned long)mod->module_init <= addr &&
78999- addr < (unsigned long)mod->module_init + mod->init_size;
79000+ return within_module_init_rx(addr, mod) || within_module_init_rw(addr, mod);
79001 }
79002
79003 /* Search for module by name: must hold module_mutex. */
79004diff --git a/include/linux/moduleloader.h b/include/linux/moduleloader.h
79005index 560ca53..ef621ef 100644
79006--- a/include/linux/moduleloader.h
79007+++ b/include/linux/moduleloader.h
79008@@ -25,9 +25,21 @@ unsigned int arch_mod_section_prepend(struct module *mod, unsigned int section);
79009 sections. Returns NULL on failure. */
79010 void *module_alloc(unsigned long size);
79011
79012+#ifdef CONFIG_PAX_KERNEXEC
79013+void *module_alloc_exec(unsigned long size);
79014+#else
79015+#define module_alloc_exec(x) module_alloc(x)
79016+#endif
79017+
79018 /* Free memory returned from module_alloc. */
79019 void module_free(struct module *mod, void *module_region);
79020
79021+#ifdef CONFIG_PAX_KERNEXEC
79022+void module_free_exec(struct module *mod, void *module_region);
79023+#else
79024+#define module_free_exec(x, y) module_free((x), (y))
79025+#endif
79026+
79027 /*
79028 * Apply the given relocation to the (simplified) ELF. Return -error
79029 * or 0.
79030@@ -45,7 +57,9 @@ static inline int apply_relocate(Elf_Shdr *sechdrs,
79031 unsigned int relsec,
79032 struct module *me)
79033 {
79034+#ifdef CONFIG_MODULES
79035 printk(KERN_ERR "module %s: REL relocation unsupported\n", me->name);
79036+#endif
79037 return -ENOEXEC;
79038 }
79039 #endif
79040@@ -67,7 +81,9 @@ static inline int apply_relocate_add(Elf_Shdr *sechdrs,
79041 unsigned int relsec,
79042 struct module *me)
79043 {
79044+#ifdef CONFIG_MODULES
79045 printk(KERN_ERR "module %s: REL relocation unsupported\n", me->name);
79046+#endif
79047 return -ENOEXEC;
79048 }
79049 #endif
79050diff --git a/include/linux/moduleparam.h b/include/linux/moduleparam.h
79051index c3eb102..073c4a6 100644
79052--- a/include/linux/moduleparam.h
79053+++ b/include/linux/moduleparam.h
79054@@ -295,7 +295,7 @@ static inline void __kernel_param_unlock(void)
79055 * @len is usually just sizeof(string).
79056 */
79057 #define module_param_string(name, string, len, perm) \
79058- static const struct kparam_string __param_string_##name \
79059+ static const struct kparam_string __param_string_##name __used \
79060 = { len, string }; \
79061 __module_param_call(MODULE_PARAM_PREFIX, name, \
79062 &param_ops_string, \
79063@@ -434,7 +434,7 @@ extern int param_set_bint(const char *val, const struct kernel_param *kp);
79064 */
79065 #define module_param_array_named(name, array, type, nump, perm) \
79066 param_check_##type(name, &(array)[0]); \
79067- static const struct kparam_array __param_arr_##name \
79068+ static const struct kparam_array __param_arr_##name __used \
79069 = { .max = ARRAY_SIZE(array), .num = nump, \
79070 .ops = &param_ops_##type, \
79071 .elemsize = sizeof(array[0]), .elem = array }; \
79072diff --git a/include/linux/mount.h b/include/linux/mount.h
79073index 38cd98f..8a9688b 100644
79074--- a/include/linux/mount.h
79075+++ b/include/linux/mount.h
79076@@ -54,7 +54,7 @@ struct vfsmount {
79077 struct dentry *mnt_root; /* root of the mounted tree */
79078 struct super_block *mnt_sb; /* pointer to superblock */
79079 int mnt_flags;
79080-};
79081+} __randomize_layout;
79082
79083 struct file; /* forward dec */
79084
79085diff --git a/include/linux/namei.h b/include/linux/namei.h
79086index 8e47bc7..c70fd73 100644
79087--- a/include/linux/namei.h
79088+++ b/include/linux/namei.h
79089@@ -19,7 +19,7 @@ struct nameidata {
79090 unsigned seq;
79091 int last_type;
79092 unsigned depth;
79093- char *saved_names[MAX_NESTED_LINKS + 1];
79094+ const char *saved_names[MAX_NESTED_LINKS + 1];
79095 };
79096
79097 /*
79098@@ -83,12 +83,12 @@ extern void unlock_rename(struct dentry *, struct dentry *);
79099
79100 extern void nd_jump_link(struct nameidata *nd, struct path *path);
79101
79102-static inline void nd_set_link(struct nameidata *nd, char *path)
79103+static inline void nd_set_link(struct nameidata *nd, const char *path)
79104 {
79105 nd->saved_names[nd->depth] = path;
79106 }
79107
79108-static inline char *nd_get_link(struct nameidata *nd)
79109+static inline const char *nd_get_link(const struct nameidata *nd)
79110 {
79111 return nd->saved_names[nd->depth];
79112 }
79113diff --git a/include/linux/net.h b/include/linux/net.h
79114index 41103f8..631edff 100644
79115--- a/include/linux/net.h
79116+++ b/include/linux/net.h
79117@@ -191,7 +191,7 @@ struct net_proto_family {
79118 int (*create)(struct net *net, struct socket *sock,
79119 int protocol, int kern);
79120 struct module *owner;
79121-};
79122+} __do_const;
79123
79124 struct iovec;
79125 struct kvec;
79126diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
79127index 21eae43..4fff130 100644
79128--- a/include/linux/netdevice.h
79129+++ b/include/linux/netdevice.h
79130@@ -1098,6 +1098,7 @@ struct net_device_ops {
79131 sa_family_t sa_family,
79132 __be16 port);
79133 };
79134+typedef struct net_device_ops __no_const net_device_ops_no_const;
79135
79136 /*
79137 * The DEVICE structure.
79138@@ -1169,7 +1170,7 @@ struct net_device {
79139 int iflink;
79140
79141 struct net_device_stats stats;
79142- atomic_long_t rx_dropped; /* dropped packets by core network
79143+ atomic_long_unchecked_t rx_dropped; /* dropped packets by core network
79144 * Do not use this in drivers.
79145 */
79146
79147diff --git a/include/linux/netfilter.h b/include/linux/netfilter.h
79148index 708fe72ab9..77084a3 100644
79149--- a/include/linux/netfilter.h
79150+++ b/include/linux/netfilter.h
79151@@ -82,7 +82,7 @@ struct nf_sockopt_ops {
79152 #endif
79153 /* Use the module struct to lock set/get code in place */
79154 struct module *owner;
79155-};
79156+} __do_const;
79157
79158 /* Function to register/unregister hook points. */
79159 int nf_register_hook(struct nf_hook_ops *reg);
79160diff --git a/include/linux/netfilter/nfnetlink.h b/include/linux/netfilter/nfnetlink.h
79161index cadb740..d7c37c0 100644
79162--- a/include/linux/netfilter/nfnetlink.h
79163+++ b/include/linux/netfilter/nfnetlink.h
79164@@ -16,7 +16,7 @@ struct nfnl_callback {
79165 const struct nlattr * const cda[]);
79166 const struct nla_policy *policy; /* netlink attribute policy */
79167 const u_int16_t attr_count; /* number of nlattr's */
79168-};
79169+} __do_const;
79170
79171 struct nfnetlink_subsystem {
79172 const char *name;
79173diff --git a/include/linux/netfilter/xt_gradm.h b/include/linux/netfilter/xt_gradm.h
79174new file mode 100644
79175index 0000000..33f4af8
79176--- /dev/null
79177+++ b/include/linux/netfilter/xt_gradm.h
79178@@ -0,0 +1,9 @@
79179+#ifndef _LINUX_NETFILTER_XT_GRADM_H
79180+#define _LINUX_NETFILTER_XT_GRADM_H 1
79181+
79182+struct xt_gradm_mtinfo {
79183+ __u16 flags;
79184+ __u16 invflags;
79185+};
79186+
79187+#endif
79188diff --git a/include/linux/nls.h b/include/linux/nls.h
79189index 5dc635f..35f5e11 100644
79190--- a/include/linux/nls.h
79191+++ b/include/linux/nls.h
79192@@ -31,7 +31,7 @@ struct nls_table {
79193 const unsigned char *charset2upper;
79194 struct module *owner;
79195 struct nls_table *next;
79196-};
79197+} __do_const;
79198
79199 /* this value hold the maximum octet of charset */
79200 #define NLS_MAX_CHARSET_SIZE 6 /* for UTF-8 */
79201diff --git a/include/linux/notifier.h b/include/linux/notifier.h
79202index d14a4c3..a078786 100644
79203--- a/include/linux/notifier.h
79204+++ b/include/linux/notifier.h
79205@@ -54,7 +54,8 @@ struct notifier_block {
79206 notifier_fn_t notifier_call;
79207 struct notifier_block __rcu *next;
79208 int priority;
79209-};
79210+} __do_const;
79211+typedef struct notifier_block __no_const notifier_block_no_const;
79212
79213 struct atomic_notifier_head {
79214 spinlock_t lock;
79215diff --git a/include/linux/oprofile.h b/include/linux/oprofile.h
79216index b2a0f15..4d7da32 100644
79217--- a/include/linux/oprofile.h
79218+++ b/include/linux/oprofile.h
79219@@ -138,9 +138,9 @@ int oprofilefs_create_ulong(struct dentry * root,
79220 int oprofilefs_create_ro_ulong(struct dentry * root,
79221 char const * name, ulong * val);
79222
79223-/** Create a file for read-only access to an atomic_t. */
79224+/** Create a file for read-only access to an atomic_unchecked_t. */
79225 int oprofilefs_create_ro_atomic(struct dentry * root,
79226- char const * name, atomic_t * val);
79227+ char const * name, atomic_unchecked_t * val);
79228
79229 /** create a directory */
79230 struct dentry *oprofilefs_mkdir(struct dentry *parent, char const *name);
79231diff --git a/include/linux/pci_hotplug.h b/include/linux/pci_hotplug.h
79232index 430dd96..544e26e 100644
79233--- a/include/linux/pci_hotplug.h
79234+++ b/include/linux/pci_hotplug.h
79235@@ -71,7 +71,8 @@ struct hotplug_slot_ops {
79236 int (*get_latch_status) (struct hotplug_slot *slot, u8 *value);
79237 int (*get_adapter_status) (struct hotplug_slot *slot, u8 *value);
79238 int (*reset_slot) (struct hotplug_slot *slot, int probe);
79239-};
79240+} __do_const;
79241+typedef struct hotplug_slot_ops __no_const hotplug_slot_ops_no_const;
79242
79243 /**
79244 * struct hotplug_slot_info - used to notify the hotplug pci core of the state of the slot
79245diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
79246index c8ba627..24bdfa8 100644
79247--- a/include/linux/perf_event.h
79248+++ b/include/linux/perf_event.h
79249@@ -327,8 +327,8 @@ struct perf_event {
79250
79251 enum perf_event_active_state state;
79252 unsigned int attach_state;
79253- local64_t count;
79254- atomic64_t child_count;
79255+ local64_t count; /* PaX: fix it one day */
79256+ atomic64_unchecked_t child_count;
79257
79258 /*
79259 * These are the total time in nanoseconds that the event
79260@@ -379,8 +379,8 @@ struct perf_event {
79261 * These accumulate total time (in nanoseconds) that children
79262 * events have been enabled and running, respectively.
79263 */
79264- atomic64_t child_total_time_enabled;
79265- atomic64_t child_total_time_running;
79266+ atomic64_unchecked_t child_total_time_enabled;
79267+ atomic64_unchecked_t child_total_time_running;
79268
79269 /*
79270 * Protect attach/detach and child_list:
79271@@ -702,7 +702,7 @@ static inline void perf_callchain_store(struct perf_callchain_entry *entry, u64
79272 entry->ip[entry->nr++] = ip;
79273 }
79274
79275-extern int sysctl_perf_event_paranoid;
79276+extern int sysctl_perf_event_legitimately_concerned;
79277 extern int sysctl_perf_event_mlock;
79278 extern int sysctl_perf_event_sample_rate;
79279 extern int sysctl_perf_cpu_time_max_percent;
79280@@ -717,19 +717,24 @@ extern int perf_cpu_time_max_percent_handler(struct ctl_table *table, int write,
79281 loff_t *ppos);
79282
79283
79284+static inline bool perf_paranoid_any(void)
79285+{
79286+ return sysctl_perf_event_legitimately_concerned > 2;
79287+}
79288+
79289 static inline bool perf_paranoid_tracepoint_raw(void)
79290 {
79291- return sysctl_perf_event_paranoid > -1;
79292+ return sysctl_perf_event_legitimately_concerned > -1;
79293 }
79294
79295 static inline bool perf_paranoid_cpu(void)
79296 {
79297- return sysctl_perf_event_paranoid > 0;
79298+ return sysctl_perf_event_legitimately_concerned > 0;
79299 }
79300
79301 static inline bool perf_paranoid_kernel(void)
79302 {
79303- return sysctl_perf_event_paranoid > 1;
79304+ return sysctl_perf_event_legitimately_concerned > 1;
79305 }
79306
79307 extern void perf_event_init(void);
79308@@ -845,7 +850,7 @@ struct perf_pmu_events_attr {
79309 struct device_attribute attr;
79310 u64 id;
79311 const char *event_str;
79312-};
79313+} __do_const;
79314
79315 #define PMU_EVENT_ATTR(_name, _var, _id, _show) \
79316 static struct perf_pmu_events_attr _var = { \
79317diff --git a/include/linux/pid_namespace.h b/include/linux/pid_namespace.h
79318index e277266..fa71bd1 100644
79319--- a/include/linux/pid_namespace.h
79320+++ b/include/linux/pid_namespace.h
79321@@ -42,7 +42,7 @@ struct pid_namespace {
79322 int hide_pid;
79323 int reboot; /* group exit code if this pidns was rebooted */
79324 unsigned int proc_inum;
79325-};
79326+} __randomize_layout;
79327
79328 extern struct pid_namespace init_pid_ns;
79329
79330diff --git a/include/linux/pipe_fs_i.h b/include/linux/pipe_fs_i.h
79331index b8809fe..ae4ccd0 100644
79332--- a/include/linux/pipe_fs_i.h
79333+++ b/include/linux/pipe_fs_i.h
79334@@ -47,10 +47,10 @@ struct pipe_inode_info {
79335 struct mutex mutex;
79336 wait_queue_head_t wait;
79337 unsigned int nrbufs, curbuf, buffers;
79338- unsigned int readers;
79339- unsigned int writers;
79340- unsigned int files;
79341- unsigned int waiting_writers;
79342+ atomic_t readers;
79343+ atomic_t writers;
79344+ atomic_t files;
79345+ atomic_t waiting_writers;
79346 unsigned int r_counter;
79347 unsigned int w_counter;
79348 struct page *tmp_page;
79349diff --git a/include/linux/platform_data/usb-ehci-s5p.h b/include/linux/platform_data/usb-ehci-s5p.h
79350index 5f28cae..3d23723 100644
79351--- a/include/linux/platform_data/usb-ehci-s5p.h
79352+++ b/include/linux/platform_data/usb-ehci-s5p.h
79353@@ -14,7 +14,7 @@
79354 struct s5p_ehci_platdata {
79355 int (*phy_init)(struct platform_device *pdev, int type);
79356 int (*phy_exit)(struct platform_device *pdev, int type);
79357-};
79358+} __no_const;
79359
79360 extern void s5p_ehci_set_platdata(struct s5p_ehci_platdata *pd);
79361
79362diff --git a/include/linux/platform_data/usb-ohci-exynos.h b/include/linux/platform_data/usb-ohci-exynos.h
79363index c256c59..8ea94c7 100644
79364--- a/include/linux/platform_data/usb-ohci-exynos.h
79365+++ b/include/linux/platform_data/usb-ohci-exynos.h
79366@@ -14,7 +14,7 @@
79367 struct exynos4_ohci_platdata {
79368 int (*phy_init)(struct platform_device *pdev, int type);
79369 int (*phy_exit)(struct platform_device *pdev, int type);
79370-};
79371+} __no_const;
79372
79373 extern void exynos4_ohci_set_platdata(struct exynos4_ohci_platdata *pd);
79374
79375diff --git a/include/linux/pm.h b/include/linux/pm.h
79376index a224c7f..92d8a97 100644
79377--- a/include/linux/pm.h
79378+++ b/include/linux/pm.h
79379@@ -576,6 +576,7 @@ extern int dev_pm_put_subsys_data(struct device *dev);
79380 struct dev_pm_domain {
79381 struct dev_pm_ops ops;
79382 };
79383+typedef struct dev_pm_domain __no_const dev_pm_domain_no_const;
79384
79385 /*
79386 * The PM_EVENT_ messages are also used by drivers implementing the legacy
79387diff --git a/include/linux/pm_domain.h b/include/linux/pm_domain.h
79388index 7c1d252..c5c773e 100644
79389--- a/include/linux/pm_domain.h
79390+++ b/include/linux/pm_domain.h
79391@@ -48,7 +48,7 @@ struct gpd_dev_ops {
79392
79393 struct gpd_cpu_data {
79394 unsigned int saved_exit_latency;
79395- struct cpuidle_state *idle_state;
79396+ cpuidle_state_no_const *idle_state;
79397 };
79398
79399 struct generic_pm_domain {
79400diff --git a/include/linux/pm_runtime.h b/include/linux/pm_runtime.h
79401index 6fa7cea..7bf6415 100644
79402--- a/include/linux/pm_runtime.h
79403+++ b/include/linux/pm_runtime.h
79404@@ -103,7 +103,7 @@ static inline bool pm_runtime_callbacks_present(struct device *dev)
79405
79406 static inline void pm_runtime_mark_last_busy(struct device *dev)
79407 {
79408- ACCESS_ONCE(dev->power.last_busy) = jiffies;
79409+ ACCESS_ONCE_RW(dev->power.last_busy) = jiffies;
79410 }
79411
79412 #else /* !CONFIG_PM_RUNTIME */
79413diff --git a/include/linux/pnp.h b/include/linux/pnp.h
79414index 195aafc..49a7bc2 100644
79415--- a/include/linux/pnp.h
79416+++ b/include/linux/pnp.h
79417@@ -297,7 +297,7 @@ static inline void pnp_set_drvdata(struct pnp_dev *pdev, void *data)
79418 struct pnp_fixup {
79419 char id[7];
79420 void (*quirk_function) (struct pnp_dev * dev); /* fixup function */
79421-};
79422+} __do_const;
79423
79424 /* config parameters */
79425 #define PNP_CONFIG_NORMAL 0x0001
79426diff --git a/include/linux/poison.h b/include/linux/poison.h
79427index 2110a81..13a11bb 100644
79428--- a/include/linux/poison.h
79429+++ b/include/linux/poison.h
79430@@ -19,8 +19,8 @@
79431 * under normal circumstances, used to verify that nobody uses
79432 * non-initialized list entries.
79433 */
79434-#define LIST_POISON1 ((void *) 0x00100100 + POISON_POINTER_DELTA)
79435-#define LIST_POISON2 ((void *) 0x00200200 + POISON_POINTER_DELTA)
79436+#define LIST_POISON1 ((void *) (long)0xFFFFFF01)
79437+#define LIST_POISON2 ((void *) (long)0xFFFFFF02)
79438
79439 /********** include/linux/timer.h **********/
79440 /*
79441diff --git a/include/linux/power/smartreflex.h b/include/linux/power/smartreflex.h
79442index d8b187c3..9a9257a 100644
79443--- a/include/linux/power/smartreflex.h
79444+++ b/include/linux/power/smartreflex.h
79445@@ -238,7 +238,7 @@ struct omap_sr_class_data {
79446 int (*notify)(struct omap_sr *sr, u32 status);
79447 u8 notify_flags;
79448 u8 class_type;
79449-};
79450+} __do_const;
79451
79452 /**
79453 * struct omap_sr_nvalue_table - Smartreflex n-target value info
79454diff --git a/include/linux/ppp-comp.h b/include/linux/ppp-comp.h
79455index 4ea1d37..80f4b33 100644
79456--- a/include/linux/ppp-comp.h
79457+++ b/include/linux/ppp-comp.h
79458@@ -84,7 +84,7 @@ struct compressor {
79459 struct module *owner;
79460 /* Extra skb space needed by the compressor algorithm */
79461 unsigned int comp_extra;
79462-};
79463+} __do_const;
79464
79465 /*
79466 * The return value from decompress routine is the length of the
79467diff --git a/include/linux/preempt.h b/include/linux/preempt.h
79468index f5d4723..a6ea2fa 100644
79469--- a/include/linux/preempt.h
79470+++ b/include/linux/preempt.h
79471@@ -18,8 +18,13 @@
79472 # define sub_preempt_count(val) do { preempt_count() -= (val); } while (0)
79473 #endif
79474
79475+#define raw_add_preempt_count(val) do { preempt_count() += (val); } while (0)
79476+#define raw_sub_preempt_count(val) do { preempt_count() -= (val); } while (0)
79477+
79478 #define inc_preempt_count() add_preempt_count(1)
79479+#define raw_inc_preempt_count() raw_add_preempt_count(1)
79480 #define dec_preempt_count() sub_preempt_count(1)
79481+#define raw_dec_preempt_count() raw_sub_preempt_count(1)
79482
79483 #define preempt_count() (current_thread_info()->preempt_count)
79484
79485@@ -64,6 +69,12 @@ do { \
79486 barrier(); \
79487 } while (0)
79488
79489+#define raw_preempt_disable() \
79490+do { \
79491+ raw_inc_preempt_count(); \
79492+ barrier(); \
79493+} while (0)
79494+
79495 #define sched_preempt_enable_no_resched() \
79496 do { \
79497 barrier(); \
79498@@ -72,6 +83,12 @@ do { \
79499
79500 #define preempt_enable_no_resched() sched_preempt_enable_no_resched()
79501
79502+#define raw_preempt_enable_no_resched() \
79503+do { \
79504+ barrier(); \
79505+ raw_dec_preempt_count(); \
79506+} while (0)
79507+
79508 #define preempt_enable() \
79509 do { \
79510 preempt_enable_no_resched(); \
79511@@ -116,8 +133,10 @@ do { \
79512 * region.
79513 */
79514 #define preempt_disable() barrier()
79515+#define raw_preempt_disable() barrier()
79516 #define sched_preempt_enable_no_resched() barrier()
79517 #define preempt_enable_no_resched() barrier()
79518+#define raw_preempt_enable_no_resched() barrier()
79519 #define preempt_enable() barrier()
79520
79521 #define preempt_disable_notrace() barrier()
79522diff --git a/include/linux/printk.h b/include/linux/printk.h
79523index e6131a78..8e9fb61 100644
79524--- a/include/linux/printk.h
79525+++ b/include/linux/printk.h
79526@@ -106,6 +106,8 @@ static inline __printf(1, 2) __cold
79527 void early_printk(const char *s, ...) { }
79528 #endif
79529
79530+extern int kptr_restrict;
79531+
79532 #ifdef CONFIG_PRINTK
79533 asmlinkage __printf(5, 0)
79534 int vprintk_emit(int facility, int level,
79535@@ -140,7 +142,6 @@ extern bool printk_timed_ratelimit(unsigned long *caller_jiffies,
79536
79537 extern int printk_delay_msec;
79538 extern int dmesg_restrict;
79539-extern int kptr_restrict;
79540
79541 extern void wake_up_klogd(void);
79542
79543diff --git a/include/linux/proc_fs.h b/include/linux/proc_fs.h
79544index 608e60a..c26f864 100644
79545--- a/include/linux/proc_fs.h
79546+++ b/include/linux/proc_fs.h
79547@@ -34,6 +34,19 @@ static inline struct proc_dir_entry *proc_create(
79548 return proc_create_data(name, mode, parent, proc_fops, NULL);
79549 }
79550
79551+static inline struct proc_dir_entry *proc_create_grsec(const char *name, umode_t mode,
79552+ struct proc_dir_entry *parent, const struct file_operations *proc_fops)
79553+{
79554+#ifdef CONFIG_GRKERNSEC_PROC_USER
79555+ return proc_create_data(name, S_IRUSR, parent, proc_fops, NULL);
79556+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
79557+ return proc_create_data(name, S_IRUSR | S_IRGRP, parent, proc_fops, NULL);
79558+#else
79559+ return proc_create_data(name, mode, parent, proc_fops, NULL);
79560+#endif
79561+}
79562+
79563+
79564 extern void proc_set_size(struct proc_dir_entry *, loff_t);
79565 extern void proc_set_user(struct proc_dir_entry *, kuid_t, kgid_t);
79566 extern void *PDE_DATA(const struct inode *);
79567diff --git a/include/linux/proc_ns.h b/include/linux/proc_ns.h
79568index 34a1e10..70f6bde 100644
79569--- a/include/linux/proc_ns.h
79570+++ b/include/linux/proc_ns.h
79571@@ -14,7 +14,7 @@ struct proc_ns_operations {
79572 void (*put)(void *ns);
79573 int (*install)(struct nsproxy *nsproxy, void *ns);
79574 unsigned int (*inum)(void *ns);
79575-};
79576+} __do_const __randomize_layout;
79577
79578 struct proc_ns {
79579 void *ns;
79580diff --git a/include/linux/quota.h b/include/linux/quota.h
79581index cc7494a..1e27036 100644
79582--- a/include/linux/quota.h
79583+++ b/include/linux/quota.h
79584@@ -70,7 +70,7 @@ struct kqid { /* Type in which we store the quota identifier */
79585
79586 extern bool qid_eq(struct kqid left, struct kqid right);
79587 extern bool qid_lt(struct kqid left, struct kqid right);
79588-extern qid_t from_kqid(struct user_namespace *to, struct kqid qid);
79589+extern qid_t from_kqid(struct user_namespace *to, struct kqid qid) __intentional_overflow(-1);
79590 extern qid_t from_kqid_munged(struct user_namespace *to, struct kqid qid);
79591 extern bool qid_valid(struct kqid qid);
79592
79593diff --git a/include/linux/random.h b/include/linux/random.h
79594index bf9085e..02aca5f 100644
79595--- a/include/linux/random.h
79596+++ b/include/linux/random.h
79597@@ -10,9 +10,19 @@
79598
79599
79600 extern void add_device_randomness(const void *, unsigned int);
79601+
79602+static inline void add_latent_entropy(void)
79603+{
79604+
79605+#ifdef LATENT_ENTROPY_PLUGIN
79606+ add_device_randomness((const void *)&latent_entropy, sizeof(latent_entropy));
79607+#endif
79608+
79609+}
79610+
79611 extern void add_input_randomness(unsigned int type, unsigned int code,
79612- unsigned int value);
79613-extern void add_interrupt_randomness(int irq, int irq_flags);
79614+ unsigned int value) __latent_entropy;
79615+extern void add_interrupt_randomness(int irq, int irq_flags) __latent_entropy;
79616
79617 extern void get_random_bytes(void *buf, int nbytes);
79618 extern void get_random_bytes_arch(void *buf, int nbytes);
79619@@ -23,16 +33,22 @@ extern int random_int_secret_init(void);
79620 extern const struct file_operations random_fops, urandom_fops;
79621 #endif
79622
79623-unsigned int get_random_int(void);
79624+unsigned int __intentional_overflow(-1) get_random_int(void);
79625 unsigned long randomize_range(unsigned long start, unsigned long end, unsigned long len);
79626
79627-u32 prandom_u32(void);
79628+u32 prandom_u32(void) __intentional_overflow(-1);
79629 void prandom_bytes(void *buf, int nbytes);
79630 void prandom_seed(u32 seed);
79631+void prandom_reseed_late(void);
79632
79633-u32 prandom_u32_state(struct rnd_state *);
79634+u32 prandom_u32_state(struct rnd_state *state);
79635 void prandom_bytes_state(struct rnd_state *state, void *buf, int nbytes);
79636
79637+static inline unsigned long __intentional_overflow(-1) pax_get_random_long(void)
79638+{
79639+ return prandom_u32() + (sizeof(long) > 4 ? (unsigned long)prandom_u32() << 32 : 0);
79640+}
79641+
79642 /*
79643 * Handle minimum values for seeds
79644 */
79645@@ -50,9 +66,10 @@ static inline void prandom_seed_state(struct rnd_state *state, u64 seed)
79646 {
79647 u32 i = (seed >> 32) ^ (seed << 10) ^ seed;
79648
79649- state->s1 = __seed(i, 2);
79650- state->s2 = __seed(i, 8);
79651- state->s3 = __seed(i, 16);
79652+ state->s1 = __seed(i, 2U);
79653+ state->s2 = __seed(i, 8U);
79654+ state->s3 = __seed(i, 16U);
79655+ state->s4 = __seed(i, 128U);
79656 }
79657
79658 #ifdef CONFIG_ARCH_RANDOM
79659diff --git a/include/linux/rbtree_augmented.h b/include/linux/rbtree_augmented.h
79660index fea49b5..2ac22bb 100644
79661--- a/include/linux/rbtree_augmented.h
79662+++ b/include/linux/rbtree_augmented.h
79663@@ -80,7 +80,9 @@ rbname ## _rotate(struct rb_node *rb_old, struct rb_node *rb_new) \
79664 old->rbaugmented = rbcompute(old); \
79665 } \
79666 rbstatic const struct rb_augment_callbacks rbname = { \
79667- rbname ## _propagate, rbname ## _copy, rbname ## _rotate \
79668+ .propagate = rbname ## _propagate, \
79669+ .copy = rbname ## _copy, \
79670+ .rotate = rbname ## _rotate \
79671 };
79672
79673
79674diff --git a/include/linux/rculist.h b/include/linux/rculist.h
79675index 4106721..132d42c 100644
79676--- a/include/linux/rculist.h
79677+++ b/include/linux/rculist.h
79678@@ -44,6 +44,9 @@ extern void __list_add_rcu(struct list_head *new,
79679 struct list_head *prev, struct list_head *next);
79680 #endif
79681
79682+extern void __pax_list_add_rcu(struct list_head *new,
79683+ struct list_head *prev, struct list_head *next);
79684+
79685 /**
79686 * list_add_rcu - add a new entry to rcu-protected list
79687 * @new: new entry to be added
79688@@ -65,6 +68,11 @@ static inline void list_add_rcu(struct list_head *new, struct list_head *head)
79689 __list_add_rcu(new, head, head->next);
79690 }
79691
79692+static inline void pax_list_add_rcu(struct list_head *new, struct list_head *head)
79693+{
79694+ __pax_list_add_rcu(new, head, head->next);
79695+}
79696+
79697 /**
79698 * list_add_tail_rcu - add a new entry to rcu-protected list
79699 * @new: new entry to be added
79700@@ -87,6 +95,12 @@ static inline void list_add_tail_rcu(struct list_head *new,
79701 __list_add_rcu(new, head->prev, head);
79702 }
79703
79704+static inline void pax_list_add_tail_rcu(struct list_head *new,
79705+ struct list_head *head)
79706+{
79707+ __pax_list_add_rcu(new, head->prev, head);
79708+}
79709+
79710 /**
79711 * list_del_rcu - deletes entry from list without re-initialization
79712 * @entry: the element to delete from the list.
79713@@ -117,6 +131,8 @@ static inline void list_del_rcu(struct list_head *entry)
79714 entry->prev = LIST_POISON2;
79715 }
79716
79717+extern void pax_list_del_rcu(struct list_head *entry);
79718+
79719 /**
79720 * hlist_del_init_rcu - deletes entry from hash list with re-initialization
79721 * @n: the element to delete from the hash list.
79722diff --git a/include/linux/reboot.h b/include/linux/reboot.h
79723index 9e7db9e..7d4fd72 100644
79724--- a/include/linux/reboot.h
79725+++ b/include/linux/reboot.h
79726@@ -44,9 +44,9 @@ extern int unregister_reboot_notifier(struct notifier_block *);
79727 */
79728
79729 extern void migrate_to_reboot_cpu(void);
79730-extern void machine_restart(char *cmd);
79731-extern void machine_halt(void);
79732-extern void machine_power_off(void);
79733+extern void machine_restart(char *cmd) __noreturn;
79734+extern void machine_halt(void) __noreturn;
79735+extern void machine_power_off(void) __noreturn;
79736
79737 extern void machine_shutdown(void);
79738 struct pt_regs;
79739@@ -57,9 +57,9 @@ extern void machine_crash_shutdown(struct pt_regs *);
79740 */
79741
79742 extern void kernel_restart_prepare(char *cmd);
79743-extern void kernel_restart(char *cmd);
79744-extern void kernel_halt(void);
79745-extern void kernel_power_off(void);
79746+extern void kernel_restart(char *cmd) __noreturn;
79747+extern void kernel_halt(void) __noreturn;
79748+extern void kernel_power_off(void) __noreturn;
79749
79750 extern int C_A_D; /* for sysctl */
79751 void ctrl_alt_del(void);
79752@@ -73,7 +73,7 @@ extern int orderly_poweroff(bool force);
79753 * Emergency restart, callable from an interrupt handler.
79754 */
79755
79756-extern void emergency_restart(void);
79757+extern void emergency_restart(void) __noreturn;
79758 #include <asm/emergency-restart.h>
79759
79760 #endif /* _LINUX_REBOOT_H */
79761diff --git a/include/linux/regset.h b/include/linux/regset.h
79762index 8e0c9fe..ac4d221 100644
79763--- a/include/linux/regset.h
79764+++ b/include/linux/regset.h
79765@@ -161,7 +161,8 @@ struct user_regset {
79766 unsigned int align;
79767 unsigned int bias;
79768 unsigned int core_note_type;
79769-};
79770+} __do_const;
79771+typedef struct user_regset __no_const user_regset_no_const;
79772
79773 /**
79774 * struct user_regset_view - available regsets
79775diff --git a/include/linux/relay.h b/include/linux/relay.h
79776index d7c8359..818daf5 100644
79777--- a/include/linux/relay.h
79778+++ b/include/linux/relay.h
79779@@ -157,7 +157,7 @@ struct rchan_callbacks
79780 * The callback should return 0 if successful, negative if not.
79781 */
79782 int (*remove_buf_file)(struct dentry *dentry);
79783-};
79784+} __no_const;
79785
79786 /*
79787 * CONFIG_RELAY kernel API, kernel/relay.c
79788diff --git a/include/linux/rio.h b/include/linux/rio.h
79789index b71d573..2f940bd 100644
79790--- a/include/linux/rio.h
79791+++ b/include/linux/rio.h
79792@@ -355,7 +355,7 @@ struct rio_ops {
79793 int (*map_inb)(struct rio_mport *mport, dma_addr_t lstart,
79794 u64 rstart, u32 size, u32 flags);
79795 void (*unmap_inb)(struct rio_mport *mport, dma_addr_t lstart);
79796-};
79797+} __no_const;
79798
79799 #define RIO_RESOURCE_MEM 0x00000100
79800 #define RIO_RESOURCE_DOORBELL 0x00000200
79801diff --git a/include/linux/rmap.h b/include/linux/rmap.h
79802index 6dacb93..6174423 100644
79803--- a/include/linux/rmap.h
79804+++ b/include/linux/rmap.h
79805@@ -145,8 +145,8 @@ static inline void anon_vma_unlock_read(struct anon_vma *anon_vma)
79806 void anon_vma_init(void); /* create anon_vma_cachep */
79807 int anon_vma_prepare(struct vm_area_struct *);
79808 void unlink_anon_vmas(struct vm_area_struct *);
79809-int anon_vma_clone(struct vm_area_struct *, struct vm_area_struct *);
79810-int anon_vma_fork(struct vm_area_struct *, struct vm_area_struct *);
79811+int anon_vma_clone(struct vm_area_struct *, const struct vm_area_struct *);
79812+int anon_vma_fork(struct vm_area_struct *, const struct vm_area_struct *);
79813
79814 static inline void anon_vma_merge(struct vm_area_struct *vma,
79815 struct vm_area_struct *next)
79816diff --git a/include/linux/sched.h b/include/linux/sched.h
79817index b1e963e..cdb6315 100644
79818--- a/include/linux/sched.h
79819+++ b/include/linux/sched.h
79820@@ -62,6 +62,7 @@ struct bio_list;
79821 struct fs_struct;
79822 struct perf_event_context;
79823 struct blk_plug;
79824+struct linux_binprm;
79825
79826 /*
79827 * List of flags we want to share for kernel threads,
79828@@ -295,7 +296,7 @@ extern char __sched_text_start[], __sched_text_end[];
79829 extern int in_sched_functions(unsigned long addr);
79830
79831 #define MAX_SCHEDULE_TIMEOUT LONG_MAX
79832-extern signed long schedule_timeout(signed long timeout);
79833+extern signed long schedule_timeout(signed long timeout) __intentional_overflow(-1);
79834 extern signed long schedule_timeout_interruptible(signed long timeout);
79835 extern signed long schedule_timeout_killable(signed long timeout);
79836 extern signed long schedule_timeout_uninterruptible(signed long timeout);
79837@@ -306,6 +307,19 @@ struct nsproxy;
79838 struct user_namespace;
79839
79840 #ifdef CONFIG_MMU
79841+
79842+#ifdef CONFIG_GRKERNSEC_RAND_THREADSTACK
79843+extern unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags);
79844+#else
79845+static inline unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags)
79846+{
79847+ return 0;
79848+}
79849+#endif
79850+
79851+extern bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len, unsigned long offset);
79852+extern unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len, unsigned long offset);
79853+
79854 extern void arch_pick_mmap_layout(struct mm_struct *mm);
79855 extern unsigned long
79856 arch_get_unmapped_area(struct file *, unsigned long, unsigned long,
79857@@ -585,6 +599,17 @@ struct signal_struct {
79858 #ifdef CONFIG_TASKSTATS
79859 struct taskstats *stats;
79860 #endif
79861+
79862+#ifdef CONFIG_GRKERNSEC
79863+ u32 curr_ip;
79864+ u32 saved_ip;
79865+ u32 gr_saddr;
79866+ u32 gr_daddr;
79867+ u16 gr_sport;
79868+ u16 gr_dport;
79869+ u8 used_accept:1;
79870+#endif
79871+
79872 #ifdef CONFIG_AUDIT
79873 unsigned audit_tty;
79874 unsigned audit_tty_log_passwd;
79875@@ -611,7 +636,7 @@ struct signal_struct {
79876 struct mutex cred_guard_mutex; /* guard against foreign influences on
79877 * credential calculations
79878 * (notably. ptrace) */
79879-};
79880+} __randomize_layout;
79881
79882 /*
79883 * Bits in flags field of signal_struct.
79884@@ -665,6 +690,14 @@ struct user_struct {
79885 struct key *session_keyring; /* UID's default session keyring */
79886 #endif
79887
79888+#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
79889+ unsigned char kernel_banned;
79890+#endif
79891+#ifdef CONFIG_GRKERNSEC_BRUTE
79892+ unsigned char suid_banned;
79893+ unsigned long suid_ban_expires;
79894+#endif
79895+
79896 /* Hash table maintenance information */
79897 struct hlist_node uidhash_node;
79898 kuid_t uid;
79899@@ -672,7 +705,7 @@ struct user_struct {
79900 #ifdef CONFIG_PERF_EVENTS
79901 atomic_long_t locked_vm;
79902 #endif
79903-};
79904+} __randomize_layout;
79905
79906 extern int uids_sysfs_init(void);
79907
79908@@ -1150,8 +1183,8 @@ struct task_struct {
79909 struct list_head thread_group;
79910
79911 struct completion *vfork_done; /* for vfork() */
79912- int __user *set_child_tid; /* CLONE_CHILD_SETTID */
79913- int __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
79914+ pid_t __user *set_child_tid; /* CLONE_CHILD_SETTID */
79915+ pid_t __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
79916
79917 cputime_t utime, stime, utimescaled, stimescaled;
79918 cputime_t gtime;
79919@@ -1176,11 +1209,6 @@ struct task_struct {
79920 struct task_cputime cputime_expires;
79921 struct list_head cpu_timers[3];
79922
79923-/* process credentials */
79924- const struct cred __rcu *real_cred; /* objective and real subjective task
79925- * credentials (COW) */
79926- const struct cred __rcu *cred; /* effective (overridable) subjective task
79927- * credentials (COW) */
79928 char comm[TASK_COMM_LEN]; /* executable name excluding path
79929 - access with [gs]et_task_comm (which lock
79930 it with task_lock())
79931@@ -1197,6 +1225,10 @@ struct task_struct {
79932 #endif
79933 /* CPU-specific state of this task */
79934 struct thread_struct thread;
79935+/* thread_info moved to task_struct */
79936+#ifdef CONFIG_X86
79937+ struct thread_info tinfo;
79938+#endif
79939 /* filesystem information */
79940 struct fs_struct *fs;
79941 /* open file information */
79942@@ -1270,6 +1302,10 @@ struct task_struct {
79943 gfp_t lockdep_reclaim_gfp;
79944 #endif
79945
79946+/* process credentials */
79947+ const struct cred __rcu *real_cred; /* objective and real subjective task
79948+ * credentials (COW) */
79949+
79950 /* journalling filesystem info */
79951 void *journal_info;
79952
79953@@ -1308,6 +1344,10 @@ struct task_struct {
79954 /* cg_list protected by css_set_lock and tsk->alloc_lock */
79955 struct list_head cg_list;
79956 #endif
79957+
79958+ const struct cred __rcu *cred; /* effective (overridable) subjective task
79959+ * credentials (COW) */
79960+
79961 #ifdef CONFIG_FUTEX
79962 struct robust_list_head __user *robust_list;
79963 #ifdef CONFIG_COMPAT
79964@@ -1411,7 +1451,78 @@ struct task_struct {
79965 unsigned int sequential_io;
79966 unsigned int sequential_io_avg;
79967 #endif
79968-};
79969+
79970+#ifdef CONFIG_GRKERNSEC
79971+ /* grsecurity */
79972+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
79973+ u64 exec_id;
79974+#endif
79975+#ifdef CONFIG_GRKERNSEC_SETXID
79976+ const struct cred *delayed_cred;
79977+#endif
79978+ struct dentry *gr_chroot_dentry;
79979+ struct acl_subject_label *acl;
79980+ struct acl_subject_label *tmpacl;
79981+ struct acl_role_label *role;
79982+ struct file *exec_file;
79983+ unsigned long brute_expires;
79984+ u16 acl_role_id;
79985+ u8 inherited;
79986+ /* is this the task that authenticated to the special role */
79987+ u8 acl_sp_role;
79988+ u8 is_writable;
79989+ u8 brute;
79990+ u8 gr_is_chrooted;
79991+#endif
79992+
79993+} __randomize_layout;
79994+
79995+#define MF_PAX_PAGEEXEC 0x01000000 /* Paging based non-executable pages */
79996+#define MF_PAX_EMUTRAMP 0x02000000 /* Emulate trampolines */
79997+#define MF_PAX_MPROTECT 0x04000000 /* Restrict mprotect() */
79998+#define MF_PAX_RANDMMAP 0x08000000 /* Randomize mmap() base */
79999+/*#define MF_PAX_RANDEXEC 0x10000000*/ /* Randomize ET_EXEC base */
80000+#define MF_PAX_SEGMEXEC 0x20000000 /* Segmentation based non-executable pages */
80001+
80002+#ifdef CONFIG_PAX_SOFTMODE
80003+extern int pax_softmode;
80004+#endif
80005+
80006+extern int pax_check_flags(unsigned long *);
80007+#define PAX_PARSE_FLAGS_FALLBACK (~0UL)
80008+
80009+/* if tsk != current then task_lock must be held on it */
80010+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
80011+static inline unsigned long pax_get_flags(struct task_struct *tsk)
80012+{
80013+ if (likely(tsk->mm))
80014+ return tsk->mm->pax_flags;
80015+ else
80016+ return 0UL;
80017+}
80018+
80019+/* if tsk != current then task_lock must be held on it */
80020+static inline long pax_set_flags(struct task_struct *tsk, unsigned long flags)
80021+{
80022+ if (likely(tsk->mm)) {
80023+ tsk->mm->pax_flags = flags;
80024+ return 0;
80025+ }
80026+ return -EINVAL;
80027+}
80028+#endif
80029+
80030+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
80031+extern void pax_set_initial_flags(struct linux_binprm *bprm);
80032+#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
80033+extern void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
80034+#endif
80035+
80036+struct path;
80037+extern char *pax_get_path(const struct path *path, char *buf, int buflen);
80038+extern void pax_report_fault(struct pt_regs *regs, void *pc, void *sp);
80039+extern void pax_report_insns(struct pt_regs *regs, void *pc, void *sp);
80040+extern void pax_report_refcount_overflow(struct pt_regs *regs);
80041
80042 /* Future-safe accessor for struct task_struct's cpus_allowed. */
80043 #define tsk_cpus_allowed(tsk) (&(tsk)->cpus_allowed)
80044@@ -1471,7 +1582,7 @@ struct pid_namespace;
80045 pid_t __task_pid_nr_ns(struct task_struct *task, enum pid_type type,
80046 struct pid_namespace *ns);
80047
80048-static inline pid_t task_pid_nr(struct task_struct *tsk)
80049+static inline pid_t task_pid_nr(const struct task_struct *tsk)
80050 {
80051 return tsk->pid;
80052 }
80053@@ -1921,7 +2032,9 @@ void yield(void);
80054 extern struct exec_domain default_exec_domain;
80055
80056 union thread_union {
80057+#ifndef CONFIG_X86
80058 struct thread_info thread_info;
80059+#endif
80060 unsigned long stack[THREAD_SIZE/sizeof(long)];
80061 };
80062
80063@@ -1954,6 +2067,7 @@ extern struct pid_namespace init_pid_ns;
80064 */
80065
80066 extern struct task_struct *find_task_by_vpid(pid_t nr);
80067+extern struct task_struct *find_task_by_vpid_unrestricted(pid_t nr);
80068 extern struct task_struct *find_task_by_pid_ns(pid_t nr,
80069 struct pid_namespace *ns);
80070
80071@@ -2118,7 +2232,7 @@ extern void __cleanup_sighand(struct sighand_struct *);
80072 extern void exit_itimers(struct signal_struct *);
80073 extern void flush_itimer_signals(void);
80074
80075-extern void do_group_exit(int);
80076+extern __noreturn void do_group_exit(int);
80077
80078 extern int allow_signal(int);
80079 extern int disallow_signal(int);
80080@@ -2309,9 +2423,9 @@ static inline unsigned long *end_of_stack(struct task_struct *p)
80081
80082 #endif
80083
80084-static inline int object_is_on_stack(void *obj)
80085+static inline int object_starts_on_stack(void *obj)
80086 {
80087- void *stack = task_stack_page(current);
80088+ const void *stack = task_stack_page(current);
80089
80090 return (obj >= stack) && (obj < (stack + THREAD_SIZE));
80091 }
80092diff --git a/include/linux/sched/sysctl.h b/include/linux/sched/sysctl.h
80093index bf8086b..962b035 100644
80094--- a/include/linux/sched/sysctl.h
80095+++ b/include/linux/sched/sysctl.h
80096@@ -30,6 +30,7 @@ enum { sysctl_hung_task_timeout_secs = 0 };
80097 #define DEFAULT_MAX_MAP_COUNT (USHRT_MAX - MAPCOUNT_ELF_CORE_MARGIN)
80098
80099 extern int sysctl_max_map_count;
80100+extern unsigned long sysctl_heap_stack_gap;
80101
80102 extern unsigned int sysctl_sched_latency;
80103 extern unsigned int sysctl_sched_min_granularity;
80104diff --git a/include/linux/security.h b/include/linux/security.h
80105index 9d37e2b..43368e4 100644
80106--- a/include/linux/security.h
80107+++ b/include/linux/security.h
80108@@ -27,6 +27,7 @@
80109 #include <linux/slab.h>
80110 #include <linux/err.h>
80111 #include <linux/string.h>
80112+#include <linux/grsecurity.h>
80113
80114 struct linux_binprm;
80115 struct cred;
80116@@ -116,8 +117,6 @@ struct seq_file;
80117
80118 extern int cap_netlink_send(struct sock *sk, struct sk_buff *skb);
80119
80120-void reset_security_ops(void);
80121-
80122 #ifdef CONFIG_MMU
80123 extern unsigned long mmap_min_addr;
80124 extern unsigned long dac_mmap_min_addr;
80125diff --git a/include/linux/semaphore.h b/include/linux/semaphore.h
80126index dc368b8..e895209 100644
80127--- a/include/linux/semaphore.h
80128+++ b/include/linux/semaphore.h
80129@@ -37,7 +37,7 @@ static inline void sema_init(struct semaphore *sem, int val)
80130 }
80131
80132 extern void down(struct semaphore *sem);
80133-extern int __must_check down_interruptible(struct semaphore *sem);
80134+extern int __must_check down_interruptible(struct semaphore *sem) __intentional_overflow(-1);
80135 extern int __must_check down_killable(struct semaphore *sem);
80136 extern int __must_check down_trylock(struct semaphore *sem);
80137 extern int __must_check down_timeout(struct semaphore *sem, long jiffies);
80138diff --git a/include/linux/seq_file.h b/include/linux/seq_file.h
80139index 4e32edc..f8f2d18 100644
80140--- a/include/linux/seq_file.h
80141+++ b/include/linux/seq_file.h
80142@@ -26,6 +26,9 @@ struct seq_file {
80143 struct mutex lock;
80144 const struct seq_operations *op;
80145 int poll_event;
80146+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
80147+ u64 exec_id;
80148+#endif
80149 #ifdef CONFIG_USER_NS
80150 struct user_namespace *user_ns;
80151 #endif
80152@@ -38,6 +41,7 @@ struct seq_operations {
80153 void * (*next) (struct seq_file *m, void *v, loff_t *pos);
80154 int (*show) (struct seq_file *m, void *v);
80155 };
80156+typedef struct seq_operations __no_const seq_operations_no_const;
80157
80158 #define SEQ_SKIP 1
80159
80160diff --git a/include/linux/shm.h b/include/linux/shm.h
80161index 429c199..4d42e38 100644
80162--- a/include/linux/shm.h
80163+++ b/include/linux/shm.h
80164@@ -21,6 +21,10 @@ struct shmid_kernel /* private to the kernel */
80165
80166 /* The task created the shm object. NULL if the task is dead. */
80167 struct task_struct *shm_creator;
80168+#ifdef CONFIG_GRKERNSEC
80169+ time_t shm_createtime;
80170+ pid_t shm_lapid;
80171+#endif
80172 };
80173
80174 /* shm_mode upper byte flags */
80175diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
80176index efa1649..ff898ac 100644
80177--- a/include/linux/skbuff.h
80178+++ b/include/linux/skbuff.h
80179@@ -639,7 +639,7 @@ extern bool skb_try_coalesce(struct sk_buff *to, struct sk_buff *from,
80180 extern struct sk_buff *__alloc_skb(unsigned int size,
80181 gfp_t priority, int flags, int node);
80182 extern struct sk_buff *build_skb(void *data, unsigned int frag_size);
80183-static inline struct sk_buff *alloc_skb(unsigned int size,
80184+static inline struct sk_buff * __intentional_overflow(0) alloc_skb(unsigned int size,
80185 gfp_t priority)
80186 {
80187 return __alloc_skb(size, priority, 0, NUMA_NO_NODE);
80188@@ -755,7 +755,7 @@ static inline struct skb_shared_hwtstamps *skb_hwtstamps(struct sk_buff *skb)
80189 */
80190 static inline int skb_queue_empty(const struct sk_buff_head *list)
80191 {
80192- return list->next == (struct sk_buff *)list;
80193+ return list->next == (const struct sk_buff *)list;
80194 }
80195
80196 /**
80197@@ -768,7 +768,7 @@ static inline int skb_queue_empty(const struct sk_buff_head *list)
80198 static inline bool skb_queue_is_last(const struct sk_buff_head *list,
80199 const struct sk_buff *skb)
80200 {
80201- return skb->next == (struct sk_buff *)list;
80202+ return skb->next == (const struct sk_buff *)list;
80203 }
80204
80205 /**
80206@@ -781,7 +781,7 @@ static inline bool skb_queue_is_last(const struct sk_buff_head *list,
80207 static inline bool skb_queue_is_first(const struct sk_buff_head *list,
80208 const struct sk_buff *skb)
80209 {
80210- return skb->prev == (struct sk_buff *)list;
80211+ return skb->prev == (const struct sk_buff *)list;
80212 }
80213
80214 /**
80215@@ -1746,7 +1746,7 @@ static inline int pskb_network_may_pull(struct sk_buff *skb, unsigned int len)
80216 * NET_IP_ALIGN(2) + ethernet_header(14) + IP_header(20/40) + ports(8)
80217 */
80218 #ifndef NET_SKB_PAD
80219-#define NET_SKB_PAD max(32, L1_CACHE_BYTES)
80220+#define NET_SKB_PAD max(_AC(32,UL), L1_CACHE_BYTES)
80221 #endif
80222
80223 extern int ___pskb_trim(struct sk_buff *skb, unsigned int len);
80224@@ -2344,7 +2344,7 @@ extern struct sk_buff *skb_recv_datagram(struct sock *sk, unsigned flags,
80225 int noblock, int *err);
80226 extern unsigned int datagram_poll(struct file *file, struct socket *sock,
80227 struct poll_table_struct *wait);
80228-extern int skb_copy_datagram_iovec(const struct sk_buff *from,
80229+extern int __intentional_overflow(0) skb_copy_datagram_iovec(const struct sk_buff *from,
80230 int offset, struct iovec *to,
80231 int size);
80232 extern int skb_copy_and_csum_datagram_iovec(struct sk_buff *skb,
80233@@ -2623,6 +2623,9 @@ static inline void nf_reset(struct sk_buff *skb)
80234 nf_bridge_put(skb->nf_bridge);
80235 skb->nf_bridge = NULL;
80236 #endif
80237+#if IS_ENABLED(CONFIG_NETFILTER_XT_TARGET_TRACE)
80238+ skb->nf_trace = 0;
80239+#endif
80240 }
80241
80242 static inline void nf_reset_trace(struct sk_buff *skb)
80243diff --git a/include/linux/slab.h b/include/linux/slab.h
80244index 74f1058..914b7da 100644
80245--- a/include/linux/slab.h
80246+++ b/include/linux/slab.h
80247@@ -14,15 +14,29 @@
80248 #include <linux/gfp.h>
80249 #include <linux/types.h>
80250 #include <linux/workqueue.h>
80251-
80252+#include <linux/err.h>
80253
80254 /*
80255 * Flags to pass to kmem_cache_create().
80256 * The ones marked DEBUG are only valid if CONFIG_SLAB_DEBUG is set.
80257 */
80258 #define SLAB_DEBUG_FREE 0x00000100UL /* DEBUG: Perform (expensive) checks on free */
80259+
80260+#ifdef CONFIG_PAX_USERCOPY_SLABS
80261+#define SLAB_USERCOPY 0x00000200UL /* PaX: Allow copying objs to/from userland */
80262+#else
80263+#define SLAB_USERCOPY 0x00000000UL
80264+#endif
80265+
80266 #define SLAB_RED_ZONE 0x00000400UL /* DEBUG: Red zone objs in a cache */
80267 #define SLAB_POISON 0x00000800UL /* DEBUG: Poison objects */
80268+
80269+#ifdef CONFIG_PAX_MEMORY_SANITIZE
80270+#define SLAB_NO_SANITIZE 0x00001000UL /* PaX: Do not sanitize objs on free */
80271+#else
80272+#define SLAB_NO_SANITIZE 0x00000000UL
80273+#endif
80274+
80275 #define SLAB_HWCACHE_ALIGN 0x00002000UL /* Align objs on cache lines */
80276 #define SLAB_CACHE_DMA 0x00004000UL /* Use GFP_DMA memory */
80277 #define SLAB_STORE_USER 0x00010000UL /* DEBUG: Store the last owner for bug hunting */
80278@@ -91,10 +105,13 @@
80279 * ZERO_SIZE_PTR can be passed to kfree though in the same way that NULL can.
80280 * Both make kfree a no-op.
80281 */
80282-#define ZERO_SIZE_PTR ((void *)16)
80283+#define ZERO_SIZE_PTR \
80284+({ \
80285+ BUILD_BUG_ON(!(MAX_ERRNO & ~PAGE_MASK));\
80286+ (void *)(-MAX_ERRNO-1L); \
80287+})
80288
80289-#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) <= \
80290- (unsigned long)ZERO_SIZE_PTR)
80291+#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) - 1 >= (unsigned long)ZERO_SIZE_PTR - 1)
80292
80293 #include <linux/kmemleak.h>
80294
80295@@ -135,6 +152,8 @@ void * __must_check krealloc(const void *, size_t, gfp_t);
80296 void kfree(const void *);
80297 void kzfree(const void *);
80298 size_t ksize(const void *);
80299+const char *check_heap_object(const void *ptr, unsigned long n);
80300+bool is_usercopy_object(const void *ptr);
80301
80302 /*
80303 * Some archs want to perform DMA into kmalloc caches and need a guaranteed
80304@@ -167,7 +186,7 @@ struct kmem_cache {
80305 unsigned int align; /* Alignment as calculated */
80306 unsigned long flags; /* Active flags on the slab */
80307 const char *name; /* Slab name for sysfs */
80308- int refcount; /* Use counter */
80309+ atomic_t refcount; /* Use counter */
80310 void (*ctor)(void *); /* Called on object slot creation */
80311 struct list_head list; /* List of all slab caches on the system */
80312 };
80313@@ -241,6 +260,10 @@ extern struct kmem_cache *kmalloc_caches[KMALLOC_SHIFT_HIGH + 1];
80314 extern struct kmem_cache *kmalloc_dma_caches[KMALLOC_SHIFT_HIGH + 1];
80315 #endif
80316
80317+#ifdef CONFIG_PAX_USERCOPY_SLABS
80318+extern struct kmem_cache *kmalloc_usercopy_caches[KMALLOC_SHIFT_HIGH + 1];
80319+#endif
80320+
80321 /*
80322 * Figure out which kmalloc slab an allocation of a certain size
80323 * belongs to.
80324@@ -249,7 +272,7 @@ extern struct kmem_cache *kmalloc_dma_caches[KMALLOC_SHIFT_HIGH + 1];
80325 * 2 = 120 .. 192 bytes
80326 * n = 2^(n-1) .. 2^n -1
80327 */
80328-static __always_inline int kmalloc_index(size_t size)
80329+static __always_inline __size_overflow(1) int kmalloc_index(size_t size)
80330 {
80331 if (!size)
80332 return 0;
80333@@ -292,11 +315,11 @@ static __always_inline int kmalloc_index(size_t size)
80334 }
80335 #endif /* !CONFIG_SLOB */
80336
80337-void *__kmalloc(size_t size, gfp_t flags);
80338+void *__kmalloc(size_t size, gfp_t flags) __alloc_size(1);
80339 void *kmem_cache_alloc(struct kmem_cache *, gfp_t flags);
80340
80341 #ifdef CONFIG_NUMA
80342-void *__kmalloc_node(size_t size, gfp_t flags, int node);
80343+void *__kmalloc_node(size_t size, gfp_t flags, int node) __alloc_size(1);
80344 void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
80345 #else
80346 static __always_inline void *__kmalloc_node(size_t size, gfp_t flags, int node)
80347diff --git a/include/linux/slab_def.h b/include/linux/slab_def.h
80348index e9346b4..1494959 100644
80349--- a/include/linux/slab_def.h
80350+++ b/include/linux/slab_def.h
80351@@ -36,7 +36,7 @@ struct kmem_cache {
80352 /* 4) cache creation/removal */
80353 const char *name;
80354 struct list_head list;
80355- int refcount;
80356+ atomic_t refcount;
80357 int object_size;
80358 int align;
80359
80360@@ -52,10 +52,14 @@ struct kmem_cache {
80361 unsigned long node_allocs;
80362 unsigned long node_frees;
80363 unsigned long node_overflow;
80364- atomic_t allochit;
80365- atomic_t allocmiss;
80366- atomic_t freehit;
80367- atomic_t freemiss;
80368+ atomic_unchecked_t allochit;
80369+ atomic_unchecked_t allocmiss;
80370+ atomic_unchecked_t freehit;
80371+ atomic_unchecked_t freemiss;
80372+#ifdef CONFIG_PAX_MEMORY_SANITIZE
80373+ atomic_unchecked_t sanitized;
80374+ atomic_unchecked_t not_sanitized;
80375+#endif
80376
80377 /*
80378 * If debugging is enabled, then the allocator can add additional
80379diff --git a/include/linux/slub_def.h b/include/linux/slub_def.h
80380index cc0b67e..a0329b1 100644
80381--- a/include/linux/slub_def.h
80382+++ b/include/linux/slub_def.h
80383@@ -74,7 +74,7 @@ struct kmem_cache {
80384 struct kmem_cache_order_objects max;
80385 struct kmem_cache_order_objects min;
80386 gfp_t allocflags; /* gfp flags to use on each alloc */
80387- int refcount; /* Refcount for slab cache destroy */
80388+ atomic_t refcount; /* Refcount for slab cache destroy */
80389 void (*ctor)(void *);
80390 int inuse; /* Offset to metadata */
80391 int align; /* Alignment */
80392diff --git a/include/linux/smp.h b/include/linux/smp.h
80393index 731f523..3340268 100644
80394--- a/include/linux/smp.h
80395+++ b/include/linux/smp.h
80396@@ -186,7 +186,9 @@ static inline void __smp_call_function_single(int cpuid,
80397 #endif
80398
80399 #define get_cpu() ({ preempt_disable(); smp_processor_id(); })
80400+#define raw_get_cpu() ({ raw_preempt_disable(); raw_smp_processor_id(); })
80401 #define put_cpu() preempt_enable()
80402+#define raw_put_cpu_no_resched() raw_preempt_enable_no_resched()
80403
80404 /*
80405 * Callback to arch code if there's nosmp or maxcpus=0 on the
80406diff --git a/include/linux/sock_diag.h b/include/linux/sock_diag.h
80407index 54f91d3..be2c379 100644
80408--- a/include/linux/sock_diag.h
80409+++ b/include/linux/sock_diag.h
80410@@ -11,7 +11,7 @@ struct sock;
80411 struct sock_diag_handler {
80412 __u8 family;
80413 int (*dump)(struct sk_buff *skb, struct nlmsghdr *nlh);
80414-};
80415+} __do_const;
80416
80417 int sock_diag_register(const struct sock_diag_handler *h);
80418 void sock_diag_unregister(const struct sock_diag_handler *h);
80419diff --git a/include/linux/sonet.h b/include/linux/sonet.h
80420index 680f9a3..f13aeb0 100644
80421--- a/include/linux/sonet.h
80422+++ b/include/linux/sonet.h
80423@@ -7,7 +7,7 @@
80424 #include <uapi/linux/sonet.h>
80425
80426 struct k_sonet_stats {
80427-#define __HANDLE_ITEM(i) atomic_t i
80428+#define __HANDLE_ITEM(i) atomic_unchecked_t i
80429 __SONET_ITEMS
80430 #undef __HANDLE_ITEM
80431 };
80432diff --git a/include/linux/sunrpc/addr.h b/include/linux/sunrpc/addr.h
80433index 07d8e53..dc934c9 100644
80434--- a/include/linux/sunrpc/addr.h
80435+++ b/include/linux/sunrpc/addr.h
80436@@ -23,9 +23,9 @@ static inline unsigned short rpc_get_port(const struct sockaddr *sap)
80437 {
80438 switch (sap->sa_family) {
80439 case AF_INET:
80440- return ntohs(((struct sockaddr_in *)sap)->sin_port);
80441+ return ntohs(((const struct sockaddr_in *)sap)->sin_port);
80442 case AF_INET6:
80443- return ntohs(((struct sockaddr_in6 *)sap)->sin6_port);
80444+ return ntohs(((const struct sockaddr_in6 *)sap)->sin6_port);
80445 }
80446 return 0;
80447 }
80448@@ -58,7 +58,7 @@ static inline bool __rpc_cmp_addr4(const struct sockaddr *sap1,
80449 static inline bool __rpc_copy_addr4(struct sockaddr *dst,
80450 const struct sockaddr *src)
80451 {
80452- const struct sockaddr_in *ssin = (struct sockaddr_in *) src;
80453+ const struct sockaddr_in *ssin = (const struct sockaddr_in *) src;
80454 struct sockaddr_in *dsin = (struct sockaddr_in *) dst;
80455
80456 dsin->sin_family = ssin->sin_family;
80457@@ -164,7 +164,7 @@ static inline u32 rpc_get_scope_id(const struct sockaddr *sa)
80458 if (sa->sa_family != AF_INET6)
80459 return 0;
80460
80461- return ((struct sockaddr_in6 *) sa)->sin6_scope_id;
80462+ return ((const struct sockaddr_in6 *) sa)->sin6_scope_id;
80463 }
80464
80465 #endif /* _LINUX_SUNRPC_ADDR_H */
80466diff --git a/include/linux/sunrpc/clnt.h b/include/linux/sunrpc/clnt.h
80467index 6740801..c535f27 100644
80468--- a/include/linux/sunrpc/clnt.h
80469+++ b/include/linux/sunrpc/clnt.h
80470@@ -96,7 +96,7 @@ struct rpc_procinfo {
80471 unsigned int p_timer; /* Which RTT timer to use */
80472 u32 p_statidx; /* Which procedure to account */
80473 const char * p_name; /* name of procedure */
80474-};
80475+} __do_const;
80476
80477 #ifdef __KERNEL__
80478
80479diff --git a/include/linux/sunrpc/svc.h b/include/linux/sunrpc/svc.h
80480index 6eecfc2..7ada79d 100644
80481--- a/include/linux/sunrpc/svc.h
80482+++ b/include/linux/sunrpc/svc.h
80483@@ -410,7 +410,7 @@ struct svc_procedure {
80484 unsigned int pc_count; /* call count */
80485 unsigned int pc_cachetype; /* cache info (NFS) */
80486 unsigned int pc_xdrressize; /* maximum size of XDR reply */
80487-};
80488+} __do_const;
80489
80490 /*
80491 * Function prototypes.
80492diff --git a/include/linux/sunrpc/svc_rdma.h b/include/linux/sunrpc/svc_rdma.h
80493index 0b8e3e6..33e0a01 100644
80494--- a/include/linux/sunrpc/svc_rdma.h
80495+++ b/include/linux/sunrpc/svc_rdma.h
80496@@ -53,15 +53,15 @@ extern unsigned int svcrdma_ord;
80497 extern unsigned int svcrdma_max_requests;
80498 extern unsigned int svcrdma_max_req_size;
80499
80500-extern atomic_t rdma_stat_recv;
80501-extern atomic_t rdma_stat_read;
80502-extern atomic_t rdma_stat_write;
80503-extern atomic_t rdma_stat_sq_starve;
80504-extern atomic_t rdma_stat_rq_starve;
80505-extern atomic_t rdma_stat_rq_poll;
80506-extern atomic_t rdma_stat_rq_prod;
80507-extern atomic_t rdma_stat_sq_poll;
80508-extern atomic_t rdma_stat_sq_prod;
80509+extern atomic_unchecked_t rdma_stat_recv;
80510+extern atomic_unchecked_t rdma_stat_read;
80511+extern atomic_unchecked_t rdma_stat_write;
80512+extern atomic_unchecked_t rdma_stat_sq_starve;
80513+extern atomic_unchecked_t rdma_stat_rq_starve;
80514+extern atomic_unchecked_t rdma_stat_rq_poll;
80515+extern atomic_unchecked_t rdma_stat_rq_prod;
80516+extern atomic_unchecked_t rdma_stat_sq_poll;
80517+extern atomic_unchecked_t rdma_stat_sq_prod;
80518
80519 #define RPCRDMA_VERSION 1
80520
80521diff --git a/include/linux/sunrpc/svcauth.h b/include/linux/sunrpc/svcauth.h
80522index 8d71d65..f79586e 100644
80523--- a/include/linux/sunrpc/svcauth.h
80524+++ b/include/linux/sunrpc/svcauth.h
80525@@ -120,7 +120,7 @@ struct auth_ops {
80526 int (*release)(struct svc_rqst *rq);
80527 void (*domain_release)(struct auth_domain *);
80528 int (*set_client)(struct svc_rqst *rq);
80529-};
80530+} __do_const;
80531
80532 #define SVC_GARBAGE 1
80533 #define SVC_SYSERR 2
80534diff --git a/include/linux/swiotlb.h b/include/linux/swiotlb.h
80535index a5ffd32..0935dea 100644
80536--- a/include/linux/swiotlb.h
80537+++ b/include/linux/swiotlb.h
80538@@ -60,7 +60,8 @@ extern void
80539
80540 extern void
80541 swiotlb_free_coherent(struct device *hwdev, size_t size,
80542- void *vaddr, dma_addr_t dma_handle);
80543+ void *vaddr, dma_addr_t dma_handle,
80544+ struct dma_attrs *attrs);
80545
80546 extern dma_addr_t swiotlb_map_page(struct device *dev, struct page *page,
80547 unsigned long offset, size_t size,
80548diff --git a/include/linux/syscalls.h b/include/linux/syscalls.h
80549index 7fac04e..de57300 100644
80550--- a/include/linux/syscalls.h
80551+++ b/include/linux/syscalls.h
80552@@ -97,8 +97,14 @@ struct sigaltstack;
80553 #define __MAP(n,...) __MAP##n(__VA_ARGS__)
80554
80555 #define __SC_DECL(t, a) t a
80556+#define __TYPE_IS_U(t) (__same_type((t)0, 0UL) || __same_type((t)0, 0U) || __same_type((t)0, (unsigned short)0) || __same_type((t)0, (unsigned char)0))
80557 #define __TYPE_IS_LL(t) (__same_type((t)0, 0LL) || __same_type((t)0, 0ULL))
80558-#define __SC_LONG(t, a) __typeof(__builtin_choose_expr(__TYPE_IS_LL(t), 0LL, 0L)) a
80559+#define __SC_LONG(t, a) __typeof( \
80560+ __builtin_choose_expr( \
80561+ sizeof(t) > sizeof(int), \
80562+ (t) 0, \
80563+ __builtin_choose_expr(__TYPE_IS_U(t), 0UL, 0L) \
80564+ )) a
80565 #define __SC_CAST(t, a) (t) a
80566 #define __SC_ARGS(t, a) a
80567 #define __SC_TEST(t, a) (void)BUILD_BUG_ON_ZERO(!__TYPE_IS_LL(t) && sizeof(t) > sizeof(long))
80568@@ -363,11 +369,11 @@ asmlinkage long sys_sync(void);
80569 asmlinkage long sys_fsync(unsigned int fd);
80570 asmlinkage long sys_fdatasync(unsigned int fd);
80571 asmlinkage long sys_bdflush(int func, long data);
80572-asmlinkage long sys_mount(char __user *dev_name, char __user *dir_name,
80573- char __user *type, unsigned long flags,
80574+asmlinkage long sys_mount(const char __user *dev_name, const char __user *dir_name,
80575+ const char __user *type, unsigned long flags,
80576 void __user *data);
80577-asmlinkage long sys_umount(char __user *name, int flags);
80578-asmlinkage long sys_oldumount(char __user *name);
80579+asmlinkage long sys_umount(const char __user *name, int flags);
80580+asmlinkage long sys_oldumount(const char __user *name);
80581 asmlinkage long sys_truncate(const char __user *path, long length);
80582 asmlinkage long sys_ftruncate(unsigned int fd, unsigned long length);
80583 asmlinkage long sys_stat(const char __user *filename,
80584@@ -579,7 +585,7 @@ asmlinkage long sys_getsockname(int, struct sockaddr __user *, int __user *);
80585 asmlinkage long sys_getpeername(int, struct sockaddr __user *, int __user *);
80586 asmlinkage long sys_send(int, void __user *, size_t, unsigned);
80587 asmlinkage long sys_sendto(int, void __user *, size_t, unsigned,
80588- struct sockaddr __user *, int);
80589+ struct sockaddr __user *, int) __intentional_overflow(0);
80590 asmlinkage long sys_sendmsg(int fd, struct msghdr __user *msg, unsigned flags);
80591 asmlinkage long sys_sendmmsg(int fd, struct mmsghdr __user *msg,
80592 unsigned int vlen, unsigned flags);
80593diff --git a/include/linux/syscore_ops.h b/include/linux/syscore_ops.h
80594index 27b3b0b..e093dd9 100644
80595--- a/include/linux/syscore_ops.h
80596+++ b/include/linux/syscore_ops.h
80597@@ -16,7 +16,7 @@ struct syscore_ops {
80598 int (*suspend)(void);
80599 void (*resume)(void);
80600 void (*shutdown)(void);
80601-};
80602+} __do_const;
80603
80604 extern void register_syscore_ops(struct syscore_ops *ops);
80605 extern void unregister_syscore_ops(struct syscore_ops *ops);
80606diff --git a/include/linux/sysctl.h b/include/linux/sysctl.h
80607index 14a8ff2..fa95f3a 100644
80608--- a/include/linux/sysctl.h
80609+++ b/include/linux/sysctl.h
80610@@ -34,13 +34,13 @@ struct ctl_table_root;
80611 struct ctl_table_header;
80612 struct ctl_dir;
80613
80614-typedef struct ctl_table ctl_table;
80615-
80616 typedef int proc_handler (struct ctl_table *ctl, int write,
80617 void __user *buffer, size_t *lenp, loff_t *ppos);
80618
80619 extern int proc_dostring(struct ctl_table *, int,
80620 void __user *, size_t *, loff_t *);
80621+extern int proc_dostring_modpriv(struct ctl_table *, int,
80622+ void __user *, size_t *, loff_t *);
80623 extern int proc_dointvec(struct ctl_table *, int,
80624 void __user *, size_t *, loff_t *);
80625 extern int proc_dointvec_minmax(struct ctl_table *, int,
80626@@ -115,7 +115,9 @@ struct ctl_table
80627 struct ctl_table_poll *poll;
80628 void *extra1;
80629 void *extra2;
80630-};
80631+} __do_const __randomize_layout;
80632+typedef struct ctl_table __no_const ctl_table_no_const;
80633+typedef struct ctl_table ctl_table;
80634
80635 struct ctl_node {
80636 struct rb_node node;
80637diff --git a/include/linux/sysfs.h b/include/linux/sysfs.h
80638index 11baec7..706f99f 100644
80639--- a/include/linux/sysfs.h
80640+++ b/include/linux/sysfs.h
80641@@ -33,7 +33,8 @@ struct attribute {
80642 struct lock_class_key *key;
80643 struct lock_class_key skey;
80644 #endif
80645-};
80646+} __do_const;
80647+typedef struct attribute __no_const attribute_no_const;
80648
80649 /**
80650 * sysfs_attr_init - initialize a dynamically allocated sysfs attribute
80651@@ -62,7 +63,8 @@ struct attribute_group {
80652 struct attribute *, int);
80653 struct attribute **attrs;
80654 struct bin_attribute **bin_attrs;
80655-};
80656+} __do_const;
80657+typedef struct attribute_group __no_const attribute_group_no_const;
80658
80659 /**
80660 * Use these macros to make defining attributes easier. See include/linux/device.h
80661@@ -126,7 +128,8 @@ struct bin_attribute {
80662 char *, loff_t, size_t);
80663 int (*mmap)(struct file *, struct kobject *, struct bin_attribute *attr,
80664 struct vm_area_struct *vma);
80665-};
80666+} __do_const;
80667+typedef struct bin_attribute __no_const bin_attribute_no_const;
80668
80669 /**
80670 * sysfs_bin_attr_init - initialize a dynamically allocated bin_attribute
80671diff --git a/include/linux/sysrq.h b/include/linux/sysrq.h
80672index 7faf933..9b85a0c 100644
80673--- a/include/linux/sysrq.h
80674+++ b/include/linux/sysrq.h
80675@@ -16,6 +16,7 @@
80676
80677 #include <linux/errno.h>
80678 #include <linux/types.h>
80679+#include <linux/compiler.h>
80680
80681 /* Enable/disable SYSRQ support by default (0==no, 1==yes). */
80682 #define SYSRQ_DEFAULT_ENABLE 1
80683@@ -36,7 +37,7 @@ struct sysrq_key_op {
80684 char *help_msg;
80685 char *action_msg;
80686 int enable_mask;
80687-};
80688+} __do_const;
80689
80690 #ifdef CONFIG_MAGIC_SYSRQ
80691
80692diff --git a/include/linux/thread_info.h b/include/linux/thread_info.h
80693index 4ae6f32..425d3e1 100644
80694--- a/include/linux/thread_info.h
80695+++ b/include/linux/thread_info.h
80696@@ -150,6 +150,15 @@ static inline bool test_and_clear_restore_sigmask(void)
80697 #error "no set_restore_sigmask() provided and default one won't work"
80698 #endif
80699
80700+extern void __check_object_size(const void *ptr, unsigned long n, bool to_user);
80701+static inline void check_object_size(const void *ptr, unsigned long n, bool to_user)
80702+{
80703+#ifndef CONFIG_PAX_USERCOPY_DEBUG
80704+ if (!__builtin_constant_p(n))
80705+#endif
80706+ __check_object_size(ptr, n, to_user);
80707+}
80708+
80709 #endif /* __KERNEL__ */
80710
80711 #endif /* _LINUX_THREAD_INFO_H */
80712diff --git a/include/linux/tty.h b/include/linux/tty.h
80713index 64f8646..924bf66 100644
80714--- a/include/linux/tty.h
80715+++ b/include/linux/tty.h
80716@@ -197,7 +197,7 @@ struct tty_port {
80717 const struct tty_port_operations *ops; /* Port operations */
80718 spinlock_t lock; /* Lock protecting tty field */
80719 int blocked_open; /* Waiting to open */
80720- int count; /* Usage count */
80721+ atomic_t count; /* Usage count */
80722 wait_queue_head_t open_wait; /* Open waiters */
80723 wait_queue_head_t close_wait; /* Close waiters */
80724 wait_queue_head_t delta_msr_wait; /* Modem status change */
80725@@ -279,7 +279,7 @@ struct tty_struct {
80726 /* If the tty has a pending do_SAK, queue it here - akpm */
80727 struct work_struct SAK_work;
80728 struct tty_port *port;
80729-};
80730+} __randomize_layout;
80731
80732 /* Each of a tty's open files has private_data pointing to tty_file_private */
80733 struct tty_file_private {
80734@@ -546,7 +546,7 @@ extern int tty_port_open(struct tty_port *port,
80735 struct tty_struct *tty, struct file *filp);
80736 static inline int tty_port_users(struct tty_port *port)
80737 {
80738- return port->count + port->blocked_open;
80739+ return atomic_read(&port->count) + port->blocked_open;
80740 }
80741
80742 extern int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc);
80743diff --git a/include/linux/tty_driver.h b/include/linux/tty_driver.h
80744index 756a609..f61242d 100644
80745--- a/include/linux/tty_driver.h
80746+++ b/include/linux/tty_driver.h
80747@@ -285,7 +285,7 @@ struct tty_operations {
80748 void (*poll_put_char)(struct tty_driver *driver, int line, char ch);
80749 #endif
80750 const struct file_operations *proc_fops;
80751-};
80752+} __do_const;
80753
80754 struct tty_driver {
80755 int magic; /* magic number for this structure */
80756@@ -319,7 +319,7 @@ struct tty_driver {
80757
80758 const struct tty_operations *ops;
80759 struct list_head tty_drivers;
80760-};
80761+} __randomize_layout;
80762
80763 extern struct list_head tty_drivers;
80764
80765diff --git a/include/linux/tty_ldisc.h b/include/linux/tty_ldisc.h
80766index f15c898..207b7d1 100644
80767--- a/include/linux/tty_ldisc.h
80768+++ b/include/linux/tty_ldisc.h
80769@@ -211,7 +211,7 @@ struct tty_ldisc_ops {
80770
80771 struct module *owner;
80772
80773- int refcount;
80774+ atomic_t refcount;
80775 };
80776
80777 struct tty_ldisc {
80778diff --git a/include/linux/types.h b/include/linux/types.h
80779index 4d118ba..c3ee9bf 100644
80780--- a/include/linux/types.h
80781+++ b/include/linux/types.h
80782@@ -176,10 +176,26 @@ typedef struct {
80783 int counter;
80784 } atomic_t;
80785
80786+#ifdef CONFIG_PAX_REFCOUNT
80787+typedef struct {
80788+ int counter;
80789+} atomic_unchecked_t;
80790+#else
80791+typedef atomic_t atomic_unchecked_t;
80792+#endif
80793+
80794 #ifdef CONFIG_64BIT
80795 typedef struct {
80796 long counter;
80797 } atomic64_t;
80798+
80799+#ifdef CONFIG_PAX_REFCOUNT
80800+typedef struct {
80801+ long counter;
80802+} atomic64_unchecked_t;
80803+#else
80804+typedef atomic64_t atomic64_unchecked_t;
80805+#endif
80806 #endif
80807
80808 struct list_head {
80809diff --git a/include/linux/uaccess.h b/include/linux/uaccess.h
80810index 5ca0951..ab496a5 100644
80811--- a/include/linux/uaccess.h
80812+++ b/include/linux/uaccess.h
80813@@ -76,11 +76,11 @@ static inline unsigned long __copy_from_user_nocache(void *to,
80814 long ret; \
80815 mm_segment_t old_fs = get_fs(); \
80816 \
80817- set_fs(KERNEL_DS); \
80818 pagefault_disable(); \
80819- ret = __copy_from_user_inatomic(&(retval), (__force typeof(retval) __user *)(addr), sizeof(retval)); \
80820- pagefault_enable(); \
80821+ set_fs(KERNEL_DS); \
80822+ ret = __copy_from_user_inatomic(&(retval), (typeof(retval) __force_user *)(addr), sizeof(retval)); \
80823 set_fs(old_fs); \
80824+ pagefault_enable(); \
80825 ret; \
80826 })
80827
80828diff --git a/include/linux/uidgid.h b/include/linux/uidgid.h
80829index 8e522cbc..aa8572d 100644
80830--- a/include/linux/uidgid.h
80831+++ b/include/linux/uidgid.h
80832@@ -197,4 +197,9 @@ static inline bool kgid_has_mapping(struct user_namespace *ns, kgid_t gid)
80833
80834 #endif /* CONFIG_USER_NS */
80835
80836+#define GR_GLOBAL_UID(x) from_kuid_munged(&init_user_ns, (x))
80837+#define GR_GLOBAL_GID(x) from_kgid_munged(&init_user_ns, (x))
80838+#define gr_is_global_root(x) uid_eq((x), GLOBAL_ROOT_UID)
80839+#define gr_is_global_nonroot(x) (!uid_eq((x), GLOBAL_ROOT_UID))
80840+
80841 #endif /* _LINUX_UIDGID_H */
80842diff --git a/include/linux/unaligned/access_ok.h b/include/linux/unaligned/access_ok.h
80843index 99c1b4d..562e6f3 100644
80844--- a/include/linux/unaligned/access_ok.h
80845+++ b/include/linux/unaligned/access_ok.h
80846@@ -4,34 +4,34 @@
80847 #include <linux/kernel.h>
80848 #include <asm/byteorder.h>
80849
80850-static inline u16 get_unaligned_le16(const void *p)
80851+static inline u16 __intentional_overflow(-1) get_unaligned_le16(const void *p)
80852 {
80853- return le16_to_cpup((__le16 *)p);
80854+ return le16_to_cpup((const __le16 *)p);
80855 }
80856
80857-static inline u32 get_unaligned_le32(const void *p)
80858+static inline u32 __intentional_overflow(-1) get_unaligned_le32(const void *p)
80859 {
80860- return le32_to_cpup((__le32 *)p);
80861+ return le32_to_cpup((const __le32 *)p);
80862 }
80863
80864-static inline u64 get_unaligned_le64(const void *p)
80865+static inline u64 __intentional_overflow(-1) get_unaligned_le64(const void *p)
80866 {
80867- return le64_to_cpup((__le64 *)p);
80868+ return le64_to_cpup((const __le64 *)p);
80869 }
80870
80871-static inline u16 get_unaligned_be16(const void *p)
80872+static inline u16 __intentional_overflow(-1) get_unaligned_be16(const void *p)
80873 {
80874- return be16_to_cpup((__be16 *)p);
80875+ return be16_to_cpup((const __be16 *)p);
80876 }
80877
80878-static inline u32 get_unaligned_be32(const void *p)
80879+static inline u32 __intentional_overflow(-1) get_unaligned_be32(const void *p)
80880 {
80881- return be32_to_cpup((__be32 *)p);
80882+ return be32_to_cpup((const __be32 *)p);
80883 }
80884
80885-static inline u64 get_unaligned_be64(const void *p)
80886+static inline u64 __intentional_overflow(-1) get_unaligned_be64(const void *p)
80887 {
80888- return be64_to_cpup((__be64 *)p);
80889+ return be64_to_cpup((const __be64 *)p);
80890 }
80891
80892 static inline void put_unaligned_le16(u16 val, void *p)
80893diff --git a/include/linux/usb.h b/include/linux/usb.h
80894index 6b02370..2355ffa 100644
80895--- a/include/linux/usb.h
80896+++ b/include/linux/usb.h
80897@@ -563,7 +563,7 @@ struct usb_device {
80898 int maxchild;
80899
80900 u32 quirks;
80901- atomic_t urbnum;
80902+ atomic_unchecked_t urbnum;
80903
80904 unsigned long active_duration;
80905
80906@@ -1639,7 +1639,7 @@ void usb_buffer_unmap_sg(const struct usb_device *dev, int is_in,
80907
80908 extern int usb_control_msg(struct usb_device *dev, unsigned int pipe,
80909 __u8 request, __u8 requesttype, __u16 value, __u16 index,
80910- void *data, __u16 size, int timeout);
80911+ void *data, __u16 size, int timeout) __intentional_overflow(-1);
80912 extern int usb_interrupt_msg(struct usb_device *usb_dev, unsigned int pipe,
80913 void *data, int len, int *actual_length, int timeout);
80914 extern int usb_bulk_msg(struct usb_device *usb_dev, unsigned int pipe,
80915diff --git a/include/linux/usb/renesas_usbhs.h b/include/linux/usb/renesas_usbhs.h
80916index e452ba6..78f8e80 100644
80917--- a/include/linux/usb/renesas_usbhs.h
80918+++ b/include/linux/usb/renesas_usbhs.h
80919@@ -39,7 +39,7 @@ enum {
80920 */
80921 struct renesas_usbhs_driver_callback {
80922 int (*notify_hotplug)(struct platform_device *pdev);
80923-};
80924+} __no_const;
80925
80926 /*
80927 * callback functions for platform
80928diff --git a/include/linux/user_namespace.h b/include/linux/user_namespace.h
80929index 4db2985..7d49cac 100644
80930--- a/include/linux/user_namespace.h
80931+++ b/include/linux/user_namespace.h
80932@@ -27,7 +27,7 @@ struct user_namespace {
80933 kuid_t owner;
80934 kgid_t group;
80935 unsigned int proc_inum;
80936-};
80937+} __randomize_layout;
80938
80939 extern struct user_namespace init_user_ns;
80940
80941diff --git a/include/linux/utsname.h b/include/linux/utsname.h
80942index 239e277..22a5cf5 100644
80943--- a/include/linux/utsname.h
80944+++ b/include/linux/utsname.h
80945@@ -24,7 +24,7 @@ struct uts_namespace {
80946 struct new_utsname name;
80947 struct user_namespace *user_ns;
80948 unsigned int proc_inum;
80949-};
80950+} __randomize_layout;
80951 extern struct uts_namespace init_uts_ns;
80952
80953 #ifdef CONFIG_UTS_NS
80954diff --git a/include/linux/vermagic.h b/include/linux/vermagic.h
80955index 6f8fbcf..8259001 100644
80956--- a/include/linux/vermagic.h
80957+++ b/include/linux/vermagic.h
80958@@ -25,9 +25,35 @@
80959 #define MODULE_ARCH_VERMAGIC ""
80960 #endif
80961
80962+#ifdef CONFIG_PAX_REFCOUNT
80963+#define MODULE_PAX_REFCOUNT "REFCOUNT "
80964+#else
80965+#define MODULE_PAX_REFCOUNT ""
80966+#endif
80967+
80968+#ifdef CONSTIFY_PLUGIN
80969+#define MODULE_CONSTIFY_PLUGIN "CONSTIFY_PLUGIN "
80970+#else
80971+#define MODULE_CONSTIFY_PLUGIN ""
80972+#endif
80973+
80974+#ifdef STACKLEAK_PLUGIN
80975+#define MODULE_STACKLEAK_PLUGIN "STACKLEAK_PLUGIN "
80976+#else
80977+#define MODULE_STACKLEAK_PLUGIN ""
80978+#endif
80979+
80980+#ifdef CONFIG_GRKERNSEC
80981+#define MODULE_GRSEC "GRSEC "
80982+#else
80983+#define MODULE_GRSEC ""
80984+#endif
80985+
80986 #define VERMAGIC_STRING \
80987 UTS_RELEASE " " \
80988 MODULE_VERMAGIC_SMP MODULE_VERMAGIC_PREEMPT \
80989 MODULE_VERMAGIC_MODULE_UNLOAD MODULE_VERMAGIC_MODVERSIONS \
80990- MODULE_ARCH_VERMAGIC
80991+ MODULE_ARCH_VERMAGIC \
80992+ MODULE_PAX_REFCOUNT MODULE_CONSTIFY_PLUGIN MODULE_STACKLEAK_PLUGIN \
80993+ MODULE_GRSEC
80994
80995diff --git a/include/linux/vga_switcheroo.h b/include/linux/vga_switcheroo.h
80996index 502073a..a7de024 100644
80997--- a/include/linux/vga_switcheroo.h
80998+++ b/include/linux/vga_switcheroo.h
80999@@ -63,8 +63,8 @@ int vga_switcheroo_get_client_state(struct pci_dev *dev);
81000
81001 void vga_switcheroo_set_dynamic_switch(struct pci_dev *pdev, enum vga_switcheroo_state dynamic);
81002
81003-int vga_switcheroo_init_domain_pm_ops(struct device *dev, struct dev_pm_domain *domain);
81004-int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, struct dev_pm_domain *domain);
81005+int vga_switcheroo_init_domain_pm_ops(struct device *dev, dev_pm_domain_no_const *domain);
81006+int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, dev_pm_domain_no_const *domain);
81007 #else
81008
81009 static inline void vga_switcheroo_unregister_client(struct pci_dev *dev) {}
81010@@ -81,8 +81,8 @@ static inline int vga_switcheroo_get_client_state(struct pci_dev *dev) { return
81011
81012 static inline void vga_switcheroo_set_dynamic_switch(struct pci_dev *pdev, enum vga_switcheroo_state dynamic) {}
81013
81014-static inline int vga_switcheroo_init_domain_pm_ops(struct device *dev, struct dev_pm_domain *domain) { return -EINVAL; }
81015-static inline int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, struct dev_pm_domain *domain) { return -EINVAL; }
81016+static inline int vga_switcheroo_init_domain_pm_ops(struct device *dev, dev_pm_domain_no_const *domain) { return -EINVAL; }
81017+static inline int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, dev_pm_domain_no_const *domain) { return -EINVAL; }
81018
81019 #endif
81020 #endif /* _LINUX_VGA_SWITCHEROO_H_ */
81021diff --git a/include/linux/vmalloc.h b/include/linux/vmalloc.h
81022index 4b8a891..cb8df6e 100644
81023--- a/include/linux/vmalloc.h
81024+++ b/include/linux/vmalloc.h
81025@@ -16,6 +16,11 @@ struct vm_area_struct; /* vma defining user mapping in mm_types.h */
81026 #define VM_USERMAP 0x00000008 /* suitable for remap_vmalloc_range */
81027 #define VM_VPAGES 0x00000010 /* buffer for pages was vmalloc'ed */
81028 #define VM_UNINITIALIZED 0x00000020 /* vm_struct is not fully initialized */
81029+
81030+#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
81031+#define VM_KERNEXEC 0x00000040 /* allocate from executable kernel memory range */
81032+#endif
81033+
81034 /* bits [20..32] reserved for arch specific ioremap internals */
81035
81036 /*
81037@@ -142,7 +147,7 @@ extern void free_vm_area(struct vm_struct *area);
81038
81039 /* for /dev/kmem */
81040 extern long vread(char *buf, char *addr, unsigned long count);
81041-extern long vwrite(char *buf, char *addr, unsigned long count);
81042+extern long vwrite(char *buf, char *addr, unsigned long count) __size_overflow(3);
81043
81044 /*
81045 * Internals. Dont't use..
81046diff --git a/include/linux/vmstat.h b/include/linux/vmstat.h
81047index e4b9480..5a5f65a 100644
81048--- a/include/linux/vmstat.h
81049+++ b/include/linux/vmstat.h
81050@@ -90,18 +90,18 @@ static inline void vm_events_fold_cpu(int cpu)
81051 /*
81052 * Zone based page accounting with per cpu differentials.
81053 */
81054-extern atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
81055+extern atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
81056
81057 static inline void zone_page_state_add(long x, struct zone *zone,
81058 enum zone_stat_item item)
81059 {
81060- atomic_long_add(x, &zone->vm_stat[item]);
81061- atomic_long_add(x, &vm_stat[item]);
81062+ atomic_long_add_unchecked(x, &zone->vm_stat[item]);
81063+ atomic_long_add_unchecked(x, &vm_stat[item]);
81064 }
81065
81066-static inline unsigned long global_page_state(enum zone_stat_item item)
81067+static inline unsigned long __intentional_overflow(-1) global_page_state(enum zone_stat_item item)
81068 {
81069- long x = atomic_long_read(&vm_stat[item]);
81070+ long x = atomic_long_read_unchecked(&vm_stat[item]);
81071 #ifdef CONFIG_SMP
81072 if (x < 0)
81073 x = 0;
81074@@ -109,10 +109,10 @@ static inline unsigned long global_page_state(enum zone_stat_item item)
81075 return x;
81076 }
81077
81078-static inline unsigned long zone_page_state(struct zone *zone,
81079+static inline unsigned long __intentional_overflow(-1) zone_page_state(struct zone *zone,
81080 enum zone_stat_item item)
81081 {
81082- long x = atomic_long_read(&zone->vm_stat[item]);
81083+ long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
81084 #ifdef CONFIG_SMP
81085 if (x < 0)
81086 x = 0;
81087@@ -129,7 +129,7 @@ static inline unsigned long zone_page_state(struct zone *zone,
81088 static inline unsigned long zone_page_state_snapshot(struct zone *zone,
81089 enum zone_stat_item item)
81090 {
81091- long x = atomic_long_read(&zone->vm_stat[item]);
81092+ long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
81093
81094 #ifdef CONFIG_SMP
81095 int cpu;
81096@@ -220,8 +220,8 @@ static inline void __mod_zone_page_state(struct zone *zone,
81097
81098 static inline void __inc_zone_state(struct zone *zone, enum zone_stat_item item)
81099 {
81100- atomic_long_inc(&zone->vm_stat[item]);
81101- atomic_long_inc(&vm_stat[item]);
81102+ atomic_long_inc_unchecked(&zone->vm_stat[item]);
81103+ atomic_long_inc_unchecked(&vm_stat[item]);
81104 }
81105
81106 static inline void __inc_zone_page_state(struct page *page,
81107@@ -232,8 +232,8 @@ static inline void __inc_zone_page_state(struct page *page,
81108
81109 static inline void __dec_zone_state(struct zone *zone, enum zone_stat_item item)
81110 {
81111- atomic_long_dec(&zone->vm_stat[item]);
81112- atomic_long_dec(&vm_stat[item]);
81113+ atomic_long_dec_unchecked(&zone->vm_stat[item]);
81114+ atomic_long_dec_unchecked(&vm_stat[item]);
81115 }
81116
81117 static inline void __dec_zone_page_state(struct page *page,
81118diff --git a/include/linux/xattr.h b/include/linux/xattr.h
81119index 91b0a68..0e9adf6 100644
81120--- a/include/linux/xattr.h
81121+++ b/include/linux/xattr.h
81122@@ -28,7 +28,7 @@ struct xattr_handler {
81123 size_t size, int handler_flags);
81124 int (*set)(struct dentry *dentry, const char *name, const void *buffer,
81125 size_t size, int flags, int handler_flags);
81126-};
81127+} __do_const;
81128
81129 struct xattr {
81130 const char *name;
81131@@ -37,6 +37,9 @@ struct xattr {
81132 };
81133
81134 ssize_t xattr_getsecurity(struct inode *, const char *, void *, size_t);
81135+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
81136+ssize_t pax_getxattr(struct dentry *, void *, size_t);
81137+#endif
81138 ssize_t vfs_getxattr(struct dentry *, const char *, void *, size_t);
81139 ssize_t vfs_listxattr(struct dentry *d, char *list, size_t size);
81140 int __vfs_setxattr_noperm(struct dentry *, const char *, const void *, size_t, int);
81141diff --git a/include/linux/zlib.h b/include/linux/zlib.h
81142index 9c5a6b4..09c9438 100644
81143--- a/include/linux/zlib.h
81144+++ b/include/linux/zlib.h
81145@@ -31,6 +31,7 @@
81146 #define _ZLIB_H
81147
81148 #include <linux/zconf.h>
81149+#include <linux/compiler.h>
81150
81151 /* zlib deflate based on ZLIB_VERSION "1.1.3" */
81152 /* zlib inflate based on ZLIB_VERSION "1.2.3" */
81153@@ -179,7 +180,7 @@ typedef z_stream *z_streamp;
81154
81155 /* basic functions */
81156
81157-extern int zlib_deflate_workspacesize (int windowBits, int memLevel);
81158+extern int zlib_deflate_workspacesize (int windowBits, int memLevel) __intentional_overflow(0);
81159 /*
81160 Returns the number of bytes that needs to be allocated for a per-
81161 stream workspace with the specified parameters. A pointer to this
81162diff --git a/include/media/v4l2-dev.h b/include/media/v4l2-dev.h
81163index c768c9f..bdcaa5a 100644
81164--- a/include/media/v4l2-dev.h
81165+++ b/include/media/v4l2-dev.h
81166@@ -76,7 +76,7 @@ struct v4l2_file_operations {
81167 int (*mmap) (struct file *, struct vm_area_struct *);
81168 int (*open) (struct file *);
81169 int (*release) (struct file *);
81170-};
81171+} __do_const;
81172
81173 /*
81174 * Newer version of video_device, handled by videodev2.c
81175diff --git a/include/media/v4l2-device.h b/include/media/v4l2-device.h
81176index c9b1593..a572459 100644
81177--- a/include/media/v4l2-device.h
81178+++ b/include/media/v4l2-device.h
81179@@ -95,7 +95,7 @@ int __must_check v4l2_device_register(struct device *dev, struct v4l2_device *v4
81180 this function returns 0. If the name ends with a digit (e.g. cx18),
81181 then the name will be set to cx18-0 since cx180 looks really odd. */
81182 int v4l2_device_set_name(struct v4l2_device *v4l2_dev, const char *basename,
81183- atomic_t *instance);
81184+ atomic_unchecked_t *instance);
81185
81186 /* Set v4l2_dev->dev to NULL. Call when the USB parent disconnects.
81187 Since the parent disappears this ensures that v4l2_dev doesn't have an
81188diff --git a/include/net/9p/transport.h b/include/net/9p/transport.h
81189index 9a36d92..0aafe2a 100644
81190--- a/include/net/9p/transport.h
81191+++ b/include/net/9p/transport.h
81192@@ -60,7 +60,7 @@ struct p9_trans_module {
81193 int (*cancel) (struct p9_client *, struct p9_req_t *req);
81194 int (*zc_request)(struct p9_client *, struct p9_req_t *,
81195 char *, char *, int , int, int, int);
81196-};
81197+} __do_const;
81198
81199 void v9fs_register_trans(struct p9_trans_module *m);
81200 void v9fs_unregister_trans(struct p9_trans_module *m);
81201diff --git a/include/net/bluetooth/l2cap.h b/include/net/bluetooth/l2cap.h
81202index 1a966af..2767cf6 100644
81203--- a/include/net/bluetooth/l2cap.h
81204+++ b/include/net/bluetooth/l2cap.h
81205@@ -551,7 +551,7 @@ struct l2cap_ops {
81206 void (*defer) (struct l2cap_chan *chan);
81207 struct sk_buff *(*alloc_skb) (struct l2cap_chan *chan,
81208 unsigned long len, int nb);
81209-};
81210+} __do_const;
81211
81212 struct l2cap_conn {
81213 struct hci_conn *hcon;
81214diff --git a/include/net/caif/cfctrl.h b/include/net/caif/cfctrl.h
81215index f2ae33d..c457cf0 100644
81216--- a/include/net/caif/cfctrl.h
81217+++ b/include/net/caif/cfctrl.h
81218@@ -52,7 +52,7 @@ struct cfctrl_rsp {
81219 void (*radioset_rsp)(void);
81220 void (*reject_rsp)(struct cflayer *layer, u8 linkid,
81221 struct cflayer *client_layer);
81222-};
81223+} __no_const;
81224
81225 /* Link Setup Parameters for CAIF-Links. */
81226 struct cfctrl_link_param {
81227@@ -101,8 +101,8 @@ struct cfctrl_request_info {
81228 struct cfctrl {
81229 struct cfsrvl serv;
81230 struct cfctrl_rsp res;
81231- atomic_t req_seq_no;
81232- atomic_t rsp_seq_no;
81233+ atomic_unchecked_t req_seq_no;
81234+ atomic_unchecked_t rsp_seq_no;
81235 struct list_head list;
81236 /* Protects from simultaneous access to first_req list */
81237 spinlock_t info_list_lock;
81238diff --git a/include/net/flow.h b/include/net/flow.h
81239index 628e11b..4c475df 100644
81240--- a/include/net/flow.h
81241+++ b/include/net/flow.h
81242@@ -221,6 +221,6 @@ extern struct flow_cache_object *flow_cache_lookup(
81243
81244 extern void flow_cache_flush(void);
81245 extern void flow_cache_flush_deferred(void);
81246-extern atomic_t flow_cache_genid;
81247+extern atomic_unchecked_t flow_cache_genid;
81248
81249 #endif
81250diff --git a/include/net/genetlink.h b/include/net/genetlink.h
81251index 8e0b6c8..73cf605 100644
81252--- a/include/net/genetlink.h
81253+++ b/include/net/genetlink.h
81254@@ -120,7 +120,7 @@ struct genl_ops {
81255 struct netlink_callback *cb);
81256 int (*done)(struct netlink_callback *cb);
81257 struct list_head ops_list;
81258-};
81259+} __do_const;
81260
81261 extern int __genl_register_family(struct genl_family *family);
81262
81263diff --git a/include/net/gro_cells.h b/include/net/gro_cells.h
81264index 734d9b5..48a9a4b 100644
81265--- a/include/net/gro_cells.h
81266+++ b/include/net/gro_cells.h
81267@@ -29,7 +29,7 @@ static inline void gro_cells_receive(struct gro_cells *gcells, struct sk_buff *s
81268 cell += skb_get_rx_queue(skb) & gcells->gro_cells_mask;
81269
81270 if (skb_queue_len(&cell->napi_skbs) > netdev_max_backlog) {
81271- atomic_long_inc(&dev->rx_dropped);
81272+ atomic_long_inc_unchecked(&dev->rx_dropped);
81273 kfree_skb(skb);
81274 return;
81275 }
81276diff --git a/include/net/inet_connection_sock.h b/include/net/inet_connection_sock.h
81277index de2c785..0588a6b 100644
81278--- a/include/net/inet_connection_sock.h
81279+++ b/include/net/inet_connection_sock.h
81280@@ -62,7 +62,7 @@ struct inet_connection_sock_af_ops {
81281 void (*addr2sockaddr)(struct sock *sk, struct sockaddr *);
81282 int (*bind_conflict)(const struct sock *sk,
81283 const struct inet_bind_bucket *tb, bool relax);
81284-};
81285+} __do_const;
81286
81287 /** inet_connection_sock - INET connection oriented sock
81288 *
81289diff --git a/include/net/inetpeer.h b/include/net/inetpeer.h
81290index 53f464d..0bd0b49 100644
81291--- a/include/net/inetpeer.h
81292+++ b/include/net/inetpeer.h
81293@@ -47,8 +47,8 @@ struct inet_peer {
81294 */
81295 union {
81296 struct {
81297- atomic_t rid; /* Frag reception counter */
81298- atomic_t ip_id_count; /* IP ID for the next packet */
81299+ atomic_unchecked_t rid; /* Frag reception counter */
81300+ atomic_unchecked_t ip_id_count; /* IP ID for the next packet */
81301 };
81302 struct rcu_head rcu;
81303 struct inet_peer *gc_next;
81304@@ -178,16 +178,13 @@ static inline void inet_peer_refcheck(const struct inet_peer *p)
81305 /* can be called with or without local BH being disabled */
81306 static inline int inet_getid(struct inet_peer *p, int more)
81307 {
81308- int old, new;
81309+ int id;
81310 more++;
81311 inet_peer_refcheck(p);
81312- do {
81313- old = atomic_read(&p->ip_id_count);
81314- new = old + more;
81315- if (!new)
81316- new = 1;
81317- } while (atomic_cmpxchg(&p->ip_id_count, old, new) != old);
81318- return new;
81319+ id = atomic_add_return_unchecked(more, &p->ip_id_count);
81320+ if (!id)
81321+ id = atomic_inc_return_unchecked(&p->ip_id_count);
81322+ return id;
81323 }
81324
81325 #endif /* _NET_INETPEER_H */
81326diff --git a/include/net/ip.h b/include/net/ip.h
81327index 301f10c..b52cdaf 100644
81328--- a/include/net/ip.h
81329+++ b/include/net/ip.h
81330@@ -212,7 +212,7 @@ extern struct local_ports {
81331 } sysctl_local_ports;
81332 extern void inet_get_local_port_range(int *low, int *high);
81333
81334-extern unsigned long *sysctl_local_reserved_ports;
81335+extern unsigned long sysctl_local_reserved_ports[65536 / 8 / sizeof(unsigned long)];
81336 static inline int inet_is_reserved_local_port(int port)
81337 {
81338 return test_bit(port, sysctl_local_reserved_ports);
81339diff --git a/include/net/ip_fib.h b/include/net/ip_fib.h
81340index cbf2be3..3683f6d 100644
81341--- a/include/net/ip_fib.h
81342+++ b/include/net/ip_fib.h
81343@@ -169,7 +169,7 @@ extern __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh);
81344
81345 #define FIB_RES_SADDR(net, res) \
81346 ((FIB_RES_NH(res).nh_saddr_genid == \
81347- atomic_read(&(net)->ipv4.dev_addr_genid)) ? \
81348+ atomic_read_unchecked(&(net)->ipv4.dev_addr_genid)) ? \
81349 FIB_RES_NH(res).nh_saddr : \
81350 fib_info_update_nh_saddr((net), &FIB_RES_NH(res)))
81351 #define FIB_RES_GW(res) (FIB_RES_NH(res).nh_gw)
81352diff --git a/include/net/ip_vs.h b/include/net/ip_vs.h
81353index 772252d..1e69799 100644
81354--- a/include/net/ip_vs.h
81355+++ b/include/net/ip_vs.h
81356@@ -558,7 +558,7 @@ struct ip_vs_conn {
81357 struct ip_vs_conn *control; /* Master control connection */
81358 atomic_t n_control; /* Number of controlled ones */
81359 struct ip_vs_dest *dest; /* real server */
81360- atomic_t in_pkts; /* incoming packet counter */
81361+ atomic_unchecked_t in_pkts; /* incoming packet counter */
81362
81363 /* packet transmitter for different forwarding methods. If it
81364 mangles the packet, it must return NF_DROP or better NF_STOLEN,
81365@@ -705,7 +705,7 @@ struct ip_vs_dest {
81366 __be16 port; /* port number of the server */
81367 union nf_inet_addr addr; /* IP address of the server */
81368 volatile unsigned int flags; /* dest status flags */
81369- atomic_t conn_flags; /* flags to copy to conn */
81370+ atomic_unchecked_t conn_flags; /* flags to copy to conn */
81371 atomic_t weight; /* server weight */
81372
81373 atomic_t refcnt; /* reference counter */
81374@@ -960,11 +960,11 @@ struct netns_ipvs {
81375 /* ip_vs_lblc */
81376 int sysctl_lblc_expiration;
81377 struct ctl_table_header *lblc_ctl_header;
81378- struct ctl_table *lblc_ctl_table;
81379+ ctl_table_no_const *lblc_ctl_table;
81380 /* ip_vs_lblcr */
81381 int sysctl_lblcr_expiration;
81382 struct ctl_table_header *lblcr_ctl_header;
81383- struct ctl_table *lblcr_ctl_table;
81384+ ctl_table_no_const *lblcr_ctl_table;
81385 /* ip_vs_est */
81386 struct list_head est_list; /* estimator list */
81387 spinlock_t est_lock;
81388diff --git a/include/net/irda/ircomm_tty.h b/include/net/irda/ircomm_tty.h
81389index 80ffde3..968b0f4 100644
81390--- a/include/net/irda/ircomm_tty.h
81391+++ b/include/net/irda/ircomm_tty.h
81392@@ -35,6 +35,7 @@
81393 #include <linux/termios.h>
81394 #include <linux/timer.h>
81395 #include <linux/tty.h> /* struct tty_struct */
81396+#include <asm/local.h>
81397
81398 #include <net/irda/irias_object.h>
81399 #include <net/irda/ircomm_core.h>
81400diff --git a/include/net/iucv/af_iucv.h b/include/net/iucv/af_iucv.h
81401index 714cc9a..ea05f3e 100644
81402--- a/include/net/iucv/af_iucv.h
81403+++ b/include/net/iucv/af_iucv.h
81404@@ -149,7 +149,7 @@ struct iucv_skb_cb {
81405 struct iucv_sock_list {
81406 struct hlist_head head;
81407 rwlock_t lock;
81408- atomic_t autobind_name;
81409+ atomic_unchecked_t autobind_name;
81410 };
81411
81412 unsigned int iucv_sock_poll(struct file *file, struct socket *sock,
81413diff --git a/include/net/llc_c_ac.h b/include/net/llc_c_ac.h
81414index df83f69..9b640b8 100644
81415--- a/include/net/llc_c_ac.h
81416+++ b/include/net/llc_c_ac.h
81417@@ -87,7 +87,7 @@
81418 #define LLC_CONN_AC_STOP_SENDACK_TMR 70
81419 #define LLC_CONN_AC_START_SENDACK_TMR_IF_NOT_RUNNING 71
81420
81421-typedef int (*llc_conn_action_t)(struct sock *sk, struct sk_buff *skb);
81422+typedef int (* const llc_conn_action_t)(struct sock *sk, struct sk_buff *skb);
81423
81424 extern int llc_conn_ac_clear_remote_busy(struct sock *sk, struct sk_buff *skb);
81425 extern int llc_conn_ac_conn_ind(struct sock *sk, struct sk_buff *skb);
81426diff --git a/include/net/llc_c_ev.h b/include/net/llc_c_ev.h
81427index 6ca3113..f8026dd 100644
81428--- a/include/net/llc_c_ev.h
81429+++ b/include/net/llc_c_ev.h
81430@@ -125,8 +125,8 @@ static __inline__ struct llc_conn_state_ev *llc_conn_ev(struct sk_buff *skb)
81431 return (struct llc_conn_state_ev *)skb->cb;
81432 }
81433
81434-typedef int (*llc_conn_ev_t)(struct sock *sk, struct sk_buff *skb);
81435-typedef int (*llc_conn_ev_qfyr_t)(struct sock *sk, struct sk_buff *skb);
81436+typedef int (* const llc_conn_ev_t)(struct sock *sk, struct sk_buff *skb);
81437+typedef int (* const llc_conn_ev_qfyr_t)(struct sock *sk, struct sk_buff *skb);
81438
81439 extern int llc_conn_ev_conn_req(struct sock *sk, struct sk_buff *skb);
81440 extern int llc_conn_ev_data_req(struct sock *sk, struct sk_buff *skb);
81441diff --git a/include/net/llc_c_st.h b/include/net/llc_c_st.h
81442index 0e79cfb..f46db31 100644
81443--- a/include/net/llc_c_st.h
81444+++ b/include/net/llc_c_st.h
81445@@ -37,7 +37,7 @@ struct llc_conn_state_trans {
81446 u8 next_state;
81447 llc_conn_ev_qfyr_t *ev_qualifiers;
81448 llc_conn_action_t *ev_actions;
81449-};
81450+} __do_const;
81451
81452 struct llc_conn_state {
81453 u8 current_state;
81454diff --git a/include/net/llc_s_ac.h b/include/net/llc_s_ac.h
81455index 37a3bbd..55a4241 100644
81456--- a/include/net/llc_s_ac.h
81457+++ b/include/net/llc_s_ac.h
81458@@ -23,7 +23,7 @@
81459 #define SAP_ACT_TEST_IND 9
81460
81461 /* All action functions must look like this */
81462-typedef int (*llc_sap_action_t)(struct llc_sap *sap, struct sk_buff *skb);
81463+typedef int (* const llc_sap_action_t)(struct llc_sap *sap, struct sk_buff *skb);
81464
81465 extern int llc_sap_action_unitdata_ind(struct llc_sap *sap,
81466 struct sk_buff *skb);
81467diff --git a/include/net/llc_s_st.h b/include/net/llc_s_st.h
81468index 567c681..cd73ac0 100644
81469--- a/include/net/llc_s_st.h
81470+++ b/include/net/llc_s_st.h
81471@@ -20,7 +20,7 @@ struct llc_sap_state_trans {
81472 llc_sap_ev_t ev;
81473 u8 next_state;
81474 llc_sap_action_t *ev_actions;
81475-};
81476+} __do_const;
81477
81478 struct llc_sap_state {
81479 u8 curr_state;
81480diff --git a/include/net/mac80211.h b/include/net/mac80211.h
81481index cc6035f..a8406fc 100644
81482--- a/include/net/mac80211.h
81483+++ b/include/net/mac80211.h
81484@@ -4361,7 +4361,7 @@ struct rate_control_ops {
81485 void (*add_sta_debugfs)(void *priv, void *priv_sta,
81486 struct dentry *dir);
81487 void (*remove_sta_debugfs)(void *priv, void *priv_sta);
81488-};
81489+} __do_const;
81490
81491 static inline int rate_supported(struct ieee80211_sta *sta,
81492 enum ieee80211_band band,
81493diff --git a/include/net/neighbour.h b/include/net/neighbour.h
81494index 536501a..74ad02bc 100644
81495--- a/include/net/neighbour.h
81496+++ b/include/net/neighbour.h
81497@@ -123,7 +123,7 @@ struct neigh_ops {
81498 void (*error_report)(struct neighbour *, struct sk_buff *);
81499 int (*output)(struct neighbour *, struct sk_buff *);
81500 int (*connected_output)(struct neighbour *, struct sk_buff *);
81501-};
81502+} __do_const;
81503
81504 struct pneigh_entry {
81505 struct pneigh_entry *next;
81506@@ -178,7 +178,7 @@ struct neigh_table {
81507 struct neigh_statistics __percpu *stats;
81508 struct neigh_hash_table __rcu *nht;
81509 struct pneigh_entry **phash_buckets;
81510-};
81511+} __randomize_layout;
81512
81513 #define NEIGH_PRIV_ALIGN sizeof(long long)
81514 #define NEIGH_ENTRY_SIZE(size) ALIGN((size), NEIGH_PRIV_ALIGN)
81515diff --git a/include/net/net_namespace.h b/include/net/net_namespace.h
81516index 9d22f08..b2a612a 100644
81517--- a/include/net/net_namespace.h
81518+++ b/include/net/net_namespace.h
81519@@ -120,8 +120,8 @@ struct net {
81520 struct netns_ipvs *ipvs;
81521 #endif
81522 struct sock *diag_nlsk;
81523- atomic_t fnhe_genid;
81524-};
81525+ atomic_unchecked_t fnhe_genid;
81526+} __randomize_layout;
81527
81528 /*
81529 * ifindex generation is per-net namespace, and loopback is
81530@@ -277,7 +277,11 @@ static inline struct net *read_pnet(struct net * const *pnet)
81531 #define __net_init __init
81532 #define __net_exit __exit_refok
81533 #define __net_initdata __initdata
81534+#ifdef CONSTIFY_PLUGIN
81535 #define __net_initconst __initconst
81536+#else
81537+#define __net_initconst __initdata
81538+#endif
81539 #endif
81540
81541 struct pernet_operations {
81542@@ -287,7 +291,7 @@ struct pernet_operations {
81543 void (*exit_batch)(struct list_head *net_exit_list);
81544 int *id;
81545 size_t size;
81546-};
81547+} __do_const;
81548
81549 /*
81550 * Use these carefully. If you implement a network device and it
81551@@ -335,23 +339,23 @@ static inline void unregister_net_sysctl_table(struct ctl_table_header *header)
81552
81553 static inline int rt_genid_ipv4(struct net *net)
81554 {
81555- return atomic_read(&net->ipv4.rt_genid);
81556+ return atomic_read_unchecked(&net->ipv4.rt_genid);
81557 }
81558
81559 static inline void rt_genid_bump_ipv4(struct net *net)
81560 {
81561- atomic_inc(&net->ipv4.rt_genid);
81562+ atomic_inc_unchecked(&net->ipv4.rt_genid);
81563 }
81564
81565 #if IS_ENABLED(CONFIG_IPV6)
81566 static inline int rt_genid_ipv6(struct net *net)
81567 {
81568- return atomic_read(&net->ipv6.rt_genid);
81569+ return atomic_read_unchecked(&net->ipv6.rt_genid);
81570 }
81571
81572 static inline void rt_genid_bump_ipv6(struct net *net)
81573 {
81574- atomic_inc(&net->ipv6.rt_genid);
81575+ atomic_inc_unchecked(&net->ipv6.rt_genid);
81576 }
81577 #else
81578 static inline int rt_genid_ipv6(struct net *net)
81579@@ -373,12 +377,12 @@ static inline void rt_genid_bump_all(struct net *net)
81580
81581 static inline int fnhe_genid(struct net *net)
81582 {
81583- return atomic_read(&net->fnhe_genid);
81584+ return atomic_read_unchecked(&net->fnhe_genid);
81585 }
81586
81587 static inline void fnhe_genid_bump(struct net *net)
81588 {
81589- atomic_inc(&net->fnhe_genid);
81590+ atomic_inc_unchecked(&net->fnhe_genid);
81591 }
81592
81593 #endif /* __NET_NET_NAMESPACE_H */
81594diff --git a/include/net/netdma.h b/include/net/netdma.h
81595index 8ba8ce2..99b7fff 100644
81596--- a/include/net/netdma.h
81597+++ b/include/net/netdma.h
81598@@ -24,7 +24,7 @@
81599 #include <linux/dmaengine.h>
81600 #include <linux/skbuff.h>
81601
81602-int dma_skb_copy_datagram_iovec(struct dma_chan* chan,
81603+int __intentional_overflow(3,5) dma_skb_copy_datagram_iovec(struct dma_chan* chan,
81604 struct sk_buff *skb, int offset, struct iovec *to,
81605 size_t len, struct dma_pinned_list *pinned_list);
81606
81607diff --git a/include/net/netlink.h b/include/net/netlink.h
81608index 9690b0f..87aded7 100644
81609--- a/include/net/netlink.h
81610+++ b/include/net/netlink.h
81611@@ -534,7 +534,7 @@ static inline void *nlmsg_get_pos(struct sk_buff *skb)
81612 static inline void nlmsg_trim(struct sk_buff *skb, const void *mark)
81613 {
81614 if (mark)
81615- skb_trim(skb, (unsigned char *) mark - skb->data);
81616+ skb_trim(skb, (const unsigned char *) mark - skb->data);
81617 }
81618
81619 /**
81620diff --git a/include/net/netns/conntrack.h b/include/net/netns/conntrack.h
81621index c9c0c53..53f24c3 100644
81622--- a/include/net/netns/conntrack.h
81623+++ b/include/net/netns/conntrack.h
81624@@ -12,10 +12,10 @@ struct nf_conntrack_ecache;
81625 struct nf_proto_net {
81626 #ifdef CONFIG_SYSCTL
81627 struct ctl_table_header *ctl_table_header;
81628- struct ctl_table *ctl_table;
81629+ ctl_table_no_const *ctl_table;
81630 #ifdef CONFIG_NF_CONNTRACK_PROC_COMPAT
81631 struct ctl_table_header *ctl_compat_header;
81632- struct ctl_table *ctl_compat_table;
81633+ ctl_table_no_const *ctl_compat_table;
81634 #endif
81635 #endif
81636 unsigned int users;
81637@@ -58,7 +58,7 @@ struct nf_ip_net {
81638 struct nf_icmp_net icmpv6;
81639 #if defined(CONFIG_SYSCTL) && defined(CONFIG_NF_CONNTRACK_PROC_COMPAT)
81640 struct ctl_table_header *ctl_table_header;
81641- struct ctl_table *ctl_table;
81642+ ctl_table_no_const *ctl_table;
81643 #endif
81644 };
81645
81646diff --git a/include/net/netns/ipv4.h b/include/net/netns/ipv4.h
81647index bf2ec22..5e7f9d9 100644
81648--- a/include/net/netns/ipv4.h
81649+++ b/include/net/netns/ipv4.h
81650@@ -67,7 +67,7 @@ struct netns_ipv4 {
81651 kgid_t sysctl_ping_group_range[2];
81652 long sysctl_tcp_mem[3];
81653
81654- atomic_t dev_addr_genid;
81655+ atomic_unchecked_t dev_addr_genid;
81656
81657 #ifdef CONFIG_IP_MROUTE
81658 #ifndef CONFIG_IP_MROUTE_MULTIPLE_TABLES
81659@@ -77,6 +77,6 @@ struct netns_ipv4 {
81660 struct fib_rules_ops *mr_rules_ops;
81661 #endif
81662 #endif
81663- atomic_t rt_genid;
81664+ atomic_unchecked_t rt_genid;
81665 };
81666 #endif
81667diff --git a/include/net/netns/ipv6.h b/include/net/netns/ipv6.h
81668index 0fb2401..477d81c 100644
81669--- a/include/net/netns/ipv6.h
81670+++ b/include/net/netns/ipv6.h
81671@@ -71,8 +71,8 @@ struct netns_ipv6 {
81672 struct fib_rules_ops *mr6_rules_ops;
81673 #endif
81674 #endif
81675- atomic_t dev_addr_genid;
81676- atomic_t rt_genid;
81677+ atomic_unchecked_t dev_addr_genid;
81678+ atomic_unchecked_t rt_genid;
81679 };
81680
81681 #if IS_ENABLED(CONFIG_NF_DEFRAG_IPV6)
81682diff --git a/include/net/ping.h b/include/net/ping.h
81683index 2b496e9..935fd8d 100644
81684--- a/include/net/ping.h
81685+++ b/include/net/ping.h
81686@@ -56,7 +56,7 @@ struct ping_iter_state {
81687 extern struct proto ping_prot;
81688 extern struct ping_table ping_table;
81689 #if IS_ENABLED(CONFIG_IPV6)
81690-extern struct pingv6_ops pingv6_ops;
81691+extern struct pingv6_ops *pingv6_ops;
81692 #endif
81693
81694 struct pingfakehdr {
81695diff --git a/include/net/protocol.h b/include/net/protocol.h
81696index 047c047..b9dad15 100644
81697--- a/include/net/protocol.h
81698+++ b/include/net/protocol.h
81699@@ -44,7 +44,7 @@ struct net_protocol {
81700 void (*err_handler)(struct sk_buff *skb, u32 info);
81701 unsigned int no_policy:1,
81702 netns_ok:1;
81703-};
81704+} __do_const;
81705
81706 #if IS_ENABLED(CONFIG_IPV6)
81707 struct inet6_protocol {
81708@@ -57,7 +57,7 @@ struct inet6_protocol {
81709 u8 type, u8 code, int offset,
81710 __be32 info);
81711 unsigned int flags; /* INET6_PROTO_xxx */
81712-};
81713+} __do_const;
81714
81715 #define INET6_PROTO_NOPOLICY 0x1
81716 #define INET6_PROTO_FINAL 0x2
81717diff --git a/include/net/rtnetlink.h b/include/net/rtnetlink.h
81718index 7026648..584cc8c 100644
81719--- a/include/net/rtnetlink.h
81720+++ b/include/net/rtnetlink.h
81721@@ -81,7 +81,7 @@ struct rtnl_link_ops {
81722 const struct net_device *dev);
81723 unsigned int (*get_num_tx_queues)(void);
81724 unsigned int (*get_num_rx_queues)(void);
81725-};
81726+} __do_const;
81727
81728 extern int __rtnl_link_register(struct rtnl_link_ops *ops);
81729 extern void __rtnl_link_unregister(struct rtnl_link_ops *ops);
81730diff --git a/include/net/sctp/sm.h b/include/net/sctp/sm.h
81731index 4ef75af..5aa073a 100644
81732--- a/include/net/sctp/sm.h
81733+++ b/include/net/sctp/sm.h
81734@@ -81,7 +81,7 @@ typedef void (sctp_timer_event_t) (unsigned long);
81735 typedef struct {
81736 sctp_state_fn_t *fn;
81737 const char *name;
81738-} sctp_sm_table_entry_t;
81739+} __do_const sctp_sm_table_entry_t;
81740
81741 /* A naming convention of "sctp_sf_xxx" applies to all the state functions
81742 * currently in use.
81743@@ -293,7 +293,7 @@ __u32 sctp_generate_tag(const struct sctp_endpoint *);
81744 __u32 sctp_generate_tsn(const struct sctp_endpoint *);
81745
81746 /* Extern declarations for major data structures. */
81747-extern sctp_timer_event_t *sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES];
81748+extern sctp_timer_event_t * const sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES];
81749
81750
81751 /* Get the size of a DATA chunk payload. */
81752diff --git a/include/net/sctp/structs.h b/include/net/sctp/structs.h
81753index 2174d8d..71d5257 100644
81754--- a/include/net/sctp/structs.h
81755+++ b/include/net/sctp/structs.h
81756@@ -508,7 +508,7 @@ struct sctp_pf {
81757 struct sctp_association *asoc);
81758 void (*addr_v4map) (struct sctp_sock *, union sctp_addr *);
81759 struct sctp_af *af;
81760-};
81761+} __do_const;
81762
81763
81764 /* Structure to track chunk fragments that have been acked, but peer
81765diff --git a/include/net/sock.h b/include/net/sock.h
81766index 808cbc2..8617e9c 100644
81767--- a/include/net/sock.h
81768+++ b/include/net/sock.h
81769@@ -332,7 +332,7 @@ struct sock {
81770 unsigned int sk_napi_id;
81771 unsigned int sk_ll_usec;
81772 #endif
81773- atomic_t sk_drops;
81774+ atomic_unchecked_t sk_drops;
81775 int sk_rcvbuf;
81776
81777 struct sk_filter __rcu *sk_filter;
81778@@ -1194,7 +1194,7 @@ static inline u64 memcg_memory_allocated_read(struct cg_proto *prot)
81779 return ret >> PAGE_SHIFT;
81780 }
81781
81782-static inline long
81783+static inline long __intentional_overflow(-1)
81784 sk_memory_allocated(const struct sock *sk)
81785 {
81786 struct proto *prot = sk->sk_prot;
81787@@ -1821,7 +1821,7 @@ static inline void sk_nocaps_add(struct sock *sk, netdev_features_t flags)
81788 }
81789
81790 static inline int skb_do_copy_data_nocache(struct sock *sk, struct sk_buff *skb,
81791- char __user *from, char *to,
81792+ char __user *from, unsigned char *to,
81793 int copy, int offset)
81794 {
81795 if (skb->ip_summed == CHECKSUM_NONE) {
81796@@ -2083,7 +2083,7 @@ static inline void sk_stream_moderate_sndbuf(struct sock *sk)
81797 }
81798 }
81799
81800-struct sk_buff *sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
81801+struct sk_buff * __intentional_overflow(0) sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
81802
81803 /**
81804 * sk_page_frag - return an appropriate page_frag
81805diff --git a/include/net/tcp.h b/include/net/tcp.h
81806index b1aa324..b8530ea 100644
81807--- a/include/net/tcp.h
81808+++ b/include/net/tcp.h
81809@@ -527,7 +527,7 @@ extern void tcp_retransmit_timer(struct sock *sk);
81810 extern void tcp_xmit_retransmit_queue(struct sock *);
81811 extern void tcp_simple_retransmit(struct sock *);
81812 extern int tcp_trim_head(struct sock *, struct sk_buff *, u32);
81813-extern int tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int);
81814+extern int __intentional_overflow(3) tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int);
81815
81816 extern void tcp_send_probe0(struct sock *);
81817 extern void tcp_send_partial(struct sock *);
81818@@ -699,8 +699,8 @@ struct tcp_skb_cb {
81819 struct inet6_skb_parm h6;
81820 #endif
81821 } header; /* For incoming frames */
81822- __u32 seq; /* Starting sequence number */
81823- __u32 end_seq; /* SEQ + FIN + SYN + datalen */
81824+ __u32 seq __intentional_overflow(0); /* Starting sequence number */
81825+ __u32 end_seq __intentional_overflow(0); /* SEQ + FIN + SYN + datalen */
81826 __u32 when; /* used to compute rtt's */
81827 __u8 tcp_flags; /* TCP header flags. (tcp[13]) */
81828
81829@@ -714,7 +714,7 @@ struct tcp_skb_cb {
81830
81831 __u8 ip_dsfield; /* IPv4 tos or IPv6 dsfield */
81832 /* 1 byte hole */
81833- __u32 ack_seq; /* Sequence number ACK'd */
81834+ __u32 ack_seq __intentional_overflow(0); /* Sequence number ACK'd */
81835 };
81836
81837 #define TCP_SKB_CB(__skb) ((struct tcp_skb_cb *)&((__skb)->cb[0]))
81838diff --git a/include/net/xfrm.h b/include/net/xfrm.h
81839index e253bf0..2278b4b 100644
81840--- a/include/net/xfrm.h
81841+++ b/include/net/xfrm.h
81842@@ -287,7 +287,6 @@ struct xfrm_dst;
81843 struct xfrm_policy_afinfo {
81844 unsigned short family;
81845 struct dst_ops *dst_ops;
81846- void (*garbage_collect)(struct net *net);
81847 struct dst_entry *(*dst_lookup)(struct net *net, int tos,
81848 const xfrm_address_t *saddr,
81849 const xfrm_address_t *daddr);
81850@@ -305,7 +304,7 @@ struct xfrm_policy_afinfo {
81851 struct net_device *dev,
81852 const struct flowi *fl);
81853 struct dst_entry *(*blackhole_route)(struct net *net, struct dst_entry *orig);
81854-};
81855+} __do_const;
81856
81857 extern int xfrm_policy_register_afinfo(struct xfrm_policy_afinfo *afinfo);
81858 extern int xfrm_policy_unregister_afinfo(struct xfrm_policy_afinfo *afinfo);
81859@@ -342,7 +341,7 @@ struct xfrm_state_afinfo {
81860 int (*transport_finish)(struct sk_buff *skb,
81861 int async);
81862 void (*local_error)(struct sk_buff *skb, u32 mtu);
81863-};
81864+} __do_const;
81865
81866 extern int xfrm_state_register_afinfo(struct xfrm_state_afinfo *afinfo);
81867 extern int xfrm_state_unregister_afinfo(struct xfrm_state_afinfo *afinfo);
81868@@ -427,7 +426,7 @@ struct xfrm_mode {
81869 struct module *owner;
81870 unsigned int encap;
81871 int flags;
81872-};
81873+} __do_const;
81874
81875 /* Flags for xfrm_mode. */
81876 enum {
81877@@ -524,7 +523,7 @@ struct xfrm_policy {
81878 struct timer_list timer;
81879
81880 struct flow_cache_object flo;
81881- atomic_t genid;
81882+ atomic_unchecked_t genid;
81883 u32 priority;
81884 u32 index;
81885 struct xfrm_mark mark;
81886@@ -1164,6 +1163,7 @@ static inline void xfrm_sk_free_policy(struct sock *sk)
81887 }
81888
81889 extern void xfrm_garbage_collect(struct net *net);
81890+extern void xfrm_garbage_collect_deferred(struct net *net);
81891
81892 #else
81893
81894@@ -1202,6 +1202,9 @@ static inline int xfrm6_policy_check_reverse(struct sock *sk, int dir,
81895 static inline void xfrm_garbage_collect(struct net *net)
81896 {
81897 }
81898+static inline void xfrm_garbage_collect_deferred(struct net *net)
81899+{
81900+}
81901 #endif
81902
81903 static __inline__
81904diff --git a/include/rdma/iw_cm.h b/include/rdma/iw_cm.h
81905index 1017e0b..227aa4d 100644
81906--- a/include/rdma/iw_cm.h
81907+++ b/include/rdma/iw_cm.h
81908@@ -122,7 +122,7 @@ struct iw_cm_verbs {
81909 int backlog);
81910
81911 int (*destroy_listen)(struct iw_cm_id *cm_id);
81912-};
81913+} __no_const;
81914
81915 /**
81916 * iw_create_cm_id - Create an IW CM identifier.
81917diff --git a/include/scsi/libfc.h b/include/scsi/libfc.h
81918index e1379b4..67eafbe 100644
81919--- a/include/scsi/libfc.h
81920+++ b/include/scsi/libfc.h
81921@@ -762,6 +762,7 @@ struct libfc_function_template {
81922 */
81923 void (*disc_stop_final) (struct fc_lport *);
81924 };
81925+typedef struct libfc_function_template __no_const libfc_function_template_no_const;
81926
81927 /**
81928 * struct fc_disc - Discovery context
81929@@ -866,7 +867,7 @@ struct fc_lport {
81930 struct fc_vport *vport;
81931
81932 /* Operational Information */
81933- struct libfc_function_template tt;
81934+ libfc_function_template_no_const tt;
81935 u8 link_up;
81936 u8 qfull;
81937 enum fc_lport_state state;
81938diff --git a/include/scsi/scsi_device.h b/include/scsi/scsi_device.h
81939index d65fbec..f80fef2 100644
81940--- a/include/scsi/scsi_device.h
81941+++ b/include/scsi/scsi_device.h
81942@@ -180,9 +180,9 @@ struct scsi_device {
81943 unsigned int max_device_blocked; /* what device_blocked counts down from */
81944 #define SCSI_DEFAULT_DEVICE_BLOCKED 3
81945
81946- atomic_t iorequest_cnt;
81947- atomic_t iodone_cnt;
81948- atomic_t ioerr_cnt;
81949+ atomic_unchecked_t iorequest_cnt;
81950+ atomic_unchecked_t iodone_cnt;
81951+ atomic_unchecked_t ioerr_cnt;
81952
81953 struct device sdev_gendev,
81954 sdev_dev;
81955diff --git a/include/scsi/scsi_transport_fc.h b/include/scsi/scsi_transport_fc.h
81956index b797e8f..8e2c3aa 100644
81957--- a/include/scsi/scsi_transport_fc.h
81958+++ b/include/scsi/scsi_transport_fc.h
81959@@ -751,7 +751,8 @@ struct fc_function_template {
81960 unsigned long show_host_system_hostname:1;
81961
81962 unsigned long disable_target_scan:1;
81963-};
81964+} __do_const;
81965+typedef struct fc_function_template __no_const fc_function_template_no_const;
81966
81967
81968 /**
81969diff --git a/include/sound/compress_driver.h b/include/sound/compress_driver.h
81970index ae6c3b8..fd748ac 100644
81971--- a/include/sound/compress_driver.h
81972+++ b/include/sound/compress_driver.h
81973@@ -128,7 +128,7 @@ struct snd_compr_ops {
81974 struct snd_compr_caps *caps);
81975 int (*get_codec_caps) (struct snd_compr_stream *stream,
81976 struct snd_compr_codec_caps *codec);
81977-};
81978+} __no_const;
81979
81980 /**
81981 * struct snd_compr: Compressed device
81982diff --git a/include/sound/soc.h b/include/sound/soc.h
81983index d22cb0a..c6ba150 100644
81984--- a/include/sound/soc.h
81985+++ b/include/sound/soc.h
81986@@ -780,7 +780,7 @@ struct snd_soc_codec_driver {
81987 /* probe ordering - for components with runtime dependencies */
81988 int probe_order;
81989 int remove_order;
81990-};
81991+} __do_const;
81992
81993 /* SoC platform interface */
81994 struct snd_soc_platform_driver {
81995@@ -826,7 +826,7 @@ struct snd_soc_platform_driver {
81996 unsigned int (*read)(struct snd_soc_platform *, unsigned int);
81997 int (*write)(struct snd_soc_platform *, unsigned int, unsigned int);
81998 int (*bespoke_trigger)(struct snd_pcm_substream *, int);
81999-};
82000+} __do_const;
82001
82002 struct snd_soc_platform {
82003 const char *name;
82004diff --git a/include/target/target_core_base.h b/include/target/target_core_base.h
82005index 23bfd10..1ff3e35 100644
82006--- a/include/target/target_core_base.h
82007+++ b/include/target/target_core_base.h
82008@@ -664,7 +664,7 @@ struct se_device {
82009 spinlock_t stats_lock;
82010 /* Active commands on this virtual SE device */
82011 atomic_t simple_cmds;
82012- atomic_t dev_ordered_id;
82013+ atomic_unchecked_t dev_ordered_id;
82014 atomic_t dev_ordered_sync;
82015 atomic_t dev_qf_count;
82016 int export_count;
82017diff --git a/include/trace/events/fs.h b/include/trace/events/fs.h
82018new file mode 100644
82019index 0000000..fb634b7
82020--- /dev/null
82021+++ b/include/trace/events/fs.h
82022@@ -0,0 +1,53 @@
82023+#undef TRACE_SYSTEM
82024+#define TRACE_SYSTEM fs
82025+
82026+#if !defined(_TRACE_FS_H) || defined(TRACE_HEADER_MULTI_READ)
82027+#define _TRACE_FS_H
82028+
82029+#include <linux/fs.h>
82030+#include <linux/tracepoint.h>
82031+
82032+TRACE_EVENT(do_sys_open,
82033+
82034+ TP_PROTO(const char *filename, int flags, int mode),
82035+
82036+ TP_ARGS(filename, flags, mode),
82037+
82038+ TP_STRUCT__entry(
82039+ __string( filename, filename )
82040+ __field( int, flags )
82041+ __field( int, mode )
82042+ ),
82043+
82044+ TP_fast_assign(
82045+ __assign_str(filename, filename);
82046+ __entry->flags = flags;
82047+ __entry->mode = mode;
82048+ ),
82049+
82050+ TP_printk("\"%s\" %x %o",
82051+ __get_str(filename), __entry->flags, __entry->mode)
82052+);
82053+
82054+TRACE_EVENT(open_exec,
82055+
82056+ TP_PROTO(const char *filename),
82057+
82058+ TP_ARGS(filename),
82059+
82060+ TP_STRUCT__entry(
82061+ __string( filename, filename )
82062+ ),
82063+
82064+ TP_fast_assign(
82065+ __assign_str(filename, filename);
82066+ ),
82067+
82068+ TP_printk("\"%s\"",
82069+ __get_str(filename))
82070+);
82071+
82072+#endif /* _TRACE_FS_H */
82073+
82074+/* This part must be outside protection */
82075+#include <trace/define_trace.h>
82076diff --git a/include/trace/events/irq.h b/include/trace/events/irq.h
82077index 1c09820..7f5ec79 100644
82078--- a/include/trace/events/irq.h
82079+++ b/include/trace/events/irq.h
82080@@ -36,7 +36,7 @@ struct softirq_action;
82081 */
82082 TRACE_EVENT(irq_handler_entry,
82083
82084- TP_PROTO(int irq, struct irqaction *action),
82085+ TP_PROTO(int irq, const struct irqaction *action),
82086
82087 TP_ARGS(irq, action),
82088
82089@@ -66,7 +66,7 @@ TRACE_EVENT(irq_handler_entry,
82090 */
82091 TRACE_EVENT(irq_handler_exit,
82092
82093- TP_PROTO(int irq, struct irqaction *action, int ret),
82094+ TP_PROTO(int irq, const struct irqaction *action, int ret),
82095
82096 TP_ARGS(irq, action, ret),
82097
82098diff --git a/include/uapi/linux/a.out.h b/include/uapi/linux/a.out.h
82099index 7caf44c..23c6f27 100644
82100--- a/include/uapi/linux/a.out.h
82101+++ b/include/uapi/linux/a.out.h
82102@@ -39,6 +39,14 @@ enum machine_type {
82103 M_MIPS2 = 152 /* MIPS R6000/R4000 binary */
82104 };
82105
82106+/* Constants for the N_FLAGS field */
82107+#define F_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
82108+#define F_PAX_EMUTRAMP 2 /* Emulate trampolines */
82109+#define F_PAX_MPROTECT 4 /* Restrict mprotect() */
82110+#define F_PAX_RANDMMAP 8 /* Randomize mmap() base */
82111+/*#define F_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
82112+#define F_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
82113+
82114 #if !defined (N_MAGIC)
82115 #define N_MAGIC(exec) ((exec).a_info & 0xffff)
82116 #endif
82117diff --git a/include/uapi/linux/byteorder/little_endian.h b/include/uapi/linux/byteorder/little_endian.h
82118index d876736..ccce5c0 100644
82119--- a/include/uapi/linux/byteorder/little_endian.h
82120+++ b/include/uapi/linux/byteorder/little_endian.h
82121@@ -42,51 +42,51 @@
82122
82123 static inline __le64 __cpu_to_le64p(const __u64 *p)
82124 {
82125- return (__force __le64)*p;
82126+ return (__force const __le64)*p;
82127 }
82128-static inline __u64 __le64_to_cpup(const __le64 *p)
82129+static inline __u64 __intentional_overflow(-1) __le64_to_cpup(const __le64 *p)
82130 {
82131- return (__force __u64)*p;
82132+ return (__force const __u64)*p;
82133 }
82134 static inline __le32 __cpu_to_le32p(const __u32 *p)
82135 {
82136- return (__force __le32)*p;
82137+ return (__force const __le32)*p;
82138 }
82139 static inline __u32 __le32_to_cpup(const __le32 *p)
82140 {
82141- return (__force __u32)*p;
82142+ return (__force const __u32)*p;
82143 }
82144 static inline __le16 __cpu_to_le16p(const __u16 *p)
82145 {
82146- return (__force __le16)*p;
82147+ return (__force const __le16)*p;
82148 }
82149 static inline __u16 __le16_to_cpup(const __le16 *p)
82150 {
82151- return (__force __u16)*p;
82152+ return (__force const __u16)*p;
82153 }
82154 static inline __be64 __cpu_to_be64p(const __u64 *p)
82155 {
82156- return (__force __be64)__swab64p(p);
82157+ return (__force const __be64)__swab64p(p);
82158 }
82159 static inline __u64 __be64_to_cpup(const __be64 *p)
82160 {
82161- return __swab64p((__u64 *)p);
82162+ return __swab64p((const __u64 *)p);
82163 }
82164 static inline __be32 __cpu_to_be32p(const __u32 *p)
82165 {
82166- return (__force __be32)__swab32p(p);
82167+ return (__force const __be32)__swab32p(p);
82168 }
82169-static inline __u32 __be32_to_cpup(const __be32 *p)
82170+static inline __u32 __intentional_overflow(-1) __be32_to_cpup(const __be32 *p)
82171 {
82172- return __swab32p((__u32 *)p);
82173+ return __swab32p((const __u32 *)p);
82174 }
82175 static inline __be16 __cpu_to_be16p(const __u16 *p)
82176 {
82177- return (__force __be16)__swab16p(p);
82178+ return (__force const __be16)__swab16p(p);
82179 }
82180 static inline __u16 __be16_to_cpup(const __be16 *p)
82181 {
82182- return __swab16p((__u16 *)p);
82183+ return __swab16p((const __u16 *)p);
82184 }
82185 #define __cpu_to_le64s(x) do { (void)(x); } while (0)
82186 #define __le64_to_cpus(x) do { (void)(x); } while (0)
82187diff --git a/include/uapi/linux/elf.h b/include/uapi/linux/elf.h
82188index ef6103b..d4e65dd 100644
82189--- a/include/uapi/linux/elf.h
82190+++ b/include/uapi/linux/elf.h
82191@@ -37,6 +37,17 @@ typedef __s64 Elf64_Sxword;
82192 #define PT_GNU_EH_FRAME 0x6474e550
82193
82194 #define PT_GNU_STACK (PT_LOOS + 0x474e551)
82195+#define PT_GNU_RELRO (PT_LOOS + 0x474e552)
82196+
82197+#define PT_PAX_FLAGS (PT_LOOS + 0x5041580)
82198+
82199+/* Constants for the e_flags field */
82200+#define EF_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
82201+#define EF_PAX_EMUTRAMP 2 /* Emulate trampolines */
82202+#define EF_PAX_MPROTECT 4 /* Restrict mprotect() */
82203+#define EF_PAX_RANDMMAP 8 /* Randomize mmap() base */
82204+/*#define EF_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
82205+#define EF_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
82206
82207 /*
82208 * Extended Numbering
82209@@ -94,6 +105,8 @@ typedef __s64 Elf64_Sxword;
82210 #define DT_DEBUG 21
82211 #define DT_TEXTREL 22
82212 #define DT_JMPREL 23
82213+#define DT_FLAGS 30
82214+ #define DF_TEXTREL 0x00000004
82215 #define DT_ENCODING 32
82216 #define OLD_DT_LOOS 0x60000000
82217 #define DT_LOOS 0x6000000d
82218@@ -240,6 +253,19 @@ typedef struct elf64_hdr {
82219 #define PF_W 0x2
82220 #define PF_X 0x1
82221
82222+#define PF_PAGEEXEC (1U << 4) /* Enable PAGEEXEC */
82223+#define PF_NOPAGEEXEC (1U << 5) /* Disable PAGEEXEC */
82224+#define PF_SEGMEXEC (1U << 6) /* Enable SEGMEXEC */
82225+#define PF_NOSEGMEXEC (1U << 7) /* Disable SEGMEXEC */
82226+#define PF_MPROTECT (1U << 8) /* Enable MPROTECT */
82227+#define PF_NOMPROTECT (1U << 9) /* Disable MPROTECT */
82228+/*#define PF_RANDEXEC (1U << 10)*/ /* Enable RANDEXEC */
82229+/*#define PF_NORANDEXEC (1U << 11)*/ /* Disable RANDEXEC */
82230+#define PF_EMUTRAMP (1U << 12) /* Enable EMUTRAMP */
82231+#define PF_NOEMUTRAMP (1U << 13) /* Disable EMUTRAMP */
82232+#define PF_RANDMMAP (1U << 14) /* Enable RANDMMAP */
82233+#define PF_NORANDMMAP (1U << 15) /* Disable RANDMMAP */
82234+
82235 typedef struct elf32_phdr{
82236 Elf32_Word p_type;
82237 Elf32_Off p_offset;
82238@@ -332,6 +358,8 @@ typedef struct elf64_shdr {
82239 #define EI_OSABI 7
82240 #define EI_PAD 8
82241
82242+#define EI_PAX 14
82243+
82244 #define ELFMAG0 0x7f /* EI_MAG */
82245 #define ELFMAG1 'E'
82246 #define ELFMAG2 'L'
82247diff --git a/include/uapi/linux/personality.h b/include/uapi/linux/personality.h
82248index aa169c4..6a2771d 100644
82249--- a/include/uapi/linux/personality.h
82250+++ b/include/uapi/linux/personality.h
82251@@ -30,6 +30,7 @@ enum {
82252 #define PER_CLEAR_ON_SETID (READ_IMPLIES_EXEC | \
82253 ADDR_NO_RANDOMIZE | \
82254 ADDR_COMPAT_LAYOUT | \
82255+ ADDR_LIMIT_3GB | \
82256 MMAP_PAGE_ZERO)
82257
82258 /*
82259diff --git a/include/uapi/linux/random.h b/include/uapi/linux/random.h
82260index 7471b5b..f97f514 100644
82261--- a/include/uapi/linux/random.h
82262+++ b/include/uapi/linux/random.h
82263@@ -41,7 +41,7 @@ struct rand_pool_info {
82264 };
82265
82266 struct rnd_state {
82267- __u32 s1, s2, s3;
82268+ __u32 s1, s2, s3, s4;
82269 };
82270
82271 /* Exported functions */
82272diff --git a/include/uapi/linux/screen_info.h b/include/uapi/linux/screen_info.h
82273index 7530e74..e714828 100644
82274--- a/include/uapi/linux/screen_info.h
82275+++ b/include/uapi/linux/screen_info.h
82276@@ -43,7 +43,8 @@ struct screen_info {
82277 __u16 pages; /* 0x32 */
82278 __u16 vesa_attributes; /* 0x34 */
82279 __u32 capabilities; /* 0x36 */
82280- __u8 _reserved[6]; /* 0x3a */
82281+ __u16 vesapm_size; /* 0x3a */
82282+ __u8 _reserved[4]; /* 0x3c */
82283 } __attribute__((packed));
82284
82285 #define VIDEO_TYPE_MDA 0x10 /* Monochrome Text Display */
82286diff --git a/include/uapi/linux/swab.h b/include/uapi/linux/swab.h
82287index 0e011eb..82681b1 100644
82288--- a/include/uapi/linux/swab.h
82289+++ b/include/uapi/linux/swab.h
82290@@ -43,7 +43,7 @@
82291 * ___swab16, ___swab32, ___swab64, ___swahw32, ___swahb32
82292 */
82293
82294-static inline __attribute_const__ __u16 __fswab16(__u16 val)
82295+static inline __intentional_overflow(-1) __attribute_const__ __u16 __fswab16(__u16 val)
82296 {
82297 #ifdef __HAVE_BUILTIN_BSWAP16__
82298 return __builtin_bswap16(val);
82299@@ -54,7 +54,7 @@ static inline __attribute_const__ __u16 __fswab16(__u16 val)
82300 #endif
82301 }
82302
82303-static inline __attribute_const__ __u32 __fswab32(__u32 val)
82304+static inline __intentional_overflow(-1) __attribute_const__ __u32 __fswab32(__u32 val)
82305 {
82306 #ifdef __HAVE_BUILTIN_BSWAP32__
82307 return __builtin_bswap32(val);
82308@@ -65,7 +65,7 @@ static inline __attribute_const__ __u32 __fswab32(__u32 val)
82309 #endif
82310 }
82311
82312-static inline __attribute_const__ __u64 __fswab64(__u64 val)
82313+static inline __intentional_overflow(-1) __attribute_const__ __u64 __fswab64(__u64 val)
82314 {
82315 #ifdef __HAVE_BUILTIN_BSWAP64__
82316 return __builtin_bswap64(val);
82317diff --git a/include/uapi/linux/sysctl.h b/include/uapi/linux/sysctl.h
82318index 6d67213..552fdd9 100644
82319--- a/include/uapi/linux/sysctl.h
82320+++ b/include/uapi/linux/sysctl.h
82321@@ -155,8 +155,6 @@ enum
82322 KERN_PANIC_ON_NMI=76, /* int: whether we will panic on an unrecovered */
82323 };
82324
82325-
82326-
82327 /* CTL_VM names: */
82328 enum
82329 {
82330diff --git a/include/uapi/linux/xattr.h b/include/uapi/linux/xattr.h
82331index e4629b9..6958086 100644
82332--- a/include/uapi/linux/xattr.h
82333+++ b/include/uapi/linux/xattr.h
82334@@ -63,5 +63,9 @@
82335 #define XATTR_POSIX_ACL_DEFAULT "posix_acl_default"
82336 #define XATTR_NAME_POSIX_ACL_DEFAULT XATTR_SYSTEM_PREFIX XATTR_POSIX_ACL_DEFAULT
82337
82338+/* User namespace */
82339+#define XATTR_PAX_PREFIX XATTR_USER_PREFIX "pax."
82340+#define XATTR_PAX_FLAGS_SUFFIX "flags"
82341+#define XATTR_NAME_PAX_FLAGS XATTR_PAX_PREFIX XATTR_PAX_FLAGS_SUFFIX
82342
82343 #endif /* _UAPI_LINUX_XATTR_H */
82344diff --git a/include/video/udlfb.h b/include/video/udlfb.h
82345index f9466fa..f4e2b81 100644
82346--- a/include/video/udlfb.h
82347+++ b/include/video/udlfb.h
82348@@ -53,10 +53,10 @@ struct dlfb_data {
82349 u32 pseudo_palette[256];
82350 int blank_mode; /*one of FB_BLANK_ */
82351 /* blit-only rendering path metrics, exposed through sysfs */
82352- atomic_t bytes_rendered; /* raw pixel-bytes driver asked to render */
82353- atomic_t bytes_identical; /* saved effort with backbuffer comparison */
82354- atomic_t bytes_sent; /* to usb, after compression including overhead */
82355- atomic_t cpu_kcycles_used; /* transpired during pixel processing */
82356+ atomic_unchecked_t bytes_rendered; /* raw pixel-bytes driver asked to render */
82357+ atomic_unchecked_t bytes_identical; /* saved effort with backbuffer comparison */
82358+ atomic_unchecked_t bytes_sent; /* to usb, after compression including overhead */
82359+ atomic_unchecked_t cpu_kcycles_used; /* transpired during pixel processing */
82360 };
82361
82362 #define NR_USB_REQUEST_I2C_SUB_IO 0x02
82363diff --git a/include/video/uvesafb.h b/include/video/uvesafb.h
82364index 30f5362..8ed8ac9 100644
82365--- a/include/video/uvesafb.h
82366+++ b/include/video/uvesafb.h
82367@@ -122,6 +122,7 @@ struct uvesafb_par {
82368 u8 ypan; /* 0 - nothing, 1 - ypan, 2 - ywrap */
82369 u8 pmi_setpal; /* PMI for palette changes */
82370 u16 *pmi_base; /* protected mode interface location */
82371+ u8 *pmi_code; /* protected mode code location */
82372 void *pmi_start;
82373 void *pmi_pal;
82374 u8 *vbe_state_orig; /*
82375diff --git a/init/Kconfig b/init/Kconfig
82376index 3ecd8a1..627843f 100644
82377--- a/init/Kconfig
82378+++ b/init/Kconfig
82379@@ -1086,6 +1086,7 @@ endif # CGROUPS
82380
82381 config CHECKPOINT_RESTORE
82382 bool "Checkpoint/restore support" if EXPERT
82383+ depends on !GRKERNSEC
82384 default n
82385 help
82386 Enables additional kernel features in a sake of checkpoint/restore.
82387@@ -1557,7 +1558,7 @@ config SLUB_DEBUG
82388
82389 config COMPAT_BRK
82390 bool "Disable heap randomization"
82391- default y
82392+ default n
82393 help
82394 Randomizing heap placement makes heap exploits harder, but it
82395 also breaks ancient binaries (including anything libc5 based).
82396@@ -1832,7 +1833,7 @@ config INIT_ALL_POSSIBLE
82397 config STOP_MACHINE
82398 bool
82399 default y
82400- depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU
82401+ depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU || GRKERNSEC
82402 help
82403 Need stop_machine() primitive.
82404
82405diff --git a/init/Makefile b/init/Makefile
82406index 7bc47ee..6da2dc7 100644
82407--- a/init/Makefile
82408+++ b/init/Makefile
82409@@ -2,6 +2,9 @@
82410 # Makefile for the linux kernel.
82411 #
82412
82413+ccflags-y := $(GCC_PLUGINS_CFLAGS)
82414+asflags-y := $(GCC_PLUGINS_AFLAGS)
82415+
82416 obj-y := main.o version.o mounts.o
82417 ifneq ($(CONFIG_BLK_DEV_INITRD),y)
82418 obj-y += noinitramfs.o
82419diff --git a/init/do_mounts.c b/init/do_mounts.c
82420index a51cddc..25c2768 100644
82421--- a/init/do_mounts.c
82422+++ b/init/do_mounts.c
82423@@ -357,11 +357,11 @@ static void __init get_fs_names(char *page)
82424 static int __init do_mount_root(char *name, char *fs, int flags, void *data)
82425 {
82426 struct super_block *s;
82427- int err = sys_mount(name, "/root", fs, flags, data);
82428+ int err = sys_mount((char __force_user *)name, (char __force_user *)"/root", (char __force_user *)fs, flags, (void __force_user *)data);
82429 if (err)
82430 return err;
82431
82432- sys_chdir("/root");
82433+ sys_chdir((const char __force_user *)"/root");
82434 s = current->fs->pwd.dentry->d_sb;
82435 ROOT_DEV = s->s_dev;
82436 printk(KERN_INFO
82437@@ -482,18 +482,18 @@ void __init change_floppy(char *fmt, ...)
82438 va_start(args, fmt);
82439 vsprintf(buf, fmt, args);
82440 va_end(args);
82441- fd = sys_open("/dev/root", O_RDWR | O_NDELAY, 0);
82442+ fd = sys_open((char __user *)"/dev/root", O_RDWR | O_NDELAY, 0);
82443 if (fd >= 0) {
82444 sys_ioctl(fd, FDEJECT, 0);
82445 sys_close(fd);
82446 }
82447 printk(KERN_NOTICE "VFS: Insert %s and press ENTER\n", buf);
82448- fd = sys_open("/dev/console", O_RDWR, 0);
82449+ fd = sys_open((__force const char __user *)"/dev/console", O_RDWR, 0);
82450 if (fd >= 0) {
82451 sys_ioctl(fd, TCGETS, (long)&termios);
82452 termios.c_lflag &= ~ICANON;
82453 sys_ioctl(fd, TCSETSF, (long)&termios);
82454- sys_read(fd, &c, 1);
82455+ sys_read(fd, (char __user *)&c, 1);
82456 termios.c_lflag |= ICANON;
82457 sys_ioctl(fd, TCSETSF, (long)&termios);
82458 sys_close(fd);
82459@@ -587,8 +587,8 @@ void __init prepare_namespace(void)
82460 mount_root();
82461 out:
82462 devtmpfs_mount("dev");
82463- sys_mount(".", "/", NULL, MS_MOVE, NULL);
82464- sys_chroot(".");
82465+ sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
82466+ sys_chroot((const char __force_user *)".");
82467 }
82468
82469 static bool is_tmpfs;
82470diff --git a/init/do_mounts.h b/init/do_mounts.h
82471index f5b978a..69dbfe8 100644
82472--- a/init/do_mounts.h
82473+++ b/init/do_mounts.h
82474@@ -15,15 +15,15 @@ extern int root_mountflags;
82475
82476 static inline int create_dev(char *name, dev_t dev)
82477 {
82478- sys_unlink(name);
82479- return sys_mknod(name, S_IFBLK|0600, new_encode_dev(dev));
82480+ sys_unlink((char __force_user *)name);
82481+ return sys_mknod((char __force_user *)name, S_IFBLK|0600, new_encode_dev(dev));
82482 }
82483
82484 #if BITS_PER_LONG == 32
82485 static inline u32 bstat(char *name)
82486 {
82487 struct stat64 stat;
82488- if (sys_stat64(name, &stat) != 0)
82489+ if (sys_stat64((char __force_user *)name, (struct stat64 __force_user *)&stat) != 0)
82490 return 0;
82491 if (!S_ISBLK(stat.st_mode))
82492 return 0;
82493@@ -35,7 +35,7 @@ static inline u32 bstat(char *name)
82494 static inline u32 bstat(char *name)
82495 {
82496 struct stat stat;
82497- if (sys_newstat(name, &stat) != 0)
82498+ if (sys_newstat((const char __force_user *)name, (struct stat __force_user *)&stat) != 0)
82499 return 0;
82500 if (!S_ISBLK(stat.st_mode))
82501 return 0;
82502diff --git a/init/do_mounts_initrd.c b/init/do_mounts_initrd.c
82503index 3e0878e..8a9d7a0 100644
82504--- a/init/do_mounts_initrd.c
82505+++ b/init/do_mounts_initrd.c
82506@@ -37,13 +37,13 @@ static int init_linuxrc(struct subprocess_info *info, struct cred *new)
82507 {
82508 sys_unshare(CLONE_FS | CLONE_FILES);
82509 /* stdin/stdout/stderr for /linuxrc */
82510- sys_open("/dev/console", O_RDWR, 0);
82511+ sys_open((const char __force_user *)"/dev/console", O_RDWR, 0);
82512 sys_dup(0);
82513 sys_dup(0);
82514 /* move initrd over / and chdir/chroot in initrd root */
82515- sys_chdir("/root");
82516- sys_mount(".", "/", NULL, MS_MOVE, NULL);
82517- sys_chroot(".");
82518+ sys_chdir((const char __force_user *)"/root");
82519+ sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
82520+ sys_chroot((const char __force_user *)".");
82521 sys_setsid();
82522 return 0;
82523 }
82524@@ -59,8 +59,8 @@ static void __init handle_initrd(void)
82525 create_dev("/dev/root.old", Root_RAM0);
82526 /* mount initrd on rootfs' /root */
82527 mount_block_root("/dev/root.old", root_mountflags & ~MS_RDONLY);
82528- sys_mkdir("/old", 0700);
82529- sys_chdir("/old");
82530+ sys_mkdir((const char __force_user *)"/old", 0700);
82531+ sys_chdir((const char __force_user *)"/old");
82532
82533 /* try loading default modules from initrd */
82534 load_default_modules();
82535@@ -80,31 +80,31 @@ static void __init handle_initrd(void)
82536 current->flags &= ~PF_FREEZER_SKIP;
82537
82538 /* move initrd to rootfs' /old */
82539- sys_mount("..", ".", NULL, MS_MOVE, NULL);
82540+ sys_mount((char __force_user *)"..", (char __force_user *)".", NULL, MS_MOVE, NULL);
82541 /* switch root and cwd back to / of rootfs */
82542- sys_chroot("..");
82543+ sys_chroot((const char __force_user *)"..");
82544
82545 if (new_decode_dev(real_root_dev) == Root_RAM0) {
82546- sys_chdir("/old");
82547+ sys_chdir((const char __force_user *)"/old");
82548 return;
82549 }
82550
82551- sys_chdir("/");
82552+ sys_chdir((const char __force_user *)"/");
82553 ROOT_DEV = new_decode_dev(real_root_dev);
82554 mount_root();
82555
82556 printk(KERN_NOTICE "Trying to move old root to /initrd ... ");
82557- error = sys_mount("/old", "/root/initrd", NULL, MS_MOVE, NULL);
82558+ error = sys_mount((char __force_user *)"/old", (char __force_user *)"/root/initrd", NULL, MS_MOVE, NULL);
82559 if (!error)
82560 printk("okay\n");
82561 else {
82562- int fd = sys_open("/dev/root.old", O_RDWR, 0);
82563+ int fd = sys_open((const char __force_user *)"/dev/root.old", O_RDWR, 0);
82564 if (error == -ENOENT)
82565 printk("/initrd does not exist. Ignored.\n");
82566 else
82567 printk("failed\n");
82568 printk(KERN_NOTICE "Unmounting old root\n");
82569- sys_umount("/old", MNT_DETACH);
82570+ sys_umount((char __force_user *)"/old", MNT_DETACH);
82571 printk(KERN_NOTICE "Trying to free ramdisk memory ... ");
82572 if (fd < 0) {
82573 error = fd;
82574@@ -127,11 +127,11 @@ int __init initrd_load(void)
82575 * mounted in the normal path.
82576 */
82577 if (rd_load_image("/initrd.image") && ROOT_DEV != Root_RAM0) {
82578- sys_unlink("/initrd.image");
82579+ sys_unlink((const char __force_user *)"/initrd.image");
82580 handle_initrd();
82581 return 1;
82582 }
82583 }
82584- sys_unlink("/initrd.image");
82585+ sys_unlink((const char __force_user *)"/initrd.image");
82586 return 0;
82587 }
82588diff --git a/init/do_mounts_md.c b/init/do_mounts_md.c
82589index 8cb6db5..d729f50 100644
82590--- a/init/do_mounts_md.c
82591+++ b/init/do_mounts_md.c
82592@@ -180,7 +180,7 @@ static void __init md_setup_drive(void)
82593 partitioned ? "_d" : "", minor,
82594 md_setup_args[ent].device_names);
82595
82596- fd = sys_open(name, 0, 0);
82597+ fd = sys_open((char __force_user *)name, 0, 0);
82598 if (fd < 0) {
82599 printk(KERN_ERR "md: open failed - cannot start "
82600 "array %s\n", name);
82601@@ -243,7 +243,7 @@ static void __init md_setup_drive(void)
82602 * array without it
82603 */
82604 sys_close(fd);
82605- fd = sys_open(name, 0, 0);
82606+ fd = sys_open((char __force_user *)name, 0, 0);
82607 sys_ioctl(fd, BLKRRPART, 0);
82608 }
82609 sys_close(fd);
82610@@ -293,7 +293,7 @@ static void __init autodetect_raid(void)
82611
82612 wait_for_device_probe();
82613
82614- fd = sys_open("/dev/md0", 0, 0);
82615+ fd = sys_open((const char __force_user *) "/dev/md0", 0, 0);
82616 if (fd >= 0) {
82617 sys_ioctl(fd, RAID_AUTORUN, raid_autopart);
82618 sys_close(fd);
82619diff --git a/init/init_task.c b/init/init_task.c
82620index ba0a7f36..2bcf1d5 100644
82621--- a/init/init_task.c
82622+++ b/init/init_task.c
82623@@ -22,5 +22,9 @@ EXPORT_SYMBOL(init_task);
82624 * Initial thread structure. Alignment of this is handled by a special
82625 * linker map entry.
82626 */
82627+#ifdef CONFIG_X86
82628+union thread_union init_thread_union __init_task_data;
82629+#else
82630 union thread_union init_thread_union __init_task_data =
82631 { INIT_THREAD_INFO(init_task) };
82632+#endif
82633diff --git a/init/initramfs.c b/init/initramfs.c
82634index a67ef9d..2d17ed9 100644
82635--- a/init/initramfs.c
82636+++ b/init/initramfs.c
82637@@ -84,7 +84,7 @@ static void __init free_hash(void)
82638 }
82639 }
82640
82641-static long __init do_utime(char *filename, time_t mtime)
82642+static long __init do_utime(char __force_user *filename, time_t mtime)
82643 {
82644 struct timespec t[2];
82645
82646@@ -119,7 +119,7 @@ static void __init dir_utime(void)
82647 struct dir_entry *de, *tmp;
82648 list_for_each_entry_safe(de, tmp, &dir_list, list) {
82649 list_del(&de->list);
82650- do_utime(de->name, de->mtime);
82651+ do_utime((char __force_user *)de->name, de->mtime);
82652 kfree(de->name);
82653 kfree(de);
82654 }
82655@@ -281,7 +281,7 @@ static int __init maybe_link(void)
82656 if (nlink >= 2) {
82657 char *old = find_link(major, minor, ino, mode, collected);
82658 if (old)
82659- return (sys_link(old, collected) < 0) ? -1 : 1;
82660+ return (sys_link((char __force_user *)old, (char __force_user *)collected) < 0) ? -1 : 1;
82661 }
82662 return 0;
82663 }
82664@@ -290,11 +290,11 @@ static void __init clean_path(char *path, umode_t mode)
82665 {
82666 struct stat st;
82667
82668- if (!sys_newlstat(path, &st) && (st.st_mode^mode) & S_IFMT) {
82669+ if (!sys_newlstat((char __force_user *)path, (struct stat __force_user *)&st) && (st.st_mode^mode) & S_IFMT) {
82670 if (S_ISDIR(st.st_mode))
82671- sys_rmdir(path);
82672+ sys_rmdir((char __force_user *)path);
82673 else
82674- sys_unlink(path);
82675+ sys_unlink((char __force_user *)path);
82676 }
82677 }
82678
82679@@ -315,7 +315,7 @@ static int __init do_name(void)
82680 int openflags = O_WRONLY|O_CREAT;
82681 if (ml != 1)
82682 openflags |= O_TRUNC;
82683- wfd = sys_open(collected, openflags, mode);
82684+ wfd = sys_open((char __force_user *)collected, openflags, mode);
82685
82686 if (wfd >= 0) {
82687 sys_fchown(wfd, uid, gid);
82688@@ -327,17 +327,17 @@ static int __init do_name(void)
82689 }
82690 }
82691 } else if (S_ISDIR(mode)) {
82692- sys_mkdir(collected, mode);
82693- sys_chown(collected, uid, gid);
82694- sys_chmod(collected, mode);
82695+ sys_mkdir((char __force_user *)collected, mode);
82696+ sys_chown((char __force_user *)collected, uid, gid);
82697+ sys_chmod((char __force_user *)collected, mode);
82698 dir_add(collected, mtime);
82699 } else if (S_ISBLK(mode) || S_ISCHR(mode) ||
82700 S_ISFIFO(mode) || S_ISSOCK(mode)) {
82701 if (maybe_link() == 0) {
82702- sys_mknod(collected, mode, rdev);
82703- sys_chown(collected, uid, gid);
82704- sys_chmod(collected, mode);
82705- do_utime(collected, mtime);
82706+ sys_mknod((char __force_user *)collected, mode, rdev);
82707+ sys_chown((char __force_user *)collected, uid, gid);
82708+ sys_chmod((char __force_user *)collected, mode);
82709+ do_utime((char __force_user *)collected, mtime);
82710 }
82711 }
82712 return 0;
82713@@ -346,15 +346,15 @@ static int __init do_name(void)
82714 static int __init do_copy(void)
82715 {
82716 if (count >= body_len) {
82717- sys_write(wfd, victim, body_len);
82718+ sys_write(wfd, (char __force_user *)victim, body_len);
82719 sys_close(wfd);
82720- do_utime(vcollected, mtime);
82721+ do_utime((char __force_user *)vcollected, mtime);
82722 kfree(vcollected);
82723 eat(body_len);
82724 state = SkipIt;
82725 return 0;
82726 } else {
82727- sys_write(wfd, victim, count);
82728+ sys_write(wfd, (char __force_user *)victim, count);
82729 body_len -= count;
82730 eat(count);
82731 return 1;
82732@@ -365,9 +365,9 @@ static int __init do_symlink(void)
82733 {
82734 collected[N_ALIGN(name_len) + body_len] = '\0';
82735 clean_path(collected, 0);
82736- sys_symlink(collected + N_ALIGN(name_len), collected);
82737- sys_lchown(collected, uid, gid);
82738- do_utime(collected, mtime);
82739+ sys_symlink((char __force_user *)collected + N_ALIGN(name_len), (char __force_user *)collected);
82740+ sys_lchown((char __force_user *)collected, uid, gid);
82741+ do_utime((char __force_user *)collected, mtime);
82742 state = SkipIt;
82743 next_state = Reset;
82744 return 0;
82745@@ -583,7 +583,7 @@ static int __init populate_rootfs(void)
82746 {
82747 char *err = unpack_to_rootfs(__initramfs_start, __initramfs_size);
82748 if (err)
82749- panic(err); /* Failed to decompress INTERNAL initramfs */
82750+ panic("%s", err); /* Failed to decompress INTERNAL initramfs */
82751 if (initrd_start) {
82752 #ifdef CONFIG_BLK_DEV_RAM
82753 int fd;
82754diff --git a/init/main.c b/init/main.c
82755index 63d3e8f..50bd5f8 100644
82756--- a/init/main.c
82757+++ b/init/main.c
82758@@ -103,6 +103,8 @@ static inline void mark_rodata_ro(void) { }
82759 extern void tc_init(void);
82760 #endif
82761
82762+extern void grsecurity_init(void);
82763+
82764 /*
82765 * Debug helper: via this flag we know that we are in 'early bootup code'
82766 * where only the boot processor is running with IRQ disabled. This means
82767@@ -156,6 +158,75 @@ static int __init set_reset_devices(char *str)
82768
82769 __setup("reset_devices", set_reset_devices);
82770
82771+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
82772+kgid_t grsec_proc_gid = KGIDT_INIT(CONFIG_GRKERNSEC_PROC_GID);
82773+static int __init setup_grsec_proc_gid(char *str)
82774+{
82775+ grsec_proc_gid = KGIDT_INIT(simple_strtol(str, NULL, 0));
82776+ return 1;
82777+}
82778+__setup("grsec_proc_gid=", setup_grsec_proc_gid);
82779+#endif
82780+
82781+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
82782+unsigned long pax_user_shadow_base __read_only;
82783+EXPORT_SYMBOL(pax_user_shadow_base);
82784+extern char pax_enter_kernel_user[];
82785+extern char pax_exit_kernel_user[];
82786+#endif
82787+
82788+#if defined(CONFIG_X86) && defined(CONFIG_PAX_MEMORY_UDEREF)
82789+static int __init setup_pax_nouderef(char *str)
82790+{
82791+#ifdef CONFIG_X86_32
82792+ unsigned int cpu;
82793+ struct desc_struct *gdt;
82794+
82795+ for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
82796+ gdt = get_cpu_gdt_table(cpu);
82797+ gdt[GDT_ENTRY_KERNEL_DS].type = 3;
82798+ gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
82799+ gdt[GDT_ENTRY_DEFAULT_USER_CS].limit = 0xf;
82800+ gdt[GDT_ENTRY_DEFAULT_USER_DS].limit = 0xf;
82801+ }
82802+ loadsegment(ds, __KERNEL_DS);
82803+ loadsegment(es, __KERNEL_DS);
82804+ loadsegment(ss, __KERNEL_DS);
82805+#else
82806+ memcpy(pax_enter_kernel_user, (unsigned char []){0xc3}, 1);
82807+ memcpy(pax_exit_kernel_user, (unsigned char []){0xc3}, 1);
82808+ clone_pgd_mask = ~(pgdval_t)0UL;
82809+ pax_user_shadow_base = 0UL;
82810+ setup_clear_cpu_cap(X86_FEATURE_PCID);
82811+ setup_clear_cpu_cap(X86_FEATURE_INVPCID);
82812+#endif
82813+
82814+ return 0;
82815+}
82816+early_param("pax_nouderef", setup_pax_nouderef);
82817+
82818+#ifdef CONFIG_X86_64
82819+static int __init setup_pax_weakuderef(char *str)
82820+{
82821+ if (clone_pgd_mask != ~(pgdval_t)0UL)
82822+ pax_user_shadow_base = 1UL << TASK_SIZE_MAX_SHIFT;
82823+ return 1;
82824+}
82825+__setup("pax_weakuderef", setup_pax_weakuderef);
82826+#endif
82827+#endif
82828+
82829+#ifdef CONFIG_PAX_SOFTMODE
82830+int pax_softmode;
82831+
82832+static int __init setup_pax_softmode(char *str)
82833+{
82834+ get_option(&str, &pax_softmode);
82835+ return 1;
82836+}
82837+__setup("pax_softmode=", setup_pax_softmode);
82838+#endif
82839+
82840 static const char * argv_init[MAX_INIT_ARGS+2] = { "init", NULL, };
82841 const char * envp_init[MAX_INIT_ENVS+2] = { "HOME=/", "TERM=linux", NULL, };
82842 static const char *panic_later, *panic_param;
82843@@ -682,25 +753,24 @@ int __init_or_module do_one_initcall(initcall_t fn)
82844 {
82845 int count = preempt_count();
82846 int ret;
82847- char msgbuf[64];
82848+ const char *msg1 = "", *msg2 = "";
82849
82850 if (initcall_debug)
82851 ret = do_one_initcall_debug(fn);
82852 else
82853 ret = fn();
82854
82855- msgbuf[0] = 0;
82856-
82857 if (preempt_count() != count) {
82858- sprintf(msgbuf, "preemption imbalance ");
82859+ msg1 = " preemption imbalance";
82860 preempt_count() = count;
82861 }
82862 if (irqs_disabled()) {
82863- strlcat(msgbuf, "disabled interrupts ", sizeof(msgbuf));
82864+ msg2 = " disabled interrupts";
82865 local_irq_enable();
82866 }
82867- WARN(msgbuf[0], "initcall %pF returned with %s\n", fn, msgbuf);
82868+ WARN(*msg1 || *msg2, "initcall %pF returned with%s%s\n", fn, msg1, msg2);
82869
82870+ add_latent_entropy();
82871 return ret;
82872 }
82873
82874@@ -807,10 +877,14 @@ static int run_init_process(const char *init_filename)
82875 {
82876 argv_init[0] = init_filename;
82877 return do_execve(init_filename,
82878- (const char __user *const __user *)argv_init,
82879- (const char __user *const __user *)envp_init);
82880+ (const char __user *const __force_user *)argv_init,
82881+ (const char __user *const __force_user *)envp_init);
82882 }
82883
82884+#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
82885+extern int gr_init_ran;
82886+#endif
82887+
82888 static noinline void __init kernel_init_freeable(void);
82889
82890 static int __ref kernel_init(void *unused)
82891@@ -831,6 +905,11 @@ static int __ref kernel_init(void *unused)
82892 pr_err("Failed to execute %s\n", ramdisk_execute_command);
82893 }
82894
82895+#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
82896+ /* if no initrd was used, be extra sure we enforce chroot restrictions */
82897+ gr_init_ran = 1;
82898+#endif
82899+
82900 /*
82901 * We try each of these until one succeeds.
82902 *
82903@@ -885,7 +964,7 @@ static noinline void __init kernel_init_freeable(void)
82904 do_basic_setup();
82905
82906 /* Open the /dev/console on the rootfs, this should never fail */
82907- if (sys_open((const char __user *) "/dev/console", O_RDWR, 0) < 0)
82908+ if (sys_open((const char __force_user *) "/dev/console", O_RDWR, 0) < 0)
82909 pr_err("Warning: unable to open an initial console.\n");
82910
82911 (void) sys_dup(0);
82912@@ -898,11 +977,13 @@ static noinline void __init kernel_init_freeable(void)
82913 if (!ramdisk_execute_command)
82914 ramdisk_execute_command = "/init";
82915
82916- if (sys_access((const char __user *) ramdisk_execute_command, 0) != 0) {
82917+ if (sys_access((const char __force_user *) ramdisk_execute_command, 0) != 0) {
82918 ramdisk_execute_command = NULL;
82919 prepare_namespace();
82920 }
82921
82922+ grsecurity_init();
82923+
82924 /*
82925 * Ok, we have completed the initial bootup, and
82926 * we're essentially up and running. Get rid of the
82927diff --git a/ipc/ipc_sysctl.c b/ipc/ipc_sysctl.c
82928index b0e99de..09f385c 100644
82929--- a/ipc/ipc_sysctl.c
82930+++ b/ipc/ipc_sysctl.c
82931@@ -30,7 +30,7 @@ static void *get_ipc(ctl_table *table)
82932 static int proc_ipc_dointvec(ctl_table *table, int write,
82933 void __user *buffer, size_t *lenp, loff_t *ppos)
82934 {
82935- struct ctl_table ipc_table;
82936+ ctl_table_no_const ipc_table;
82937
82938 memcpy(&ipc_table, table, sizeof(ipc_table));
82939 ipc_table.data = get_ipc(table);
82940@@ -41,7 +41,7 @@ static int proc_ipc_dointvec(ctl_table *table, int write,
82941 static int proc_ipc_dointvec_minmax(ctl_table *table, int write,
82942 void __user *buffer, size_t *lenp, loff_t *ppos)
82943 {
82944- struct ctl_table ipc_table;
82945+ ctl_table_no_const ipc_table;
82946
82947 memcpy(&ipc_table, table, sizeof(ipc_table));
82948 ipc_table.data = get_ipc(table);
82949@@ -65,7 +65,7 @@ static int proc_ipc_dointvec_minmax_orphans(ctl_table *table, int write,
82950 static int proc_ipc_callback_dointvec_minmax(ctl_table *table, int write,
82951 void __user *buffer, size_t *lenp, loff_t *ppos)
82952 {
82953- struct ctl_table ipc_table;
82954+ ctl_table_no_const ipc_table;
82955 size_t lenp_bef = *lenp;
82956 int rc;
82957
82958@@ -88,7 +88,7 @@ static int proc_ipc_callback_dointvec_minmax(ctl_table *table, int write,
82959 static int proc_ipc_doulongvec_minmax(ctl_table *table, int write,
82960 void __user *buffer, size_t *lenp, loff_t *ppos)
82961 {
82962- struct ctl_table ipc_table;
82963+ ctl_table_no_const ipc_table;
82964 memcpy(&ipc_table, table, sizeof(ipc_table));
82965 ipc_table.data = get_ipc(table);
82966
82967@@ -122,7 +122,7 @@ static void ipc_auto_callback(int val)
82968 static int proc_ipcauto_dointvec_minmax(ctl_table *table, int write,
82969 void __user *buffer, size_t *lenp, loff_t *ppos)
82970 {
82971- struct ctl_table ipc_table;
82972+ ctl_table_no_const ipc_table;
82973 size_t lenp_bef = *lenp;
82974 int oldval;
82975 int rc;
82976diff --git a/ipc/mq_sysctl.c b/ipc/mq_sysctl.c
82977index 383d638..943fdbb 100644
82978--- a/ipc/mq_sysctl.c
82979+++ b/ipc/mq_sysctl.c
82980@@ -25,7 +25,7 @@ static void *get_mq(ctl_table *table)
82981 static int proc_mq_dointvec_minmax(ctl_table *table, int write,
82982 void __user *buffer, size_t *lenp, loff_t *ppos)
82983 {
82984- struct ctl_table mq_table;
82985+ ctl_table_no_const mq_table;
82986 memcpy(&mq_table, table, sizeof(mq_table));
82987 mq_table.data = get_mq(table);
82988
82989diff --git a/ipc/mqueue.c b/ipc/mqueue.c
82990index ae1996d..a35f2cc 100644
82991--- a/ipc/mqueue.c
82992+++ b/ipc/mqueue.c
82993@@ -278,6 +278,7 @@ static struct inode *mqueue_get_inode(struct super_block *sb,
82994 mq_bytes = mq_treesize + (info->attr.mq_maxmsg *
82995 info->attr.mq_msgsize);
82996
82997+ gr_learn_resource(current, RLIMIT_MSGQUEUE, u->mq_bytes + mq_bytes, 1);
82998 spin_lock(&mq_lock);
82999 if (u->mq_bytes + mq_bytes < u->mq_bytes ||
83000 u->mq_bytes + mq_bytes > rlimit(RLIMIT_MSGQUEUE)) {
83001diff --git a/ipc/msg.c b/ipc/msg.c
83002index 558aa91..359e718 100644
83003--- a/ipc/msg.c
83004+++ b/ipc/msg.c
83005@@ -297,18 +297,19 @@ static inline int msg_security(struct kern_ipc_perm *ipcp, int msgflg)
83006 return security_msg_queue_associate(msq, msgflg);
83007 }
83008
83009+static struct ipc_ops msg_ops = {
83010+ .getnew = newque,
83011+ .associate = msg_security,
83012+ .more_checks = NULL
83013+};
83014+
83015 SYSCALL_DEFINE2(msgget, key_t, key, int, msgflg)
83016 {
83017 struct ipc_namespace *ns;
83018- struct ipc_ops msg_ops;
83019 struct ipc_params msg_params;
83020
83021 ns = current->nsproxy->ipc_ns;
83022
83023- msg_ops.getnew = newque;
83024- msg_ops.associate = msg_security;
83025- msg_ops.more_checks = NULL;
83026-
83027 msg_params.key = key;
83028 msg_params.flg = msgflg;
83029
83030diff --git a/ipc/sem.c b/ipc/sem.c
83031index db9d241..bc8427c 100644
83032--- a/ipc/sem.c
83033+++ b/ipc/sem.c
83034@@ -562,10 +562,15 @@ static inline int sem_more_checks(struct kern_ipc_perm *ipcp,
83035 return 0;
83036 }
83037
83038+static struct ipc_ops sem_ops = {
83039+ .getnew = newary,
83040+ .associate = sem_security,
83041+ .more_checks = sem_more_checks
83042+};
83043+
83044 SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
83045 {
83046 struct ipc_namespace *ns;
83047- struct ipc_ops sem_ops;
83048 struct ipc_params sem_params;
83049
83050 ns = current->nsproxy->ipc_ns;
83051@@ -573,10 +578,6 @@ SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
83052 if (nsems < 0 || nsems > ns->sc_semmsl)
83053 return -EINVAL;
83054
83055- sem_ops.getnew = newary;
83056- sem_ops.associate = sem_security;
83057- sem_ops.more_checks = sem_more_checks;
83058-
83059 sem_params.key = key;
83060 sem_params.flg = semflg;
83061 sem_params.u.nsems = nsems;
83062diff --git a/ipc/shm.c b/ipc/shm.c
83063index 7a51443..3a257d8 100644
83064--- a/ipc/shm.c
83065+++ b/ipc/shm.c
83066@@ -72,6 +72,14 @@ static void shm_destroy (struct ipc_namespace *ns, struct shmid_kernel *shp);
83067 static int sysvipc_shm_proc_show(struct seq_file *s, void *it);
83068 #endif
83069
83070+#ifdef CONFIG_GRKERNSEC
83071+extern int gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
83072+ const time_t shm_createtime, const kuid_t cuid,
83073+ const int shmid);
83074+extern int gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
83075+ const time_t shm_createtime);
83076+#endif
83077+
83078 void shm_init_ns(struct ipc_namespace *ns)
83079 {
83080 ns->shm_ctlmax = SHMMAX;
83081@@ -554,6 +562,14 @@ static int newseg(struct ipc_namespace *ns, struct ipc_params *params)
83082 shp->shm_lprid = 0;
83083 shp->shm_atim = shp->shm_dtim = 0;
83084 shp->shm_ctim = get_seconds();
83085+#ifdef CONFIG_GRKERNSEC
83086+ {
83087+ struct timespec timeval;
83088+ do_posix_clock_monotonic_gettime(&timeval);
83089+
83090+ shp->shm_createtime = timeval.tv_sec;
83091+ }
83092+#endif
83093 shp->shm_segsz = size;
83094 shp->shm_nattch = 0;
83095 shp->shm_file = file;
83096@@ -607,18 +623,19 @@ static inline int shm_more_checks(struct kern_ipc_perm *ipcp,
83097 return 0;
83098 }
83099
83100+static struct ipc_ops shm_ops = {
83101+ .getnew = newseg,
83102+ .associate = shm_security,
83103+ .more_checks = shm_more_checks
83104+};
83105+
83106 SYSCALL_DEFINE3(shmget, key_t, key, size_t, size, int, shmflg)
83107 {
83108 struct ipc_namespace *ns;
83109- struct ipc_ops shm_ops;
83110 struct ipc_params shm_params;
83111
83112 ns = current->nsproxy->ipc_ns;
83113
83114- shm_ops.getnew = newseg;
83115- shm_ops.associate = shm_security;
83116- shm_ops.more_checks = shm_more_checks;
83117-
83118 shm_params.key = key;
83119 shm_params.flg = shmflg;
83120 shm_params.u.size = size;
83121@@ -1089,6 +1106,12 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
83122 f_mode = FMODE_READ | FMODE_WRITE;
83123 }
83124 if (shmflg & SHM_EXEC) {
83125+
83126+#ifdef CONFIG_PAX_MPROTECT
83127+ if (current->mm->pax_flags & MF_PAX_MPROTECT)
83128+ goto out;
83129+#endif
83130+
83131 prot |= PROT_EXEC;
83132 acc_mode |= S_IXUGO;
83133 }
83134@@ -1113,6 +1136,15 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
83135 if (err)
83136 goto out_unlock;
83137
83138+#ifdef CONFIG_GRKERNSEC
83139+ if (!gr_handle_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime,
83140+ shp->shm_perm.cuid, shmid) ||
83141+ !gr_chroot_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime)) {
83142+ err = -EACCES;
83143+ goto out_unlock;
83144+ }
83145+#endif
83146+
83147 ipc_lock_object(&shp->shm_perm);
83148
83149 /* check if shm_destroy() is tearing down shp */
83150@@ -1125,6 +1157,9 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
83151 path = shp->shm_file->f_path;
83152 path_get(&path);
83153 shp->shm_nattch++;
83154+#ifdef CONFIG_GRKERNSEC
83155+ shp->shm_lapid = current->pid;
83156+#endif
83157 size = i_size_read(path.dentry->d_inode);
83158 ipc_unlock_object(&shp->shm_perm);
83159 rcu_read_unlock();
83160diff --git a/ipc/util.c b/ipc/util.c
83161index 7684f41..5bf1880 100644
83162--- a/ipc/util.c
83163+++ b/ipc/util.c
83164@@ -71,6 +71,8 @@ struct ipc_proc_iface {
83165 int (*show)(struct seq_file *, void *);
83166 };
83167
83168+extern int gr_ipc_permitted(struct ipc_namespace *ns, struct kern_ipc_perm *ipcp, int requested_mode, int granted_mode);
83169+
83170 static void ipc_memory_notifier(struct work_struct *work)
83171 {
83172 ipcns_notify(IPCNS_MEMCHANGED);
83173@@ -560,6 +562,10 @@ int ipcperms(struct ipc_namespace *ns, struct kern_ipc_perm *ipcp, short flag)
83174 granted_mode >>= 6;
83175 else if (in_group_p(ipcp->cgid) || in_group_p(ipcp->gid))
83176 granted_mode >>= 3;
83177+
83178+ if (!gr_ipc_permitted(ns, ipcp, requested_mode, granted_mode))
83179+ return -1;
83180+
83181 /* is there some bit set in requested_mode but not in granted_mode? */
83182 if ((requested_mode & ~granted_mode & 0007) &&
83183 !ns_capable(ns->user_ns, CAP_IPC_OWNER))
83184diff --git a/kernel/acct.c b/kernel/acct.c
83185index 8d6e145..33e0b1e 100644
83186--- a/kernel/acct.c
83187+++ b/kernel/acct.c
83188@@ -556,7 +556,7 @@ static void do_acct_process(struct bsd_acct_struct *acct,
83189 */
83190 flim = current->signal->rlim[RLIMIT_FSIZE].rlim_cur;
83191 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = RLIM_INFINITY;
83192- file->f_op->write(file, (char *)&ac,
83193+ file->f_op->write(file, (char __force_user *)&ac,
83194 sizeof(acct_t), &file->f_pos);
83195 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = flim;
83196 set_fs(fs);
83197diff --git a/kernel/audit.c b/kernel/audit.c
83198index 7ddfd8a..49766eb 100644
83199--- a/kernel/audit.c
83200+++ b/kernel/audit.c
83201@@ -118,7 +118,7 @@ u32 audit_sig_sid = 0;
83202 3) suppressed due to audit_rate_limit
83203 4) suppressed due to audit_backlog_limit
83204 */
83205-static atomic_t audit_lost = ATOMIC_INIT(0);
83206+static atomic_unchecked_t audit_lost = ATOMIC_INIT(0);
83207
83208 /* The netlink socket. */
83209 static struct sock *audit_sock;
83210@@ -240,7 +240,7 @@ void audit_log_lost(const char *message)
83211 unsigned long now;
83212 int print;
83213
83214- atomic_inc(&audit_lost);
83215+ atomic_inc_unchecked(&audit_lost);
83216
83217 print = (audit_failure == AUDIT_FAIL_PANIC || !audit_rate_limit);
83218
83219@@ -259,7 +259,7 @@ void audit_log_lost(const char *message)
83220 printk(KERN_WARNING
83221 "audit: audit_lost=%d audit_rate_limit=%d "
83222 "audit_backlog_limit=%d\n",
83223- atomic_read(&audit_lost),
83224+ atomic_read_unchecked(&audit_lost),
83225 audit_rate_limit,
83226 audit_backlog_limit);
83227 audit_panic(message);
83228@@ -665,7 +665,7 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
83229 status_set.pid = audit_pid;
83230 status_set.rate_limit = audit_rate_limit;
83231 status_set.backlog_limit = audit_backlog_limit;
83232- status_set.lost = atomic_read(&audit_lost);
83233+ status_set.lost = atomic_read_unchecked(&audit_lost);
83234 status_set.backlog = skb_queue_len(&audit_skb_queue);
83235 audit_send_reply(NETLINK_CB(skb).portid, seq, AUDIT_GET, 0, 0,
83236 &status_set, sizeof(status_set));
83237@@ -1252,7 +1252,7 @@ void audit_log_n_hex(struct audit_buffer *ab, const unsigned char *buf,
83238 int i, avail, new_len;
83239 unsigned char *ptr;
83240 struct sk_buff *skb;
83241- static const unsigned char *hex = "0123456789ABCDEF";
83242+ static const unsigned char hex[] = "0123456789ABCDEF";
83243
83244 if (!ab)
83245 return;
83246diff --git a/kernel/auditsc.c b/kernel/auditsc.c
83247index 9845cb3..3ec9369 100644
83248--- a/kernel/auditsc.c
83249+++ b/kernel/auditsc.c
83250@@ -1962,7 +1962,7 @@ int auditsc_get_stamp(struct audit_context *ctx,
83251 }
83252
83253 /* global counter which is incremented every time something logs in */
83254-static atomic_t session_id = ATOMIC_INIT(0);
83255+static atomic_unchecked_t session_id = ATOMIC_INIT(0);
83256
83257 /**
83258 * audit_set_loginuid - set current task's audit_context loginuid
83259@@ -1986,7 +1986,7 @@ int audit_set_loginuid(kuid_t loginuid)
83260 return -EPERM;
83261 #endif /* CONFIG_AUDIT_LOGINUID_IMMUTABLE */
83262
83263- sessionid = atomic_inc_return(&session_id);
83264+ sessionid = atomic_inc_return_unchecked(&session_id);
83265 if (context && context->in_syscall) {
83266 struct audit_buffer *ab;
83267
83268diff --git a/kernel/capability.c b/kernel/capability.c
83269index 4e66bf9..cdccecf 100644
83270--- a/kernel/capability.c
83271+++ b/kernel/capability.c
83272@@ -202,6 +202,9 @@ SYSCALL_DEFINE2(capget, cap_user_header_t, header, cap_user_data_t, dataptr)
83273 * before modification is attempted and the application
83274 * fails.
83275 */
83276+ if (tocopy > ARRAY_SIZE(kdata))
83277+ return -EFAULT;
83278+
83279 if (copy_to_user(dataptr, kdata, tocopy
83280 * sizeof(struct __user_cap_data_struct))) {
83281 return -EFAULT;
83282@@ -303,10 +306,11 @@ bool has_ns_capability(struct task_struct *t,
83283 int ret;
83284
83285 rcu_read_lock();
83286- ret = security_capable(__task_cred(t), ns, cap);
83287+ ret = security_capable(__task_cred(t), ns, cap) == 0 &&
83288+ gr_task_is_capable(t, __task_cred(t), cap);
83289 rcu_read_unlock();
83290
83291- return (ret == 0);
83292+ return ret;
83293 }
83294
83295 /**
83296@@ -343,10 +347,10 @@ bool has_ns_capability_noaudit(struct task_struct *t,
83297 int ret;
83298
83299 rcu_read_lock();
83300- ret = security_capable_noaudit(__task_cred(t), ns, cap);
83301+ ret = security_capable_noaudit(__task_cred(t), ns, cap) == 0 && gr_task_is_capable_nolog(t, cap);
83302 rcu_read_unlock();
83303
83304- return (ret == 0);
83305+ return ret;
83306 }
83307
83308 /**
83309@@ -384,7 +388,7 @@ bool ns_capable(struct user_namespace *ns, int cap)
83310 BUG();
83311 }
83312
83313- if (security_capable(current_cred(), ns, cap) == 0) {
83314+ if (security_capable(current_cred(), ns, cap) == 0 && gr_is_capable(cap)) {
83315 current->flags |= PF_SUPERPRIV;
83316 return true;
83317 }
83318@@ -392,6 +396,21 @@ bool ns_capable(struct user_namespace *ns, int cap)
83319 }
83320 EXPORT_SYMBOL(ns_capable);
83321
83322+bool ns_capable_nolog(struct user_namespace *ns, int cap)
83323+{
83324+ if (unlikely(!cap_valid(cap))) {
83325+ printk(KERN_CRIT "capable_nolog() called with invalid cap=%u\n", cap);
83326+ BUG();
83327+ }
83328+
83329+ if (security_capable_noaudit(current_cred(), ns, cap) == 0 && gr_is_capable_nolog(cap)) {
83330+ current->flags |= PF_SUPERPRIV;
83331+ return true;
83332+ }
83333+ return false;
83334+}
83335+EXPORT_SYMBOL(ns_capable_nolog);
83336+
83337 /**
83338 * file_ns_capable - Determine if the file's opener had a capability in effect
83339 * @file: The file we want to check
83340@@ -432,6 +451,12 @@ bool capable(int cap)
83341 }
83342 EXPORT_SYMBOL(capable);
83343
83344+bool capable_nolog(int cap)
83345+{
83346+ return ns_capable_nolog(&init_user_ns, cap);
83347+}
83348+EXPORT_SYMBOL(capable_nolog);
83349+
83350 /**
83351 * inode_capable - Check superior capability over inode
83352 * @inode: The inode in question
83353@@ -453,3 +478,11 @@ bool inode_capable(const struct inode *inode, int cap)
83354 return ns_capable(ns, cap) && kuid_has_mapping(ns, inode->i_uid);
83355 }
83356 EXPORT_SYMBOL(inode_capable);
83357+
83358+bool inode_capable_nolog(const struct inode *inode, int cap)
83359+{
83360+ struct user_namespace *ns = current_user_ns();
83361+
83362+ return ns_capable_nolog(ns, cap) && kuid_has_mapping(ns, inode->i_uid);
83363+}
83364+EXPORT_SYMBOL(inode_capable_nolog);
83365diff --git a/kernel/cgroup.c b/kernel/cgroup.c
83366index b6fd783..7f526b7 100644
83367--- a/kernel/cgroup.c
83368+++ b/kernel/cgroup.c
83369@@ -5855,7 +5855,7 @@ static int cgroup_css_links_read(struct cgroup_subsys_state *css,
83370 struct css_set *cset = link->cset;
83371 struct task_struct *task;
83372 int count = 0;
83373- seq_printf(seq, "css_set %p\n", cset);
83374+ seq_printf(seq, "css_set %pK\n", cset);
83375 list_for_each_entry(task, &cset->tasks, cg_list) {
83376 if (count++ > MAX_TASKS_SHOWN_PER_CSS) {
83377 seq_puts(seq, " ...\n");
83378diff --git a/kernel/compat.c b/kernel/compat.c
83379index 0a09e48..f44f3f0 100644
83380--- a/kernel/compat.c
83381+++ b/kernel/compat.c
83382@@ -13,6 +13,7 @@
83383
83384 #include <linux/linkage.h>
83385 #include <linux/compat.h>
83386+#include <linux/module.h>
83387 #include <linux/errno.h>
83388 #include <linux/time.h>
83389 #include <linux/signal.h>
83390@@ -220,7 +221,7 @@ static long compat_nanosleep_restart(struct restart_block *restart)
83391 mm_segment_t oldfs;
83392 long ret;
83393
83394- restart->nanosleep.rmtp = (struct timespec __user *) &rmt;
83395+ restart->nanosleep.rmtp = (struct timespec __force_user *) &rmt;
83396 oldfs = get_fs();
83397 set_fs(KERNEL_DS);
83398 ret = hrtimer_nanosleep_restart(restart);
83399@@ -252,7 +253,7 @@ asmlinkage long compat_sys_nanosleep(struct compat_timespec __user *rqtp,
83400 oldfs = get_fs();
83401 set_fs(KERNEL_DS);
83402 ret = hrtimer_nanosleep(&tu,
83403- rmtp ? (struct timespec __user *)&rmt : NULL,
83404+ rmtp ? (struct timespec __force_user *)&rmt : NULL,
83405 HRTIMER_MODE_REL, CLOCK_MONOTONIC);
83406 set_fs(oldfs);
83407
83408@@ -361,7 +362,7 @@ asmlinkage long compat_sys_sigpending(compat_old_sigset_t __user *set)
83409 mm_segment_t old_fs = get_fs();
83410
83411 set_fs(KERNEL_DS);
83412- ret = sys_sigpending((old_sigset_t __user *) &s);
83413+ ret = sys_sigpending((old_sigset_t __force_user *) &s);
83414 set_fs(old_fs);
83415 if (ret == 0)
83416 ret = put_user(s, set);
83417@@ -451,7 +452,7 @@ asmlinkage long compat_sys_old_getrlimit(unsigned int resource,
83418 mm_segment_t old_fs = get_fs();
83419
83420 set_fs(KERNEL_DS);
83421- ret = sys_old_getrlimit(resource, &r);
83422+ ret = sys_old_getrlimit(resource, (struct rlimit __force_user *)&r);
83423 set_fs(old_fs);
83424
83425 if (!ret) {
83426@@ -533,8 +534,8 @@ COMPAT_SYSCALL_DEFINE4(wait4,
83427 set_fs (KERNEL_DS);
83428 ret = sys_wait4(pid,
83429 (stat_addr ?
83430- (unsigned int __user *) &status : NULL),
83431- options, (struct rusage __user *) &r);
83432+ (unsigned int __force_user *) &status : NULL),
83433+ options, (struct rusage __force_user *) &r);
83434 set_fs (old_fs);
83435
83436 if (ret > 0) {
83437@@ -560,8 +561,8 @@ COMPAT_SYSCALL_DEFINE5(waitid,
83438 memset(&info, 0, sizeof(info));
83439
83440 set_fs(KERNEL_DS);
83441- ret = sys_waitid(which, pid, (siginfo_t __user *)&info, options,
83442- uru ? (struct rusage __user *)&ru : NULL);
83443+ ret = sys_waitid(which, pid, (siginfo_t __force_user *)&info, options,
83444+ uru ? (struct rusage __force_user *)&ru : NULL);
83445 set_fs(old_fs);
83446
83447 if ((ret < 0) || (info.si_signo == 0))
83448@@ -695,8 +696,8 @@ long compat_sys_timer_settime(timer_t timer_id, int flags,
83449 oldfs = get_fs();
83450 set_fs(KERNEL_DS);
83451 err = sys_timer_settime(timer_id, flags,
83452- (struct itimerspec __user *) &newts,
83453- (struct itimerspec __user *) &oldts);
83454+ (struct itimerspec __force_user *) &newts,
83455+ (struct itimerspec __force_user *) &oldts);
83456 set_fs(oldfs);
83457 if (!err && old && put_compat_itimerspec(old, &oldts))
83458 return -EFAULT;
83459@@ -713,7 +714,7 @@ long compat_sys_timer_gettime(timer_t timer_id,
83460 oldfs = get_fs();
83461 set_fs(KERNEL_DS);
83462 err = sys_timer_gettime(timer_id,
83463- (struct itimerspec __user *) &ts);
83464+ (struct itimerspec __force_user *) &ts);
83465 set_fs(oldfs);
83466 if (!err && put_compat_itimerspec(setting, &ts))
83467 return -EFAULT;
83468@@ -732,7 +733,7 @@ long compat_sys_clock_settime(clockid_t which_clock,
83469 oldfs = get_fs();
83470 set_fs(KERNEL_DS);
83471 err = sys_clock_settime(which_clock,
83472- (struct timespec __user *) &ts);
83473+ (struct timespec __force_user *) &ts);
83474 set_fs(oldfs);
83475 return err;
83476 }
83477@@ -747,7 +748,7 @@ long compat_sys_clock_gettime(clockid_t which_clock,
83478 oldfs = get_fs();
83479 set_fs(KERNEL_DS);
83480 err = sys_clock_gettime(which_clock,
83481- (struct timespec __user *) &ts);
83482+ (struct timespec __force_user *) &ts);
83483 set_fs(oldfs);
83484 if (!err && put_compat_timespec(&ts, tp))
83485 return -EFAULT;
83486@@ -767,7 +768,7 @@ long compat_sys_clock_adjtime(clockid_t which_clock,
83487
83488 oldfs = get_fs();
83489 set_fs(KERNEL_DS);
83490- ret = sys_clock_adjtime(which_clock, (struct timex __user *) &txc);
83491+ ret = sys_clock_adjtime(which_clock, (struct timex __force_user *) &txc);
83492 set_fs(oldfs);
83493
83494 err = compat_put_timex(utp, &txc);
83495@@ -787,7 +788,7 @@ long compat_sys_clock_getres(clockid_t which_clock,
83496 oldfs = get_fs();
83497 set_fs(KERNEL_DS);
83498 err = sys_clock_getres(which_clock,
83499- (struct timespec __user *) &ts);
83500+ (struct timespec __force_user *) &ts);
83501 set_fs(oldfs);
83502 if (!err && tp && put_compat_timespec(&ts, tp))
83503 return -EFAULT;
83504@@ -799,9 +800,9 @@ static long compat_clock_nanosleep_restart(struct restart_block *restart)
83505 long err;
83506 mm_segment_t oldfs;
83507 struct timespec tu;
83508- struct compat_timespec *rmtp = restart->nanosleep.compat_rmtp;
83509+ struct compat_timespec __user *rmtp = restart->nanosleep.compat_rmtp;
83510
83511- restart->nanosleep.rmtp = (struct timespec __user *) &tu;
83512+ restart->nanosleep.rmtp = (struct timespec __force_user *) &tu;
83513 oldfs = get_fs();
83514 set_fs(KERNEL_DS);
83515 err = clock_nanosleep_restart(restart);
83516@@ -833,8 +834,8 @@ long compat_sys_clock_nanosleep(clockid_t which_clock, int flags,
83517 oldfs = get_fs();
83518 set_fs(KERNEL_DS);
83519 err = sys_clock_nanosleep(which_clock, flags,
83520- (struct timespec __user *) &in,
83521- (struct timespec __user *) &out);
83522+ (struct timespec __force_user *) &in,
83523+ (struct timespec __force_user *) &out);
83524 set_fs(oldfs);
83525
83526 if ((err == -ERESTART_RESTARTBLOCK) && rmtp &&
83527diff --git a/kernel/configs.c b/kernel/configs.c
83528index c18b1f1..b9a0132 100644
83529--- a/kernel/configs.c
83530+++ b/kernel/configs.c
83531@@ -74,8 +74,19 @@ static int __init ikconfig_init(void)
83532 struct proc_dir_entry *entry;
83533
83534 /* create the current config file */
83535+#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
83536+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_HIDESYM)
83537+ entry = proc_create("config.gz", S_IFREG | S_IRUSR, NULL,
83538+ &ikconfig_file_ops);
83539+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
83540+ entry = proc_create("config.gz", S_IFREG | S_IRUSR | S_IRGRP, NULL,
83541+ &ikconfig_file_ops);
83542+#endif
83543+#else
83544 entry = proc_create("config.gz", S_IFREG | S_IRUGO, NULL,
83545 &ikconfig_file_ops);
83546+#endif
83547+
83548 if (!entry)
83549 return -ENOMEM;
83550
83551diff --git a/kernel/cred.c b/kernel/cred.c
83552index e0573a4..3874e41 100644
83553--- a/kernel/cred.c
83554+++ b/kernel/cred.c
83555@@ -164,6 +164,16 @@ void exit_creds(struct task_struct *tsk)
83556 validate_creds(cred);
83557 alter_cred_subscribers(cred, -1);
83558 put_cred(cred);
83559+
83560+#ifdef CONFIG_GRKERNSEC_SETXID
83561+ cred = (struct cred *) tsk->delayed_cred;
83562+ if (cred != NULL) {
83563+ tsk->delayed_cred = NULL;
83564+ validate_creds(cred);
83565+ alter_cred_subscribers(cred, -1);
83566+ put_cred(cred);
83567+ }
83568+#endif
83569 }
83570
83571 /**
83572@@ -411,7 +421,7 @@ static bool cred_cap_issubset(const struct cred *set, const struct cred *subset)
83573 * Always returns 0 thus allowing this function to be tail-called at the end
83574 * of, say, sys_setgid().
83575 */
83576-int commit_creds(struct cred *new)
83577+static int __commit_creds(struct cred *new)
83578 {
83579 struct task_struct *task = current;
83580 const struct cred *old = task->real_cred;
83581@@ -430,6 +440,8 @@ int commit_creds(struct cred *new)
83582
83583 get_cred(new); /* we will require a ref for the subj creds too */
83584
83585+ gr_set_role_label(task, new->uid, new->gid);
83586+
83587 /* dumpability changes */
83588 if (!uid_eq(old->euid, new->euid) ||
83589 !gid_eq(old->egid, new->egid) ||
83590@@ -479,6 +491,102 @@ int commit_creds(struct cred *new)
83591 put_cred(old);
83592 return 0;
83593 }
83594+#ifdef CONFIG_GRKERNSEC_SETXID
83595+extern int set_user(struct cred *new);
83596+
83597+void gr_delayed_cred_worker(void)
83598+{
83599+ const struct cred *new = current->delayed_cred;
83600+ struct cred *ncred;
83601+
83602+ current->delayed_cred = NULL;
83603+
83604+ if (!uid_eq(current_uid(), GLOBAL_ROOT_UID) && new != NULL) {
83605+ // from doing get_cred on it when queueing this
83606+ put_cred(new);
83607+ return;
83608+ } else if (new == NULL)
83609+ return;
83610+
83611+ ncred = prepare_creds();
83612+ if (!ncred)
83613+ goto die;
83614+ // uids
83615+ ncred->uid = new->uid;
83616+ ncred->euid = new->euid;
83617+ ncred->suid = new->suid;
83618+ ncred->fsuid = new->fsuid;
83619+ // gids
83620+ ncred->gid = new->gid;
83621+ ncred->egid = new->egid;
83622+ ncred->sgid = new->sgid;
83623+ ncred->fsgid = new->fsgid;
83624+ // groups
83625+ if (set_groups(ncred, new->group_info) < 0) {
83626+ abort_creds(ncred);
83627+ goto die;
83628+ }
83629+ // caps
83630+ ncred->securebits = new->securebits;
83631+ ncred->cap_inheritable = new->cap_inheritable;
83632+ ncred->cap_permitted = new->cap_permitted;
83633+ ncred->cap_effective = new->cap_effective;
83634+ ncred->cap_bset = new->cap_bset;
83635+
83636+ if (set_user(ncred)) {
83637+ abort_creds(ncred);
83638+ goto die;
83639+ }
83640+
83641+ // from doing get_cred on it when queueing this
83642+ put_cred(new);
83643+
83644+ __commit_creds(ncred);
83645+ return;
83646+die:
83647+ // from doing get_cred on it when queueing this
83648+ put_cred(new);
83649+ do_group_exit(SIGKILL);
83650+}
83651+#endif
83652+
83653+int commit_creds(struct cred *new)
83654+{
83655+#ifdef CONFIG_GRKERNSEC_SETXID
83656+ int ret;
83657+ int schedule_it = 0;
83658+ struct task_struct *t;
83659+
83660+ /* we won't get called with tasklist_lock held for writing
83661+ and interrupts disabled as the cred struct in that case is
83662+ init_cred
83663+ */
83664+ if (grsec_enable_setxid && !current_is_single_threaded() &&
83665+ uid_eq(current_uid(), GLOBAL_ROOT_UID) &&
83666+ !uid_eq(new->uid, GLOBAL_ROOT_UID)) {
83667+ schedule_it = 1;
83668+ }
83669+ ret = __commit_creds(new);
83670+ if (schedule_it) {
83671+ rcu_read_lock();
83672+ read_lock(&tasklist_lock);
83673+ for (t = next_thread(current); t != current;
83674+ t = next_thread(t)) {
83675+ if (t->delayed_cred == NULL) {
83676+ t->delayed_cred = get_cred(new);
83677+ set_tsk_thread_flag(t, TIF_GRSEC_SETXID);
83678+ set_tsk_need_resched(t);
83679+ }
83680+ }
83681+ read_unlock(&tasklist_lock);
83682+ rcu_read_unlock();
83683+ }
83684+ return ret;
83685+#else
83686+ return __commit_creds(new);
83687+#endif
83688+}
83689+
83690 EXPORT_SYMBOL(commit_creds);
83691
83692 /**
83693diff --git a/kernel/debug/debug_core.c b/kernel/debug/debug_core.c
83694index 0506d44..2c20034 100644
83695--- a/kernel/debug/debug_core.c
83696+++ b/kernel/debug/debug_core.c
83697@@ -123,7 +123,7 @@ static DEFINE_RAW_SPINLOCK(dbg_slave_lock);
83698 */
83699 static atomic_t masters_in_kgdb;
83700 static atomic_t slaves_in_kgdb;
83701-static atomic_t kgdb_break_tasklet_var;
83702+static atomic_unchecked_t kgdb_break_tasklet_var;
83703 atomic_t kgdb_setting_breakpoint;
83704
83705 struct task_struct *kgdb_usethread;
83706@@ -133,7 +133,7 @@ int kgdb_single_step;
83707 static pid_t kgdb_sstep_pid;
83708
83709 /* to keep track of the CPU which is doing the single stepping*/
83710-atomic_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
83711+atomic_unchecked_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
83712
83713 /*
83714 * If you are debugging a problem where roundup (the collection of
83715@@ -541,7 +541,7 @@ return_normal:
83716 * kernel will only try for the value of sstep_tries before
83717 * giving up and continuing on.
83718 */
83719- if (atomic_read(&kgdb_cpu_doing_single_step) != -1 &&
83720+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1 &&
83721 (kgdb_info[cpu].task &&
83722 kgdb_info[cpu].task->pid != kgdb_sstep_pid) && --sstep_tries) {
83723 atomic_set(&kgdb_active, -1);
83724@@ -635,8 +635,8 @@ cpu_master_loop:
83725 }
83726
83727 kgdb_restore:
83728- if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
83729- int sstep_cpu = atomic_read(&kgdb_cpu_doing_single_step);
83730+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
83731+ int sstep_cpu = atomic_read_unchecked(&kgdb_cpu_doing_single_step);
83732 if (kgdb_info[sstep_cpu].task)
83733 kgdb_sstep_pid = kgdb_info[sstep_cpu].task->pid;
83734 else
83735@@ -888,18 +888,18 @@ static void kgdb_unregister_callbacks(void)
83736 static void kgdb_tasklet_bpt(unsigned long ing)
83737 {
83738 kgdb_breakpoint();
83739- atomic_set(&kgdb_break_tasklet_var, 0);
83740+ atomic_set_unchecked(&kgdb_break_tasklet_var, 0);
83741 }
83742
83743 static DECLARE_TASKLET(kgdb_tasklet_breakpoint, kgdb_tasklet_bpt, 0);
83744
83745 void kgdb_schedule_breakpoint(void)
83746 {
83747- if (atomic_read(&kgdb_break_tasklet_var) ||
83748+ if (atomic_read_unchecked(&kgdb_break_tasklet_var) ||
83749 atomic_read(&kgdb_active) != -1 ||
83750 atomic_read(&kgdb_setting_breakpoint))
83751 return;
83752- atomic_inc(&kgdb_break_tasklet_var);
83753+ atomic_inc_unchecked(&kgdb_break_tasklet_var);
83754 tasklet_schedule(&kgdb_tasklet_breakpoint);
83755 }
83756 EXPORT_SYMBOL_GPL(kgdb_schedule_breakpoint);
83757diff --git a/kernel/debug/kdb/kdb_main.c b/kernel/debug/kdb/kdb_main.c
83758index 00eb8f7..d7e3244 100644
83759--- a/kernel/debug/kdb/kdb_main.c
83760+++ b/kernel/debug/kdb/kdb_main.c
83761@@ -1974,7 +1974,7 @@ static int kdb_lsmod(int argc, const char **argv)
83762 continue;
83763
83764 kdb_printf("%-20s%8u 0x%p ", mod->name,
83765- mod->core_size, (void *)mod);
83766+ mod->core_size_rx + mod->core_size_rw, (void *)mod);
83767 #ifdef CONFIG_MODULE_UNLOAD
83768 kdb_printf("%4ld ", module_refcount(mod));
83769 #endif
83770@@ -1984,7 +1984,7 @@ static int kdb_lsmod(int argc, const char **argv)
83771 kdb_printf(" (Loading)");
83772 else
83773 kdb_printf(" (Live)");
83774- kdb_printf(" 0x%p", mod->module_core);
83775+ kdb_printf(" 0x%p 0x%p", mod->module_core_rx, mod->module_core_rw);
83776
83777 #ifdef CONFIG_MODULE_UNLOAD
83778 {
83779diff --git a/kernel/events/core.c b/kernel/events/core.c
83780index 953c143..5646bb1 100644
83781--- a/kernel/events/core.c
83782+++ b/kernel/events/core.c
83783@@ -157,8 +157,15 @@ static struct srcu_struct pmus_srcu;
83784 * 0 - disallow raw tracepoint access for unpriv
83785 * 1 - disallow cpu events for unpriv
83786 * 2 - disallow kernel profiling for unpriv
83787+ * 3 - disallow all unpriv perf event use
83788 */
83789-int sysctl_perf_event_paranoid __read_mostly = 1;
83790+#ifdef CONFIG_GRKERNSEC_PERF_HARDEN
83791+int sysctl_perf_event_legitimately_concerned __read_mostly = 3;
83792+#elif defined(CONFIG_GRKERNSEC_HIDESYM)
83793+int sysctl_perf_event_legitimately_concerned __read_mostly = 2;
83794+#else
83795+int sysctl_perf_event_legitimately_concerned __read_mostly = 1;
83796+#endif
83797
83798 /* Minimum for 512 kiB + 1 user control page */
83799 int sysctl_perf_event_mlock __read_mostly = 512 + (PAGE_SIZE / 1024); /* 'free' kiB per user */
83800@@ -271,7 +278,7 @@ void perf_sample_event_took(u64 sample_len_ns)
83801 update_perf_cpu_limits();
83802 }
83803
83804-static atomic64_t perf_event_id;
83805+static atomic64_unchecked_t perf_event_id;
83806
83807 static void cpu_ctx_sched_out(struct perf_cpu_context *cpuctx,
83808 enum event_type_t event_type);
83809@@ -2940,7 +2947,7 @@ static void __perf_event_read(void *info)
83810
83811 static inline u64 perf_event_count(struct perf_event *event)
83812 {
83813- return local64_read(&event->count) + atomic64_read(&event->child_count);
83814+ return local64_read(&event->count) + atomic64_read_unchecked(&event->child_count);
83815 }
83816
83817 static u64 perf_event_read(struct perf_event *event)
83818@@ -3308,9 +3315,9 @@ u64 perf_event_read_value(struct perf_event *event, u64 *enabled, u64 *running)
83819 mutex_lock(&event->child_mutex);
83820 total += perf_event_read(event);
83821 *enabled += event->total_time_enabled +
83822- atomic64_read(&event->child_total_time_enabled);
83823+ atomic64_read_unchecked(&event->child_total_time_enabled);
83824 *running += event->total_time_running +
83825- atomic64_read(&event->child_total_time_running);
83826+ atomic64_read_unchecked(&event->child_total_time_running);
83827
83828 list_for_each_entry(child, &event->child_list, child_list) {
83829 total += perf_event_read(child);
83830@@ -3725,10 +3732,10 @@ void perf_event_update_userpage(struct perf_event *event)
83831 userpg->offset -= local64_read(&event->hw.prev_count);
83832
83833 userpg->time_enabled = enabled +
83834- atomic64_read(&event->child_total_time_enabled);
83835+ atomic64_read_unchecked(&event->child_total_time_enabled);
83836
83837 userpg->time_running = running +
83838- atomic64_read(&event->child_total_time_running);
83839+ atomic64_read_unchecked(&event->child_total_time_running);
83840
83841 arch_perf_update_userpage(userpg, now);
83842
83843@@ -4279,7 +4286,7 @@ perf_output_sample_ustack(struct perf_output_handle *handle, u64 dump_size,
83844
83845 /* Data. */
83846 sp = perf_user_stack_pointer(regs);
83847- rem = __output_copy_user(handle, (void *) sp, dump_size);
83848+ rem = __output_copy_user(handle, (void __user *) sp, dump_size);
83849 dyn_size = dump_size - rem;
83850
83851 perf_output_skip(handle, rem);
83852@@ -4370,11 +4377,11 @@ static void perf_output_read_one(struct perf_output_handle *handle,
83853 values[n++] = perf_event_count(event);
83854 if (read_format & PERF_FORMAT_TOTAL_TIME_ENABLED) {
83855 values[n++] = enabled +
83856- atomic64_read(&event->child_total_time_enabled);
83857+ atomic64_read_unchecked(&event->child_total_time_enabled);
83858 }
83859 if (read_format & PERF_FORMAT_TOTAL_TIME_RUNNING) {
83860 values[n++] = running +
83861- atomic64_read(&event->child_total_time_running);
83862+ atomic64_read_unchecked(&event->child_total_time_running);
83863 }
83864 if (read_format & PERF_FORMAT_ID)
83865 values[n++] = primary_event_id(event);
83866@@ -5112,12 +5119,12 @@ static void perf_event_mmap_event(struct perf_mmap_event *mmap_event)
83867 * need to add enough zero bytes after the string to handle
83868 * the 64bit alignment we do later.
83869 */
83870- buf = kzalloc(PATH_MAX + sizeof(u64), GFP_KERNEL);
83871+ buf = kzalloc(PATH_MAX, GFP_KERNEL);
83872 if (!buf) {
83873 name = strncpy(tmp, "//enomem", sizeof(tmp));
83874 goto got_name;
83875 }
83876- name = d_path(&file->f_path, buf, PATH_MAX);
83877+ name = d_path(&file->f_path, buf, PATH_MAX - sizeof(u64));
83878 if (IS_ERR(name)) {
83879 name = strncpy(tmp, "//toolong", sizeof(tmp));
83880 goto got_name;
83881@@ -6639,7 +6646,7 @@ perf_event_alloc(struct perf_event_attr *attr, int cpu,
83882 event->parent = parent_event;
83883
83884 event->ns = get_pid_ns(task_active_pid_ns(current));
83885- event->id = atomic64_inc_return(&perf_event_id);
83886+ event->id = atomic64_inc_return_unchecked(&perf_event_id);
83887
83888 event->state = PERF_EVENT_STATE_INACTIVE;
83889
83890@@ -6938,6 +6945,11 @@ SYSCALL_DEFINE5(perf_event_open,
83891 if (flags & ~PERF_FLAG_ALL)
83892 return -EINVAL;
83893
83894+#ifdef CONFIG_GRKERNSEC_PERF_HARDEN
83895+ if (perf_paranoid_any() && !capable(CAP_SYS_ADMIN))
83896+ return -EACCES;
83897+#endif
83898+
83899 err = perf_copy_attr(attr_uptr, &attr);
83900 if (err)
83901 return err;
83902@@ -7271,10 +7283,10 @@ static void sync_child_event(struct perf_event *child_event,
83903 /*
83904 * Add back the child's count to the parent's count:
83905 */
83906- atomic64_add(child_val, &parent_event->child_count);
83907- atomic64_add(child_event->total_time_enabled,
83908+ atomic64_add_unchecked(child_val, &parent_event->child_count);
83909+ atomic64_add_unchecked(child_event->total_time_enabled,
83910 &parent_event->child_total_time_enabled);
83911- atomic64_add(child_event->total_time_running,
83912+ atomic64_add_unchecked(child_event->total_time_running,
83913 &parent_event->child_total_time_running);
83914
83915 /*
83916diff --git a/kernel/events/internal.h b/kernel/events/internal.h
83917index ca65997..60df03d 100644
83918--- a/kernel/events/internal.h
83919+++ b/kernel/events/internal.h
83920@@ -81,10 +81,10 @@ static inline unsigned long perf_data_size(struct ring_buffer *rb)
83921 return rb->nr_pages << (PAGE_SHIFT + page_order(rb));
83922 }
83923
83924-#define DEFINE_OUTPUT_COPY(func_name, memcpy_func) \
83925-static inline unsigned int \
83926+#define DEFINE_OUTPUT_COPY(func_name, memcpy_func, user) \
83927+static inline unsigned long \
83928 func_name(struct perf_output_handle *handle, \
83929- const void *buf, unsigned int len) \
83930+ const void user *buf, unsigned long len) \
83931 { \
83932 unsigned long size, written; \
83933 \
83934@@ -116,17 +116,17 @@ static inline int memcpy_common(void *dst, const void *src, size_t n)
83935 return n;
83936 }
83937
83938-DEFINE_OUTPUT_COPY(__output_copy, memcpy_common)
83939+DEFINE_OUTPUT_COPY(__output_copy, memcpy_common, )
83940
83941 #define MEMCPY_SKIP(dst, src, n) (n)
83942
83943-DEFINE_OUTPUT_COPY(__output_skip, MEMCPY_SKIP)
83944+DEFINE_OUTPUT_COPY(__output_skip, MEMCPY_SKIP, )
83945
83946 #ifndef arch_perf_out_copy_user
83947 #define arch_perf_out_copy_user __copy_from_user_inatomic
83948 #endif
83949
83950-DEFINE_OUTPUT_COPY(__output_copy_user, arch_perf_out_copy_user)
83951+DEFINE_OUTPUT_COPY(__output_copy_user, arch_perf_out_copy_user, __user)
83952
83953 /* Callchain handling */
83954 extern struct perf_callchain_entry *
83955diff --git a/kernel/events/uprobes.c b/kernel/events/uprobes.c
83956index ad8e1bd..fed7ba9 100644
83957--- a/kernel/events/uprobes.c
83958+++ b/kernel/events/uprobes.c
83959@@ -1556,7 +1556,7 @@ static int is_trap_at_addr(struct mm_struct *mm, unsigned long vaddr)
83960 {
83961 struct page *page;
83962 uprobe_opcode_t opcode;
83963- int result;
83964+ long result;
83965
83966 pagefault_disable();
83967 result = __copy_from_user_inatomic(&opcode, (void __user*)vaddr,
83968diff --git a/kernel/exit.c b/kernel/exit.c
83969index a949819..a5f127d 100644
83970--- a/kernel/exit.c
83971+++ b/kernel/exit.c
83972@@ -172,6 +172,10 @@ void release_task(struct task_struct * p)
83973 struct task_struct *leader;
83974 int zap_leader;
83975 repeat:
83976+#ifdef CONFIG_NET
83977+ gr_del_task_from_ip_table(p);
83978+#endif
83979+
83980 /* don't need to get the RCU readlock here - the process is dead and
83981 * can't be modifying its own credentials. But shut RCU-lockdep up */
83982 rcu_read_lock();
83983@@ -329,7 +333,7 @@ int allow_signal(int sig)
83984 * know it'll be handled, so that they don't get converted to
83985 * SIGKILL or just silently dropped.
83986 */
83987- current->sighand->action[(sig)-1].sa.sa_handler = (void __user *)2;
83988+ current->sighand->action[(sig)-1].sa.sa_handler = (__force void __user *)2;
83989 recalc_sigpending();
83990 spin_unlock_irq(&current->sighand->siglock);
83991 return 0;
83992@@ -698,6 +702,8 @@ void do_exit(long code)
83993 struct task_struct *tsk = current;
83994 int group_dead;
83995
83996+ set_fs(USER_DS);
83997+
83998 profile_task_exit(tsk);
83999
84000 WARN_ON(blk_needs_flush_plug(tsk));
84001@@ -714,7 +720,6 @@ void do_exit(long code)
84002 * mm_release()->clear_child_tid() from writing to a user-controlled
84003 * kernel address.
84004 */
84005- set_fs(USER_DS);
84006
84007 ptrace_event(PTRACE_EVENT_EXIT, code);
84008
84009@@ -773,6 +778,9 @@ void do_exit(long code)
84010 tsk->exit_code = code;
84011 taskstats_exit(tsk, group_dead);
84012
84013+ gr_acl_handle_psacct(tsk, code);
84014+ gr_acl_handle_exit();
84015+
84016 exit_mm(tsk);
84017
84018 if (group_dead)
84019@@ -894,7 +902,7 @@ SYSCALL_DEFINE1(exit, int, error_code)
84020 * Take down every thread in the group. This is called by fatal signals
84021 * as well as by sys_exit_group (below).
84022 */
84023-void
84024+__noreturn void
84025 do_group_exit(int exit_code)
84026 {
84027 struct signal_struct *sig = current->signal;
84028diff --git a/kernel/fork.c b/kernel/fork.c
84029index 690cfac..3be2d98 100644
84030--- a/kernel/fork.c
84031+++ b/kernel/fork.c
84032@@ -319,7 +319,7 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
84033 *stackend = STACK_END_MAGIC; /* for overflow detection */
84034
84035 #ifdef CONFIG_CC_STACKPROTECTOR
84036- tsk->stack_canary = get_random_int();
84037+ tsk->stack_canary = pax_get_random_long();
84038 #endif
84039
84040 /*
84041@@ -345,12 +345,80 @@ free_tsk:
84042 }
84043
84044 #ifdef CONFIG_MMU
84045-static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
84046+static struct vm_area_struct *dup_vma(struct mm_struct *mm, struct mm_struct *oldmm, struct vm_area_struct *mpnt)
84047+{
84048+ struct vm_area_struct *tmp;
84049+ unsigned long charge;
84050+ struct file *file;
84051+ int retval;
84052+
84053+ charge = 0;
84054+ if (mpnt->vm_flags & VM_ACCOUNT) {
84055+ unsigned long len = vma_pages(mpnt);
84056+
84057+ if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
84058+ goto fail_nomem;
84059+ charge = len;
84060+ }
84061+ tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
84062+ if (!tmp)
84063+ goto fail_nomem;
84064+ *tmp = *mpnt;
84065+ tmp->vm_mm = mm;
84066+ INIT_LIST_HEAD(&tmp->anon_vma_chain);
84067+ retval = vma_dup_policy(mpnt, tmp);
84068+ if (retval)
84069+ goto fail_nomem_policy;
84070+ if (anon_vma_fork(tmp, mpnt))
84071+ goto fail_nomem_anon_vma_fork;
84072+ tmp->vm_flags &= ~VM_LOCKED;
84073+ tmp->vm_next = tmp->vm_prev = NULL;
84074+ tmp->vm_mirror = NULL;
84075+ file = tmp->vm_file;
84076+ if (file) {
84077+ struct inode *inode = file_inode(file);
84078+ struct address_space *mapping = file->f_mapping;
84079+
84080+ get_file(file);
84081+ if (tmp->vm_flags & VM_DENYWRITE)
84082+ atomic_dec(&inode->i_writecount);
84083+ mutex_lock(&mapping->i_mmap_mutex);
84084+ if (tmp->vm_flags & VM_SHARED)
84085+ mapping->i_mmap_writable++;
84086+ flush_dcache_mmap_lock(mapping);
84087+ /* insert tmp into the share list, just after mpnt */
84088+ if (unlikely(tmp->vm_flags & VM_NONLINEAR))
84089+ vma_nonlinear_insert(tmp, &mapping->i_mmap_nonlinear);
84090+ else
84091+ vma_interval_tree_insert_after(tmp, mpnt, &mapping->i_mmap);
84092+ flush_dcache_mmap_unlock(mapping);
84093+ mutex_unlock(&mapping->i_mmap_mutex);
84094+ }
84095+
84096+ /*
84097+ * Clear hugetlb-related page reserves for children. This only
84098+ * affects MAP_PRIVATE mappings. Faults generated by the child
84099+ * are not guaranteed to succeed, even if read-only
84100+ */
84101+ if (is_vm_hugetlb_page(tmp))
84102+ reset_vma_resv_huge_pages(tmp);
84103+
84104+ return tmp;
84105+
84106+fail_nomem_anon_vma_fork:
84107+ mpol_put(vma_policy(tmp));
84108+fail_nomem_policy:
84109+ kmem_cache_free(vm_area_cachep, tmp);
84110+fail_nomem:
84111+ vm_unacct_memory(charge);
84112+ return NULL;
84113+}
84114+
84115+static __latent_entropy int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
84116 {
84117 struct vm_area_struct *mpnt, *tmp, *prev, **pprev;
84118 struct rb_node **rb_link, *rb_parent;
84119 int retval;
84120- unsigned long charge;
84121
84122 uprobe_start_dup_mmap();
84123 down_write(&oldmm->mmap_sem);
84124@@ -379,55 +447,15 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
84125
84126 prev = NULL;
84127 for (mpnt = oldmm->mmap; mpnt; mpnt = mpnt->vm_next) {
84128- struct file *file;
84129-
84130 if (mpnt->vm_flags & VM_DONTCOPY) {
84131 vm_stat_account(mm, mpnt->vm_flags, mpnt->vm_file,
84132 -vma_pages(mpnt));
84133 continue;
84134 }
84135- charge = 0;
84136- if (mpnt->vm_flags & VM_ACCOUNT) {
84137- unsigned long len = vma_pages(mpnt);
84138-
84139- if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
84140- goto fail_nomem;
84141- charge = len;
84142- }
84143- tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
84144- if (!tmp)
84145- goto fail_nomem;
84146- *tmp = *mpnt;
84147- INIT_LIST_HEAD(&tmp->anon_vma_chain);
84148- retval = vma_dup_policy(mpnt, tmp);
84149- if (retval)
84150- goto fail_nomem_policy;
84151- tmp->vm_mm = mm;
84152- if (anon_vma_fork(tmp, mpnt))
84153- goto fail_nomem_anon_vma_fork;
84154- tmp->vm_flags &= ~VM_LOCKED;
84155- tmp->vm_next = tmp->vm_prev = NULL;
84156- file = tmp->vm_file;
84157- if (file) {
84158- struct inode *inode = file_inode(file);
84159- struct address_space *mapping = file->f_mapping;
84160-
84161- get_file(file);
84162- if (tmp->vm_flags & VM_DENYWRITE)
84163- atomic_dec(&inode->i_writecount);
84164- mutex_lock(&mapping->i_mmap_mutex);
84165- if (tmp->vm_flags & VM_SHARED)
84166- mapping->i_mmap_writable++;
84167- flush_dcache_mmap_lock(mapping);
84168- /* insert tmp into the share list, just after mpnt */
84169- if (unlikely(tmp->vm_flags & VM_NONLINEAR))
84170- vma_nonlinear_insert(tmp,
84171- &mapping->i_mmap_nonlinear);
84172- else
84173- vma_interval_tree_insert_after(tmp, mpnt,
84174- &mapping->i_mmap);
84175- flush_dcache_mmap_unlock(mapping);
84176- mutex_unlock(&mapping->i_mmap_mutex);
84177+ tmp = dup_vma(mm, oldmm, mpnt);
84178+ if (!tmp) {
84179+ retval = -ENOMEM;
84180+ goto out;
84181 }
84182
84183 /*
84184@@ -459,6 +487,31 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
84185 if (retval)
84186 goto out;
84187 }
84188+
84189+#ifdef CONFIG_PAX_SEGMEXEC
84190+ if (oldmm->pax_flags & MF_PAX_SEGMEXEC) {
84191+ struct vm_area_struct *mpnt_m;
84192+
84193+ for (mpnt = oldmm->mmap, mpnt_m = mm->mmap; mpnt; mpnt = mpnt->vm_next, mpnt_m = mpnt_m->vm_next) {
84194+ BUG_ON(!mpnt_m || mpnt_m->vm_mirror || mpnt->vm_mm != oldmm || mpnt_m->vm_mm != mm);
84195+
84196+ if (!mpnt->vm_mirror)
84197+ continue;
84198+
84199+ if (mpnt->vm_end <= SEGMEXEC_TASK_SIZE) {
84200+ BUG_ON(mpnt->vm_mirror->vm_mirror != mpnt);
84201+ mpnt->vm_mirror = mpnt_m;
84202+ } else {
84203+ BUG_ON(mpnt->vm_mirror->vm_mirror == mpnt || mpnt->vm_mirror->vm_mirror->vm_mm != mm);
84204+ mpnt_m->vm_mirror = mpnt->vm_mirror->vm_mirror;
84205+ mpnt_m->vm_mirror->vm_mirror = mpnt_m;
84206+ mpnt->vm_mirror->vm_mirror = mpnt;
84207+ }
84208+ }
84209+ BUG_ON(mpnt_m);
84210+ }
84211+#endif
84212+
84213 /* a new mm has just been created */
84214 arch_dup_mmap(oldmm, mm);
84215 retval = 0;
84216@@ -468,14 +521,6 @@ out:
84217 up_write(&oldmm->mmap_sem);
84218 uprobe_end_dup_mmap();
84219 return retval;
84220-fail_nomem_anon_vma_fork:
84221- mpol_put(vma_policy(tmp));
84222-fail_nomem_policy:
84223- kmem_cache_free(vm_area_cachep, tmp);
84224-fail_nomem:
84225- retval = -ENOMEM;
84226- vm_unacct_memory(charge);
84227- goto out;
84228 }
84229
84230 static inline int mm_alloc_pgd(struct mm_struct *mm)
84231@@ -689,8 +734,8 @@ struct mm_struct *mm_access(struct task_struct *task, unsigned int mode)
84232 return ERR_PTR(err);
84233
84234 mm = get_task_mm(task);
84235- if (mm && mm != current->mm &&
84236- !ptrace_may_access(task, mode)) {
84237+ if (mm && ((mm != current->mm && !ptrace_may_access(task, mode)) ||
84238+ (mode == PTRACE_MODE_ATTACH && (gr_handle_proc_ptrace(task) || gr_acl_handle_procpidmem(task))))) {
84239 mmput(mm);
84240 mm = ERR_PTR(-EACCES);
84241 }
84242@@ -912,13 +957,20 @@ static int copy_fs(unsigned long clone_flags, struct task_struct *tsk)
84243 spin_unlock(&fs->lock);
84244 return -EAGAIN;
84245 }
84246- fs->users++;
84247+ atomic_inc(&fs->users);
84248 spin_unlock(&fs->lock);
84249 return 0;
84250 }
84251 tsk->fs = copy_fs_struct(fs);
84252 if (!tsk->fs)
84253 return -ENOMEM;
84254+ /* Carry through gr_chroot_dentry and is_chrooted instead
84255+ of recomputing it here. Already copied when the task struct
84256+ is duplicated. This allows pivot_root to not be treated as
84257+ a chroot
84258+ */
84259+ //gr_set_chroot_entries(tsk, &tsk->fs->root);
84260+
84261 return 0;
84262 }
84263
84264@@ -1129,7 +1181,7 @@ init_task_pid(struct task_struct *task, enum pid_type type, struct pid *pid)
84265 * parts of the process environment (as per the clone
84266 * flags). The actual kick-off is left to the caller.
84267 */
84268-static struct task_struct *copy_process(unsigned long clone_flags,
84269+static __latent_entropy struct task_struct *copy_process(unsigned long clone_flags,
84270 unsigned long stack_start,
84271 unsigned long stack_size,
84272 int __user *child_tidptr,
84273@@ -1201,6 +1253,9 @@ static struct task_struct *copy_process(unsigned long clone_flags,
84274 DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
84275 #endif
84276 retval = -EAGAIN;
84277+
84278+ gr_learn_resource(p, RLIMIT_NPROC, atomic_read(&p->real_cred->user->processes), 0);
84279+
84280 if (atomic_read(&p->real_cred->user->processes) >=
84281 task_rlimit(p, RLIMIT_NPROC)) {
84282 if (p->real_cred->user != INIT_USER &&
84283@@ -1450,6 +1505,11 @@ static struct task_struct *copy_process(unsigned long clone_flags,
84284 goto bad_fork_free_pid;
84285 }
84286
84287+ /* synchronizes with gr_set_acls()
84288+ we need to call this past the point of no return for fork()
84289+ */
84290+ gr_copy_label(p);
84291+
84292 if (likely(p->pid)) {
84293 ptrace_init_task(p, (clone_flags & CLONE_PTRACE) || trace);
84294
84295@@ -1535,6 +1595,8 @@ bad_fork_cleanup_count:
84296 bad_fork_free:
84297 free_task(p);
84298 fork_out:
84299+ gr_log_forkfail(retval);
84300+
84301 return ERR_PTR(retval);
84302 }
84303
84304@@ -1596,6 +1658,7 @@ long do_fork(unsigned long clone_flags,
84305
84306 p = copy_process(clone_flags, stack_start, stack_size,
84307 child_tidptr, NULL, trace);
84308+ add_latent_entropy();
84309 /*
84310 * Do this prior waking up the new thread - the thread pointer
84311 * might get invalid after that point, if the thread exits quickly.
84312@@ -1610,6 +1673,8 @@ long do_fork(unsigned long clone_flags,
84313 if (clone_flags & CLONE_PARENT_SETTID)
84314 put_user(nr, parent_tidptr);
84315
84316+ gr_handle_brute_check();
84317+
84318 if (clone_flags & CLONE_VFORK) {
84319 p->vfork_done = &vfork;
84320 init_completion(&vfork);
84321@@ -1726,7 +1791,7 @@ void __init proc_caches_init(void)
84322 mm_cachep = kmem_cache_create("mm_struct",
84323 sizeof(struct mm_struct), ARCH_MIN_MMSTRUCT_ALIGN,
84324 SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_NOTRACK, NULL);
84325- vm_area_cachep = KMEM_CACHE(vm_area_struct, SLAB_PANIC);
84326+ vm_area_cachep = KMEM_CACHE(vm_area_struct, SLAB_PANIC | SLAB_NO_SANITIZE);
84327 mmap_init();
84328 nsproxy_cache_init();
84329 }
84330@@ -1766,7 +1831,7 @@ static int unshare_fs(unsigned long unshare_flags, struct fs_struct **new_fsp)
84331 return 0;
84332
84333 /* don't need lock here; in the worst case we'll do useless copy */
84334- if (fs->users == 1)
84335+ if (atomic_read(&fs->users) == 1)
84336 return 0;
84337
84338 *new_fsp = copy_fs_struct(fs);
84339@@ -1873,7 +1938,8 @@ SYSCALL_DEFINE1(unshare, unsigned long, unshare_flags)
84340 fs = current->fs;
84341 spin_lock(&fs->lock);
84342 current->fs = new_fs;
84343- if (--fs->users)
84344+ gr_set_chroot_entries(current, &current->fs->root);
84345+ if (atomic_dec_return(&fs->users))
84346 new_fs = NULL;
84347 else
84348 new_fs = fs;
84349diff --git a/kernel/futex.c b/kernel/futex.c
84350index 221a58f..1b8cfce 100644
84351--- a/kernel/futex.c
84352+++ b/kernel/futex.c
84353@@ -54,6 +54,7 @@
84354 #include <linux/mount.h>
84355 #include <linux/pagemap.h>
84356 #include <linux/syscalls.h>
84357+#include <linux/ptrace.h>
84358 #include <linux/signal.h>
84359 #include <linux/export.h>
84360 #include <linux/magic.h>
84361@@ -243,6 +244,11 @@ get_futex_key(u32 __user *uaddr, int fshared, union futex_key *key, int rw)
84362 struct page *page, *page_head;
84363 int err, ro = 0;
84364
84365+#ifdef CONFIG_PAX_SEGMEXEC
84366+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && address >= SEGMEXEC_TASK_SIZE)
84367+ return -EFAULT;
84368+#endif
84369+
84370 /*
84371 * The futex address must be "naturally" aligned.
84372 */
84373@@ -441,7 +447,7 @@ static int cmpxchg_futex_value_locked(u32 *curval, u32 __user *uaddr,
84374
84375 static int get_futex_value_locked(u32 *dest, u32 __user *from)
84376 {
84377- int ret;
84378+ unsigned long ret;
84379
84380 pagefault_disable();
84381 ret = __copy_from_user_inatomic(dest, from, sizeof(u32));
84382@@ -2734,6 +2740,7 @@ static int __init futex_init(void)
84383 {
84384 u32 curval;
84385 int i;
84386+ mm_segment_t oldfs;
84387
84388 /*
84389 * This will fail and we want it. Some arch implementations do
84390@@ -2745,8 +2752,11 @@ static int __init futex_init(void)
84391 * implementation, the non-functional ones will return
84392 * -ENOSYS.
84393 */
84394+ oldfs = get_fs();
84395+ set_fs(USER_DS);
84396 if (cmpxchg_futex_value_locked(&curval, NULL, 0, 0) == -EFAULT)
84397 futex_cmpxchg_enabled = 1;
84398+ set_fs(oldfs);
84399
84400 for (i = 0; i < ARRAY_SIZE(futex_queues); i++) {
84401 plist_head_init(&futex_queues[i].chain);
84402diff --git a/kernel/futex_compat.c b/kernel/futex_compat.c
84403index f9f44fd..29885e4 100644
84404--- a/kernel/futex_compat.c
84405+++ b/kernel/futex_compat.c
84406@@ -32,7 +32,7 @@ fetch_robust_entry(compat_uptr_t *uentry, struct robust_list __user **entry,
84407 return 0;
84408 }
84409
84410-static void __user *futex_uaddr(struct robust_list __user *entry,
84411+static void __user __intentional_overflow(-1) *futex_uaddr(struct robust_list __user *entry,
84412 compat_long_t futex_offset)
84413 {
84414 compat_uptr_t base = ptr_to_compat(entry);
84415diff --git a/kernel/gcov/base.c b/kernel/gcov/base.c
84416index 9b22d03..6295b62 100644
84417--- a/kernel/gcov/base.c
84418+++ b/kernel/gcov/base.c
84419@@ -102,11 +102,6 @@ void gcov_enable_events(void)
84420 }
84421
84422 #ifdef CONFIG_MODULES
84423-static inline int within(void *addr, void *start, unsigned long size)
84424-{
84425- return ((addr >= start) && (addr < start + size));
84426-}
84427-
84428 /* Update list and generate events when modules are unloaded. */
84429 static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
84430 void *data)
84431@@ -121,7 +116,7 @@ static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
84432 prev = NULL;
84433 /* Remove entries located in module from linked list. */
84434 for (info = gcov_info_head; info; info = info->next) {
84435- if (within(info, mod->module_core, mod->core_size)) {
84436+ if (within_module_core_rw((unsigned long)info, mod)) {
84437 if (prev)
84438 prev->next = info->next;
84439 else
84440diff --git a/kernel/hrtimer.c b/kernel/hrtimer.c
84441index 383319b..56ebb13 100644
84442--- a/kernel/hrtimer.c
84443+++ b/kernel/hrtimer.c
84444@@ -1438,7 +1438,7 @@ void hrtimer_peek_ahead_timers(void)
84445 local_irq_restore(flags);
84446 }
84447
84448-static void run_hrtimer_softirq(struct softirq_action *h)
84449+static __latent_entropy void run_hrtimer_softirq(void)
84450 {
84451 hrtimer_peek_ahead_timers();
84452 }
84453diff --git a/kernel/irq_work.c b/kernel/irq_work.c
84454index 55fcce6..0e4cf34 100644
84455--- a/kernel/irq_work.c
84456+++ b/kernel/irq_work.c
84457@@ -189,12 +189,13 @@ static int irq_work_cpu_notify(struct notifier_block *self,
84458 return NOTIFY_OK;
84459 }
84460
84461-static struct notifier_block cpu_notify;
84462+static struct notifier_block cpu_notify = {
84463+ .notifier_call = irq_work_cpu_notify,
84464+ .priority = 0,
84465+};
84466
84467 static __init int irq_work_init_cpu_notifier(void)
84468 {
84469- cpu_notify.notifier_call = irq_work_cpu_notify;
84470- cpu_notify.priority = 0;
84471 register_cpu_notifier(&cpu_notify);
84472 return 0;
84473 }
84474diff --git a/kernel/jump_label.c b/kernel/jump_label.c
84475index 297a924..7290070 100644
84476--- a/kernel/jump_label.c
84477+++ b/kernel/jump_label.c
84478@@ -14,6 +14,7 @@
84479 #include <linux/err.h>
84480 #include <linux/static_key.h>
84481 #include <linux/jump_label_ratelimit.h>
84482+#include <linux/mm.h>
84483
84484 #ifdef HAVE_JUMP_LABEL
84485
84486@@ -51,7 +52,9 @@ jump_label_sort_entries(struct jump_entry *start, struct jump_entry *stop)
84487
84488 size = (((unsigned long)stop - (unsigned long)start)
84489 / sizeof(struct jump_entry));
84490+ pax_open_kernel();
84491 sort(start, size, sizeof(struct jump_entry), jump_label_cmp, NULL);
84492+ pax_close_kernel();
84493 }
84494
84495 static void jump_label_update(struct static_key *key, int enable);
84496@@ -358,10 +361,12 @@ static void jump_label_invalidate_module_init(struct module *mod)
84497 struct jump_entry *iter_stop = iter_start + mod->num_jump_entries;
84498 struct jump_entry *iter;
84499
84500+ pax_open_kernel();
84501 for (iter = iter_start; iter < iter_stop; iter++) {
84502 if (within_module_init(iter->code, mod))
84503 iter->code = 0;
84504 }
84505+ pax_close_kernel();
84506 }
84507
84508 static int
84509diff --git a/kernel/kallsyms.c b/kernel/kallsyms.c
84510index 3127ad5..159d880 100644
84511--- a/kernel/kallsyms.c
84512+++ b/kernel/kallsyms.c
84513@@ -11,6 +11,9 @@
84514 * Changed the compression method from stem compression to "table lookup"
84515 * compression (see scripts/kallsyms.c for a more complete description)
84516 */
84517+#ifdef CONFIG_GRKERNSEC_HIDESYM
84518+#define __INCLUDED_BY_HIDESYM 1
84519+#endif
84520 #include <linux/kallsyms.h>
84521 #include <linux/module.h>
84522 #include <linux/init.h>
84523@@ -53,12 +56,33 @@ extern const unsigned long kallsyms_markers[] __attribute__((weak));
84524
84525 static inline int is_kernel_inittext(unsigned long addr)
84526 {
84527+ if (system_state != SYSTEM_BOOTING)
84528+ return 0;
84529+
84530 if (addr >= (unsigned long)_sinittext
84531 && addr <= (unsigned long)_einittext)
84532 return 1;
84533 return 0;
84534 }
84535
84536+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
84537+#ifdef CONFIG_MODULES
84538+static inline int is_module_text(unsigned long addr)
84539+{
84540+ if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END)
84541+ return 1;
84542+
84543+ addr = ktla_ktva(addr);
84544+ return (unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END;
84545+}
84546+#else
84547+static inline int is_module_text(unsigned long addr)
84548+{
84549+ return 0;
84550+}
84551+#endif
84552+#endif
84553+
84554 static inline int is_kernel_text(unsigned long addr)
84555 {
84556 if ((addr >= (unsigned long)_stext && addr <= (unsigned long)_etext) ||
84557@@ -69,13 +93,28 @@ static inline int is_kernel_text(unsigned long addr)
84558
84559 static inline int is_kernel(unsigned long addr)
84560 {
84561+
84562+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
84563+ if (is_kernel_text(addr) || is_kernel_inittext(addr))
84564+ return 1;
84565+
84566+ if (ktla_ktva((unsigned long)_text) <= addr && addr < (unsigned long)_end)
84567+#else
84568 if (addr >= (unsigned long)_stext && addr <= (unsigned long)_end)
84569+#endif
84570+
84571 return 1;
84572 return in_gate_area_no_mm(addr);
84573 }
84574
84575 static int is_ksym_addr(unsigned long addr)
84576 {
84577+
84578+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
84579+ if (is_module_text(addr))
84580+ return 0;
84581+#endif
84582+
84583 if (all_var)
84584 return is_kernel(addr);
84585
84586@@ -480,7 +519,6 @@ static unsigned long get_ksymbol_core(struct kallsym_iter *iter)
84587
84588 static void reset_iter(struct kallsym_iter *iter, loff_t new_pos)
84589 {
84590- iter->name[0] = '\0';
84591 iter->nameoff = get_symbol_offset(new_pos);
84592 iter->pos = new_pos;
84593 }
84594@@ -528,6 +566,11 @@ static int s_show(struct seq_file *m, void *p)
84595 {
84596 struct kallsym_iter *iter = m->private;
84597
84598+#ifdef CONFIG_GRKERNSEC_HIDESYM
84599+ if (!uid_eq(current_uid(), GLOBAL_ROOT_UID))
84600+ return 0;
84601+#endif
84602+
84603 /* Some debugging symbols have no name. Ignore them. */
84604 if (!iter->name[0])
84605 return 0;
84606@@ -541,6 +584,7 @@ static int s_show(struct seq_file *m, void *p)
84607 */
84608 type = iter->exported ? toupper(iter->type) :
84609 tolower(iter->type);
84610+
84611 seq_printf(m, "%pK %c %s\t[%s]\n", (void *)iter->value,
84612 type, iter->name, iter->module_name);
84613 } else
84614@@ -566,7 +610,7 @@ static int kallsyms_open(struct inode *inode, struct file *file)
84615 struct kallsym_iter *iter;
84616 int ret;
84617
84618- iter = kmalloc(sizeof(*iter), GFP_KERNEL);
84619+ iter = kzalloc(sizeof(*iter), GFP_KERNEL);
84620 if (!iter)
84621 return -ENOMEM;
84622 reset_iter(iter, 0);
84623diff --git a/kernel/kcmp.c b/kernel/kcmp.c
84624index e30ac0f..3528cac 100644
84625--- a/kernel/kcmp.c
84626+++ b/kernel/kcmp.c
84627@@ -99,6 +99,10 @@ SYSCALL_DEFINE5(kcmp, pid_t, pid1, pid_t, pid2, int, type,
84628 struct task_struct *task1, *task2;
84629 int ret;
84630
84631+#ifdef CONFIG_GRKERNSEC
84632+ return -ENOSYS;
84633+#endif
84634+
84635 rcu_read_lock();
84636
84637 /*
84638diff --git a/kernel/kexec.c b/kernel/kexec.c
84639index 355e13a..06b25d2 100644
84640--- a/kernel/kexec.c
84641+++ b/kernel/kexec.c
84642@@ -1044,7 +1044,8 @@ asmlinkage long compat_sys_kexec_load(unsigned long entry,
84643 unsigned long flags)
84644 {
84645 struct compat_kexec_segment in;
84646- struct kexec_segment out, __user *ksegments;
84647+ struct kexec_segment out;
84648+ struct kexec_segment __user *ksegments;
84649 unsigned long i, result;
84650
84651 /* Don't allow clients that don't understand the native
84652diff --git a/kernel/kmod.c b/kernel/kmod.c
84653index b086006..6d2e579 100644
84654--- a/kernel/kmod.c
84655+++ b/kernel/kmod.c
84656@@ -75,7 +75,7 @@ static void free_modprobe_argv(struct subprocess_info *info)
84657 kfree(info->argv);
84658 }
84659
84660-static int call_modprobe(char *module_name, int wait)
84661+static int call_modprobe(char *module_name, char *module_param, int wait)
84662 {
84663 struct subprocess_info *info;
84664 static char *envp[] = {
84665@@ -85,7 +85,7 @@ static int call_modprobe(char *module_name, int wait)
84666 NULL
84667 };
84668
84669- char **argv = kmalloc(sizeof(char *[5]), GFP_KERNEL);
84670+ char **argv = kmalloc(sizeof(char *[6]), GFP_KERNEL);
84671 if (!argv)
84672 goto out;
84673
84674@@ -97,7 +97,8 @@ static int call_modprobe(char *module_name, int wait)
84675 argv[1] = "-q";
84676 argv[2] = "--";
84677 argv[3] = module_name; /* check free_modprobe_argv() */
84678- argv[4] = NULL;
84679+ argv[4] = module_param;
84680+ argv[5] = NULL;
84681
84682 info = call_usermodehelper_setup(modprobe_path, argv, envp, GFP_KERNEL,
84683 NULL, free_modprobe_argv, NULL);
84684@@ -129,9 +130,8 @@ out:
84685 * If module auto-loading support is disabled then this function
84686 * becomes a no-operation.
84687 */
84688-int __request_module(bool wait, const char *fmt, ...)
84689+static int ____request_module(bool wait, char *module_param, const char *fmt, va_list ap)
84690 {
84691- va_list args;
84692 char module_name[MODULE_NAME_LEN];
84693 unsigned int max_modprobes;
84694 int ret;
84695@@ -150,9 +150,7 @@ int __request_module(bool wait, const char *fmt, ...)
84696 if (!modprobe_path[0])
84697 return 0;
84698
84699- va_start(args, fmt);
84700- ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, args);
84701- va_end(args);
84702+ ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, ap);
84703 if (ret >= MODULE_NAME_LEN)
84704 return -ENAMETOOLONG;
84705
84706@@ -160,6 +158,20 @@ int __request_module(bool wait, const char *fmt, ...)
84707 if (ret)
84708 return ret;
84709
84710+#ifdef CONFIG_GRKERNSEC_MODHARDEN
84711+ if (uid_eq(current_uid(), GLOBAL_ROOT_UID)) {
84712+ /* hack to workaround consolekit/udisks stupidity */
84713+ read_lock(&tasklist_lock);
84714+ if (!strcmp(current->comm, "mount") &&
84715+ current->real_parent && !strncmp(current->real_parent->comm, "udisk", 5)) {
84716+ read_unlock(&tasklist_lock);
84717+ printk(KERN_ALERT "grsec: denied attempt to auto-load fs module %.64s by udisks\n", module_name);
84718+ return -EPERM;
84719+ }
84720+ read_unlock(&tasklist_lock);
84721+ }
84722+#endif
84723+
84724 /* If modprobe needs a service that is in a module, we get a recursive
84725 * loop. Limit the number of running kmod threads to max_threads/2 or
84726 * MAX_KMOD_CONCURRENT, whichever is the smaller. A cleaner method
84727@@ -188,11 +200,52 @@ int __request_module(bool wait, const char *fmt, ...)
84728
84729 trace_module_request(module_name, wait, _RET_IP_);
84730
84731- ret = call_modprobe(module_name, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
84732+ ret = call_modprobe(module_name, module_param, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
84733
84734 atomic_dec(&kmod_concurrent);
84735 return ret;
84736 }
84737+
84738+int ___request_module(bool wait, char *module_param, const char *fmt, ...)
84739+{
84740+ va_list args;
84741+ int ret;
84742+
84743+ va_start(args, fmt);
84744+ ret = ____request_module(wait, module_param, fmt, args);
84745+ va_end(args);
84746+
84747+ return ret;
84748+}
84749+
84750+int __request_module(bool wait, const char *fmt, ...)
84751+{
84752+ va_list args;
84753+ int ret;
84754+
84755+#ifdef CONFIG_GRKERNSEC_MODHARDEN
84756+ if (!uid_eq(current_uid(), GLOBAL_ROOT_UID)) {
84757+ char module_param[MODULE_NAME_LEN];
84758+
84759+ memset(module_param, 0, sizeof(module_param));
84760+
84761+ snprintf(module_param, sizeof(module_param) - 1, "grsec_modharden_normal%u_", GR_GLOBAL_UID(current_uid()));
84762+
84763+ va_start(args, fmt);
84764+ ret = ____request_module(wait, module_param, fmt, args);
84765+ va_end(args);
84766+
84767+ return ret;
84768+ }
84769+#endif
84770+
84771+ va_start(args, fmt);
84772+ ret = ____request_module(wait, NULL, fmt, args);
84773+ va_end(args);
84774+
84775+ return ret;
84776+}
84777+
84778 EXPORT_SYMBOL(__request_module);
84779 #endif /* CONFIG_MODULES */
84780
84781@@ -218,6 +271,19 @@ static int ____call_usermodehelper(void *data)
84782 */
84783 set_user_nice(current, 0);
84784
84785+#ifdef CONFIG_GRKERNSEC
84786+ /* this is race-free as far as userland is concerned as we copied
84787+ out the path to be used prior to this point and are now operating
84788+ on that copy
84789+ */
84790+ if ((strncmp(sub_info->path, "/sbin/", 6) && strncmp(sub_info->path, "/usr/lib/", 9) &&
84791+ strncmp(sub_info->path, "/lib/", 5) && strncmp(sub_info->path, "/lib64/", 7)) || strstr(sub_info->path, "..")) {
84792+ printk(KERN_ALERT "grsec: denied exec of usermode helper binary %.950s located outside of /sbin and system library paths\n", sub_info->path);
84793+ retval = -EPERM;
84794+ goto fail;
84795+ }
84796+#endif
84797+
84798 retval = -ENOMEM;
84799 new = prepare_kernel_cred(current);
84800 if (!new)
84801@@ -260,6 +326,10 @@ static int call_helper(void *data)
84802
84803 static void call_usermodehelper_freeinfo(struct subprocess_info *info)
84804 {
84805+#ifdef CONFIG_GRKERNSEC
84806+ kfree(info->path);
84807+ info->path = info->origpath;
84808+#endif
84809 if (info->cleanup)
84810 (*info->cleanup)(info);
84811 kfree(info);
84812@@ -303,7 +373,7 @@ static int wait_for_helper(void *data)
84813 *
84814 * Thus the __user pointer cast is valid here.
84815 */
84816- sys_wait4(pid, (int __user *)&ret, 0, NULL);
84817+ sys_wait4(pid, (int __force_user *)&ret, 0, NULL);
84818
84819 /*
84820 * If ret is 0, either ____call_usermodehelper failed and the
84821@@ -542,7 +612,12 @@ struct subprocess_info *call_usermodehelper_setup(char *path, char **argv,
84822 goto out;
84823
84824 INIT_WORK(&sub_info->work, __call_usermodehelper);
84825+#ifdef CONFIG_GRKERNSEC
84826+ sub_info->origpath = path;
84827+ sub_info->path = kstrdup(path, gfp_mask);
84828+#else
84829 sub_info->path = path;
84830+#endif
84831 sub_info->argv = argv;
84832 sub_info->envp = envp;
84833
84834@@ -650,7 +725,7 @@ EXPORT_SYMBOL(call_usermodehelper);
84835 static int proc_cap_handler(struct ctl_table *table, int write,
84836 void __user *buffer, size_t *lenp, loff_t *ppos)
84837 {
84838- struct ctl_table t;
84839+ ctl_table_no_const t;
84840 unsigned long cap_array[_KERNEL_CAPABILITY_U32S];
84841 kernel_cap_t new_cap;
84842 int err, i;
84843diff --git a/kernel/kprobes.c b/kernel/kprobes.c
84844index a0d367a..11c18b6 100644
84845--- a/kernel/kprobes.c
84846+++ b/kernel/kprobes.c
84847@@ -31,6 +31,9 @@
84848 * <jkenisto@us.ibm.com> and Prasanna S Panchamukhi
84849 * <prasanna@in.ibm.com> added function-return probes.
84850 */
84851+#ifdef CONFIG_GRKERNSEC_HIDESYM
84852+#define __INCLUDED_BY_HIDESYM 1
84853+#endif
84854 #include <linux/kprobes.h>
84855 #include <linux/hash.h>
84856 #include <linux/init.h>
84857@@ -135,12 +138,12 @@ enum kprobe_slot_state {
84858
84859 static void *alloc_insn_page(void)
84860 {
84861- return module_alloc(PAGE_SIZE);
84862+ return module_alloc_exec(PAGE_SIZE);
84863 }
84864
84865 static void free_insn_page(void *page)
84866 {
84867- module_free(NULL, page);
84868+ module_free_exec(NULL, page);
84869 }
84870
84871 struct kprobe_insn_cache kprobe_insn_slots = {
84872@@ -2066,7 +2069,7 @@ static int __init init_kprobes(void)
84873 {
84874 int i, err = 0;
84875 unsigned long offset = 0, size = 0;
84876- char *modname, namebuf[128];
84877+ char *modname, namebuf[KSYM_NAME_LEN];
84878 const char *symbol_name;
84879 void *addr;
84880 struct kprobe_blackpoint *kb;
84881@@ -2151,11 +2154,11 @@ static void __kprobes report_probe(struct seq_file *pi, struct kprobe *p,
84882 kprobe_type = "k";
84883
84884 if (sym)
84885- seq_printf(pi, "%p %s %s+0x%x %s ",
84886+ seq_printf(pi, "%pK %s %s+0x%x %s ",
84887 p->addr, kprobe_type, sym, offset,
84888 (modname ? modname : " "));
84889 else
84890- seq_printf(pi, "%p %s %p ",
84891+ seq_printf(pi, "%pK %s %pK ",
84892 p->addr, kprobe_type, p->addr);
84893
84894 if (!pp)
84895@@ -2192,7 +2195,7 @@ static int __kprobes show_kprobe_addr(struct seq_file *pi, void *v)
84896 const char *sym = NULL;
84897 unsigned int i = *(loff_t *) v;
84898 unsigned long offset = 0;
84899- char *modname, namebuf[128];
84900+ char *modname, namebuf[KSYM_NAME_LEN];
84901
84902 head = &kprobe_table[i];
84903 preempt_disable();
84904diff --git a/kernel/ksysfs.c b/kernel/ksysfs.c
84905index 9659d38..bffd520 100644
84906--- a/kernel/ksysfs.c
84907+++ b/kernel/ksysfs.c
84908@@ -46,6 +46,8 @@ static ssize_t uevent_helper_store(struct kobject *kobj,
84909 {
84910 if (count+1 > UEVENT_HELPER_PATH_LEN)
84911 return -ENOENT;
84912+ if (!capable(CAP_SYS_ADMIN))
84913+ return -EPERM;
84914 memcpy(uevent_helper, buf, count);
84915 uevent_helper[count] = '\0';
84916 if (count && uevent_helper[count-1] == '\n')
84917@@ -172,7 +174,7 @@ static ssize_t notes_read(struct file *filp, struct kobject *kobj,
84918 return count;
84919 }
84920
84921-static struct bin_attribute notes_attr = {
84922+static bin_attribute_no_const notes_attr __read_only = {
84923 .attr = {
84924 .name = "notes",
84925 .mode = S_IRUGO,
84926diff --git a/kernel/lockdep.c b/kernel/lockdep.c
84927index e16c45b..6f49c48 100644
84928--- a/kernel/lockdep.c
84929+++ b/kernel/lockdep.c
84930@@ -596,6 +596,10 @@ static int static_obj(void *obj)
84931 end = (unsigned long) &_end,
84932 addr = (unsigned long) obj;
84933
84934+#ifdef CONFIG_PAX_KERNEXEC
84935+ start = ktla_ktva(start);
84936+#endif
84937+
84938 /*
84939 * static variable?
84940 */
84941@@ -736,6 +740,7 @@ register_lock_class(struct lockdep_map *lock, unsigned int subclass, int force)
84942 if (!static_obj(lock->key)) {
84943 debug_locks_off();
84944 printk("INFO: trying to register non-static key.\n");
84945+ printk("lock:%pS key:%pS.\n", lock, lock->key);
84946 printk("the code is fine but needs lockdep annotation.\n");
84947 printk("turning off the locking correctness validator.\n");
84948 dump_stack();
84949@@ -3080,7 +3085,7 @@ static int __lock_acquire(struct lockdep_map *lock, unsigned int subclass,
84950 if (!class)
84951 return 0;
84952 }
84953- atomic_inc((atomic_t *)&class->ops);
84954+ atomic_inc_unchecked((atomic_unchecked_t *)&class->ops);
84955 if (very_verbose(class)) {
84956 printk("\nacquire class [%p] %s", class->key, class->name);
84957 if (class->name_version > 1)
84958diff --git a/kernel/lockdep_proc.c b/kernel/lockdep_proc.c
84959index b2c71c5..7b88d63 100644
84960--- a/kernel/lockdep_proc.c
84961+++ b/kernel/lockdep_proc.c
84962@@ -65,7 +65,7 @@ static int l_show(struct seq_file *m, void *v)
84963 return 0;
84964 }
84965
84966- seq_printf(m, "%p", class->key);
84967+ seq_printf(m, "%pK", class->key);
84968 #ifdef CONFIG_DEBUG_LOCKDEP
84969 seq_printf(m, " OPS:%8ld", class->ops);
84970 #endif
84971@@ -83,7 +83,7 @@ static int l_show(struct seq_file *m, void *v)
84972
84973 list_for_each_entry(entry, &class->locks_after, entry) {
84974 if (entry->distance == 1) {
84975- seq_printf(m, " -> [%p] ", entry->class->key);
84976+ seq_printf(m, " -> [%pK] ", entry->class->key);
84977 print_name(m, entry->class);
84978 seq_puts(m, "\n");
84979 }
84980@@ -152,7 +152,7 @@ static int lc_show(struct seq_file *m, void *v)
84981 if (!class->key)
84982 continue;
84983
84984- seq_printf(m, "[%p] ", class->key);
84985+ seq_printf(m, "[%pK] ", class->key);
84986 print_name(m, class);
84987 seq_puts(m, "\n");
84988 }
84989@@ -495,7 +495,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
84990 if (!i)
84991 seq_line(m, '-', 40-namelen, namelen);
84992
84993- snprintf(ip, sizeof(ip), "[<%p>]",
84994+ snprintf(ip, sizeof(ip), "[<%pK>]",
84995 (void *)class->contention_point[i]);
84996 seq_printf(m, "%40s %14lu %29s %pS\n",
84997 name, stats->contention_point[i],
84998@@ -510,7 +510,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
84999 if (!i)
85000 seq_line(m, '-', 40-namelen, namelen);
85001
85002- snprintf(ip, sizeof(ip), "[<%p>]",
85003+ snprintf(ip, sizeof(ip), "[<%pK>]",
85004 (void *)class->contending_point[i]);
85005 seq_printf(m, "%40s %14lu %29s %pS\n",
85006 name, stats->contending_point[i],
85007diff --git a/kernel/module.c b/kernel/module.c
85008index dc58274..3ddfa55 100644
85009--- a/kernel/module.c
85010+++ b/kernel/module.c
85011@@ -61,6 +61,7 @@
85012 #include <linux/pfn.h>
85013 #include <linux/bsearch.h>
85014 #include <linux/fips.h>
85015+#include <linux/grsecurity.h>
85016 #include <uapi/linux/module.h>
85017 #include "module-internal.h"
85018
85019@@ -157,7 +158,8 @@ static BLOCKING_NOTIFIER_HEAD(module_notify_list);
85020
85021 /* Bounds of module allocation, for speeding __module_address.
85022 * Protected by module_mutex. */
85023-static unsigned long module_addr_min = -1UL, module_addr_max = 0;
85024+static unsigned long module_addr_min_rw = -1UL, module_addr_max_rw = 0;
85025+static unsigned long module_addr_min_rx = -1UL, module_addr_max_rx = 0;
85026
85027 int register_module_notifier(struct notifier_block * nb)
85028 {
85029@@ -324,7 +326,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
85030 return true;
85031
85032 list_for_each_entry_rcu(mod, &modules, list) {
85033- struct symsearch arr[] = {
85034+ struct symsearch modarr[] = {
85035 { mod->syms, mod->syms + mod->num_syms, mod->crcs,
85036 NOT_GPL_ONLY, false },
85037 { mod->gpl_syms, mod->gpl_syms + mod->num_gpl_syms,
85038@@ -349,7 +351,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
85039 if (mod->state == MODULE_STATE_UNFORMED)
85040 continue;
85041
85042- if (each_symbol_in_section(arr, ARRAY_SIZE(arr), mod, fn, data))
85043+ if (each_symbol_in_section(modarr, ARRAY_SIZE(modarr), mod, fn, data))
85044 return true;
85045 }
85046 return false;
85047@@ -491,7 +493,7 @@ static int percpu_modalloc(struct module *mod, struct load_info *info)
85048 if (!pcpusec->sh_size)
85049 return 0;
85050
85051- if (align > PAGE_SIZE) {
85052+ if (align-1 >= PAGE_SIZE) {
85053 printk(KERN_WARNING "%s: per-cpu alignment %li > %li\n",
85054 mod->name, align, PAGE_SIZE);
85055 align = PAGE_SIZE;
85056@@ -1097,7 +1099,7 @@ struct module_attribute module_uevent =
85057 static ssize_t show_coresize(struct module_attribute *mattr,
85058 struct module_kobject *mk, char *buffer)
85059 {
85060- return sprintf(buffer, "%u\n", mk->mod->core_size);
85061+ return sprintf(buffer, "%u\n", mk->mod->core_size_rx + mk->mod->core_size_rw);
85062 }
85063
85064 static struct module_attribute modinfo_coresize =
85065@@ -1106,7 +1108,7 @@ static struct module_attribute modinfo_coresize =
85066 static ssize_t show_initsize(struct module_attribute *mattr,
85067 struct module_kobject *mk, char *buffer)
85068 {
85069- return sprintf(buffer, "%u\n", mk->mod->init_size);
85070+ return sprintf(buffer, "%u\n", mk->mod->init_size_rx + mk->mod->init_size_rw);
85071 }
85072
85073 static struct module_attribute modinfo_initsize =
85074@@ -1321,7 +1323,7 @@ resolve_symbol_wait(struct module *mod,
85075 */
85076 #ifdef CONFIG_SYSFS
85077
85078-#ifdef CONFIG_KALLSYMS
85079+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
85080 static inline bool sect_empty(const Elf_Shdr *sect)
85081 {
85082 return !(sect->sh_flags & SHF_ALLOC) || sect->sh_size == 0;
85083@@ -1461,7 +1463,7 @@ static void add_notes_attrs(struct module *mod, const struct load_info *info)
85084 {
85085 unsigned int notes, loaded, i;
85086 struct module_notes_attrs *notes_attrs;
85087- struct bin_attribute *nattr;
85088+ bin_attribute_no_const *nattr;
85089
85090 /* failed to create section attributes, so can't create notes */
85091 if (!mod->sect_attrs)
85092@@ -1573,7 +1575,7 @@ static void del_usage_links(struct module *mod)
85093 static int module_add_modinfo_attrs(struct module *mod)
85094 {
85095 struct module_attribute *attr;
85096- struct module_attribute *temp_attr;
85097+ module_attribute_no_const *temp_attr;
85098 int error = 0;
85099 int i;
85100
85101@@ -1795,21 +1797,21 @@ static void set_section_ro_nx(void *base,
85102
85103 static void unset_module_core_ro_nx(struct module *mod)
85104 {
85105- set_page_attributes(mod->module_core + mod->core_text_size,
85106- mod->module_core + mod->core_size,
85107+ set_page_attributes(mod->module_core_rw,
85108+ mod->module_core_rw + mod->core_size_rw,
85109 set_memory_x);
85110- set_page_attributes(mod->module_core,
85111- mod->module_core + mod->core_ro_size,
85112+ set_page_attributes(mod->module_core_rx,
85113+ mod->module_core_rx + mod->core_size_rx,
85114 set_memory_rw);
85115 }
85116
85117 static void unset_module_init_ro_nx(struct module *mod)
85118 {
85119- set_page_attributes(mod->module_init + mod->init_text_size,
85120- mod->module_init + mod->init_size,
85121+ set_page_attributes(mod->module_init_rw,
85122+ mod->module_init_rw + mod->init_size_rw,
85123 set_memory_x);
85124- set_page_attributes(mod->module_init,
85125- mod->module_init + mod->init_ro_size,
85126+ set_page_attributes(mod->module_init_rx,
85127+ mod->module_init_rx + mod->init_size_rx,
85128 set_memory_rw);
85129 }
85130
85131@@ -1822,14 +1824,14 @@ void set_all_modules_text_rw(void)
85132 list_for_each_entry_rcu(mod, &modules, list) {
85133 if (mod->state == MODULE_STATE_UNFORMED)
85134 continue;
85135- if ((mod->module_core) && (mod->core_text_size)) {
85136- set_page_attributes(mod->module_core,
85137- mod->module_core + mod->core_text_size,
85138+ if ((mod->module_core_rx) && (mod->core_size_rx)) {
85139+ set_page_attributes(mod->module_core_rx,
85140+ mod->module_core_rx + mod->core_size_rx,
85141 set_memory_rw);
85142 }
85143- if ((mod->module_init) && (mod->init_text_size)) {
85144- set_page_attributes(mod->module_init,
85145- mod->module_init + mod->init_text_size,
85146+ if ((mod->module_init_rx) && (mod->init_size_rx)) {
85147+ set_page_attributes(mod->module_init_rx,
85148+ mod->module_init_rx + mod->init_size_rx,
85149 set_memory_rw);
85150 }
85151 }
85152@@ -1845,14 +1847,14 @@ void set_all_modules_text_ro(void)
85153 list_for_each_entry_rcu(mod, &modules, list) {
85154 if (mod->state == MODULE_STATE_UNFORMED)
85155 continue;
85156- if ((mod->module_core) && (mod->core_text_size)) {
85157- set_page_attributes(mod->module_core,
85158- mod->module_core + mod->core_text_size,
85159+ if ((mod->module_core_rx) && (mod->core_size_rx)) {
85160+ set_page_attributes(mod->module_core_rx,
85161+ mod->module_core_rx + mod->core_size_rx,
85162 set_memory_ro);
85163 }
85164- if ((mod->module_init) && (mod->init_text_size)) {
85165- set_page_attributes(mod->module_init,
85166- mod->module_init + mod->init_text_size,
85167+ if ((mod->module_init_rx) && (mod->init_size_rx)) {
85168+ set_page_attributes(mod->module_init_rx,
85169+ mod->module_init_rx + mod->init_size_rx,
85170 set_memory_ro);
85171 }
85172 }
85173@@ -1903,16 +1905,19 @@ static void free_module(struct module *mod)
85174
85175 /* This may be NULL, but that's OK */
85176 unset_module_init_ro_nx(mod);
85177- module_free(mod, mod->module_init);
85178+ module_free(mod, mod->module_init_rw);
85179+ module_free_exec(mod, mod->module_init_rx);
85180 kfree(mod->args);
85181 percpu_modfree(mod);
85182
85183 /* Free lock-classes: */
85184- lockdep_free_key_range(mod->module_core, mod->core_size);
85185+ lockdep_free_key_range(mod->module_core_rx, mod->core_size_rx);
85186+ lockdep_free_key_range(mod->module_core_rw, mod->core_size_rw);
85187
85188 /* Finally, free the core (containing the module structure) */
85189 unset_module_core_ro_nx(mod);
85190- module_free(mod, mod->module_core);
85191+ module_free_exec(mod, mod->module_core_rx);
85192+ module_free(mod, mod->module_core_rw);
85193
85194 #ifdef CONFIG_MPU
85195 update_protections(current->mm);
85196@@ -1982,9 +1987,31 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
85197 int ret = 0;
85198 const struct kernel_symbol *ksym;
85199
85200+#ifdef CONFIG_GRKERNSEC_MODHARDEN
85201+ int is_fs_load = 0;
85202+ int register_filesystem_found = 0;
85203+ char *p;
85204+
85205+ p = strstr(mod->args, "grsec_modharden_fs");
85206+ if (p) {
85207+ char *endptr = p + sizeof("grsec_modharden_fs") - 1;
85208+ /* copy \0 as well */
85209+ memmove(p, endptr, strlen(mod->args) - (unsigned int)(endptr - mod->args) + 1);
85210+ is_fs_load = 1;
85211+ }
85212+#endif
85213+
85214 for (i = 1; i < symsec->sh_size / sizeof(Elf_Sym); i++) {
85215 const char *name = info->strtab + sym[i].st_name;
85216
85217+#ifdef CONFIG_GRKERNSEC_MODHARDEN
85218+ /* it's a real shame this will never get ripped and copied
85219+ upstream! ;(
85220+ */
85221+ if (is_fs_load && !strcmp(name, "register_filesystem"))
85222+ register_filesystem_found = 1;
85223+#endif
85224+
85225 switch (sym[i].st_shndx) {
85226 case SHN_COMMON:
85227 /* We compiled with -fno-common. These are not
85228@@ -2005,7 +2032,9 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
85229 ksym = resolve_symbol_wait(mod, info, name);
85230 /* Ok if resolved. */
85231 if (ksym && !IS_ERR(ksym)) {
85232+ pax_open_kernel();
85233 sym[i].st_value = ksym->value;
85234+ pax_close_kernel();
85235 break;
85236 }
85237
85238@@ -2024,11 +2053,20 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
85239 secbase = (unsigned long)mod_percpu(mod);
85240 else
85241 secbase = info->sechdrs[sym[i].st_shndx].sh_addr;
85242+ pax_open_kernel();
85243 sym[i].st_value += secbase;
85244+ pax_close_kernel();
85245 break;
85246 }
85247 }
85248
85249+#ifdef CONFIG_GRKERNSEC_MODHARDEN
85250+ if (is_fs_load && !register_filesystem_found) {
85251+ printk(KERN_ALERT "grsec: Denied attempt to load non-fs module %.64s through mount\n", mod->name);
85252+ ret = -EPERM;
85253+ }
85254+#endif
85255+
85256 return ret;
85257 }
85258
85259@@ -2112,22 +2150,12 @@ static void layout_sections(struct module *mod, struct load_info *info)
85260 || s->sh_entsize != ~0UL
85261 || strstarts(sname, ".init"))
85262 continue;
85263- s->sh_entsize = get_offset(mod, &mod->core_size, s, i);
85264+ if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
85265+ s->sh_entsize = get_offset(mod, &mod->core_size_rw, s, i);
85266+ else
85267+ s->sh_entsize = get_offset(mod, &mod->core_size_rx, s, i);
85268 pr_debug("\t%s\n", sname);
85269 }
85270- switch (m) {
85271- case 0: /* executable */
85272- mod->core_size = debug_align(mod->core_size);
85273- mod->core_text_size = mod->core_size;
85274- break;
85275- case 1: /* RO: text and ro-data */
85276- mod->core_size = debug_align(mod->core_size);
85277- mod->core_ro_size = mod->core_size;
85278- break;
85279- case 3: /* whole core */
85280- mod->core_size = debug_align(mod->core_size);
85281- break;
85282- }
85283 }
85284
85285 pr_debug("Init section allocation order:\n");
85286@@ -2141,23 +2169,13 @@ static void layout_sections(struct module *mod, struct load_info *info)
85287 || s->sh_entsize != ~0UL
85288 || !strstarts(sname, ".init"))
85289 continue;
85290- s->sh_entsize = (get_offset(mod, &mod->init_size, s, i)
85291- | INIT_OFFSET_MASK);
85292+ if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
85293+ s->sh_entsize = get_offset(mod, &mod->init_size_rw, s, i);
85294+ else
85295+ s->sh_entsize = get_offset(mod, &mod->init_size_rx, s, i);
85296+ s->sh_entsize |= INIT_OFFSET_MASK;
85297 pr_debug("\t%s\n", sname);
85298 }
85299- switch (m) {
85300- case 0: /* executable */
85301- mod->init_size = debug_align(mod->init_size);
85302- mod->init_text_size = mod->init_size;
85303- break;
85304- case 1: /* RO: text and ro-data */
85305- mod->init_size = debug_align(mod->init_size);
85306- mod->init_ro_size = mod->init_size;
85307- break;
85308- case 3: /* whole init */
85309- mod->init_size = debug_align(mod->init_size);
85310- break;
85311- }
85312 }
85313 }
85314
85315@@ -2330,7 +2348,7 @@ static void layout_symtab(struct module *mod, struct load_info *info)
85316
85317 /* Put symbol section at end of init part of module. */
85318 symsect->sh_flags |= SHF_ALLOC;
85319- symsect->sh_entsize = get_offset(mod, &mod->init_size, symsect,
85320+ symsect->sh_entsize = get_offset(mod, &mod->init_size_rx, symsect,
85321 info->index.sym) | INIT_OFFSET_MASK;
85322 pr_debug("\t%s\n", info->secstrings + symsect->sh_name);
85323
85324@@ -2347,13 +2365,13 @@ static void layout_symtab(struct module *mod, struct load_info *info)
85325 }
85326
85327 /* Append room for core symbols at end of core part. */
85328- info->symoffs = ALIGN(mod->core_size, symsect->sh_addralign ?: 1);
85329- info->stroffs = mod->core_size = info->symoffs + ndst * sizeof(Elf_Sym);
85330- mod->core_size += strtab_size;
85331+ info->symoffs = ALIGN(mod->core_size_rx, symsect->sh_addralign ?: 1);
85332+ info->stroffs = mod->core_size_rx = info->symoffs + ndst * sizeof(Elf_Sym);
85333+ mod->core_size_rx += strtab_size;
85334
85335 /* Put string table section at end of init part of module. */
85336 strsect->sh_flags |= SHF_ALLOC;
85337- strsect->sh_entsize = get_offset(mod, &mod->init_size, strsect,
85338+ strsect->sh_entsize = get_offset(mod, &mod->init_size_rx, strsect,
85339 info->index.str) | INIT_OFFSET_MASK;
85340 pr_debug("\t%s\n", info->secstrings + strsect->sh_name);
85341 }
85342@@ -2371,12 +2389,14 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
85343 /* Make sure we get permanent strtab: don't use info->strtab. */
85344 mod->strtab = (void *)info->sechdrs[info->index.str].sh_addr;
85345
85346+ pax_open_kernel();
85347+
85348 /* Set types up while we still have access to sections. */
85349 for (i = 0; i < mod->num_symtab; i++)
85350 mod->symtab[i].st_info = elf_type(&mod->symtab[i], info);
85351
85352- mod->core_symtab = dst = mod->module_core + info->symoffs;
85353- mod->core_strtab = s = mod->module_core + info->stroffs;
85354+ mod->core_symtab = dst = mod->module_core_rx + info->symoffs;
85355+ mod->core_strtab = s = mod->module_core_rx + info->stroffs;
85356 src = mod->symtab;
85357 for (ndst = i = 0; i < mod->num_symtab; i++) {
85358 if (i == 0 ||
85359@@ -2388,6 +2408,8 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
85360 }
85361 }
85362 mod->core_num_syms = ndst;
85363+
85364+ pax_close_kernel();
85365 }
85366 #else
85367 static inline void layout_symtab(struct module *mod, struct load_info *info)
85368@@ -2421,17 +2443,33 @@ void * __weak module_alloc(unsigned long size)
85369 return vmalloc_exec(size);
85370 }
85371
85372-static void *module_alloc_update_bounds(unsigned long size)
85373+static void *module_alloc_update_bounds_rw(unsigned long size)
85374 {
85375 void *ret = module_alloc(size);
85376
85377 if (ret) {
85378 mutex_lock(&module_mutex);
85379 /* Update module bounds. */
85380- if ((unsigned long)ret < module_addr_min)
85381- module_addr_min = (unsigned long)ret;
85382- if ((unsigned long)ret + size > module_addr_max)
85383- module_addr_max = (unsigned long)ret + size;
85384+ if ((unsigned long)ret < module_addr_min_rw)
85385+ module_addr_min_rw = (unsigned long)ret;
85386+ if ((unsigned long)ret + size > module_addr_max_rw)
85387+ module_addr_max_rw = (unsigned long)ret + size;
85388+ mutex_unlock(&module_mutex);
85389+ }
85390+ return ret;
85391+}
85392+
85393+static void *module_alloc_update_bounds_rx(unsigned long size)
85394+{
85395+ void *ret = module_alloc_exec(size);
85396+
85397+ if (ret) {
85398+ mutex_lock(&module_mutex);
85399+ /* Update module bounds. */
85400+ if ((unsigned long)ret < module_addr_min_rx)
85401+ module_addr_min_rx = (unsigned long)ret;
85402+ if ((unsigned long)ret + size > module_addr_max_rx)
85403+ module_addr_max_rx = (unsigned long)ret + size;
85404 mutex_unlock(&module_mutex);
85405 }
85406 return ret;
85407@@ -2706,8 +2744,14 @@ static struct module *setup_load_info(struct load_info *info, int flags)
85408 static int check_modinfo(struct module *mod, struct load_info *info, int flags)
85409 {
85410 const char *modmagic = get_modinfo(info, "vermagic");
85411+ const char *license = get_modinfo(info, "license");
85412 int err;
85413
85414+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
85415+ if (!license || !license_is_gpl_compatible(license))
85416+ return -ENOEXEC;
85417+#endif
85418+
85419 if (flags & MODULE_INIT_IGNORE_VERMAGIC)
85420 modmagic = NULL;
85421
85422@@ -2733,7 +2777,7 @@ static int check_modinfo(struct module *mod, struct load_info *info, int flags)
85423 }
85424
85425 /* Set up license info based on the info section */
85426- set_license(mod, get_modinfo(info, "license"));
85427+ set_license(mod, license);
85428
85429 return 0;
85430 }
85431@@ -2814,7 +2858,7 @@ static int move_module(struct module *mod, struct load_info *info)
85432 void *ptr;
85433
85434 /* Do the allocs. */
85435- ptr = module_alloc_update_bounds(mod->core_size);
85436+ ptr = module_alloc_update_bounds_rw(mod->core_size_rw);
85437 /*
85438 * The pointer to this block is stored in the module structure
85439 * which is inside the block. Just mark it as not being a
85440@@ -2824,11 +2868,11 @@ static int move_module(struct module *mod, struct load_info *info)
85441 if (!ptr)
85442 return -ENOMEM;
85443
85444- memset(ptr, 0, mod->core_size);
85445- mod->module_core = ptr;
85446+ memset(ptr, 0, mod->core_size_rw);
85447+ mod->module_core_rw = ptr;
85448
85449- if (mod->init_size) {
85450- ptr = module_alloc_update_bounds(mod->init_size);
85451+ if (mod->init_size_rw) {
85452+ ptr = module_alloc_update_bounds_rw(mod->init_size_rw);
85453 /*
85454 * The pointer to this block is stored in the module structure
85455 * which is inside the block. This block doesn't need to be
85456@@ -2837,13 +2881,45 @@ static int move_module(struct module *mod, struct load_info *info)
85457 */
85458 kmemleak_ignore(ptr);
85459 if (!ptr) {
85460- module_free(mod, mod->module_core);
85461+ module_free(mod, mod->module_core_rw);
85462 return -ENOMEM;
85463 }
85464- memset(ptr, 0, mod->init_size);
85465- mod->module_init = ptr;
85466+ memset(ptr, 0, mod->init_size_rw);
85467+ mod->module_init_rw = ptr;
85468 } else
85469- mod->module_init = NULL;
85470+ mod->module_init_rw = NULL;
85471+
85472+ ptr = module_alloc_update_bounds_rx(mod->core_size_rx);
85473+ kmemleak_not_leak(ptr);
85474+ if (!ptr) {
85475+ if (mod->module_init_rw)
85476+ module_free(mod, mod->module_init_rw);
85477+ module_free(mod, mod->module_core_rw);
85478+ return -ENOMEM;
85479+ }
85480+
85481+ pax_open_kernel();
85482+ memset(ptr, 0, mod->core_size_rx);
85483+ pax_close_kernel();
85484+ mod->module_core_rx = ptr;
85485+
85486+ if (mod->init_size_rx) {
85487+ ptr = module_alloc_update_bounds_rx(mod->init_size_rx);
85488+ kmemleak_ignore(ptr);
85489+ if (!ptr && mod->init_size_rx) {
85490+ module_free_exec(mod, mod->module_core_rx);
85491+ if (mod->module_init_rw)
85492+ module_free(mod, mod->module_init_rw);
85493+ module_free(mod, mod->module_core_rw);
85494+ return -ENOMEM;
85495+ }
85496+
85497+ pax_open_kernel();
85498+ memset(ptr, 0, mod->init_size_rx);
85499+ pax_close_kernel();
85500+ mod->module_init_rx = ptr;
85501+ } else
85502+ mod->module_init_rx = NULL;
85503
85504 /* Transfer each section which specifies SHF_ALLOC */
85505 pr_debug("final section addresses:\n");
85506@@ -2854,16 +2930,45 @@ static int move_module(struct module *mod, struct load_info *info)
85507 if (!(shdr->sh_flags & SHF_ALLOC))
85508 continue;
85509
85510- if (shdr->sh_entsize & INIT_OFFSET_MASK)
85511- dest = mod->module_init
85512- + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
85513- else
85514- dest = mod->module_core + shdr->sh_entsize;
85515+ if (shdr->sh_entsize & INIT_OFFSET_MASK) {
85516+ if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
85517+ dest = mod->module_init_rw
85518+ + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
85519+ else
85520+ dest = mod->module_init_rx
85521+ + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
85522+ } else {
85523+ if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
85524+ dest = mod->module_core_rw + shdr->sh_entsize;
85525+ else
85526+ dest = mod->module_core_rx + shdr->sh_entsize;
85527+ }
85528+
85529+ if (shdr->sh_type != SHT_NOBITS) {
85530+
85531+#ifdef CONFIG_PAX_KERNEXEC
85532+#ifdef CONFIG_X86_64
85533+ if ((shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_EXECINSTR))
85534+ set_memory_x((unsigned long)dest, (shdr->sh_size + PAGE_SIZE) >> PAGE_SHIFT);
85535+#endif
85536+ if (!(shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_ALLOC)) {
85537+ pax_open_kernel();
85538+ memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
85539+ pax_close_kernel();
85540+ } else
85541+#endif
85542
85543- if (shdr->sh_type != SHT_NOBITS)
85544 memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
85545+ }
85546 /* Update sh_addr to point to copy in image. */
85547- shdr->sh_addr = (unsigned long)dest;
85548+
85549+#ifdef CONFIG_PAX_KERNEXEC
85550+ if (shdr->sh_flags & SHF_EXECINSTR)
85551+ shdr->sh_addr = ktva_ktla((unsigned long)dest);
85552+ else
85553+#endif
85554+
85555+ shdr->sh_addr = (unsigned long)dest;
85556 pr_debug("\t0x%lx %s\n",
85557 (long)shdr->sh_addr, info->secstrings + shdr->sh_name);
85558 }
85559@@ -2920,12 +3025,12 @@ static void flush_module_icache(const struct module *mod)
85560 * Do it before processing of module parameters, so the module
85561 * can provide parameter accessor functions of its own.
85562 */
85563- if (mod->module_init)
85564- flush_icache_range((unsigned long)mod->module_init,
85565- (unsigned long)mod->module_init
85566- + mod->init_size);
85567- flush_icache_range((unsigned long)mod->module_core,
85568- (unsigned long)mod->module_core + mod->core_size);
85569+ if (mod->module_init_rx)
85570+ flush_icache_range((unsigned long)mod->module_init_rx,
85571+ (unsigned long)mod->module_init_rx
85572+ + mod->init_size_rx);
85573+ flush_icache_range((unsigned long)mod->module_core_rx,
85574+ (unsigned long)mod->module_core_rx + mod->core_size_rx);
85575
85576 set_fs(old_fs);
85577 }
85578@@ -2982,8 +3087,10 @@ static struct module *layout_and_allocate(struct load_info *info, int flags)
85579 static void module_deallocate(struct module *mod, struct load_info *info)
85580 {
85581 percpu_modfree(mod);
85582- module_free(mod, mod->module_init);
85583- module_free(mod, mod->module_core);
85584+ module_free_exec(mod, mod->module_init_rx);
85585+ module_free_exec(mod, mod->module_core_rx);
85586+ module_free(mod, mod->module_init_rw);
85587+ module_free(mod, mod->module_core_rw);
85588 }
85589
85590 int __weak module_finalize(const Elf_Ehdr *hdr,
85591@@ -2996,7 +3103,9 @@ int __weak module_finalize(const Elf_Ehdr *hdr,
85592 static int post_relocation(struct module *mod, const struct load_info *info)
85593 {
85594 /* Sort exception table now relocations are done. */
85595+ pax_open_kernel();
85596 sort_extable(mod->extable, mod->extable + mod->num_exentries);
85597+ pax_close_kernel();
85598
85599 /* Copy relocated percpu area over. */
85600 percpu_modcopy(mod, (void *)info->sechdrs[info->index.pcpu].sh_addr,
85601@@ -3050,16 +3159,16 @@ static int do_init_module(struct module *mod)
85602 MODULE_STATE_COMING, mod);
85603
85604 /* Set RO and NX regions for core */
85605- set_section_ro_nx(mod->module_core,
85606- mod->core_text_size,
85607- mod->core_ro_size,
85608- mod->core_size);
85609+ set_section_ro_nx(mod->module_core_rx,
85610+ mod->core_size_rx,
85611+ mod->core_size_rx,
85612+ mod->core_size_rx);
85613
85614 /* Set RO and NX regions for init */
85615- set_section_ro_nx(mod->module_init,
85616- mod->init_text_size,
85617- mod->init_ro_size,
85618- mod->init_size);
85619+ set_section_ro_nx(mod->module_init_rx,
85620+ mod->init_size_rx,
85621+ mod->init_size_rx,
85622+ mod->init_size_rx);
85623
85624 do_mod_ctors(mod);
85625 /* Start the module */
85626@@ -3121,11 +3230,12 @@ static int do_init_module(struct module *mod)
85627 mod->strtab = mod->core_strtab;
85628 #endif
85629 unset_module_init_ro_nx(mod);
85630- module_free(mod, mod->module_init);
85631- mod->module_init = NULL;
85632- mod->init_size = 0;
85633- mod->init_ro_size = 0;
85634- mod->init_text_size = 0;
85635+ module_free(mod, mod->module_init_rw);
85636+ module_free_exec(mod, mod->module_init_rx);
85637+ mod->module_init_rw = NULL;
85638+ mod->module_init_rx = NULL;
85639+ mod->init_size_rw = 0;
85640+ mod->init_size_rx = 0;
85641 mutex_unlock(&module_mutex);
85642 wake_up_all(&module_wq);
85643
85644@@ -3269,9 +3379,38 @@ static int load_module(struct load_info *info, const char __user *uargs,
85645 if (err)
85646 goto free_unload;
85647
85648+ /* Now copy in args */
85649+ mod->args = strndup_user(uargs, ~0UL >> 1);
85650+ if (IS_ERR(mod->args)) {
85651+ err = PTR_ERR(mod->args);
85652+ goto free_unload;
85653+ }
85654+
85655 /* Set up MODINFO_ATTR fields */
85656 setup_modinfo(mod, info);
85657
85658+#ifdef CONFIG_GRKERNSEC_MODHARDEN
85659+ {
85660+ char *p, *p2;
85661+
85662+ if (strstr(mod->args, "grsec_modharden_netdev")) {
85663+ 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);
85664+ err = -EPERM;
85665+ goto free_modinfo;
85666+ } else if ((p = strstr(mod->args, "grsec_modharden_normal"))) {
85667+ p += sizeof("grsec_modharden_normal") - 1;
85668+ p2 = strstr(p, "_");
85669+ if (p2) {
85670+ *p2 = '\0';
85671+ printk(KERN_ALERT "grsec: denied kernel module auto-load of %.64s by uid %.9s\n", mod->name, p);
85672+ *p2 = '_';
85673+ }
85674+ err = -EPERM;
85675+ goto free_modinfo;
85676+ }
85677+ }
85678+#endif
85679+
85680 /* Fix up syms, so that st_value is a pointer to location. */
85681 err = simplify_symbols(mod, info);
85682 if (err < 0)
85683@@ -3287,13 +3426,6 @@ static int load_module(struct load_info *info, const char __user *uargs,
85684
85685 flush_module_icache(mod);
85686
85687- /* Now copy in args */
85688- mod->args = strndup_user(uargs, ~0UL >> 1);
85689- if (IS_ERR(mod->args)) {
85690- err = PTR_ERR(mod->args);
85691- goto free_arch_cleanup;
85692- }
85693-
85694 dynamic_debug_setup(info->debug, info->num_debug);
85695
85696 /* Finally it's fully formed, ready to start executing. */
85697@@ -3328,11 +3460,10 @@ static int load_module(struct load_info *info, const char __user *uargs,
85698 ddebug_cleanup:
85699 dynamic_debug_remove(info->debug);
85700 synchronize_sched();
85701- kfree(mod->args);
85702- free_arch_cleanup:
85703 module_arch_cleanup(mod);
85704 free_modinfo:
85705 free_modinfo(mod);
85706+ kfree(mod->args);
85707 free_unload:
85708 module_unload_free(mod);
85709 unlink_mod:
85710@@ -3415,10 +3546,16 @@ static const char *get_ksymbol(struct module *mod,
85711 unsigned long nextval;
85712
85713 /* At worse, next value is at end of module */
85714- if (within_module_init(addr, mod))
85715- nextval = (unsigned long)mod->module_init+mod->init_text_size;
85716+ if (within_module_init_rx(addr, mod))
85717+ nextval = (unsigned long)mod->module_init_rx+mod->init_size_rx;
85718+ else if (within_module_init_rw(addr, mod))
85719+ nextval = (unsigned long)mod->module_init_rw+mod->init_size_rw;
85720+ else if (within_module_core_rx(addr, mod))
85721+ nextval = (unsigned long)mod->module_core_rx+mod->core_size_rx;
85722+ else if (within_module_core_rw(addr, mod))
85723+ nextval = (unsigned long)mod->module_core_rw+mod->core_size_rw;
85724 else
85725- nextval = (unsigned long)mod->module_core+mod->core_text_size;
85726+ return NULL;
85727
85728 /* Scan for closest preceding symbol, and next symbol. (ELF
85729 starts real symbols at 1). */
85730@@ -3669,7 +3806,7 @@ static int m_show(struct seq_file *m, void *p)
85731 return 0;
85732
85733 seq_printf(m, "%s %u",
85734- mod->name, mod->init_size + mod->core_size);
85735+ mod->name, mod->init_size_rx + mod->init_size_rw + mod->core_size_rx + mod->core_size_rw);
85736 print_unload_info(m, mod);
85737
85738 /* Informative for users. */
85739@@ -3678,7 +3815,7 @@ static int m_show(struct seq_file *m, void *p)
85740 mod->state == MODULE_STATE_COMING ? "Loading":
85741 "Live");
85742 /* Used by oprofile and other similar tools. */
85743- seq_printf(m, " 0x%pK", mod->module_core);
85744+ seq_printf(m, " 0x%pK 0x%pK", mod->module_core_rx, mod->module_core_rw);
85745
85746 /* Taints info */
85747 if (mod->taints)
85748@@ -3714,7 +3851,17 @@ static const struct file_operations proc_modules_operations = {
85749
85750 static int __init proc_modules_init(void)
85751 {
85752+#ifndef CONFIG_GRKERNSEC_HIDESYM
85753+#ifdef CONFIG_GRKERNSEC_PROC_USER
85754+ proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
85755+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
85756+ proc_create("modules", S_IRUSR | S_IRGRP, NULL, &proc_modules_operations);
85757+#else
85758 proc_create("modules", 0, NULL, &proc_modules_operations);
85759+#endif
85760+#else
85761+ proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
85762+#endif
85763 return 0;
85764 }
85765 module_init(proc_modules_init);
85766@@ -3775,14 +3922,14 @@ struct module *__module_address(unsigned long addr)
85767 {
85768 struct module *mod;
85769
85770- if (addr < module_addr_min || addr > module_addr_max)
85771+ if ((addr < module_addr_min_rx || addr > module_addr_max_rx) &&
85772+ (addr < module_addr_min_rw || addr > module_addr_max_rw))
85773 return NULL;
85774
85775 list_for_each_entry_rcu(mod, &modules, list) {
85776 if (mod->state == MODULE_STATE_UNFORMED)
85777 continue;
85778- if (within_module_core(addr, mod)
85779- || within_module_init(addr, mod))
85780+ if (within_module_init(addr, mod) || within_module_core(addr, mod))
85781 return mod;
85782 }
85783 return NULL;
85784@@ -3817,11 +3964,20 @@ bool is_module_text_address(unsigned long addr)
85785 */
85786 struct module *__module_text_address(unsigned long addr)
85787 {
85788- struct module *mod = __module_address(addr);
85789+ struct module *mod;
85790+
85791+#ifdef CONFIG_X86_32
85792+ addr = ktla_ktva(addr);
85793+#endif
85794+
85795+ if (addr < module_addr_min_rx || addr > module_addr_max_rx)
85796+ return NULL;
85797+
85798+ mod = __module_address(addr);
85799+
85800 if (mod) {
85801 /* Make sure it's within the text section. */
85802- if (!within(addr, mod->module_init, mod->init_text_size)
85803- && !within(addr, mod->module_core, mod->core_text_size))
85804+ if (!within_module_init_rx(addr, mod) && !within_module_core_rx(addr, mod))
85805 mod = NULL;
85806 }
85807 return mod;
85808diff --git a/kernel/mutex-debug.c b/kernel/mutex-debug.c
85809index 7e3443f..b2a1e6b 100644
85810--- a/kernel/mutex-debug.c
85811+++ b/kernel/mutex-debug.c
85812@@ -49,21 +49,21 @@ void debug_mutex_free_waiter(struct mutex_waiter *waiter)
85813 }
85814
85815 void debug_mutex_add_waiter(struct mutex *lock, struct mutex_waiter *waiter,
85816- struct thread_info *ti)
85817+ struct task_struct *task)
85818 {
85819 SMP_DEBUG_LOCKS_WARN_ON(!spin_is_locked(&lock->wait_lock));
85820
85821 /* Mark the current thread as blocked on the lock: */
85822- ti->task->blocked_on = waiter;
85823+ task->blocked_on = waiter;
85824 }
85825
85826 void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
85827- struct thread_info *ti)
85828+ struct task_struct *task)
85829 {
85830 DEBUG_LOCKS_WARN_ON(list_empty(&waiter->list));
85831- DEBUG_LOCKS_WARN_ON(waiter->task != ti->task);
85832- DEBUG_LOCKS_WARN_ON(ti->task->blocked_on != waiter);
85833- ti->task->blocked_on = NULL;
85834+ DEBUG_LOCKS_WARN_ON(waiter->task != task);
85835+ DEBUG_LOCKS_WARN_ON(task->blocked_on != waiter);
85836+ task->blocked_on = NULL;
85837
85838 list_del_init(&waiter->list);
85839 waiter->task = NULL;
85840diff --git a/kernel/mutex-debug.h b/kernel/mutex-debug.h
85841index 0799fd3..d06ae3b 100644
85842--- a/kernel/mutex-debug.h
85843+++ b/kernel/mutex-debug.h
85844@@ -20,9 +20,9 @@ extern void debug_mutex_wake_waiter(struct mutex *lock,
85845 extern void debug_mutex_free_waiter(struct mutex_waiter *waiter);
85846 extern void debug_mutex_add_waiter(struct mutex *lock,
85847 struct mutex_waiter *waiter,
85848- struct thread_info *ti);
85849+ struct task_struct *task);
85850 extern void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
85851- struct thread_info *ti);
85852+ struct task_struct *task);
85853 extern void debug_mutex_unlock(struct mutex *lock);
85854 extern void debug_mutex_init(struct mutex *lock, const char *name,
85855 struct lock_class_key *key);
85856diff --git a/kernel/mutex.c b/kernel/mutex.c
85857index d24105b..15648eb 100644
85858--- a/kernel/mutex.c
85859+++ b/kernel/mutex.c
85860@@ -135,7 +135,7 @@ void mspin_lock(struct mspin_node **lock, struct mspin_node *node)
85861 node->locked = 1;
85862 return;
85863 }
85864- ACCESS_ONCE(prev->next) = node;
85865+ ACCESS_ONCE_RW(prev->next) = node;
85866 smp_wmb();
85867 /* Wait until the lock holder passes the lock down */
85868 while (!ACCESS_ONCE(node->locked))
85869@@ -156,7 +156,7 @@ static void mspin_unlock(struct mspin_node **lock, struct mspin_node *node)
85870 while (!(next = ACCESS_ONCE(node->next)))
85871 arch_mutex_cpu_relax();
85872 }
85873- ACCESS_ONCE(next->locked) = 1;
85874+ ACCESS_ONCE_RW(next->locked) = 1;
85875 smp_wmb();
85876 }
85877
85878@@ -520,7 +520,7 @@ slowpath:
85879 goto skip_wait;
85880
85881 debug_mutex_lock_common(lock, &waiter);
85882- debug_mutex_add_waiter(lock, &waiter, task_thread_info(task));
85883+ debug_mutex_add_waiter(lock, &waiter, task);
85884
85885 /* add waiting tasks to the end of the waitqueue (FIFO): */
85886 list_add_tail(&waiter.list, &lock->wait_list);
85887@@ -564,7 +564,7 @@ slowpath:
85888 schedule_preempt_disabled();
85889 spin_lock_mutex(&lock->wait_lock, flags);
85890 }
85891- mutex_remove_waiter(lock, &waiter, current_thread_info());
85892+ mutex_remove_waiter(lock, &waiter, task);
85893 /* set it to 0 if there are no waiters left: */
85894 if (likely(list_empty(&lock->wait_list)))
85895 atomic_set(&lock->count, 0);
85896@@ -601,7 +601,7 @@ skip_wait:
85897 return 0;
85898
85899 err:
85900- mutex_remove_waiter(lock, &waiter, task_thread_info(task));
85901+ mutex_remove_waiter(lock, &waiter, task);
85902 spin_unlock_mutex(&lock->wait_lock, flags);
85903 debug_mutex_free_waiter(&waiter);
85904 mutex_release(&lock->dep_map, 1, ip);
85905diff --git a/kernel/notifier.c b/kernel/notifier.c
85906index 2d5cc4c..d9ea600 100644
85907--- a/kernel/notifier.c
85908+++ b/kernel/notifier.c
85909@@ -5,6 +5,7 @@
85910 #include <linux/rcupdate.h>
85911 #include <linux/vmalloc.h>
85912 #include <linux/reboot.h>
85913+#include <linux/mm.h>
85914
85915 /*
85916 * Notifier list for kernel code which wants to be called
85917@@ -24,10 +25,12 @@ static int notifier_chain_register(struct notifier_block **nl,
85918 while ((*nl) != NULL) {
85919 if (n->priority > (*nl)->priority)
85920 break;
85921- nl = &((*nl)->next);
85922+ nl = (struct notifier_block **)&((*nl)->next);
85923 }
85924- n->next = *nl;
85925+ pax_open_kernel();
85926+ *(const void **)&n->next = *nl;
85927 rcu_assign_pointer(*nl, n);
85928+ pax_close_kernel();
85929 return 0;
85930 }
85931
85932@@ -39,10 +42,12 @@ static int notifier_chain_cond_register(struct notifier_block **nl,
85933 return 0;
85934 if (n->priority > (*nl)->priority)
85935 break;
85936- nl = &((*nl)->next);
85937+ nl = (struct notifier_block **)&((*nl)->next);
85938 }
85939- n->next = *nl;
85940+ pax_open_kernel();
85941+ *(const void **)&n->next = *nl;
85942 rcu_assign_pointer(*nl, n);
85943+ pax_close_kernel();
85944 return 0;
85945 }
85946
85947@@ -51,10 +56,12 @@ static int notifier_chain_unregister(struct notifier_block **nl,
85948 {
85949 while ((*nl) != NULL) {
85950 if ((*nl) == n) {
85951+ pax_open_kernel();
85952 rcu_assign_pointer(*nl, n->next);
85953+ pax_close_kernel();
85954 return 0;
85955 }
85956- nl = &((*nl)->next);
85957+ nl = (struct notifier_block **)&((*nl)->next);
85958 }
85959 return -ENOENT;
85960 }
85961diff --git a/kernel/panic.c b/kernel/panic.c
85962index b6c482c..5578061 100644
85963--- a/kernel/panic.c
85964+++ b/kernel/panic.c
85965@@ -407,7 +407,7 @@ static void warn_slowpath_common(const char *file, int line, void *caller,
85966 disable_trace_on_warning();
85967
85968 pr_warn("------------[ cut here ]------------\n");
85969- pr_warn("WARNING: CPU: %d PID: %d at %s:%d %pS()\n",
85970+ pr_warn("WARNING: CPU: %d PID: %d at %s:%d %pA()\n",
85971 raw_smp_processor_id(), current->pid, file, line, caller);
85972
85973 if (args)
85974@@ -461,7 +461,8 @@ EXPORT_SYMBOL(warn_slowpath_null);
85975 */
85976 void __stack_chk_fail(void)
85977 {
85978- panic("stack-protector: Kernel stack is corrupted in: %p\n",
85979+ dump_stack();
85980+ panic("stack-protector: Kernel stack is corrupted in: %pA\n",
85981 __builtin_return_address(0));
85982 }
85983 EXPORT_SYMBOL(__stack_chk_fail);
85984diff --git a/kernel/pid.c b/kernel/pid.c
85985index 9b9a266..c20ef80 100644
85986--- a/kernel/pid.c
85987+++ b/kernel/pid.c
85988@@ -33,6 +33,7 @@
85989 #include <linux/rculist.h>
85990 #include <linux/bootmem.h>
85991 #include <linux/hash.h>
85992+#include <linux/security.h>
85993 #include <linux/pid_namespace.h>
85994 #include <linux/init_task.h>
85995 #include <linux/syscalls.h>
85996@@ -47,7 +48,7 @@ struct pid init_struct_pid = INIT_STRUCT_PID;
85997
85998 int pid_max = PID_MAX_DEFAULT;
85999
86000-#define RESERVED_PIDS 300
86001+#define RESERVED_PIDS 500
86002
86003 int pid_max_min = RESERVED_PIDS + 1;
86004 int pid_max_max = PID_MAX_LIMIT;
86005@@ -445,10 +446,18 @@ EXPORT_SYMBOL(pid_task);
86006 */
86007 struct task_struct *find_task_by_pid_ns(pid_t nr, struct pid_namespace *ns)
86008 {
86009+ struct task_struct *task;
86010+
86011 rcu_lockdep_assert(rcu_read_lock_held(),
86012 "find_task_by_pid_ns() needs rcu_read_lock()"
86013 " protection");
86014- return pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
86015+
86016+ task = pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
86017+
86018+ if (gr_pid_is_chrooted(task))
86019+ return NULL;
86020+
86021+ return task;
86022 }
86023
86024 struct task_struct *find_task_by_vpid(pid_t vnr)
86025@@ -456,6 +465,14 @@ struct task_struct *find_task_by_vpid(pid_t vnr)
86026 return find_task_by_pid_ns(vnr, task_active_pid_ns(current));
86027 }
86028
86029+struct task_struct *find_task_by_vpid_unrestricted(pid_t vnr)
86030+{
86031+ rcu_lockdep_assert(rcu_read_lock_held(),
86032+ "find_task_by_pid_ns() needs rcu_read_lock()"
86033+ " protection");
86034+ return pid_task(find_pid_ns(vnr, task_active_pid_ns(current)), PIDTYPE_PID);
86035+}
86036+
86037 struct pid *get_task_pid(struct task_struct *task, enum pid_type type)
86038 {
86039 struct pid *pid;
86040diff --git a/kernel/pid_namespace.c b/kernel/pid_namespace.c
86041index 4208655..19f36a5 100644
86042--- a/kernel/pid_namespace.c
86043+++ b/kernel/pid_namespace.c
86044@@ -247,7 +247,7 @@ static int pid_ns_ctl_handler(struct ctl_table *table, int write,
86045 void __user *buffer, size_t *lenp, loff_t *ppos)
86046 {
86047 struct pid_namespace *pid_ns = task_active_pid_ns(current);
86048- struct ctl_table tmp = *table;
86049+ ctl_table_no_const tmp = *table;
86050
86051 if (write && !ns_capable(pid_ns->user_ns, CAP_SYS_ADMIN))
86052 return -EPERM;
86053diff --git a/kernel/posix-cpu-timers.c b/kernel/posix-cpu-timers.c
86054index c7f31aa..2b44977 100644
86055--- a/kernel/posix-cpu-timers.c
86056+++ b/kernel/posix-cpu-timers.c
86057@@ -1521,14 +1521,14 @@ struct k_clock clock_posix_cpu = {
86058
86059 static __init int init_posix_cpu_timers(void)
86060 {
86061- struct k_clock process = {
86062+ static struct k_clock process = {
86063 .clock_getres = process_cpu_clock_getres,
86064 .clock_get = process_cpu_clock_get,
86065 .timer_create = process_cpu_timer_create,
86066 .nsleep = process_cpu_nsleep,
86067 .nsleep_restart = process_cpu_nsleep_restart,
86068 };
86069- struct k_clock thread = {
86070+ static struct k_clock thread = {
86071 .clock_getres = thread_cpu_clock_getres,
86072 .clock_get = thread_cpu_clock_get,
86073 .timer_create = thread_cpu_timer_create,
86074diff --git a/kernel/posix-timers.c b/kernel/posix-timers.c
86075index 424c2d4..679242f 100644
86076--- a/kernel/posix-timers.c
86077+++ b/kernel/posix-timers.c
86078@@ -43,6 +43,7 @@
86079 #include <linux/hash.h>
86080 #include <linux/posix-clock.h>
86081 #include <linux/posix-timers.h>
86082+#include <linux/grsecurity.h>
86083 #include <linux/syscalls.h>
86084 #include <linux/wait.h>
86085 #include <linux/workqueue.h>
86086@@ -122,7 +123,7 @@ static DEFINE_SPINLOCK(hash_lock);
86087 * which we beg off on and pass to do_sys_settimeofday().
86088 */
86089
86090-static struct k_clock posix_clocks[MAX_CLOCKS];
86091+static struct k_clock *posix_clocks[MAX_CLOCKS];
86092
86093 /*
86094 * These ones are defined below.
86095@@ -275,7 +276,7 @@ static int posix_get_tai(clockid_t which_clock, struct timespec *tp)
86096 */
86097 static __init int init_posix_timers(void)
86098 {
86099- struct k_clock clock_realtime = {
86100+ static struct k_clock clock_realtime = {
86101 .clock_getres = hrtimer_get_res,
86102 .clock_get = posix_clock_realtime_get,
86103 .clock_set = posix_clock_realtime_set,
86104@@ -287,7 +288,7 @@ static __init int init_posix_timers(void)
86105 .timer_get = common_timer_get,
86106 .timer_del = common_timer_del,
86107 };
86108- struct k_clock clock_monotonic = {
86109+ static struct k_clock clock_monotonic = {
86110 .clock_getres = hrtimer_get_res,
86111 .clock_get = posix_ktime_get_ts,
86112 .nsleep = common_nsleep,
86113@@ -297,19 +298,19 @@ static __init int init_posix_timers(void)
86114 .timer_get = common_timer_get,
86115 .timer_del = common_timer_del,
86116 };
86117- struct k_clock clock_monotonic_raw = {
86118+ static struct k_clock clock_monotonic_raw = {
86119 .clock_getres = hrtimer_get_res,
86120 .clock_get = posix_get_monotonic_raw,
86121 };
86122- struct k_clock clock_realtime_coarse = {
86123+ static struct k_clock clock_realtime_coarse = {
86124 .clock_getres = posix_get_coarse_res,
86125 .clock_get = posix_get_realtime_coarse,
86126 };
86127- struct k_clock clock_monotonic_coarse = {
86128+ static struct k_clock clock_monotonic_coarse = {
86129 .clock_getres = posix_get_coarse_res,
86130 .clock_get = posix_get_monotonic_coarse,
86131 };
86132- struct k_clock clock_tai = {
86133+ static struct k_clock clock_tai = {
86134 .clock_getres = hrtimer_get_res,
86135 .clock_get = posix_get_tai,
86136 .nsleep = common_nsleep,
86137@@ -319,7 +320,7 @@ static __init int init_posix_timers(void)
86138 .timer_get = common_timer_get,
86139 .timer_del = common_timer_del,
86140 };
86141- struct k_clock clock_boottime = {
86142+ static struct k_clock clock_boottime = {
86143 .clock_getres = hrtimer_get_res,
86144 .clock_get = posix_get_boottime,
86145 .nsleep = common_nsleep,
86146@@ -531,7 +532,7 @@ void posix_timers_register_clock(const clockid_t clock_id,
86147 return;
86148 }
86149
86150- posix_clocks[clock_id] = *new_clock;
86151+ posix_clocks[clock_id] = new_clock;
86152 }
86153 EXPORT_SYMBOL_GPL(posix_timers_register_clock);
86154
86155@@ -577,9 +578,9 @@ static struct k_clock *clockid_to_kclock(const clockid_t id)
86156 return (id & CLOCKFD_MASK) == CLOCKFD ?
86157 &clock_posix_dynamic : &clock_posix_cpu;
86158
86159- if (id >= MAX_CLOCKS || !posix_clocks[id].clock_getres)
86160+ if (id >= MAX_CLOCKS || !posix_clocks[id] || !posix_clocks[id]->clock_getres)
86161 return NULL;
86162- return &posix_clocks[id];
86163+ return posix_clocks[id];
86164 }
86165
86166 static int common_timer_create(struct k_itimer *new_timer)
86167@@ -597,7 +598,7 @@ SYSCALL_DEFINE3(timer_create, const clockid_t, which_clock,
86168 struct k_clock *kc = clockid_to_kclock(which_clock);
86169 struct k_itimer *new_timer;
86170 int error, new_timer_id;
86171- sigevent_t event;
86172+ sigevent_t event = { };
86173 int it_id_set = IT_ID_NOT_SET;
86174
86175 if (!kc)
86176@@ -1011,6 +1012,13 @@ SYSCALL_DEFINE2(clock_settime, const clockid_t, which_clock,
86177 if (copy_from_user(&new_tp, tp, sizeof (*tp)))
86178 return -EFAULT;
86179
86180+ /* only the CLOCK_REALTIME clock can be set, all other clocks
86181+ have their clock_set fptr set to a nosettime dummy function
86182+ CLOCK_REALTIME has a NULL clock_set fptr which causes it to
86183+ call common_clock_set, which calls do_sys_settimeofday, which
86184+ we hook
86185+ */
86186+
86187 return kc->clock_set(which_clock, &new_tp);
86188 }
86189
86190diff --git a/kernel/power/Kconfig b/kernel/power/Kconfig
86191index d444c4e..bc3de51 100644
86192--- a/kernel/power/Kconfig
86193+++ b/kernel/power/Kconfig
86194@@ -24,6 +24,8 @@ config HIBERNATE_CALLBACKS
86195 config HIBERNATION
86196 bool "Hibernation (aka 'suspend to disk')"
86197 depends on SWAP && ARCH_HIBERNATION_POSSIBLE
86198+ depends on !GRKERNSEC_KMEM
86199+ depends on !PAX_MEMORY_SANITIZE
86200 select HIBERNATE_CALLBACKS
86201 select LZO_COMPRESS
86202 select LZO_DECOMPRESS
86203diff --git a/kernel/power/process.c b/kernel/power/process.c
86204index 06ec886..9dba35e 100644
86205--- a/kernel/power/process.c
86206+++ b/kernel/power/process.c
86207@@ -34,6 +34,7 @@ static int try_to_freeze_tasks(bool user_only)
86208 unsigned int elapsed_msecs;
86209 bool wakeup = false;
86210 int sleep_usecs = USEC_PER_MSEC;
86211+ bool timedout = false;
86212
86213 do_gettimeofday(&start);
86214
86215@@ -44,13 +45,20 @@ static int try_to_freeze_tasks(bool user_only)
86216
86217 while (true) {
86218 todo = 0;
86219+ if (time_after(jiffies, end_time))
86220+ timedout = true;
86221 read_lock(&tasklist_lock);
86222 do_each_thread(g, p) {
86223 if (p == current || !freeze_task(p))
86224 continue;
86225
86226- if (!freezer_should_skip(p))
86227+ if (!freezer_should_skip(p)) {
86228 todo++;
86229+ if (timedout) {
86230+ printk(KERN_ERR "Task refusing to freeze:\n");
86231+ sched_show_task(p);
86232+ }
86233+ }
86234 } while_each_thread(g, p);
86235 read_unlock(&tasklist_lock);
86236
86237@@ -59,7 +67,7 @@ static int try_to_freeze_tasks(bool user_only)
86238 todo += wq_busy;
86239 }
86240
86241- if (!todo || time_after(jiffies, end_time))
86242+ if (!todo || timedout)
86243 break;
86244
86245 if (pm_wakeup_pending()) {
86246diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
86247index b4e8500..b457a6c 100644
86248--- a/kernel/printk/printk.c
86249+++ b/kernel/printk/printk.c
86250@@ -385,6 +385,11 @@ static int check_syslog_permissions(int type, bool from_file)
86251 if (from_file && type != SYSLOG_ACTION_OPEN)
86252 return 0;
86253
86254+#ifdef CONFIG_GRKERNSEC_DMESG
86255+ if (grsec_enable_dmesg && !capable(CAP_SYSLOG) && !capable_nolog(CAP_SYS_ADMIN))
86256+ return -EPERM;
86257+#endif
86258+
86259 if (syslog_action_restricted(type)) {
86260 if (capable(CAP_SYSLOG))
86261 return 0;
86262diff --git a/kernel/profile.c b/kernel/profile.c
86263index 6631e1e..310c266 100644
86264--- a/kernel/profile.c
86265+++ b/kernel/profile.c
86266@@ -37,7 +37,7 @@ struct profile_hit {
86267 #define NR_PROFILE_HIT (PAGE_SIZE/sizeof(struct profile_hit))
86268 #define NR_PROFILE_GRP (NR_PROFILE_HIT/PROFILE_GRPSZ)
86269
86270-static atomic_t *prof_buffer;
86271+static atomic_unchecked_t *prof_buffer;
86272 static unsigned long prof_len, prof_shift;
86273
86274 int prof_on __read_mostly;
86275@@ -260,7 +260,7 @@ static void profile_flip_buffers(void)
86276 hits[i].pc = 0;
86277 continue;
86278 }
86279- atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
86280+ atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
86281 hits[i].hits = hits[i].pc = 0;
86282 }
86283 }
86284@@ -321,9 +321,9 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
86285 * Add the current hit(s) and flush the write-queue out
86286 * to the global buffer:
86287 */
86288- atomic_add(nr_hits, &prof_buffer[pc]);
86289+ atomic_add_unchecked(nr_hits, &prof_buffer[pc]);
86290 for (i = 0; i < NR_PROFILE_HIT; ++i) {
86291- atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
86292+ atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
86293 hits[i].pc = hits[i].hits = 0;
86294 }
86295 out:
86296@@ -398,7 +398,7 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
86297 {
86298 unsigned long pc;
86299 pc = ((unsigned long)__pc - (unsigned long)_stext) >> prof_shift;
86300- atomic_add(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
86301+ atomic_add_unchecked(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
86302 }
86303 #endif /* !CONFIG_SMP */
86304
86305@@ -494,7 +494,7 @@ read_profile(struct file *file, char __user *buf, size_t count, loff_t *ppos)
86306 return -EFAULT;
86307 buf++; p++; count--; read++;
86308 }
86309- pnt = (char *)prof_buffer + p - sizeof(atomic_t);
86310+ pnt = (char *)prof_buffer + p - sizeof(atomic_unchecked_t);
86311 if (copy_to_user(buf, (void *)pnt, count))
86312 return -EFAULT;
86313 read += count;
86314@@ -525,7 +525,7 @@ static ssize_t write_profile(struct file *file, const char __user *buf,
86315 }
86316 #endif
86317 profile_discard_flip_buffers();
86318- memset(prof_buffer, 0, prof_len * sizeof(atomic_t));
86319+ memset(prof_buffer, 0, prof_len * sizeof(atomic_unchecked_t));
86320 return count;
86321 }
86322
86323diff --git a/kernel/ptrace.c b/kernel/ptrace.c
86324index 1f4bcb3..99cf7ab 100644
86325--- a/kernel/ptrace.c
86326+++ b/kernel/ptrace.c
86327@@ -327,7 +327,7 @@ static int ptrace_attach(struct task_struct *task, long request,
86328 if (seize)
86329 flags |= PT_SEIZED;
86330 rcu_read_lock();
86331- if (ns_capable(__task_cred(task)->user_ns, CAP_SYS_PTRACE))
86332+ if (ns_capable_nolog(__task_cred(task)->user_ns, CAP_SYS_PTRACE))
86333 flags |= PT_PTRACE_CAP;
86334 rcu_read_unlock();
86335 task->ptrace = flags;
86336@@ -538,7 +538,7 @@ int ptrace_readdata(struct task_struct *tsk, unsigned long src, char __user *dst
86337 break;
86338 return -EIO;
86339 }
86340- if (copy_to_user(dst, buf, retval))
86341+ if (retval > sizeof(buf) || copy_to_user(dst, buf, retval))
86342 return -EFAULT;
86343 copied += retval;
86344 src += retval;
86345@@ -806,7 +806,7 @@ int ptrace_request(struct task_struct *child, long request,
86346 bool seized = child->ptrace & PT_SEIZED;
86347 int ret = -EIO;
86348 siginfo_t siginfo, *si;
86349- void __user *datavp = (void __user *) data;
86350+ void __user *datavp = (__force void __user *) data;
86351 unsigned long __user *datalp = datavp;
86352 unsigned long flags;
86353
86354@@ -1052,14 +1052,21 @@ SYSCALL_DEFINE4(ptrace, long, request, long, pid, unsigned long, addr,
86355 goto out;
86356 }
86357
86358+ if (gr_handle_ptrace(child, request)) {
86359+ ret = -EPERM;
86360+ goto out_put_task_struct;
86361+ }
86362+
86363 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
86364 ret = ptrace_attach(child, request, addr, data);
86365 /*
86366 * Some architectures need to do book-keeping after
86367 * a ptrace attach.
86368 */
86369- if (!ret)
86370+ if (!ret) {
86371 arch_ptrace_attach(child);
86372+ gr_audit_ptrace(child);
86373+ }
86374 goto out_put_task_struct;
86375 }
86376
86377@@ -1087,7 +1094,7 @@ int generic_ptrace_peekdata(struct task_struct *tsk, unsigned long addr,
86378 copied = access_process_vm(tsk, addr, &tmp, sizeof(tmp), 0);
86379 if (copied != sizeof(tmp))
86380 return -EIO;
86381- return put_user(tmp, (unsigned long __user *)data);
86382+ return put_user(tmp, (__force unsigned long __user *)data);
86383 }
86384
86385 int generic_ptrace_pokedata(struct task_struct *tsk, unsigned long addr,
86386@@ -1181,7 +1188,7 @@ int compat_ptrace_request(struct task_struct *child, compat_long_t request,
86387 }
86388
86389 asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
86390- compat_long_t addr, compat_long_t data)
86391+ compat_ulong_t addr, compat_ulong_t data)
86392 {
86393 struct task_struct *child;
86394 long ret;
86395@@ -1197,14 +1204,21 @@ asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
86396 goto out;
86397 }
86398
86399+ if (gr_handle_ptrace(child, request)) {
86400+ ret = -EPERM;
86401+ goto out_put_task_struct;
86402+ }
86403+
86404 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
86405 ret = ptrace_attach(child, request, addr, data);
86406 /*
86407 * Some architectures need to do book-keeping after
86408 * a ptrace attach.
86409 */
86410- if (!ret)
86411+ if (!ret) {
86412 arch_ptrace_attach(child);
86413+ gr_audit_ptrace(child);
86414+ }
86415 goto out_put_task_struct;
86416 }
86417
86418diff --git a/kernel/rcupdate.c b/kernel/rcupdate.c
86419index b02a339..ce2d20c 100644
86420--- a/kernel/rcupdate.c
86421+++ b/kernel/rcupdate.c
86422@@ -312,10 +312,10 @@ int rcu_jiffies_till_stall_check(void)
86423 * for CONFIG_RCU_CPU_STALL_TIMEOUT.
86424 */
86425 if (till_stall_check < 3) {
86426- ACCESS_ONCE(rcu_cpu_stall_timeout) = 3;
86427+ ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 3;
86428 till_stall_check = 3;
86429 } else if (till_stall_check > 300) {
86430- ACCESS_ONCE(rcu_cpu_stall_timeout) = 300;
86431+ ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 300;
86432 till_stall_check = 300;
86433 }
86434 return till_stall_check * HZ + RCU_STALL_DELAY_DELTA;
86435diff --git a/kernel/rcutiny.c b/kernel/rcutiny.c
86436index 9ed6075..c9e8a63 100644
86437--- a/kernel/rcutiny.c
86438+++ b/kernel/rcutiny.c
86439@@ -45,7 +45,7 @@
86440 /* Forward declarations for rcutiny_plugin.h. */
86441 struct rcu_ctrlblk;
86442 static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp);
86443-static void rcu_process_callbacks(struct softirq_action *unused);
86444+static void rcu_process_callbacks(void);
86445 static void __call_rcu(struct rcu_head *head,
86446 void (*func)(struct rcu_head *rcu),
86447 struct rcu_ctrlblk *rcp);
86448@@ -309,7 +309,7 @@ static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp)
86449 false));
86450 }
86451
86452-static void rcu_process_callbacks(struct softirq_action *unused)
86453+static __latent_entropy void rcu_process_callbacks(void)
86454 {
86455 __rcu_process_callbacks(&rcu_sched_ctrlblk);
86456 __rcu_process_callbacks(&rcu_bh_ctrlblk);
86457diff --git a/kernel/rcutorture.c b/kernel/rcutorture.c
86458index be63101..05cf721 100644
86459--- a/kernel/rcutorture.c
86460+++ b/kernel/rcutorture.c
86461@@ -170,12 +170,12 @@ static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_count) =
86462 { 0 };
86463 static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_batch) =
86464 { 0 };
86465-static atomic_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
86466-static atomic_t n_rcu_torture_alloc;
86467-static atomic_t n_rcu_torture_alloc_fail;
86468-static atomic_t n_rcu_torture_free;
86469-static atomic_t n_rcu_torture_mberror;
86470-static atomic_t n_rcu_torture_error;
86471+static atomic_unchecked_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
86472+static atomic_unchecked_t n_rcu_torture_alloc;
86473+static atomic_unchecked_t n_rcu_torture_alloc_fail;
86474+static atomic_unchecked_t n_rcu_torture_free;
86475+static atomic_unchecked_t n_rcu_torture_mberror;
86476+static atomic_unchecked_t n_rcu_torture_error;
86477 static long n_rcu_torture_barrier_error;
86478 static long n_rcu_torture_boost_ktrerror;
86479 static long n_rcu_torture_boost_rterror;
86480@@ -293,11 +293,11 @@ rcu_torture_alloc(void)
86481
86482 spin_lock_bh(&rcu_torture_lock);
86483 if (list_empty(&rcu_torture_freelist)) {
86484- atomic_inc(&n_rcu_torture_alloc_fail);
86485+ atomic_inc_unchecked(&n_rcu_torture_alloc_fail);
86486 spin_unlock_bh(&rcu_torture_lock);
86487 return NULL;
86488 }
86489- atomic_inc(&n_rcu_torture_alloc);
86490+ atomic_inc_unchecked(&n_rcu_torture_alloc);
86491 p = rcu_torture_freelist.next;
86492 list_del_init(p);
86493 spin_unlock_bh(&rcu_torture_lock);
86494@@ -310,7 +310,7 @@ rcu_torture_alloc(void)
86495 static void
86496 rcu_torture_free(struct rcu_torture *p)
86497 {
86498- atomic_inc(&n_rcu_torture_free);
86499+ atomic_inc_unchecked(&n_rcu_torture_free);
86500 spin_lock_bh(&rcu_torture_lock);
86501 list_add_tail(&p->rtort_free, &rcu_torture_freelist);
86502 spin_unlock_bh(&rcu_torture_lock);
86503@@ -431,7 +431,7 @@ rcu_torture_cb(struct rcu_head *p)
86504 i = rp->rtort_pipe_count;
86505 if (i > RCU_TORTURE_PIPE_LEN)
86506 i = RCU_TORTURE_PIPE_LEN;
86507- atomic_inc(&rcu_torture_wcount[i]);
86508+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
86509 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
86510 rp->rtort_mbtest = 0;
86511 rcu_torture_free(rp);
86512@@ -821,7 +821,7 @@ rcu_torture_writer(void *arg)
86513 i = old_rp->rtort_pipe_count;
86514 if (i > RCU_TORTURE_PIPE_LEN)
86515 i = RCU_TORTURE_PIPE_LEN;
86516- atomic_inc(&rcu_torture_wcount[i]);
86517+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
86518 old_rp->rtort_pipe_count++;
86519 if (gp_normal == gp_exp)
86520 exp = !!(rcu_random(&rand) & 0x80);
86521@@ -839,7 +839,7 @@ rcu_torture_writer(void *arg)
86522 i = rp->rtort_pipe_count;
86523 if (i > RCU_TORTURE_PIPE_LEN)
86524 i = RCU_TORTURE_PIPE_LEN;
86525- atomic_inc(&rcu_torture_wcount[i]);
86526+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
86527 if (++rp->rtort_pipe_count >=
86528 RCU_TORTURE_PIPE_LEN) {
86529 rp->rtort_mbtest = 0;
86530@@ -938,7 +938,7 @@ static void rcu_torture_timer(unsigned long unused)
86531 return;
86532 }
86533 if (p->rtort_mbtest == 0)
86534- atomic_inc(&n_rcu_torture_mberror);
86535+ atomic_inc_unchecked(&n_rcu_torture_mberror);
86536 spin_lock(&rand_lock);
86537 cur_ops->read_delay(&rand);
86538 n_rcu_torture_timers++;
86539@@ -1008,7 +1008,7 @@ rcu_torture_reader(void *arg)
86540 continue;
86541 }
86542 if (p->rtort_mbtest == 0)
86543- atomic_inc(&n_rcu_torture_mberror);
86544+ atomic_inc_unchecked(&n_rcu_torture_mberror);
86545 cur_ops->read_delay(&rand);
86546 preempt_disable();
86547 pipe_count = p->rtort_pipe_count;
86548@@ -1071,11 +1071,11 @@ rcu_torture_printk(char *page)
86549 rcu_torture_current,
86550 rcu_torture_current_version,
86551 list_empty(&rcu_torture_freelist),
86552- atomic_read(&n_rcu_torture_alloc),
86553- atomic_read(&n_rcu_torture_alloc_fail),
86554- atomic_read(&n_rcu_torture_free));
86555+ atomic_read_unchecked(&n_rcu_torture_alloc),
86556+ atomic_read_unchecked(&n_rcu_torture_alloc_fail),
86557+ atomic_read_unchecked(&n_rcu_torture_free));
86558 cnt += sprintf(&page[cnt], "rtmbe: %d rtbke: %ld rtbre: %ld ",
86559- atomic_read(&n_rcu_torture_mberror),
86560+ atomic_read_unchecked(&n_rcu_torture_mberror),
86561 n_rcu_torture_boost_ktrerror,
86562 n_rcu_torture_boost_rterror);
86563 cnt += sprintf(&page[cnt], "rtbf: %ld rtb: %ld nt: %ld ",
86564@@ -1094,14 +1094,14 @@ rcu_torture_printk(char *page)
86565 n_barrier_attempts,
86566 n_rcu_torture_barrier_error);
86567 cnt += sprintf(&page[cnt], "\n%s%s ", torture_type, TORTURE_FLAG);
86568- if (atomic_read(&n_rcu_torture_mberror) != 0 ||
86569+ if (atomic_read_unchecked(&n_rcu_torture_mberror) != 0 ||
86570 n_rcu_torture_barrier_error != 0 ||
86571 n_rcu_torture_boost_ktrerror != 0 ||
86572 n_rcu_torture_boost_rterror != 0 ||
86573 n_rcu_torture_boost_failure != 0 ||
86574 i > 1) {
86575 cnt += sprintf(&page[cnt], "!!! ");
86576- atomic_inc(&n_rcu_torture_error);
86577+ atomic_inc_unchecked(&n_rcu_torture_error);
86578 WARN_ON_ONCE(1);
86579 }
86580 cnt += sprintf(&page[cnt], "Reader Pipe: ");
86581@@ -1115,7 +1115,7 @@ rcu_torture_printk(char *page)
86582 cnt += sprintf(&page[cnt], "Free-Block Circulation: ");
86583 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
86584 cnt += sprintf(&page[cnt], " %d",
86585- atomic_read(&rcu_torture_wcount[i]));
86586+ atomic_read_unchecked(&rcu_torture_wcount[i]));
86587 }
86588 cnt += sprintf(&page[cnt], "\n");
86589 if (cur_ops->stats)
86590@@ -1830,7 +1830,7 @@ rcu_torture_cleanup(void)
86591
86592 rcu_torture_stats_print(); /* -After- the stats thread is stopped! */
86593
86594- if (atomic_read(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
86595+ if (atomic_read_unchecked(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
86596 rcu_torture_print_module_parms(cur_ops, "End of test: FAILURE");
86597 else if (n_online_successes != n_online_attempts ||
86598 n_offline_successes != n_offline_attempts)
86599@@ -1952,18 +1952,18 @@ rcu_torture_init(void)
86600
86601 rcu_torture_current = NULL;
86602 rcu_torture_current_version = 0;
86603- atomic_set(&n_rcu_torture_alloc, 0);
86604- atomic_set(&n_rcu_torture_alloc_fail, 0);
86605- atomic_set(&n_rcu_torture_free, 0);
86606- atomic_set(&n_rcu_torture_mberror, 0);
86607- atomic_set(&n_rcu_torture_error, 0);
86608+ atomic_set_unchecked(&n_rcu_torture_alloc, 0);
86609+ atomic_set_unchecked(&n_rcu_torture_alloc_fail, 0);
86610+ atomic_set_unchecked(&n_rcu_torture_free, 0);
86611+ atomic_set_unchecked(&n_rcu_torture_mberror, 0);
86612+ atomic_set_unchecked(&n_rcu_torture_error, 0);
86613 n_rcu_torture_barrier_error = 0;
86614 n_rcu_torture_boost_ktrerror = 0;
86615 n_rcu_torture_boost_rterror = 0;
86616 n_rcu_torture_boost_failure = 0;
86617 n_rcu_torture_boosts = 0;
86618 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
86619- atomic_set(&rcu_torture_wcount[i], 0);
86620+ atomic_set_unchecked(&rcu_torture_wcount[i], 0);
86621 for_each_possible_cpu(cpu) {
86622 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
86623 per_cpu(rcu_torture_count, cpu)[i] = 0;
86624diff --git a/kernel/rcutree.c b/kernel/rcutree.c
86625index 32618b3..c1fb822 100644
86626--- a/kernel/rcutree.c
86627+++ b/kernel/rcutree.c
86628@@ -382,9 +382,9 @@ static void rcu_eqs_enter_common(struct rcu_dynticks *rdtp, long long oldval,
86629 rcu_prepare_for_idle(smp_processor_id());
86630 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
86631 smp_mb__before_atomic_inc(); /* See above. */
86632- atomic_inc(&rdtp->dynticks);
86633+ atomic_inc_unchecked(&rdtp->dynticks);
86634 smp_mb__after_atomic_inc(); /* Force ordering with next sojourn. */
86635- WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
86636+ WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
86637
86638 /*
86639 * It is illegal to enter an extended quiescent state while
86640@@ -501,10 +501,10 @@ static void rcu_eqs_exit_common(struct rcu_dynticks *rdtp, long long oldval,
86641 int user)
86642 {
86643 smp_mb__before_atomic_inc(); /* Force ordering w/previous sojourn. */
86644- atomic_inc(&rdtp->dynticks);
86645+ atomic_inc_unchecked(&rdtp->dynticks);
86646 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
86647 smp_mb__after_atomic_inc(); /* See above. */
86648- WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
86649+ WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
86650 rcu_cleanup_after_idle(smp_processor_id());
86651 trace_rcu_dyntick(TPS("End"), oldval, rdtp->dynticks_nesting);
86652 if (!user && !is_idle_task(current)) {
86653@@ -623,14 +623,14 @@ void rcu_nmi_enter(void)
86654 struct rcu_dynticks *rdtp = &__get_cpu_var(rcu_dynticks);
86655
86656 if (rdtp->dynticks_nmi_nesting == 0 &&
86657- (atomic_read(&rdtp->dynticks) & 0x1))
86658+ (atomic_read_unchecked(&rdtp->dynticks) & 0x1))
86659 return;
86660 rdtp->dynticks_nmi_nesting++;
86661 smp_mb__before_atomic_inc(); /* Force delay from prior write. */
86662- atomic_inc(&rdtp->dynticks);
86663+ atomic_inc_unchecked(&rdtp->dynticks);
86664 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
86665 smp_mb__after_atomic_inc(); /* See above. */
86666- WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
86667+ WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
86668 }
86669
86670 /**
86671@@ -649,9 +649,9 @@ void rcu_nmi_exit(void)
86672 return;
86673 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
86674 smp_mb__before_atomic_inc(); /* See above. */
86675- atomic_inc(&rdtp->dynticks);
86676+ atomic_inc_unchecked(&rdtp->dynticks);
86677 smp_mb__after_atomic_inc(); /* Force delay to next write. */
86678- WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
86679+ WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
86680 }
86681
86682 /**
86683@@ -665,7 +665,7 @@ int rcu_is_cpu_idle(void)
86684 int ret;
86685
86686 preempt_disable();
86687- ret = (atomic_read(&__get_cpu_var(rcu_dynticks).dynticks) & 0x1) == 0;
86688+ ret = (atomic_read_unchecked(&__get_cpu_var(rcu_dynticks).dynticks) & 0x1) == 0;
86689 preempt_enable();
86690 return ret;
86691 }
86692@@ -734,7 +734,7 @@ static int rcu_is_cpu_rrupt_from_idle(void)
86693 static int dyntick_save_progress_counter(struct rcu_data *rdp,
86694 bool *isidle, unsigned long *maxj)
86695 {
86696- rdp->dynticks_snap = atomic_add_return(0, &rdp->dynticks->dynticks);
86697+ rdp->dynticks_snap = atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
86698 rcu_sysidle_check_cpu(rdp, isidle, maxj);
86699 return (rdp->dynticks_snap & 0x1) == 0;
86700 }
86701@@ -751,7 +751,7 @@ static int rcu_implicit_dynticks_qs(struct rcu_data *rdp,
86702 unsigned int curr;
86703 unsigned int snap;
86704
86705- curr = (unsigned int)atomic_add_return(0, &rdp->dynticks->dynticks);
86706+ curr = (unsigned int)atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
86707 snap = (unsigned int)rdp->dynticks_snap;
86708
86709 /*
86710@@ -1341,9 +1341,9 @@ static int rcu_gp_init(struct rcu_state *rsp)
86711 rdp = this_cpu_ptr(rsp->rda);
86712 rcu_preempt_check_blocked_tasks(rnp);
86713 rnp->qsmask = rnp->qsmaskinit;
86714- ACCESS_ONCE(rnp->gpnum) = rsp->gpnum;
86715+ ACCESS_ONCE_RW(rnp->gpnum) = rsp->gpnum;
86716 WARN_ON_ONCE(rnp->completed != rsp->completed);
86717- ACCESS_ONCE(rnp->completed) = rsp->completed;
86718+ ACCESS_ONCE_RW(rnp->completed) = rsp->completed;
86719 if (rnp == rdp->mynode)
86720 __note_gp_changes(rsp, rnp, rdp);
86721 rcu_preempt_boost_start_gp(rnp);
86722@@ -1434,7 +1434,7 @@ static void rcu_gp_cleanup(struct rcu_state *rsp)
86723 */
86724 rcu_for_each_node_breadth_first(rsp, rnp) {
86725 raw_spin_lock_irq(&rnp->lock);
86726- ACCESS_ONCE(rnp->completed) = rsp->gpnum;
86727+ ACCESS_ONCE_RW(rnp->completed) = rsp->gpnum;
86728 rdp = this_cpu_ptr(rsp->rda);
86729 if (rnp == rdp->mynode)
86730 __note_gp_changes(rsp, rnp, rdp);
86731@@ -1766,7 +1766,7 @@ rcu_send_cbs_to_orphanage(int cpu, struct rcu_state *rsp,
86732 rsp->qlen += rdp->qlen;
86733 rdp->n_cbs_orphaned += rdp->qlen;
86734 rdp->qlen_lazy = 0;
86735- ACCESS_ONCE(rdp->qlen) = 0;
86736+ ACCESS_ONCE_RW(rdp->qlen) = 0;
86737 }
86738
86739 /*
86740@@ -2012,7 +2012,7 @@ static void rcu_do_batch(struct rcu_state *rsp, struct rcu_data *rdp)
86741 }
86742 smp_mb(); /* List handling before counting for rcu_barrier(). */
86743 rdp->qlen_lazy -= count_lazy;
86744- ACCESS_ONCE(rdp->qlen) -= count;
86745+ ACCESS_ONCE_RW(rdp->qlen) -= count;
86746 rdp->n_cbs_invoked += count;
86747
86748 /* Reinstate batch limit if we have worked down the excess. */
86749@@ -2209,7 +2209,7 @@ __rcu_process_callbacks(struct rcu_state *rsp)
86750 /*
86751 * Do RCU core processing for the current CPU.
86752 */
86753-static void rcu_process_callbacks(struct softirq_action *unused)
86754+static __latent_entropy void rcu_process_callbacks(void)
86755 {
86756 struct rcu_state *rsp;
86757
86758@@ -2316,7 +2316,7 @@ __call_rcu(struct rcu_head *head, void (*func)(struct rcu_head *rcu),
86759 WARN_ON_ONCE((unsigned long)head & 0x3); /* Misaligned rcu_head! */
86760 if (debug_rcu_head_queue(head)) {
86761 /* Probable double call_rcu(), so leak the callback. */
86762- ACCESS_ONCE(head->func) = rcu_leak_callback;
86763+ ACCESS_ONCE_RW(head->func) = rcu_leak_callback;
86764 WARN_ONCE(1, "__call_rcu(): Leaked duplicate callback\n");
86765 return;
86766 }
86767@@ -2344,7 +2344,7 @@ __call_rcu(struct rcu_head *head, void (*func)(struct rcu_head *rcu),
86768 local_irq_restore(flags);
86769 return;
86770 }
86771- ACCESS_ONCE(rdp->qlen)++;
86772+ ACCESS_ONCE_RW(rdp->qlen)++;
86773 if (lazy)
86774 rdp->qlen_lazy++;
86775 else
86776@@ -2553,11 +2553,11 @@ void synchronize_sched_expedited(void)
86777 * counter wrap on a 32-bit system. Quite a few more CPUs would of
86778 * course be required on a 64-bit system.
86779 */
86780- if (ULONG_CMP_GE((ulong)atomic_long_read(&rsp->expedited_start),
86781+ if (ULONG_CMP_GE((ulong)atomic_long_read_unchecked(&rsp->expedited_start),
86782 (ulong)atomic_long_read(&rsp->expedited_done) +
86783 ULONG_MAX / 8)) {
86784 synchronize_sched();
86785- atomic_long_inc(&rsp->expedited_wrap);
86786+ atomic_long_inc_unchecked(&rsp->expedited_wrap);
86787 return;
86788 }
86789
86790@@ -2565,7 +2565,7 @@ void synchronize_sched_expedited(void)
86791 * Take a ticket. Note that atomic_inc_return() implies a
86792 * full memory barrier.
86793 */
86794- snap = atomic_long_inc_return(&rsp->expedited_start);
86795+ snap = atomic_long_inc_return_unchecked(&rsp->expedited_start);
86796 firstsnap = snap;
86797 get_online_cpus();
86798 WARN_ON_ONCE(cpu_is_offline(raw_smp_processor_id()));
86799@@ -2578,14 +2578,14 @@ void synchronize_sched_expedited(void)
86800 synchronize_sched_expedited_cpu_stop,
86801 NULL) == -EAGAIN) {
86802 put_online_cpus();
86803- atomic_long_inc(&rsp->expedited_tryfail);
86804+ atomic_long_inc_unchecked(&rsp->expedited_tryfail);
86805
86806 /* Check to see if someone else did our work for us. */
86807 s = atomic_long_read(&rsp->expedited_done);
86808 if (ULONG_CMP_GE((ulong)s, (ulong)firstsnap)) {
86809 /* ensure test happens before caller kfree */
86810 smp_mb__before_atomic_inc(); /* ^^^ */
86811- atomic_long_inc(&rsp->expedited_workdone1);
86812+ atomic_long_inc_unchecked(&rsp->expedited_workdone1);
86813 return;
86814 }
86815
86816@@ -2594,7 +2594,7 @@ void synchronize_sched_expedited(void)
86817 udelay(trycount * num_online_cpus());
86818 } else {
86819 wait_rcu_gp(call_rcu_sched);
86820- atomic_long_inc(&rsp->expedited_normal);
86821+ atomic_long_inc_unchecked(&rsp->expedited_normal);
86822 return;
86823 }
86824
86825@@ -2603,7 +2603,7 @@ void synchronize_sched_expedited(void)
86826 if (ULONG_CMP_GE((ulong)s, (ulong)firstsnap)) {
86827 /* ensure test happens before caller kfree */
86828 smp_mb__before_atomic_inc(); /* ^^^ */
86829- atomic_long_inc(&rsp->expedited_workdone2);
86830+ atomic_long_inc_unchecked(&rsp->expedited_workdone2);
86831 return;
86832 }
86833
86834@@ -2615,10 +2615,10 @@ void synchronize_sched_expedited(void)
86835 * period works for us.
86836 */
86837 get_online_cpus();
86838- snap = atomic_long_read(&rsp->expedited_start);
86839+ snap = atomic_long_read_unchecked(&rsp->expedited_start);
86840 smp_mb(); /* ensure read is before try_stop_cpus(). */
86841 }
86842- atomic_long_inc(&rsp->expedited_stoppedcpus);
86843+ atomic_long_inc_unchecked(&rsp->expedited_stoppedcpus);
86844
86845 /*
86846 * Everyone up to our most recent fetch is covered by our grace
86847@@ -2627,16 +2627,16 @@ void synchronize_sched_expedited(void)
86848 * than we did already did their update.
86849 */
86850 do {
86851- atomic_long_inc(&rsp->expedited_done_tries);
86852+ atomic_long_inc_unchecked(&rsp->expedited_done_tries);
86853 s = atomic_long_read(&rsp->expedited_done);
86854 if (ULONG_CMP_GE((ulong)s, (ulong)snap)) {
86855 /* ensure test happens before caller kfree */
86856 smp_mb__before_atomic_inc(); /* ^^^ */
86857- atomic_long_inc(&rsp->expedited_done_lost);
86858+ atomic_long_inc_unchecked(&rsp->expedited_done_lost);
86859 break;
86860 }
86861 } while (atomic_long_cmpxchg(&rsp->expedited_done, s, snap) != s);
86862- atomic_long_inc(&rsp->expedited_done_exit);
86863+ atomic_long_inc_unchecked(&rsp->expedited_done_exit);
86864
86865 put_online_cpus();
86866 }
86867@@ -2829,7 +2829,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
86868 * ACCESS_ONCE() to prevent the compiler from speculating
86869 * the increment to precede the early-exit check.
86870 */
86871- ACCESS_ONCE(rsp->n_barrier_done)++;
86872+ ACCESS_ONCE_RW(rsp->n_barrier_done)++;
86873 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 1);
86874 _rcu_barrier_trace(rsp, "Inc1", -1, rsp->n_barrier_done);
86875 smp_mb(); /* Order ->n_barrier_done increment with below mechanism. */
86876@@ -2879,7 +2879,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
86877
86878 /* Increment ->n_barrier_done to prevent duplicate work. */
86879 smp_mb(); /* Keep increment after above mechanism. */
86880- ACCESS_ONCE(rsp->n_barrier_done)++;
86881+ ACCESS_ONCE_RW(rsp->n_barrier_done)++;
86882 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 0);
86883 _rcu_barrier_trace(rsp, "Inc2", -1, rsp->n_barrier_done);
86884 smp_mb(); /* Keep increment before caller's subsequent code. */
86885@@ -2924,10 +2924,10 @@ rcu_boot_init_percpu_data(int cpu, struct rcu_state *rsp)
86886 rdp->grpmask = 1UL << (cpu - rdp->mynode->grplo);
86887 init_callback_list(rdp);
86888 rdp->qlen_lazy = 0;
86889- ACCESS_ONCE(rdp->qlen) = 0;
86890+ ACCESS_ONCE_RW(rdp->qlen) = 0;
86891 rdp->dynticks = &per_cpu(rcu_dynticks, cpu);
86892 WARN_ON_ONCE(rdp->dynticks->dynticks_nesting != DYNTICK_TASK_EXIT_IDLE);
86893- WARN_ON_ONCE(atomic_read(&rdp->dynticks->dynticks) != 1);
86894+ WARN_ON_ONCE(atomic_read_unchecked(&rdp->dynticks->dynticks) != 1);
86895 rdp->cpu = cpu;
86896 rdp->rsp = rsp;
86897 rcu_boot_init_nocb_percpu_data(rdp);
86898@@ -2961,8 +2961,8 @@ rcu_init_percpu_data(int cpu, struct rcu_state *rsp, int preemptible)
86899 init_callback_list(rdp); /* Re-enable callbacks on this CPU. */
86900 rdp->dynticks->dynticks_nesting = DYNTICK_TASK_EXIT_IDLE;
86901 rcu_sysidle_init_percpu_data(rdp->dynticks);
86902- atomic_set(&rdp->dynticks->dynticks,
86903- (atomic_read(&rdp->dynticks->dynticks) & ~0x1) + 1);
86904+ atomic_set_unchecked(&rdp->dynticks->dynticks,
86905+ (atomic_read_unchecked(&rdp->dynticks->dynticks) & ~0x1) + 1);
86906 raw_spin_unlock(&rnp->lock); /* irqs remain disabled. */
86907
86908 /* Add CPU to rcu_node bitmasks. */
86909diff --git a/kernel/rcutree.h b/kernel/rcutree.h
86910index 5f97eab..db8f687 100644
86911--- a/kernel/rcutree.h
86912+++ b/kernel/rcutree.h
86913@@ -87,11 +87,11 @@ struct rcu_dynticks {
86914 long long dynticks_nesting; /* Track irq/process nesting level. */
86915 /* Process level is worth LLONG_MAX/2. */
86916 int dynticks_nmi_nesting; /* Track NMI nesting level. */
86917- atomic_t dynticks; /* Even value for idle, else odd. */
86918+ atomic_unchecked_t dynticks;/* Even value for idle, else odd. */
86919 #ifdef CONFIG_NO_HZ_FULL_SYSIDLE
86920 long long dynticks_idle_nesting;
86921 /* irq/process nesting level from idle. */
86922- atomic_t dynticks_idle; /* Even value for idle, else odd. */
86923+ atomic_unchecked_t dynticks_idle; /* Even value for idle, else odd. */
86924 /* "Idle" excludes userspace execution. */
86925 unsigned long dynticks_idle_jiffies;
86926 /* End of last non-NMI non-idle period. */
86927@@ -427,17 +427,17 @@ struct rcu_state {
86928 /* _rcu_barrier(). */
86929 /* End of fields guarded by barrier_mutex. */
86930
86931- atomic_long_t expedited_start; /* Starting ticket. */
86932- atomic_long_t expedited_done; /* Done ticket. */
86933- atomic_long_t expedited_wrap; /* # near-wrap incidents. */
86934- atomic_long_t expedited_tryfail; /* # acquisition failures. */
86935- atomic_long_t expedited_workdone1; /* # done by others #1. */
86936- atomic_long_t expedited_workdone2; /* # done by others #2. */
86937- atomic_long_t expedited_normal; /* # fallbacks to normal. */
86938- atomic_long_t expedited_stoppedcpus; /* # successful stop_cpus. */
86939- atomic_long_t expedited_done_tries; /* # tries to update _done. */
86940- atomic_long_t expedited_done_lost; /* # times beaten to _done. */
86941- atomic_long_t expedited_done_exit; /* # times exited _done loop. */
86942+ atomic_long_unchecked_t expedited_start; /* Starting ticket. */
86943+ atomic_long_t expedited_done; /* Done ticket. */
86944+ atomic_long_unchecked_t expedited_wrap; /* # near-wrap incidents. */
86945+ atomic_long_unchecked_t expedited_tryfail; /* # acquisition failures. */
86946+ atomic_long_unchecked_t expedited_workdone1; /* # done by others #1. */
86947+ atomic_long_unchecked_t expedited_workdone2; /* # done by others #2. */
86948+ atomic_long_unchecked_t expedited_normal; /* # fallbacks to normal. */
86949+ atomic_long_unchecked_t expedited_stoppedcpus; /* # successful stop_cpus. */
86950+ atomic_long_unchecked_t expedited_done_tries; /* # tries to update _done. */
86951+ atomic_long_unchecked_t expedited_done_lost; /* # times beaten to _done. */
86952+ atomic_long_unchecked_t expedited_done_exit; /* # times exited _done loop. */
86953
86954 unsigned long jiffies_force_qs; /* Time at which to invoke */
86955 /* force_quiescent_state(). */
86956diff --git a/kernel/rcutree_plugin.h b/kernel/rcutree_plugin.h
86957index 130c97b..bcbe7f7 100644
86958--- a/kernel/rcutree_plugin.h
86959+++ b/kernel/rcutree_plugin.h
86960@@ -744,7 +744,7 @@ static int rcu_preempted_readers_exp(struct rcu_node *rnp)
86961 static int sync_rcu_preempt_exp_done(struct rcu_node *rnp)
86962 {
86963 return !rcu_preempted_readers_exp(rnp) &&
86964- ACCESS_ONCE(rnp->expmask) == 0;
86965+ ACCESS_ONCE_RW(rnp->expmask) == 0;
86966 }
86967
86968 /*
86969@@ -900,7 +900,7 @@ void synchronize_rcu_expedited(void)
86970
86971 /* Clean up and exit. */
86972 smp_mb(); /* ensure expedited GP seen before counter increment. */
86973- ACCESS_ONCE(sync_rcu_preempt_exp_count)++;
86974+ ACCESS_ONCE_RW(sync_rcu_preempt_exp_count)++;
86975 unlock_mb_ret:
86976 mutex_unlock(&sync_rcu_preempt_exp_mutex);
86977 mb_ret:
86978@@ -1474,7 +1474,7 @@ static void rcu_boost_kthread_setaffinity(struct rcu_node *rnp, int outgoingcpu)
86979 free_cpumask_var(cm);
86980 }
86981
86982-static struct smp_hotplug_thread rcu_cpu_thread_spec = {
86983+static struct smp_hotplug_thread rcu_cpu_thread_spec __read_only = {
86984 .store = &rcu_cpu_kthread_task,
86985 .thread_should_run = rcu_cpu_kthread_should_run,
86986 .thread_fn = rcu_cpu_kthread,
86987@@ -1939,7 +1939,7 @@ static void print_cpu_stall_info(struct rcu_state *rsp, int cpu)
86988 print_cpu_stall_fast_no_hz(fast_no_hz, cpu);
86989 pr_err("\t%d: (%lu %s) idle=%03x/%llx/%d softirq=%u/%u %s\n",
86990 cpu, ticks_value, ticks_title,
86991- atomic_read(&rdtp->dynticks) & 0xfff,
86992+ atomic_read_unchecked(&rdtp->dynticks) & 0xfff,
86993 rdtp->dynticks_nesting, rdtp->dynticks_nmi_nesting,
86994 rdp->softirq_snap, kstat_softirqs_cpu(RCU_SOFTIRQ, cpu),
86995 fast_no_hz);
86996@@ -2102,7 +2102,7 @@ static void __call_rcu_nocb_enqueue(struct rcu_data *rdp,
86997
86998 /* Enqueue the callback on the nocb list and update counts. */
86999 old_rhpp = xchg(&rdp->nocb_tail, rhtp);
87000- ACCESS_ONCE(*old_rhpp) = rhp;
87001+ ACCESS_ONCE_RW(*old_rhpp) = rhp;
87002 atomic_long_add(rhcount, &rdp->nocb_q_count);
87003 atomic_long_add(rhcount_lazy, &rdp->nocb_q_count_lazy);
87004
87005@@ -2242,12 +2242,12 @@ static int rcu_nocb_kthread(void *arg)
87006 * Extract queued callbacks, update counts, and wait
87007 * for a grace period to elapse.
87008 */
87009- ACCESS_ONCE(rdp->nocb_head) = NULL;
87010+ ACCESS_ONCE_RW(rdp->nocb_head) = NULL;
87011 tail = xchg(&rdp->nocb_tail, &rdp->nocb_head);
87012 c = atomic_long_xchg(&rdp->nocb_q_count, 0);
87013 cl = atomic_long_xchg(&rdp->nocb_q_count_lazy, 0);
87014- ACCESS_ONCE(rdp->nocb_p_count) += c;
87015- ACCESS_ONCE(rdp->nocb_p_count_lazy) += cl;
87016+ ACCESS_ONCE_RW(rdp->nocb_p_count) += c;
87017+ ACCESS_ONCE_RW(rdp->nocb_p_count_lazy) += cl;
87018 rcu_nocb_wait_gp(rdp);
87019
87020 /* Each pass through the following loop invokes a callback. */
87021@@ -2269,8 +2269,8 @@ static int rcu_nocb_kthread(void *arg)
87022 list = next;
87023 }
87024 trace_rcu_batch_end(rdp->rsp->name, c, !!list, 0, 0, 1);
87025- ACCESS_ONCE(rdp->nocb_p_count) -= c;
87026- ACCESS_ONCE(rdp->nocb_p_count_lazy) -= cl;
87027+ ACCESS_ONCE_RW(rdp->nocb_p_count) -= c;
87028+ ACCESS_ONCE_RW(rdp->nocb_p_count_lazy) -= cl;
87029 rdp->n_nocbs_invoked += c;
87030 }
87031 return 0;
87032@@ -2297,7 +2297,7 @@ static void __init rcu_spawn_nocb_kthreads(struct rcu_state *rsp)
87033 t = kthread_run(rcu_nocb_kthread, rdp,
87034 "rcuo%c/%d", rsp->abbr, cpu);
87035 BUG_ON(IS_ERR(t));
87036- ACCESS_ONCE(rdp->nocb_kthread) = t;
87037+ ACCESS_ONCE_RW(rdp->nocb_kthread) = t;
87038 }
87039 }
87040
87041@@ -2423,11 +2423,11 @@ static void rcu_sysidle_enter(struct rcu_dynticks *rdtp, int irq)
87042
87043 /* Record start of fully idle period. */
87044 j = jiffies;
87045- ACCESS_ONCE(rdtp->dynticks_idle_jiffies) = j;
87046+ ACCESS_ONCE_RW(rdtp->dynticks_idle_jiffies) = j;
87047 smp_mb__before_atomic_inc();
87048- atomic_inc(&rdtp->dynticks_idle);
87049+ atomic_inc_unchecked(&rdtp->dynticks_idle);
87050 smp_mb__after_atomic_inc();
87051- WARN_ON_ONCE(atomic_read(&rdtp->dynticks_idle) & 0x1);
87052+ WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks_idle) & 0x1);
87053 }
87054
87055 /*
87056@@ -2492,9 +2492,9 @@ static void rcu_sysidle_exit(struct rcu_dynticks *rdtp, int irq)
87057
87058 /* Record end of idle period. */
87059 smp_mb__before_atomic_inc();
87060- atomic_inc(&rdtp->dynticks_idle);
87061+ atomic_inc_unchecked(&rdtp->dynticks_idle);
87062 smp_mb__after_atomic_inc();
87063- WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks_idle) & 0x1));
87064+ WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks_idle) & 0x1));
87065
87066 /*
87067 * If we are the timekeeping CPU, we are permitted to be non-idle
87068@@ -2535,7 +2535,7 @@ static void rcu_sysidle_check_cpu(struct rcu_data *rdp, bool *isidle,
87069 WARN_ON_ONCE(smp_processor_id() != tick_do_timer_cpu);
87070
87071 /* Pick up current idle and NMI-nesting counter and check. */
87072- cur = atomic_read(&rdtp->dynticks_idle);
87073+ cur = atomic_read_unchecked(&rdtp->dynticks_idle);
87074 if (cur & 0x1) {
87075 *isidle = false; /* We are not idle! */
87076 return;
87077@@ -2598,7 +2598,7 @@ static void rcu_sysidle(unsigned long j)
87078 case RCU_SYSIDLE_NOT:
87079
87080 /* First time all are idle, so note a short idle period. */
87081- ACCESS_ONCE(full_sysidle_state) = RCU_SYSIDLE_SHORT;
87082+ ACCESS_ONCE_RW(full_sysidle_state) = RCU_SYSIDLE_SHORT;
87083 break;
87084
87085 case RCU_SYSIDLE_SHORT:
87086@@ -2635,7 +2635,7 @@ static void rcu_sysidle(unsigned long j)
87087 static void rcu_sysidle_cancel(void)
87088 {
87089 smp_mb();
87090- ACCESS_ONCE(full_sysidle_state) = RCU_SYSIDLE_NOT;
87091+ ACCESS_ONCE_RW(full_sysidle_state) = RCU_SYSIDLE_NOT;
87092 }
87093
87094 /*
87095@@ -2683,7 +2683,7 @@ static void rcu_sysidle_cb(struct rcu_head *rhp)
87096 smp_mb(); /* grace period precedes setting inuse. */
87097
87098 rshp = container_of(rhp, struct rcu_sysidle_head, rh);
87099- ACCESS_ONCE(rshp->inuse) = 0;
87100+ ACCESS_ONCE_RW(rshp->inuse) = 0;
87101 }
87102
87103 /*
87104diff --git a/kernel/rcutree_trace.c b/kernel/rcutree_trace.c
87105index cf6c174..a8f4b50 100644
87106--- a/kernel/rcutree_trace.c
87107+++ b/kernel/rcutree_trace.c
87108@@ -121,7 +121,7 @@ static void print_one_rcu_data(struct seq_file *m, struct rcu_data *rdp)
87109 ulong2long(rdp->completed), ulong2long(rdp->gpnum),
87110 rdp->passed_quiesce, rdp->qs_pending);
87111 seq_printf(m, " dt=%d/%llx/%d df=%lu",
87112- atomic_read(&rdp->dynticks->dynticks),
87113+ atomic_read_unchecked(&rdp->dynticks->dynticks),
87114 rdp->dynticks->dynticks_nesting,
87115 rdp->dynticks->dynticks_nmi_nesting,
87116 rdp->dynticks_fqs);
87117@@ -182,17 +182,17 @@ static int show_rcuexp(struct seq_file *m, void *v)
87118 struct rcu_state *rsp = (struct rcu_state *)m->private;
87119
87120 seq_printf(m, "s=%lu d=%lu w=%lu tf=%lu wd1=%lu wd2=%lu n=%lu sc=%lu dt=%lu dl=%lu dx=%lu\n",
87121- atomic_long_read(&rsp->expedited_start),
87122+ atomic_long_read_unchecked(&rsp->expedited_start),
87123 atomic_long_read(&rsp->expedited_done),
87124- atomic_long_read(&rsp->expedited_wrap),
87125- atomic_long_read(&rsp->expedited_tryfail),
87126- atomic_long_read(&rsp->expedited_workdone1),
87127- atomic_long_read(&rsp->expedited_workdone2),
87128- atomic_long_read(&rsp->expedited_normal),
87129- atomic_long_read(&rsp->expedited_stoppedcpus),
87130- atomic_long_read(&rsp->expedited_done_tries),
87131- atomic_long_read(&rsp->expedited_done_lost),
87132- atomic_long_read(&rsp->expedited_done_exit));
87133+ atomic_long_read_unchecked(&rsp->expedited_wrap),
87134+ atomic_long_read_unchecked(&rsp->expedited_tryfail),
87135+ atomic_long_read_unchecked(&rsp->expedited_workdone1),
87136+ atomic_long_read_unchecked(&rsp->expedited_workdone2),
87137+ atomic_long_read_unchecked(&rsp->expedited_normal),
87138+ atomic_long_read_unchecked(&rsp->expedited_stoppedcpus),
87139+ atomic_long_read_unchecked(&rsp->expedited_done_tries),
87140+ atomic_long_read_unchecked(&rsp->expedited_done_lost),
87141+ atomic_long_read_unchecked(&rsp->expedited_done_exit));
87142 return 0;
87143 }
87144
87145diff --git a/kernel/resource.c b/kernel/resource.c
87146index 3f285dc..5755f62 100644
87147--- a/kernel/resource.c
87148+++ b/kernel/resource.c
87149@@ -152,8 +152,18 @@ static const struct file_operations proc_iomem_operations = {
87150
87151 static int __init ioresources_init(void)
87152 {
87153+#ifdef CONFIG_GRKERNSEC_PROC_ADD
87154+#ifdef CONFIG_GRKERNSEC_PROC_USER
87155+ proc_create("ioports", S_IRUSR, NULL, &proc_ioports_operations);
87156+ proc_create("iomem", S_IRUSR, NULL, &proc_iomem_operations);
87157+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
87158+ proc_create("ioports", S_IRUSR | S_IRGRP, NULL, &proc_ioports_operations);
87159+ proc_create("iomem", S_IRUSR | S_IRGRP, NULL, &proc_iomem_operations);
87160+#endif
87161+#else
87162 proc_create("ioports", 0, NULL, &proc_ioports_operations);
87163 proc_create("iomem", 0, NULL, &proc_iomem_operations);
87164+#endif
87165 return 0;
87166 }
87167 __initcall(ioresources_init);
87168diff --git a/kernel/rtmutex-tester.c b/kernel/rtmutex-tester.c
87169index 1d96dd0..994ff19 100644
87170--- a/kernel/rtmutex-tester.c
87171+++ b/kernel/rtmutex-tester.c
87172@@ -22,7 +22,7 @@
87173 #define MAX_RT_TEST_MUTEXES 8
87174
87175 static spinlock_t rttest_lock;
87176-static atomic_t rttest_event;
87177+static atomic_unchecked_t rttest_event;
87178
87179 struct test_thread_data {
87180 int opcode;
87181@@ -63,7 +63,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
87182
87183 case RTTEST_LOCKCONT:
87184 td->mutexes[td->opdata] = 1;
87185- td->event = atomic_add_return(1, &rttest_event);
87186+ td->event = atomic_add_return_unchecked(1, &rttest_event);
87187 return 0;
87188
87189 case RTTEST_RESET:
87190@@ -76,7 +76,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
87191 return 0;
87192
87193 case RTTEST_RESETEVENT:
87194- atomic_set(&rttest_event, 0);
87195+ atomic_set_unchecked(&rttest_event, 0);
87196 return 0;
87197
87198 default:
87199@@ -93,9 +93,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
87200 return ret;
87201
87202 td->mutexes[id] = 1;
87203- td->event = atomic_add_return(1, &rttest_event);
87204+ td->event = atomic_add_return_unchecked(1, &rttest_event);
87205 rt_mutex_lock(&mutexes[id]);
87206- td->event = atomic_add_return(1, &rttest_event);
87207+ td->event = atomic_add_return_unchecked(1, &rttest_event);
87208 td->mutexes[id] = 4;
87209 return 0;
87210
87211@@ -106,9 +106,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
87212 return ret;
87213
87214 td->mutexes[id] = 1;
87215- td->event = atomic_add_return(1, &rttest_event);
87216+ td->event = atomic_add_return_unchecked(1, &rttest_event);
87217 ret = rt_mutex_lock_interruptible(&mutexes[id], 0);
87218- td->event = atomic_add_return(1, &rttest_event);
87219+ td->event = atomic_add_return_unchecked(1, &rttest_event);
87220 td->mutexes[id] = ret ? 0 : 4;
87221 return ret ? -EINTR : 0;
87222
87223@@ -117,9 +117,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
87224 if (id < 0 || id >= MAX_RT_TEST_MUTEXES || td->mutexes[id] != 4)
87225 return ret;
87226
87227- td->event = atomic_add_return(1, &rttest_event);
87228+ td->event = atomic_add_return_unchecked(1, &rttest_event);
87229 rt_mutex_unlock(&mutexes[id]);
87230- td->event = atomic_add_return(1, &rttest_event);
87231+ td->event = atomic_add_return_unchecked(1, &rttest_event);
87232 td->mutexes[id] = 0;
87233 return 0;
87234
87235@@ -166,7 +166,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
87236 break;
87237
87238 td->mutexes[dat] = 2;
87239- td->event = atomic_add_return(1, &rttest_event);
87240+ td->event = atomic_add_return_unchecked(1, &rttest_event);
87241 break;
87242
87243 default:
87244@@ -186,7 +186,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
87245 return;
87246
87247 td->mutexes[dat] = 3;
87248- td->event = atomic_add_return(1, &rttest_event);
87249+ td->event = atomic_add_return_unchecked(1, &rttest_event);
87250 break;
87251
87252 case RTTEST_LOCKNOWAIT:
87253@@ -198,7 +198,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
87254 return;
87255
87256 td->mutexes[dat] = 1;
87257- td->event = atomic_add_return(1, &rttest_event);
87258+ td->event = atomic_add_return_unchecked(1, &rttest_event);
87259 return;
87260
87261 default:
87262diff --git a/kernel/sched/auto_group.c b/kernel/sched/auto_group.c
87263index 4a07353..66b5291 100644
87264--- a/kernel/sched/auto_group.c
87265+++ b/kernel/sched/auto_group.c
87266@@ -11,7 +11,7 @@
87267
87268 unsigned int __read_mostly sysctl_sched_autogroup_enabled = 1;
87269 static struct autogroup autogroup_default;
87270-static atomic_t autogroup_seq_nr;
87271+static atomic_unchecked_t autogroup_seq_nr;
87272
87273 void __init autogroup_init(struct task_struct *init_task)
87274 {
87275@@ -79,7 +79,7 @@ static inline struct autogroup *autogroup_create(void)
87276
87277 kref_init(&ag->kref);
87278 init_rwsem(&ag->lock);
87279- ag->id = atomic_inc_return(&autogroup_seq_nr);
87280+ ag->id = atomic_inc_return_unchecked(&autogroup_seq_nr);
87281 ag->tg = tg;
87282 #ifdef CONFIG_RT_GROUP_SCHED
87283 /*
87284diff --git a/kernel/sched/core.c b/kernel/sched/core.c
87285index ceae65e..3ac1344 100644
87286--- a/kernel/sched/core.c
87287+++ b/kernel/sched/core.c
87288@@ -2868,7 +2868,7 @@ EXPORT_SYMBOL(wait_for_completion_interruptible);
87289 * Return: -ERESTARTSYS if interrupted, 0 if timed out, positive (at least 1,
87290 * or number of jiffies left till timeout) if completed.
87291 */
87292-long __sched
87293+long __sched __intentional_overflow(-1)
87294 wait_for_completion_interruptible_timeout(struct completion *x,
87295 unsigned long timeout)
87296 {
87297@@ -2885,7 +2885,7 @@ EXPORT_SYMBOL(wait_for_completion_interruptible_timeout);
87298 *
87299 * Return: -ERESTARTSYS if interrupted, 0 if completed.
87300 */
87301-int __sched wait_for_completion_killable(struct completion *x)
87302+int __sched __intentional_overflow(-1) wait_for_completion_killable(struct completion *x)
87303 {
87304 long t = wait_for_common(x, MAX_SCHEDULE_TIMEOUT, TASK_KILLABLE);
87305 if (t == -ERESTARTSYS)
87306@@ -2906,7 +2906,7 @@ EXPORT_SYMBOL(wait_for_completion_killable);
87307 * Return: -ERESTARTSYS if interrupted, 0 if timed out, positive (at least 1,
87308 * or number of jiffies left till timeout) if completed.
87309 */
87310-long __sched
87311+long __sched __intentional_overflow(-1)
87312 wait_for_completion_killable_timeout(struct completion *x,
87313 unsigned long timeout)
87314 {
87315@@ -3132,6 +3132,8 @@ int can_nice(const struct task_struct *p, const int nice)
87316 /* convert nice value [19,-20] to rlimit style value [1,40] */
87317 int nice_rlim = 20 - nice;
87318
87319+ gr_learn_resource(p, RLIMIT_NICE, nice_rlim, 1);
87320+
87321 return (nice_rlim <= task_rlimit(p, RLIMIT_NICE) ||
87322 capable(CAP_SYS_NICE));
87323 }
87324@@ -3165,7 +3167,8 @@ SYSCALL_DEFINE1(nice, int, increment)
87325 if (nice > 19)
87326 nice = 19;
87327
87328- if (increment < 0 && !can_nice(current, nice))
87329+ if (increment < 0 && (!can_nice(current, nice) ||
87330+ gr_handle_chroot_nice()))
87331 return -EPERM;
87332
87333 retval = security_task_setnice(current, nice);
87334@@ -3327,6 +3330,7 @@ recheck:
87335 unsigned long rlim_rtprio =
87336 task_rlimit(p, RLIMIT_RTPRIO);
87337
87338+ gr_learn_resource(p, RLIMIT_RTPRIO, param->sched_priority, 1);
87339 /* can't set/change the rt policy */
87340 if (policy != p->policy && !rlim_rtprio)
87341 return -EPERM;
87342@@ -4456,7 +4460,7 @@ static void migrate_tasks(unsigned int dead_cpu)
87343
87344 #if defined(CONFIG_SCHED_DEBUG) && defined(CONFIG_SYSCTL)
87345
87346-static struct ctl_table sd_ctl_dir[] = {
87347+static ctl_table_no_const sd_ctl_dir[] __read_only = {
87348 {
87349 .procname = "sched_domain",
87350 .mode = 0555,
87351@@ -4473,17 +4477,17 @@ static struct ctl_table sd_ctl_root[] = {
87352 {}
87353 };
87354
87355-static struct ctl_table *sd_alloc_ctl_entry(int n)
87356+static ctl_table_no_const *sd_alloc_ctl_entry(int n)
87357 {
87358- struct ctl_table *entry =
87359+ ctl_table_no_const *entry =
87360 kcalloc(n, sizeof(struct ctl_table), GFP_KERNEL);
87361
87362 return entry;
87363 }
87364
87365-static void sd_free_ctl_entry(struct ctl_table **tablep)
87366+static void sd_free_ctl_entry(ctl_table_no_const *tablep)
87367 {
87368- struct ctl_table *entry;
87369+ ctl_table_no_const *entry;
87370
87371 /*
87372 * In the intermediate directories, both the child directory and
87373@@ -4491,22 +4495,25 @@ static void sd_free_ctl_entry(struct ctl_table **tablep)
87374 * will always be set. In the lowest directory the names are
87375 * static strings and all have proc handlers.
87376 */
87377- for (entry = *tablep; entry->mode; entry++) {
87378- if (entry->child)
87379- sd_free_ctl_entry(&entry->child);
87380+ for (entry = tablep; entry->mode; entry++) {
87381+ if (entry->child) {
87382+ sd_free_ctl_entry(entry->child);
87383+ pax_open_kernel();
87384+ entry->child = NULL;
87385+ pax_close_kernel();
87386+ }
87387 if (entry->proc_handler == NULL)
87388 kfree(entry->procname);
87389 }
87390
87391- kfree(*tablep);
87392- *tablep = NULL;
87393+ kfree(tablep);
87394 }
87395
87396 static int min_load_idx = 0;
87397 static int max_load_idx = CPU_LOAD_IDX_MAX-1;
87398
87399 static void
87400-set_table_entry(struct ctl_table *entry,
87401+set_table_entry(ctl_table_no_const *entry,
87402 const char *procname, void *data, int maxlen,
87403 umode_t mode, proc_handler *proc_handler,
87404 bool load_idx)
87405@@ -4526,7 +4533,7 @@ set_table_entry(struct ctl_table *entry,
87406 static struct ctl_table *
87407 sd_alloc_ctl_domain_table(struct sched_domain *sd)
87408 {
87409- struct ctl_table *table = sd_alloc_ctl_entry(13);
87410+ ctl_table_no_const *table = sd_alloc_ctl_entry(13);
87411
87412 if (table == NULL)
87413 return NULL;
87414@@ -4561,9 +4568,9 @@ sd_alloc_ctl_domain_table(struct sched_domain *sd)
87415 return table;
87416 }
87417
87418-static struct ctl_table *sd_alloc_ctl_cpu_table(int cpu)
87419+static ctl_table_no_const *sd_alloc_ctl_cpu_table(int cpu)
87420 {
87421- struct ctl_table *entry, *table;
87422+ ctl_table_no_const *entry, *table;
87423 struct sched_domain *sd;
87424 int domain_num = 0, i;
87425 char buf[32];
87426@@ -4590,11 +4597,13 @@ static struct ctl_table_header *sd_sysctl_header;
87427 static void register_sched_domain_sysctl(void)
87428 {
87429 int i, cpu_num = num_possible_cpus();
87430- struct ctl_table *entry = sd_alloc_ctl_entry(cpu_num + 1);
87431+ ctl_table_no_const *entry = sd_alloc_ctl_entry(cpu_num + 1);
87432 char buf[32];
87433
87434 WARN_ON(sd_ctl_dir[0].child);
87435+ pax_open_kernel();
87436 sd_ctl_dir[0].child = entry;
87437+ pax_close_kernel();
87438
87439 if (entry == NULL)
87440 return;
87441@@ -4617,8 +4626,12 @@ static void unregister_sched_domain_sysctl(void)
87442 if (sd_sysctl_header)
87443 unregister_sysctl_table(sd_sysctl_header);
87444 sd_sysctl_header = NULL;
87445- if (sd_ctl_dir[0].child)
87446- sd_free_ctl_entry(&sd_ctl_dir[0].child);
87447+ if (sd_ctl_dir[0].child) {
87448+ sd_free_ctl_entry(sd_ctl_dir[0].child);
87449+ pax_open_kernel();
87450+ sd_ctl_dir[0].child = NULL;
87451+ pax_close_kernel();
87452+ }
87453 }
87454 #else
87455 static void register_sched_domain_sysctl(void)
87456diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
87457index 4117323..91c91ac 100644
87458--- a/kernel/sched/fair.c
87459+++ b/kernel/sched/fair.c
87460@@ -869,7 +869,7 @@ void task_numa_fault(int node, int pages, bool migrated)
87461
87462 static void reset_ptenuma_scan(struct task_struct *p)
87463 {
87464- ACCESS_ONCE(p->mm->numa_scan_seq)++;
87465+ ACCESS_ONCE_RW(p->mm->numa_scan_seq)++;
87466 p->mm->numa_scan_offset = 0;
87467 }
87468
87469@@ -5864,7 +5864,7 @@ static void nohz_idle_balance(int this_cpu, enum cpu_idle_type idle) { }
87470 * run_rebalance_domains is triggered when needed from the scheduler tick.
87471 * Also triggered for nohz idle balancing (with nohz_balancing_kick set).
87472 */
87473-static void run_rebalance_domains(struct softirq_action *h)
87474+static __latent_entropy void run_rebalance_domains(void)
87475 {
87476 int this_cpu = smp_processor_id();
87477 struct rq *this_rq = cpu_rq(this_cpu);
87478diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h
87479index a6208af..a2d7bb5 100644
87480--- a/kernel/sched/sched.h
87481+++ b/kernel/sched/sched.h
87482@@ -1004,7 +1004,7 @@ struct sched_class {
87483 #ifdef CONFIG_FAIR_GROUP_SCHED
87484 void (*task_move_group) (struct task_struct *p, int on_rq);
87485 #endif
87486-};
87487+} __do_const;
87488
87489 #define sched_class_highest (&stop_sched_class)
87490 #define for_each_class(class) \
87491diff --git a/kernel/signal.c b/kernel/signal.c
87492index ded28b9..6886c08 100644
87493--- a/kernel/signal.c
87494+++ b/kernel/signal.c
87495@@ -51,12 +51,12 @@ static struct kmem_cache *sigqueue_cachep;
87496
87497 int print_fatal_signals __read_mostly;
87498
87499-static void __user *sig_handler(struct task_struct *t, int sig)
87500+static __sighandler_t sig_handler(struct task_struct *t, int sig)
87501 {
87502 return t->sighand->action[sig - 1].sa.sa_handler;
87503 }
87504
87505-static int sig_handler_ignored(void __user *handler, int sig)
87506+static int sig_handler_ignored(__sighandler_t handler, int sig)
87507 {
87508 /* Is it explicitly or implicitly ignored? */
87509 return handler == SIG_IGN ||
87510@@ -65,7 +65,7 @@ static int sig_handler_ignored(void __user *handler, int sig)
87511
87512 static int sig_task_ignored(struct task_struct *t, int sig, bool force)
87513 {
87514- void __user *handler;
87515+ __sighandler_t handler;
87516
87517 handler = sig_handler(t, sig);
87518
87519@@ -369,6 +369,9 @@ __sigqueue_alloc(int sig, struct task_struct *t, gfp_t flags, int override_rlimi
87520 atomic_inc(&user->sigpending);
87521 rcu_read_unlock();
87522
87523+ if (!override_rlimit)
87524+ gr_learn_resource(t, RLIMIT_SIGPENDING, atomic_read(&user->sigpending), 1);
87525+
87526 if (override_rlimit ||
87527 atomic_read(&user->sigpending) <=
87528 task_rlimit(t, RLIMIT_SIGPENDING)) {
87529@@ -496,7 +499,7 @@ flush_signal_handlers(struct task_struct *t, int force_default)
87530
87531 int unhandled_signal(struct task_struct *tsk, int sig)
87532 {
87533- void __user *handler = tsk->sighand->action[sig-1].sa.sa_handler;
87534+ __sighandler_t handler = tsk->sighand->action[sig-1].sa.sa_handler;
87535 if (is_global_init(tsk))
87536 return 1;
87537 if (handler != SIG_IGN && handler != SIG_DFL)
87538@@ -816,6 +819,13 @@ static int check_kill_permission(int sig, struct siginfo *info,
87539 }
87540 }
87541
87542+ /* allow glibc communication via tgkill to other threads in our
87543+ thread group */
87544+ if ((info == SEND_SIG_NOINFO || info->si_code != SI_TKILL ||
87545+ sig != (SIGRTMIN+1) || task_tgid_vnr(t) != info->si_pid)
87546+ && gr_handle_signal(t, sig))
87547+ return -EPERM;
87548+
87549 return security_task_kill(t, info, sig, 0);
87550 }
87551
87552@@ -1199,7 +1209,7 @@ __group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
87553 return send_signal(sig, info, p, 1);
87554 }
87555
87556-static int
87557+int
87558 specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t)
87559 {
87560 return send_signal(sig, info, t, 0);
87561@@ -1236,6 +1246,7 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
87562 unsigned long int flags;
87563 int ret, blocked, ignored;
87564 struct k_sigaction *action;
87565+ int is_unhandled = 0;
87566
87567 spin_lock_irqsave(&t->sighand->siglock, flags);
87568 action = &t->sighand->action[sig-1];
87569@@ -1250,9 +1261,18 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
87570 }
87571 if (action->sa.sa_handler == SIG_DFL)
87572 t->signal->flags &= ~SIGNAL_UNKILLABLE;
87573+ if (action->sa.sa_handler == SIG_IGN || action->sa.sa_handler == SIG_DFL)
87574+ is_unhandled = 1;
87575 ret = specific_send_sig_info(sig, info, t);
87576 spin_unlock_irqrestore(&t->sighand->siglock, flags);
87577
87578+ /* only deal with unhandled signals, java etc trigger SIGSEGV during
87579+ normal operation */
87580+ if (is_unhandled) {
87581+ gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, t);
87582+ gr_handle_crash(t, sig);
87583+ }
87584+
87585 return ret;
87586 }
87587
87588@@ -1319,8 +1339,11 @@ int group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
87589 ret = check_kill_permission(sig, info, p);
87590 rcu_read_unlock();
87591
87592- if (!ret && sig)
87593+ if (!ret && sig) {
87594 ret = do_send_sig_info(sig, info, p, true);
87595+ if (!ret)
87596+ gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, p);
87597+ }
87598
87599 return ret;
87600 }
87601@@ -2926,7 +2949,15 @@ do_send_specific(pid_t tgid, pid_t pid, int sig, struct siginfo *info)
87602 int error = -ESRCH;
87603
87604 rcu_read_lock();
87605- p = find_task_by_vpid(pid);
87606+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
87607+ /* allow glibc communication via tgkill to other threads in our
87608+ thread group */
87609+ if (grsec_enable_chroot_findtask && info->si_code == SI_TKILL &&
87610+ sig == (SIGRTMIN+1) && tgid == info->si_pid)
87611+ p = find_task_by_vpid_unrestricted(pid);
87612+ else
87613+#endif
87614+ p = find_task_by_vpid(pid);
87615 if (p && (tgid <= 0 || task_tgid_vnr(p) == tgid)) {
87616 error = check_kill_permission(sig, info, p);
87617 /*
87618@@ -3240,8 +3271,8 @@ COMPAT_SYSCALL_DEFINE2(sigaltstack,
87619 }
87620 seg = get_fs();
87621 set_fs(KERNEL_DS);
87622- ret = do_sigaltstack((stack_t __force __user *) (uss_ptr ? &uss : NULL),
87623- (stack_t __force __user *) &uoss,
87624+ ret = do_sigaltstack((stack_t __force_user *) (uss_ptr ? &uss : NULL),
87625+ (stack_t __force_user *) &uoss,
87626 compat_user_stack_pointer());
87627 set_fs(seg);
87628 if (ret >= 0 && uoss_ptr) {
87629diff --git a/kernel/smpboot.c b/kernel/smpboot.c
87630index eb89e18..a4e6792 100644
87631--- a/kernel/smpboot.c
87632+++ b/kernel/smpboot.c
87633@@ -288,7 +288,7 @@ int smpboot_register_percpu_thread(struct smp_hotplug_thread *plug_thread)
87634 }
87635 smpboot_unpark_thread(plug_thread, cpu);
87636 }
87637- list_add(&plug_thread->list, &hotplug_threads);
87638+ pax_list_add(&plug_thread->list, &hotplug_threads);
87639 out:
87640 mutex_unlock(&smpboot_threads_lock);
87641 return ret;
87642@@ -305,7 +305,7 @@ void smpboot_unregister_percpu_thread(struct smp_hotplug_thread *plug_thread)
87643 {
87644 get_online_cpus();
87645 mutex_lock(&smpboot_threads_lock);
87646- list_del(&plug_thread->list);
87647+ pax_list_del(&plug_thread->list);
87648 smpboot_destroy_threads(plug_thread);
87649 mutex_unlock(&smpboot_threads_lock);
87650 put_online_cpus();
87651diff --git a/kernel/softirq.c b/kernel/softirq.c
87652index d7d498d..94fe0f7 100644
87653--- a/kernel/softirq.c
87654+++ b/kernel/softirq.c
87655@@ -53,11 +53,11 @@ irq_cpustat_t irq_stat[NR_CPUS] ____cacheline_aligned;
87656 EXPORT_SYMBOL(irq_stat);
87657 #endif
87658
87659-static struct softirq_action softirq_vec[NR_SOFTIRQS] __cacheline_aligned_in_smp;
87660+static struct softirq_action softirq_vec[NR_SOFTIRQS] __read_only __aligned(PAGE_SIZE);
87661
87662 DEFINE_PER_CPU(struct task_struct *, ksoftirqd);
87663
87664-char *softirq_to_name[NR_SOFTIRQS] = {
87665+const char * const softirq_to_name[NR_SOFTIRQS] = {
87666 "HI", "TIMER", "NET_TX", "NET_RX", "BLOCK", "BLOCK_IOPOLL",
87667 "TASKLET", "SCHED", "HRTIMER", "RCU"
87668 };
87669@@ -248,7 +248,7 @@ restart:
87670 kstat_incr_softirqs_this_cpu(vec_nr);
87671
87672 trace_softirq_entry(vec_nr);
87673- h->action(h);
87674+ h->action();
87675 trace_softirq_exit(vec_nr);
87676 if (unlikely(prev_count != preempt_count())) {
87677 printk(KERN_ERR "huh, entered softirq %u %s %p"
87678@@ -412,7 +412,7 @@ void __raise_softirq_irqoff(unsigned int nr)
87679 or_softirq_pending(1UL << nr);
87680 }
87681
87682-void open_softirq(int nr, void (*action)(struct softirq_action *))
87683+void __init open_softirq(int nr, void (*action)(void))
87684 {
87685 softirq_vec[nr].action = action;
87686 }
87687@@ -468,7 +468,7 @@ void __tasklet_hi_schedule_first(struct tasklet_struct *t)
87688
87689 EXPORT_SYMBOL(__tasklet_hi_schedule_first);
87690
87691-static void tasklet_action(struct softirq_action *a)
87692+static __latent_entropy void tasklet_action(void)
87693 {
87694 struct tasklet_struct *list;
87695
87696@@ -503,7 +503,7 @@ static void tasklet_action(struct softirq_action *a)
87697 }
87698 }
87699
87700-static void tasklet_hi_action(struct softirq_action *a)
87701+static __latent_entropy void tasklet_hi_action(void)
87702 {
87703 struct tasklet_struct *list;
87704
87705@@ -858,7 +858,7 @@ static struct notifier_block cpu_nfb = {
87706 .notifier_call = cpu_callback
87707 };
87708
87709-static struct smp_hotplug_thread softirq_threads = {
87710+static struct smp_hotplug_thread softirq_threads __read_only = {
87711 .store = &ksoftirqd,
87712 .thread_should_run = ksoftirqd_should_run,
87713 .thread_fn = run_ksoftirqd,
87714diff --git a/kernel/srcu.c b/kernel/srcu.c
87715index 01d5ccb..cdcbee6 100644
87716--- a/kernel/srcu.c
87717+++ b/kernel/srcu.c
87718@@ -300,9 +300,9 @@ int __srcu_read_lock(struct srcu_struct *sp)
87719
87720 idx = ACCESS_ONCE(sp->completed) & 0x1;
87721 preempt_disable();
87722- ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) += 1;
87723+ ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) += 1;
87724 smp_mb(); /* B */ /* Avoid leaking the critical section. */
87725- ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->seq[idx]) += 1;
87726+ ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->seq[idx]) += 1;
87727 preempt_enable();
87728 return idx;
87729 }
87730diff --git a/kernel/sys.c b/kernel/sys.c
87731index c18ecca..b3c2dd2 100644
87732--- a/kernel/sys.c
87733+++ b/kernel/sys.c
87734@@ -149,6 +149,12 @@ static int set_one_prio(struct task_struct *p, int niceval, int error)
87735 error = -EACCES;
87736 goto out;
87737 }
87738+
87739+ if (gr_handle_chroot_setpriority(p, niceval)) {
87740+ error = -EACCES;
87741+ goto out;
87742+ }
87743+
87744 no_nice = security_task_setnice(p, niceval);
87745 if (no_nice) {
87746 error = no_nice;
87747@@ -352,6 +358,9 @@ SYSCALL_DEFINE2(setregid, gid_t, rgid, gid_t, egid)
87748 goto error;
87749 }
87750
87751+ if (gr_check_group_change(new->gid, new->egid, INVALID_GID))
87752+ goto error;
87753+
87754 if (rgid != (gid_t) -1 ||
87755 (egid != (gid_t) -1 && !gid_eq(kegid, old->gid)))
87756 new->sgid = new->egid;
87757@@ -387,6 +396,10 @@ SYSCALL_DEFINE1(setgid, gid_t, gid)
87758 old = current_cred();
87759
87760 retval = -EPERM;
87761+
87762+ if (gr_check_group_change(kgid, kgid, kgid))
87763+ goto error;
87764+
87765 if (ns_capable(old->user_ns, CAP_SETGID))
87766 new->gid = new->egid = new->sgid = new->fsgid = kgid;
87767 else if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->sgid))
87768@@ -404,7 +417,7 @@ error:
87769 /*
87770 * change the user struct in a credentials set to match the new UID
87771 */
87772-static int set_user(struct cred *new)
87773+int set_user(struct cred *new)
87774 {
87775 struct user_struct *new_user;
87776
87777@@ -484,6 +497,9 @@ SYSCALL_DEFINE2(setreuid, uid_t, ruid, uid_t, euid)
87778 goto error;
87779 }
87780
87781+ if (gr_check_user_change(new->uid, new->euid, INVALID_UID))
87782+ goto error;
87783+
87784 if (!uid_eq(new->uid, old->uid)) {
87785 retval = set_user(new);
87786 if (retval < 0)
87787@@ -534,6 +550,12 @@ SYSCALL_DEFINE1(setuid, uid_t, uid)
87788 old = current_cred();
87789
87790 retval = -EPERM;
87791+
87792+ if (gr_check_crash_uid(kuid))
87793+ goto error;
87794+ if (gr_check_user_change(kuid, kuid, kuid))
87795+ goto error;
87796+
87797 if (ns_capable(old->user_ns, CAP_SETUID)) {
87798 new->suid = new->uid = kuid;
87799 if (!uid_eq(kuid, old->uid)) {
87800@@ -603,6 +625,9 @@ SYSCALL_DEFINE3(setresuid, uid_t, ruid, uid_t, euid, uid_t, suid)
87801 goto error;
87802 }
87803
87804+ if (gr_check_user_change(kruid, keuid, INVALID_UID))
87805+ goto error;
87806+
87807 if (ruid != (uid_t) -1) {
87808 new->uid = kruid;
87809 if (!uid_eq(kruid, old->uid)) {
87810@@ -685,6 +710,9 @@ SYSCALL_DEFINE3(setresgid, gid_t, rgid, gid_t, egid, gid_t, sgid)
87811 goto error;
87812 }
87813
87814+ if (gr_check_group_change(krgid, kegid, INVALID_GID))
87815+ goto error;
87816+
87817 if (rgid != (gid_t) -1)
87818 new->gid = krgid;
87819 if (egid != (gid_t) -1)
87820@@ -746,12 +774,16 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
87821 uid_eq(kuid, old->suid) || uid_eq(kuid, old->fsuid) ||
87822 ns_capable(old->user_ns, CAP_SETUID)) {
87823 if (!uid_eq(kuid, old->fsuid)) {
87824+ if (gr_check_user_change(INVALID_UID, INVALID_UID, kuid))
87825+ goto error;
87826+
87827 new->fsuid = kuid;
87828 if (security_task_fix_setuid(new, old, LSM_SETID_FS) == 0)
87829 goto change_okay;
87830 }
87831 }
87832
87833+error:
87834 abort_creds(new);
87835 return old_fsuid;
87836
87837@@ -784,12 +816,16 @@ SYSCALL_DEFINE1(setfsgid, gid_t, gid)
87838 if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->egid) ||
87839 gid_eq(kgid, old->sgid) || gid_eq(kgid, old->fsgid) ||
87840 ns_capable(old->user_ns, CAP_SETGID)) {
87841+ if (gr_check_group_change(INVALID_GID, INVALID_GID, kgid))
87842+ goto error;
87843+
87844 if (!gid_eq(kgid, old->fsgid)) {
87845 new->fsgid = kgid;
87846 goto change_okay;
87847 }
87848 }
87849
87850+error:
87851 abort_creds(new);
87852 return old_fsgid;
87853
87854@@ -1169,19 +1205,19 @@ SYSCALL_DEFINE1(olduname, struct oldold_utsname __user *, name)
87855 return -EFAULT;
87856
87857 down_read(&uts_sem);
87858- error = __copy_to_user(&name->sysname, &utsname()->sysname,
87859+ error = __copy_to_user(name->sysname, &utsname()->sysname,
87860 __OLD_UTS_LEN);
87861 error |= __put_user(0, name->sysname + __OLD_UTS_LEN);
87862- error |= __copy_to_user(&name->nodename, &utsname()->nodename,
87863+ error |= __copy_to_user(name->nodename, &utsname()->nodename,
87864 __OLD_UTS_LEN);
87865 error |= __put_user(0, name->nodename + __OLD_UTS_LEN);
87866- error |= __copy_to_user(&name->release, &utsname()->release,
87867+ error |= __copy_to_user(name->release, &utsname()->release,
87868 __OLD_UTS_LEN);
87869 error |= __put_user(0, name->release + __OLD_UTS_LEN);
87870- error |= __copy_to_user(&name->version, &utsname()->version,
87871+ error |= __copy_to_user(name->version, &utsname()->version,
87872 __OLD_UTS_LEN);
87873 error |= __put_user(0, name->version + __OLD_UTS_LEN);
87874- error |= __copy_to_user(&name->machine, &utsname()->machine,
87875+ error |= __copy_to_user(name->machine, &utsname()->machine,
87876 __OLD_UTS_LEN);
87877 error |= __put_user(0, name->machine + __OLD_UTS_LEN);
87878 up_read(&uts_sem);
87879@@ -1383,6 +1419,13 @@ int do_prlimit(struct task_struct *tsk, unsigned int resource,
87880 */
87881 new_rlim->rlim_cur = 1;
87882 }
87883+ /* Handle the case where a fork and setuid occur and then RLIMIT_NPROC
87884+ is changed to a lower value. Since tasks can be created by the same
87885+ user in between this limit change and an execve by this task, force
87886+ a recheck only for this task by setting PF_NPROC_EXCEEDED
87887+ */
87888+ if (resource == RLIMIT_NPROC && tsk->real_cred->user != INIT_USER)
87889+ tsk->flags |= PF_NPROC_EXCEEDED;
87890 }
87891 if (!retval) {
87892 if (old_rlim)
87893diff --git a/kernel/sysctl.c b/kernel/sysctl.c
87894index b2f06f3..e6354ab 100644
87895--- a/kernel/sysctl.c
87896+++ b/kernel/sysctl.c
87897@@ -93,7 +93,6 @@
87898
87899
87900 #if defined(CONFIG_SYSCTL)
87901-
87902 /* External variables not in a header file. */
87903 extern int sysctl_overcommit_memory;
87904 extern int sysctl_overcommit_ratio;
87905@@ -119,17 +118,18 @@ extern int blk_iopoll_enabled;
87906
87907 /* Constants used for minimum and maximum */
87908 #ifdef CONFIG_LOCKUP_DETECTOR
87909-static int sixty = 60;
87910+static int sixty __read_only = 60;
87911 #endif
87912
87913-static int zero;
87914-static int __maybe_unused one = 1;
87915-static int __maybe_unused two = 2;
87916-static int __maybe_unused three = 3;
87917-static unsigned long one_ul = 1;
87918-static int one_hundred = 100;
87919+static int neg_one __read_only = -1;
87920+static int zero __read_only = 0;
87921+static int __maybe_unused one __read_only = 1;
87922+static int __maybe_unused two __read_only = 2;
87923+static int __maybe_unused three __read_only = 3;
87924+static unsigned long one_ul __read_only = 1;
87925+static int one_hundred __read_only = 100;
87926 #ifdef CONFIG_PRINTK
87927-static int ten_thousand = 10000;
87928+static int ten_thousand __read_only = 10000;
87929 #endif
87930
87931 /* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
87932@@ -176,10 +176,8 @@ static int proc_taint(struct ctl_table *table, int write,
87933 void __user *buffer, size_t *lenp, loff_t *ppos);
87934 #endif
87935
87936-#ifdef CONFIG_PRINTK
87937 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
87938 void __user *buffer, size_t *lenp, loff_t *ppos);
87939-#endif
87940
87941 static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
87942 void __user *buffer, size_t *lenp, loff_t *ppos);
87943@@ -210,6 +208,8 @@ static int sysrq_sysctl_handler(ctl_table *table, int write,
87944
87945 #endif
87946
87947+extern struct ctl_table grsecurity_table[];
87948+
87949 static struct ctl_table kern_table[];
87950 static struct ctl_table vm_table[];
87951 static struct ctl_table fs_table[];
87952@@ -224,6 +224,20 @@ extern struct ctl_table epoll_table[];
87953 int sysctl_legacy_va_layout;
87954 #endif
87955
87956+#ifdef CONFIG_PAX_SOFTMODE
87957+static ctl_table pax_table[] = {
87958+ {
87959+ .procname = "softmode",
87960+ .data = &pax_softmode,
87961+ .maxlen = sizeof(unsigned int),
87962+ .mode = 0600,
87963+ .proc_handler = &proc_dointvec,
87964+ },
87965+
87966+ { }
87967+};
87968+#endif
87969+
87970 /* The default sysctl tables: */
87971
87972 static struct ctl_table sysctl_base_table[] = {
87973@@ -272,6 +286,22 @@ static int max_extfrag_threshold = 1000;
87974 #endif
87975
87976 static struct ctl_table kern_table[] = {
87977+#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
87978+ {
87979+ .procname = "grsecurity",
87980+ .mode = 0500,
87981+ .child = grsecurity_table,
87982+ },
87983+#endif
87984+
87985+#ifdef CONFIG_PAX_SOFTMODE
87986+ {
87987+ .procname = "pax",
87988+ .mode = 0500,
87989+ .child = pax_table,
87990+ },
87991+#endif
87992+
87993 {
87994 .procname = "sched_child_runs_first",
87995 .data = &sysctl_sched_child_runs_first,
87996@@ -613,7 +643,7 @@ static struct ctl_table kern_table[] = {
87997 .data = &modprobe_path,
87998 .maxlen = KMOD_PATH_LEN,
87999 .mode = 0644,
88000- .proc_handler = proc_dostring,
88001+ .proc_handler = proc_dostring_modpriv,
88002 },
88003 {
88004 .procname = "modules_disabled",
88005@@ -780,16 +810,20 @@ static struct ctl_table kern_table[] = {
88006 .extra1 = &zero,
88007 .extra2 = &one,
88008 },
88009+#endif
88010 {
88011 .procname = "kptr_restrict",
88012 .data = &kptr_restrict,
88013 .maxlen = sizeof(int),
88014 .mode = 0644,
88015 .proc_handler = proc_dointvec_minmax_sysadmin,
88016+#ifdef CONFIG_GRKERNSEC_HIDESYM
88017+ .extra1 = &two,
88018+#else
88019 .extra1 = &zero,
88020+#endif
88021 .extra2 = &two,
88022 },
88023-#endif
88024 {
88025 .procname = "ngroups_max",
88026 .data = &ngroups_max,
88027@@ -1031,10 +1065,17 @@ static struct ctl_table kern_table[] = {
88028 */
88029 {
88030 .procname = "perf_event_paranoid",
88031- .data = &sysctl_perf_event_paranoid,
88032- .maxlen = sizeof(sysctl_perf_event_paranoid),
88033+ .data = &sysctl_perf_event_legitimately_concerned,
88034+ .maxlen = sizeof(sysctl_perf_event_legitimately_concerned),
88035 .mode = 0644,
88036- .proc_handler = proc_dointvec,
88037+ /* go ahead, be a hero */
88038+ .proc_handler = proc_dointvec_minmax_sysadmin,
88039+ .extra1 = &neg_one,
88040+#ifdef CONFIG_GRKERNSEC_PERF_HARDEN
88041+ .extra2 = &three,
88042+#else
88043+ .extra2 = &two,
88044+#endif
88045 },
88046 {
88047 .procname = "perf_event_mlock_kb",
88048@@ -1297,6 +1338,13 @@ static struct ctl_table vm_table[] = {
88049 .proc_handler = proc_dointvec_minmax,
88050 .extra1 = &zero,
88051 },
88052+ {
88053+ .procname = "heap_stack_gap",
88054+ .data = &sysctl_heap_stack_gap,
88055+ .maxlen = sizeof(sysctl_heap_stack_gap),
88056+ .mode = 0644,
88057+ .proc_handler = proc_doulongvec_minmax,
88058+ },
88059 #else
88060 {
88061 .procname = "nr_trim_pages",
88062@@ -1761,6 +1809,16 @@ int proc_dostring(struct ctl_table *table, int write,
88063 buffer, lenp, ppos);
88064 }
88065
88066+int proc_dostring_modpriv(struct ctl_table *table, int write,
88067+ void __user *buffer, size_t *lenp, loff_t *ppos)
88068+{
88069+ if (write && !capable(CAP_SYS_MODULE))
88070+ return -EPERM;
88071+
88072+ return _proc_do_string(table->data, table->maxlen, write,
88073+ buffer, lenp, ppos);
88074+}
88075+
88076 static size_t proc_skip_spaces(char **buf)
88077 {
88078 size_t ret;
88079@@ -1866,6 +1924,8 @@ static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
88080 len = strlen(tmp);
88081 if (len > *size)
88082 len = *size;
88083+ if (len > sizeof(tmp))
88084+ len = sizeof(tmp);
88085 if (copy_to_user(*buf, tmp, len))
88086 return -EFAULT;
88087 *size -= len;
88088@@ -2030,7 +2090,7 @@ int proc_dointvec(struct ctl_table *table, int write,
88089 static int proc_taint(struct ctl_table *table, int write,
88090 void __user *buffer, size_t *lenp, loff_t *ppos)
88091 {
88092- struct ctl_table t;
88093+ ctl_table_no_const t;
88094 unsigned long tmptaint = get_taint();
88095 int err;
88096
88097@@ -2058,7 +2118,6 @@ static int proc_taint(struct ctl_table *table, int write,
88098 return err;
88099 }
88100
88101-#ifdef CONFIG_PRINTK
88102 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
88103 void __user *buffer, size_t *lenp, loff_t *ppos)
88104 {
88105@@ -2067,7 +2126,6 @@ static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
88106
88107 return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
88108 }
88109-#endif
88110
88111 struct do_proc_dointvec_minmax_conv_param {
88112 int *min;
88113@@ -2214,8 +2272,11 @@ static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int
88114 *i = val;
88115 } else {
88116 val = convdiv * (*i) / convmul;
88117- if (!first)
88118+ if (!first) {
88119 err = proc_put_char(&buffer, &left, '\t');
88120+ if (err)
88121+ break;
88122+ }
88123 err = proc_put_long(&buffer, &left, val, false);
88124 if (err)
88125 break;
88126@@ -2611,6 +2672,12 @@ int proc_dostring(struct ctl_table *table, int write,
88127 return -ENOSYS;
88128 }
88129
88130+int proc_dostring_modpriv(struct ctl_table *table, int write,
88131+ void __user *buffer, size_t *lenp, loff_t *ppos)
88132+{
88133+ return -ENOSYS;
88134+}
88135+
88136 int proc_dointvec(struct ctl_table *table, int write,
88137 void __user *buffer, size_t *lenp, loff_t *ppos)
88138 {
88139@@ -2667,5 +2734,6 @@ EXPORT_SYMBOL(proc_dointvec_minmax);
88140 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
88141 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
88142 EXPORT_SYMBOL(proc_dostring);
88143+EXPORT_SYMBOL(proc_dostring_modpriv);
88144 EXPORT_SYMBOL(proc_doulongvec_minmax);
88145 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
88146diff --git a/kernel/taskstats.c b/kernel/taskstats.c
88147index 145bb4d..b2aa969 100644
88148--- a/kernel/taskstats.c
88149+++ b/kernel/taskstats.c
88150@@ -28,9 +28,12 @@
88151 #include <linux/fs.h>
88152 #include <linux/file.h>
88153 #include <linux/pid_namespace.h>
88154+#include <linux/grsecurity.h>
88155 #include <net/genetlink.h>
88156 #include <linux/atomic.h>
88157
88158+extern int gr_is_taskstats_denied(int pid);
88159+
88160 /*
88161 * Maximum length of a cpumask that can be specified in
88162 * the TASKSTATS_CMD_ATTR_REGISTER/DEREGISTER_CPUMASK attribute
88163@@ -570,6 +573,9 @@ err:
88164
88165 static int taskstats_user_cmd(struct sk_buff *skb, struct genl_info *info)
88166 {
88167+ if (gr_is_taskstats_denied(current->pid))
88168+ return -EACCES;
88169+
88170 if (info->attrs[TASKSTATS_CMD_ATTR_REGISTER_CPUMASK])
88171 return cmd_attr_register_cpumask(info);
88172 else if (info->attrs[TASKSTATS_CMD_ATTR_DEREGISTER_CPUMASK])
88173diff --git a/kernel/time.c b/kernel/time.c
88174index 7c7964c..2a0d412 100644
88175--- a/kernel/time.c
88176+++ b/kernel/time.c
88177@@ -172,6 +172,11 @@ int do_sys_settimeofday(const struct timespec *tv, const struct timezone *tz)
88178 return error;
88179
88180 if (tz) {
88181+ /* we log in do_settimeofday called below, so don't log twice
88182+ */
88183+ if (!tv)
88184+ gr_log_timechange();
88185+
88186 sys_tz = *tz;
88187 update_vsyscall_tz();
88188 if (firsttime) {
88189diff --git a/kernel/time/alarmtimer.c b/kernel/time/alarmtimer.c
88190index 88c9c65..7497ebc 100644
88191--- a/kernel/time/alarmtimer.c
88192+++ b/kernel/time/alarmtimer.c
88193@@ -795,7 +795,7 @@ static int __init alarmtimer_init(void)
88194 struct platform_device *pdev;
88195 int error = 0;
88196 int i;
88197- struct k_clock alarm_clock = {
88198+ static struct k_clock alarm_clock = {
88199 .clock_getres = alarm_clock_getres,
88200 .clock_get = alarm_clock_get,
88201 .timer_create = alarm_timer_create,
88202diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
88203index 5cf6c70..ac341b0 100644
88204--- a/kernel/time/timekeeping.c
88205+++ b/kernel/time/timekeeping.c
88206@@ -15,6 +15,7 @@
88207 #include <linux/init.h>
88208 #include <linux/mm.h>
88209 #include <linux/sched.h>
88210+#include <linux/grsecurity.h>
88211 #include <linux/syscore_ops.h>
88212 #include <linux/clocksource.h>
88213 #include <linux/jiffies.h>
88214@@ -500,6 +501,8 @@ int do_settimeofday(const struct timespec *tv)
88215 if (!timespec_valid_strict(tv))
88216 return -EINVAL;
88217
88218+ gr_log_timechange();
88219+
88220 raw_spin_lock_irqsave(&timekeeper_lock, flags);
88221 write_seqcount_begin(&timekeeper_seq);
88222
88223diff --git a/kernel/time/timer_list.c b/kernel/time/timer_list.c
88224index 61ed862..3b52c65 100644
88225--- a/kernel/time/timer_list.c
88226+++ b/kernel/time/timer_list.c
88227@@ -45,12 +45,16 @@ DECLARE_PER_CPU(struct hrtimer_cpu_base, hrtimer_bases);
88228
88229 static void print_name_offset(struct seq_file *m, void *sym)
88230 {
88231+#ifdef CONFIG_GRKERNSEC_HIDESYM
88232+ SEQ_printf(m, "<%p>", NULL);
88233+#else
88234 char symname[KSYM_NAME_LEN];
88235
88236 if (lookup_symbol_name((unsigned long)sym, symname) < 0)
88237 SEQ_printf(m, "<%pK>", sym);
88238 else
88239 SEQ_printf(m, "%s", symname);
88240+#endif
88241 }
88242
88243 static void
88244@@ -119,7 +123,11 @@ next_one:
88245 static void
88246 print_base(struct seq_file *m, struct hrtimer_clock_base *base, u64 now)
88247 {
88248+#ifdef CONFIG_GRKERNSEC_HIDESYM
88249+ SEQ_printf(m, " .base: %p\n", NULL);
88250+#else
88251 SEQ_printf(m, " .base: %pK\n", base);
88252+#endif
88253 SEQ_printf(m, " .index: %d\n",
88254 base->index);
88255 SEQ_printf(m, " .resolution: %Lu nsecs\n",
88256@@ -362,7 +370,11 @@ static int __init init_timer_list_procfs(void)
88257 {
88258 struct proc_dir_entry *pe;
88259
88260+#ifdef CONFIG_GRKERNSEC_PROC_ADD
88261+ pe = proc_create("timer_list", 0400, NULL, &timer_list_fops);
88262+#else
88263 pe = proc_create("timer_list", 0444, NULL, &timer_list_fops);
88264+#endif
88265 if (!pe)
88266 return -ENOMEM;
88267 return 0;
88268diff --git a/kernel/time/timer_stats.c b/kernel/time/timer_stats.c
88269index 0b537f2..40d6c20 100644
88270--- a/kernel/time/timer_stats.c
88271+++ b/kernel/time/timer_stats.c
88272@@ -116,7 +116,7 @@ static ktime_t time_start, time_stop;
88273 static unsigned long nr_entries;
88274 static struct entry entries[MAX_ENTRIES];
88275
88276-static atomic_t overflow_count;
88277+static atomic_unchecked_t overflow_count;
88278
88279 /*
88280 * The entries are in a hash-table, for fast lookup:
88281@@ -140,7 +140,7 @@ static void reset_entries(void)
88282 nr_entries = 0;
88283 memset(entries, 0, sizeof(entries));
88284 memset(tstat_hash_table, 0, sizeof(tstat_hash_table));
88285- atomic_set(&overflow_count, 0);
88286+ atomic_set_unchecked(&overflow_count, 0);
88287 }
88288
88289 static struct entry *alloc_entry(void)
88290@@ -261,7 +261,7 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
88291 if (likely(entry))
88292 entry->count++;
88293 else
88294- atomic_inc(&overflow_count);
88295+ atomic_inc_unchecked(&overflow_count);
88296
88297 out_unlock:
88298 raw_spin_unlock_irqrestore(lock, flags);
88299@@ -269,12 +269,16 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
88300
88301 static void print_name_offset(struct seq_file *m, unsigned long addr)
88302 {
88303+#ifdef CONFIG_GRKERNSEC_HIDESYM
88304+ seq_printf(m, "<%p>", NULL);
88305+#else
88306 char symname[KSYM_NAME_LEN];
88307
88308 if (lookup_symbol_name(addr, symname) < 0)
88309- seq_printf(m, "<%p>", (void *)addr);
88310+ seq_printf(m, "<%pK>", (void *)addr);
88311 else
88312 seq_printf(m, "%s", symname);
88313+#endif
88314 }
88315
88316 static int tstats_show(struct seq_file *m, void *v)
88317@@ -300,9 +304,9 @@ static int tstats_show(struct seq_file *m, void *v)
88318
88319 seq_puts(m, "Timer Stats Version: v0.2\n");
88320 seq_printf(m, "Sample period: %ld.%03ld s\n", period.tv_sec, ms);
88321- if (atomic_read(&overflow_count))
88322+ if (atomic_read_unchecked(&overflow_count))
88323 seq_printf(m, "Overflow: %d entries\n",
88324- atomic_read(&overflow_count));
88325+ atomic_read_unchecked(&overflow_count));
88326
88327 for (i = 0; i < nr_entries; i++) {
88328 entry = entries + i;
88329@@ -417,7 +421,11 @@ static int __init init_tstats_procfs(void)
88330 {
88331 struct proc_dir_entry *pe;
88332
88333+#ifdef CONFIG_GRKERNSEC_PROC_ADD
88334+ pe = proc_create("timer_stats", 0600, NULL, &tstats_fops);
88335+#else
88336 pe = proc_create("timer_stats", 0644, NULL, &tstats_fops);
88337+#endif
88338 if (!pe)
88339 return -ENOMEM;
88340 return 0;
88341diff --git a/kernel/timer.c b/kernel/timer.c
88342index 4296d13..0164b04 100644
88343--- a/kernel/timer.c
88344+++ b/kernel/timer.c
88345@@ -1366,7 +1366,7 @@ void update_process_times(int user_tick)
88346 /*
88347 * This function runs timers and the timer-tq in bottom half context.
88348 */
88349-static void run_timer_softirq(struct softirq_action *h)
88350+static __latent_entropy void run_timer_softirq(void)
88351 {
88352 struct tvec_base *base = __this_cpu_read(tvec_bases);
88353
88354@@ -1429,7 +1429,7 @@ static void process_timeout(unsigned long __data)
88355 *
88356 * In all cases the return value is guaranteed to be non-negative.
88357 */
88358-signed long __sched schedule_timeout(signed long timeout)
88359+signed long __sched __intentional_overflow(-1) schedule_timeout(signed long timeout)
88360 {
88361 struct timer_list timer;
88362 unsigned long expire;
88363diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c
88364index b8b8560..75b1a09 100644
88365--- a/kernel/trace/blktrace.c
88366+++ b/kernel/trace/blktrace.c
88367@@ -317,7 +317,7 @@ static ssize_t blk_dropped_read(struct file *filp, char __user *buffer,
88368 struct blk_trace *bt = filp->private_data;
88369 char buf[16];
88370
88371- snprintf(buf, sizeof(buf), "%u\n", atomic_read(&bt->dropped));
88372+ snprintf(buf, sizeof(buf), "%u\n", atomic_read_unchecked(&bt->dropped));
88373
88374 return simple_read_from_buffer(buffer, count, ppos, buf, strlen(buf));
88375 }
88376@@ -375,7 +375,7 @@ static int blk_subbuf_start_callback(struct rchan_buf *buf, void *subbuf,
88377 return 1;
88378
88379 bt = buf->chan->private_data;
88380- atomic_inc(&bt->dropped);
88381+ atomic_inc_unchecked(&bt->dropped);
88382 return 0;
88383 }
88384
88385@@ -476,7 +476,7 @@ int do_blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
88386
88387 bt->dir = dir;
88388 bt->dev = dev;
88389- atomic_set(&bt->dropped, 0);
88390+ atomic_set_unchecked(&bt->dropped, 0);
88391
88392 ret = -EIO;
88393 bt->dropped_file = debugfs_create_file("dropped", 0444, dir, bt,
88394diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
88395index 1345d9f..db46efe 100644
88396--- a/kernel/trace/ftrace.c
88397+++ b/kernel/trace/ftrace.c
88398@@ -1944,12 +1944,17 @@ ftrace_code_disable(struct module *mod, struct dyn_ftrace *rec)
88399 if (unlikely(ftrace_disabled))
88400 return 0;
88401
88402+ ret = ftrace_arch_code_modify_prepare();
88403+ FTRACE_WARN_ON(ret);
88404+ if (ret)
88405+ return 0;
88406+
88407 ret = ftrace_make_nop(mod, rec, MCOUNT_ADDR);
88408+ FTRACE_WARN_ON(ftrace_arch_code_modify_post_process());
88409 if (ret) {
88410 ftrace_bug(ret, ip);
88411- return 0;
88412 }
88413- return 1;
88414+ return ret ? 0 : 1;
88415 }
88416
88417 /*
88418@@ -4043,8 +4048,10 @@ static int ftrace_process_locs(struct module *mod,
88419 if (!count)
88420 return 0;
88421
88422+ pax_open_kernel();
88423 sort(start, count, sizeof(*start),
88424 ftrace_cmp_ips, ftrace_swap_ips);
88425+ pax_close_kernel();
88426
88427 start_pg = ftrace_allocate_pages(count);
88428 if (!start_pg)
88429@@ -4766,8 +4773,6 @@ ftrace_enable_sysctl(struct ctl_table *table, int write,
88430 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
88431
88432 static int ftrace_graph_active;
88433-static struct notifier_block ftrace_suspend_notifier;
88434-
88435 int ftrace_graph_entry_stub(struct ftrace_graph_ent *trace)
88436 {
88437 return 0;
88438@@ -4918,6 +4923,10 @@ static struct ftrace_ops fgraph_ops __read_mostly = {
88439 FTRACE_OPS_FL_RECURSION_SAFE,
88440 };
88441
88442+static struct notifier_block ftrace_suspend_notifier = {
88443+ .notifier_call = ftrace_suspend_notifier_call
88444+};
88445+
88446 int register_ftrace_graph(trace_func_graph_ret_t retfunc,
88447 trace_func_graph_ent_t entryfunc)
88448 {
88449@@ -4931,7 +4940,6 @@ int register_ftrace_graph(trace_func_graph_ret_t retfunc,
88450 goto out;
88451 }
88452
88453- ftrace_suspend_notifier.notifier_call = ftrace_suspend_notifier_call;
88454 register_pm_notifier(&ftrace_suspend_notifier);
88455
88456 ftrace_graph_active++;
88457diff --git a/kernel/trace/ring_buffer.c b/kernel/trace/ring_buffer.c
88458index cc2f66f..05edd54 100644
88459--- a/kernel/trace/ring_buffer.c
88460+++ b/kernel/trace/ring_buffer.c
88461@@ -352,9 +352,9 @@ struct buffer_data_page {
88462 */
88463 struct buffer_page {
88464 struct list_head list; /* list of buffer pages */
88465- local_t write; /* index for next write */
88466+ local_unchecked_t write; /* index for next write */
88467 unsigned read; /* index for next read */
88468- local_t entries; /* entries on this page */
88469+ local_unchecked_t entries; /* entries on this page */
88470 unsigned long real_end; /* real end of data */
88471 struct buffer_data_page *page; /* Actual data page */
88472 };
88473@@ -473,8 +473,8 @@ struct ring_buffer_per_cpu {
88474 unsigned long last_overrun;
88475 local_t entries_bytes;
88476 local_t entries;
88477- local_t overrun;
88478- local_t commit_overrun;
88479+ local_unchecked_t overrun;
88480+ local_unchecked_t commit_overrun;
88481 local_t dropped_events;
88482 local_t committing;
88483 local_t commits;
88484@@ -992,8 +992,8 @@ static int rb_tail_page_update(struct ring_buffer_per_cpu *cpu_buffer,
88485 *
88486 * We add a counter to the write field to denote this.
88487 */
88488- old_write = local_add_return(RB_WRITE_INTCNT, &next_page->write);
88489- old_entries = local_add_return(RB_WRITE_INTCNT, &next_page->entries);
88490+ old_write = local_add_return_unchecked(RB_WRITE_INTCNT, &next_page->write);
88491+ old_entries = local_add_return_unchecked(RB_WRITE_INTCNT, &next_page->entries);
88492
88493 /*
88494 * Just make sure we have seen our old_write and synchronize
88495@@ -1021,8 +1021,8 @@ static int rb_tail_page_update(struct ring_buffer_per_cpu *cpu_buffer,
88496 * cmpxchg to only update if an interrupt did not already
88497 * do it for us. If the cmpxchg fails, we don't care.
88498 */
88499- (void)local_cmpxchg(&next_page->write, old_write, val);
88500- (void)local_cmpxchg(&next_page->entries, old_entries, eval);
88501+ (void)local_cmpxchg_unchecked(&next_page->write, old_write, val);
88502+ (void)local_cmpxchg_unchecked(&next_page->entries, old_entries, eval);
88503
88504 /*
88505 * No need to worry about races with clearing out the commit.
88506@@ -1386,12 +1386,12 @@ static void rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer);
88507
88508 static inline unsigned long rb_page_entries(struct buffer_page *bpage)
88509 {
88510- return local_read(&bpage->entries) & RB_WRITE_MASK;
88511+ return local_read_unchecked(&bpage->entries) & RB_WRITE_MASK;
88512 }
88513
88514 static inline unsigned long rb_page_write(struct buffer_page *bpage)
88515 {
88516- return local_read(&bpage->write) & RB_WRITE_MASK;
88517+ return local_read_unchecked(&bpage->write) & RB_WRITE_MASK;
88518 }
88519
88520 static int
88521@@ -1486,7 +1486,7 @@ rb_remove_pages(struct ring_buffer_per_cpu *cpu_buffer, unsigned int nr_pages)
88522 * bytes consumed in ring buffer from here.
88523 * Increment overrun to account for the lost events.
88524 */
88525- local_add(page_entries, &cpu_buffer->overrun);
88526+ local_add_unchecked(page_entries, &cpu_buffer->overrun);
88527 local_sub(BUF_PAGE_SIZE, &cpu_buffer->entries_bytes);
88528 }
88529
88530@@ -2064,7 +2064,7 @@ rb_handle_head_page(struct ring_buffer_per_cpu *cpu_buffer,
88531 * it is our responsibility to update
88532 * the counters.
88533 */
88534- local_add(entries, &cpu_buffer->overrun);
88535+ local_add_unchecked(entries, &cpu_buffer->overrun);
88536 local_sub(BUF_PAGE_SIZE, &cpu_buffer->entries_bytes);
88537
88538 /*
88539@@ -2214,7 +2214,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
88540 if (tail == BUF_PAGE_SIZE)
88541 tail_page->real_end = 0;
88542
88543- local_sub(length, &tail_page->write);
88544+ local_sub_unchecked(length, &tail_page->write);
88545 return;
88546 }
88547
88548@@ -2249,7 +2249,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
88549 rb_event_set_padding(event);
88550
88551 /* Set the write back to the previous setting */
88552- local_sub(length, &tail_page->write);
88553+ local_sub_unchecked(length, &tail_page->write);
88554 return;
88555 }
88556
88557@@ -2261,7 +2261,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
88558
88559 /* Set write to end of buffer */
88560 length = (tail + length) - BUF_PAGE_SIZE;
88561- local_sub(length, &tail_page->write);
88562+ local_sub_unchecked(length, &tail_page->write);
88563 }
88564
88565 /*
88566@@ -2287,7 +2287,7 @@ rb_move_tail(struct ring_buffer_per_cpu *cpu_buffer,
88567 * about it.
88568 */
88569 if (unlikely(next_page == commit_page)) {
88570- local_inc(&cpu_buffer->commit_overrun);
88571+ local_inc_unchecked(&cpu_buffer->commit_overrun);
88572 goto out_reset;
88573 }
88574
88575@@ -2343,7 +2343,7 @@ rb_move_tail(struct ring_buffer_per_cpu *cpu_buffer,
88576 cpu_buffer->tail_page) &&
88577 (cpu_buffer->commit_page ==
88578 cpu_buffer->reader_page))) {
88579- local_inc(&cpu_buffer->commit_overrun);
88580+ local_inc_unchecked(&cpu_buffer->commit_overrun);
88581 goto out_reset;
88582 }
88583 }
88584@@ -2391,7 +2391,7 @@ __rb_reserve_next(struct ring_buffer_per_cpu *cpu_buffer,
88585 length += RB_LEN_TIME_EXTEND;
88586
88587 tail_page = cpu_buffer->tail_page;
88588- write = local_add_return(length, &tail_page->write);
88589+ write = local_add_return_unchecked(length, &tail_page->write);
88590
88591 /* set write to only the index of the write */
88592 write &= RB_WRITE_MASK;
88593@@ -2408,7 +2408,7 @@ __rb_reserve_next(struct ring_buffer_per_cpu *cpu_buffer,
88594 kmemcheck_annotate_bitfield(event, bitfield);
88595 rb_update_event(cpu_buffer, event, length, add_timestamp, delta);
88596
88597- local_inc(&tail_page->entries);
88598+ local_inc_unchecked(&tail_page->entries);
88599
88600 /*
88601 * If this is the first commit on the page, then update
88602@@ -2441,7 +2441,7 @@ rb_try_to_discard(struct ring_buffer_per_cpu *cpu_buffer,
88603
88604 if (bpage->page == (void *)addr && rb_page_write(bpage) == old_index) {
88605 unsigned long write_mask =
88606- local_read(&bpage->write) & ~RB_WRITE_MASK;
88607+ local_read_unchecked(&bpage->write) & ~RB_WRITE_MASK;
88608 unsigned long event_length = rb_event_length(event);
88609 /*
88610 * This is on the tail page. It is possible that
88611@@ -2451,7 +2451,7 @@ rb_try_to_discard(struct ring_buffer_per_cpu *cpu_buffer,
88612 */
88613 old_index += write_mask;
88614 new_index += write_mask;
88615- index = local_cmpxchg(&bpage->write, old_index, new_index);
88616+ index = local_cmpxchg_unchecked(&bpage->write, old_index, new_index);
88617 if (index == old_index) {
88618 /* update counters */
88619 local_sub(event_length, &cpu_buffer->entries_bytes);
88620@@ -2843,7 +2843,7 @@ rb_decrement_entry(struct ring_buffer_per_cpu *cpu_buffer,
88621
88622 /* Do the likely case first */
88623 if (likely(bpage->page == (void *)addr)) {
88624- local_dec(&bpage->entries);
88625+ local_dec_unchecked(&bpage->entries);
88626 return;
88627 }
88628
88629@@ -2855,7 +2855,7 @@ rb_decrement_entry(struct ring_buffer_per_cpu *cpu_buffer,
88630 start = bpage;
88631 do {
88632 if (bpage->page == (void *)addr) {
88633- local_dec(&bpage->entries);
88634+ local_dec_unchecked(&bpage->entries);
88635 return;
88636 }
88637 rb_inc_page(cpu_buffer, &bpage);
88638@@ -3139,7 +3139,7 @@ static inline unsigned long
88639 rb_num_of_entries(struct ring_buffer_per_cpu *cpu_buffer)
88640 {
88641 return local_read(&cpu_buffer->entries) -
88642- (local_read(&cpu_buffer->overrun) + cpu_buffer->read);
88643+ (local_read_unchecked(&cpu_buffer->overrun) + cpu_buffer->read);
88644 }
88645
88646 /**
88647@@ -3228,7 +3228,7 @@ unsigned long ring_buffer_overrun_cpu(struct ring_buffer *buffer, int cpu)
88648 return 0;
88649
88650 cpu_buffer = buffer->buffers[cpu];
88651- ret = local_read(&cpu_buffer->overrun);
88652+ ret = local_read_unchecked(&cpu_buffer->overrun);
88653
88654 return ret;
88655 }
88656@@ -3251,7 +3251,7 @@ ring_buffer_commit_overrun_cpu(struct ring_buffer *buffer, int cpu)
88657 return 0;
88658
88659 cpu_buffer = buffer->buffers[cpu];
88660- ret = local_read(&cpu_buffer->commit_overrun);
88661+ ret = local_read_unchecked(&cpu_buffer->commit_overrun);
88662
88663 return ret;
88664 }
88665@@ -3336,7 +3336,7 @@ unsigned long ring_buffer_overruns(struct ring_buffer *buffer)
88666 /* if you care about this being correct, lock the buffer */
88667 for_each_buffer_cpu(buffer, cpu) {
88668 cpu_buffer = buffer->buffers[cpu];
88669- overruns += local_read(&cpu_buffer->overrun);
88670+ overruns += local_read_unchecked(&cpu_buffer->overrun);
88671 }
88672
88673 return overruns;
88674@@ -3512,8 +3512,8 @@ rb_get_reader_page(struct ring_buffer_per_cpu *cpu_buffer)
88675 /*
88676 * Reset the reader page to size zero.
88677 */
88678- local_set(&cpu_buffer->reader_page->write, 0);
88679- local_set(&cpu_buffer->reader_page->entries, 0);
88680+ local_set_unchecked(&cpu_buffer->reader_page->write, 0);
88681+ local_set_unchecked(&cpu_buffer->reader_page->entries, 0);
88682 local_set(&cpu_buffer->reader_page->page->commit, 0);
88683 cpu_buffer->reader_page->real_end = 0;
88684
88685@@ -3547,7 +3547,7 @@ rb_get_reader_page(struct ring_buffer_per_cpu *cpu_buffer)
88686 * want to compare with the last_overrun.
88687 */
88688 smp_mb();
88689- overwrite = local_read(&(cpu_buffer->overrun));
88690+ overwrite = local_read_unchecked(&(cpu_buffer->overrun));
88691
88692 /*
88693 * Here's the tricky part.
88694@@ -4117,8 +4117,8 @@ rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer)
88695
88696 cpu_buffer->head_page
88697 = list_entry(cpu_buffer->pages, struct buffer_page, list);
88698- local_set(&cpu_buffer->head_page->write, 0);
88699- local_set(&cpu_buffer->head_page->entries, 0);
88700+ local_set_unchecked(&cpu_buffer->head_page->write, 0);
88701+ local_set_unchecked(&cpu_buffer->head_page->entries, 0);
88702 local_set(&cpu_buffer->head_page->page->commit, 0);
88703
88704 cpu_buffer->head_page->read = 0;
88705@@ -4128,14 +4128,14 @@ rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer)
88706
88707 INIT_LIST_HEAD(&cpu_buffer->reader_page->list);
88708 INIT_LIST_HEAD(&cpu_buffer->new_pages);
88709- local_set(&cpu_buffer->reader_page->write, 0);
88710- local_set(&cpu_buffer->reader_page->entries, 0);
88711+ local_set_unchecked(&cpu_buffer->reader_page->write, 0);
88712+ local_set_unchecked(&cpu_buffer->reader_page->entries, 0);
88713 local_set(&cpu_buffer->reader_page->page->commit, 0);
88714 cpu_buffer->reader_page->read = 0;
88715
88716 local_set(&cpu_buffer->entries_bytes, 0);
88717- local_set(&cpu_buffer->overrun, 0);
88718- local_set(&cpu_buffer->commit_overrun, 0);
88719+ local_set_unchecked(&cpu_buffer->overrun, 0);
88720+ local_set_unchecked(&cpu_buffer->commit_overrun, 0);
88721 local_set(&cpu_buffer->dropped_events, 0);
88722 local_set(&cpu_buffer->entries, 0);
88723 local_set(&cpu_buffer->committing, 0);
88724@@ -4540,8 +4540,8 @@ int ring_buffer_read_page(struct ring_buffer *buffer,
88725 rb_init_page(bpage);
88726 bpage = reader->page;
88727 reader->page = *data_page;
88728- local_set(&reader->write, 0);
88729- local_set(&reader->entries, 0);
88730+ local_set_unchecked(&reader->write, 0);
88731+ local_set_unchecked(&reader->entries, 0);
88732 reader->read = 0;
88733 *data_page = bpage;
88734
88735diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
88736index b778e96..4e84621 100644
88737--- a/kernel/trace/trace.c
88738+++ b/kernel/trace/trace.c
88739@@ -3335,7 +3335,7 @@ int trace_keep_overwrite(struct tracer *tracer, u32 mask, int set)
88740 return 0;
88741 }
88742
88743-int set_tracer_flag(struct trace_array *tr, unsigned int mask, int enabled)
88744+int set_tracer_flag(struct trace_array *tr, unsigned long mask, int enabled)
88745 {
88746 /* do nothing if flag is already set */
88747 if (!!(trace_flags & mask) == !!enabled)
88748diff --git a/kernel/trace/trace.h b/kernel/trace/trace.h
88749index 10c86fb..645ab0a 100644
88750--- a/kernel/trace/trace.h
88751+++ b/kernel/trace/trace.h
88752@@ -1029,7 +1029,7 @@ extern const char *__stop___tracepoint_str[];
88753 void trace_printk_init_buffers(void);
88754 void trace_printk_start_comm(void);
88755 int trace_keep_overwrite(struct tracer *tracer, u32 mask, int set);
88756-int set_tracer_flag(struct trace_array *tr, unsigned int mask, int enabled);
88757+int set_tracer_flag(struct trace_array *tr, unsigned long mask, int enabled);
88758
88759 /*
88760 * Normal trace_printk() and friends allocates special buffers
88761diff --git a/kernel/trace/trace_clock.c b/kernel/trace/trace_clock.c
88762index 26dc348..8708ca7 100644
88763--- a/kernel/trace/trace_clock.c
88764+++ b/kernel/trace/trace_clock.c
88765@@ -123,7 +123,7 @@ u64 notrace trace_clock_global(void)
88766 return now;
88767 }
88768
88769-static atomic64_t trace_counter;
88770+static atomic64_unchecked_t trace_counter;
88771
88772 /*
88773 * trace_clock_counter(): simply an atomic counter.
88774@@ -132,5 +132,5 @@ static atomic64_t trace_counter;
88775 */
88776 u64 notrace trace_clock_counter(void)
88777 {
88778- return atomic64_add_return(1, &trace_counter);
88779+ return atomic64_inc_return_unchecked(&trace_counter);
88780 }
88781diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
88782index 368a4d5..7b6d1d5 100644
88783--- a/kernel/trace/trace_events.c
88784+++ b/kernel/trace/trace_events.c
88785@@ -1673,7 +1673,6 @@ __trace_early_add_new_event(struct ftrace_event_call *call,
88786 return 0;
88787 }
88788
88789-struct ftrace_module_file_ops;
88790 static void __add_event_to_tracers(struct ftrace_event_call *call);
88791
88792 /* Add an additional event_call dynamically */
88793diff --git a/kernel/trace/trace_mmiotrace.c b/kernel/trace/trace_mmiotrace.c
88794index b3dcfb2..ebee344 100644
88795--- a/kernel/trace/trace_mmiotrace.c
88796+++ b/kernel/trace/trace_mmiotrace.c
88797@@ -24,7 +24,7 @@ struct header_iter {
88798 static struct trace_array *mmio_trace_array;
88799 static bool overrun_detected;
88800 static unsigned long prev_overruns;
88801-static atomic_t dropped_count;
88802+static atomic_unchecked_t dropped_count;
88803
88804 static void mmio_reset_data(struct trace_array *tr)
88805 {
88806@@ -127,7 +127,7 @@ static void mmio_close(struct trace_iterator *iter)
88807
88808 static unsigned long count_overruns(struct trace_iterator *iter)
88809 {
88810- unsigned long cnt = atomic_xchg(&dropped_count, 0);
88811+ unsigned long cnt = atomic_xchg_unchecked(&dropped_count, 0);
88812 unsigned long over = ring_buffer_overruns(iter->trace_buffer->buffer);
88813
88814 if (over > prev_overruns)
88815@@ -317,7 +317,7 @@ static void __trace_mmiotrace_rw(struct trace_array *tr,
88816 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_RW,
88817 sizeof(*entry), 0, pc);
88818 if (!event) {
88819- atomic_inc(&dropped_count);
88820+ atomic_inc_unchecked(&dropped_count);
88821 return;
88822 }
88823 entry = ring_buffer_event_data(event);
88824@@ -347,7 +347,7 @@ static void __trace_mmiotrace_map(struct trace_array *tr,
88825 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_MAP,
88826 sizeof(*entry), 0, pc);
88827 if (!event) {
88828- atomic_inc(&dropped_count);
88829+ atomic_inc_unchecked(&dropped_count);
88830 return;
88831 }
88832 entry = ring_buffer_event_data(event);
88833diff --git a/kernel/trace/trace_output.c b/kernel/trace/trace_output.c
88834index 34e7cba..6f9a729 100644
88835--- a/kernel/trace/trace_output.c
88836+++ b/kernel/trace/trace_output.c
88837@@ -294,7 +294,7 @@ int trace_seq_path(struct trace_seq *s, const struct path *path)
88838
88839 p = d_path(path, s->buffer + s->len, PAGE_SIZE - s->len);
88840 if (!IS_ERR(p)) {
88841- p = mangle_path(s->buffer + s->len, p, "\n");
88842+ p = mangle_path(s->buffer + s->len, p, "\n\\");
88843 if (p) {
88844 s->len = p - s->buffer;
88845 return 1;
88846@@ -893,14 +893,16 @@ int register_ftrace_event(struct trace_event *event)
88847 goto out;
88848 }
88849
88850+ pax_open_kernel();
88851 if (event->funcs->trace == NULL)
88852- event->funcs->trace = trace_nop_print;
88853+ *(void **)&event->funcs->trace = trace_nop_print;
88854 if (event->funcs->raw == NULL)
88855- event->funcs->raw = trace_nop_print;
88856+ *(void **)&event->funcs->raw = trace_nop_print;
88857 if (event->funcs->hex == NULL)
88858- event->funcs->hex = trace_nop_print;
88859+ *(void **)&event->funcs->hex = trace_nop_print;
88860 if (event->funcs->binary == NULL)
88861- event->funcs->binary = trace_nop_print;
88862+ *(void **)&event->funcs->binary = trace_nop_print;
88863+ pax_close_kernel();
88864
88865 key = event->type & (EVENT_HASHSIZE - 1);
88866
88867diff --git a/kernel/trace/trace_stack.c b/kernel/trace/trace_stack.c
88868index b20428c..4845a10 100644
88869--- a/kernel/trace/trace_stack.c
88870+++ b/kernel/trace/trace_stack.c
88871@@ -68,7 +68,7 @@ check_stack(unsigned long ip, unsigned long *stack)
88872 return;
88873
88874 /* we do not handle interrupt stacks yet */
88875- if (!object_is_on_stack(stack))
88876+ if (!object_starts_on_stack(stack))
88877 return;
88878
88879 local_irq_save(flags);
88880diff --git a/kernel/user_namespace.c b/kernel/user_namespace.c
88881index 13fb113..a6ced3f 100644
88882--- a/kernel/user_namespace.c
88883+++ b/kernel/user_namespace.c
88884@@ -82,6 +82,21 @@ int create_user_ns(struct cred *new)
88885 !kgid_has_mapping(parent_ns, group))
88886 return -EPERM;
88887
88888+#ifdef CONFIG_GRKERNSEC
88889+ /*
88890+ * This doesn't really inspire confidence:
88891+ * http://marc.info/?l=linux-kernel&m=135543612731939&w=2
88892+ * http://marc.info/?l=linux-kernel&m=135545831607095&w=2
88893+ * Increases kernel attack surface in areas developers
88894+ * previously cared little about ("low importance due
88895+ * to requiring "root" capability")
88896+ * To be removed when this code receives *proper* review
88897+ */
88898+ if (!capable(CAP_SYS_ADMIN) || !capable(CAP_SETUID) ||
88899+ !capable(CAP_SETGID))
88900+ return -EPERM;
88901+#endif
88902+
88903 ns = kmem_cache_zalloc(user_ns_cachep, GFP_KERNEL);
88904 if (!ns)
88905 return -ENOMEM;
88906@@ -860,7 +875,7 @@ static int userns_install(struct nsproxy *nsproxy, void *ns)
88907 if (atomic_read(&current->mm->mm_users) > 1)
88908 return -EINVAL;
88909
88910- if (current->fs->users != 1)
88911+ if (atomic_read(&current->fs->users) != 1)
88912 return -EINVAL;
88913
88914 if (!ns_capable(user_ns, CAP_SYS_ADMIN))
88915diff --git a/kernel/utsname_sysctl.c b/kernel/utsname_sysctl.c
88916index 4f69f9a..7c6f8f8 100644
88917--- a/kernel/utsname_sysctl.c
88918+++ b/kernel/utsname_sysctl.c
88919@@ -47,7 +47,7 @@ static void put_uts(ctl_table *table, int write, void *which)
88920 static int proc_do_uts_string(ctl_table *table, int write,
88921 void __user *buffer, size_t *lenp, loff_t *ppos)
88922 {
88923- struct ctl_table uts_table;
88924+ ctl_table_no_const uts_table;
88925 int r;
88926 memcpy(&uts_table, table, sizeof(uts_table));
88927 uts_table.data = get_uts(table, write);
88928diff --git a/kernel/watchdog.c b/kernel/watchdog.c
88929index 4431610..4265616 100644
88930--- a/kernel/watchdog.c
88931+++ b/kernel/watchdog.c
88932@@ -475,7 +475,7 @@ static int watchdog_nmi_enable(unsigned int cpu) { return 0; }
88933 static void watchdog_nmi_disable(unsigned int cpu) { return; }
88934 #endif /* CONFIG_HARDLOCKUP_DETECTOR */
88935
88936-static struct smp_hotplug_thread watchdog_threads = {
88937+static struct smp_hotplug_thread watchdog_threads __read_only = {
88938 .store = &softlockup_watchdog,
88939 .thread_should_run = watchdog_should_run,
88940 .thread_fn = watchdog,
88941diff --git a/kernel/workqueue.c b/kernel/workqueue.c
88942index 93c2652..66a1cfd 100644
88943--- a/kernel/workqueue.c
88944+++ b/kernel/workqueue.c
88945@@ -4668,7 +4668,7 @@ static void rebind_workers(struct worker_pool *pool)
88946 WARN_ON_ONCE(!(worker_flags & WORKER_UNBOUND));
88947 worker_flags |= WORKER_REBOUND;
88948 worker_flags &= ~WORKER_UNBOUND;
88949- ACCESS_ONCE(worker->flags) = worker_flags;
88950+ ACCESS_ONCE_RW(worker->flags) = worker_flags;
88951 }
88952
88953 spin_unlock_irq(&pool->lock);
88954diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
88955index 094f315..244a824 100644
88956--- a/lib/Kconfig.debug
88957+++ b/lib/Kconfig.debug
88958@@ -836,7 +836,7 @@ config DEBUG_MUTEXES
88959
88960 config DEBUG_WW_MUTEX_SLOWPATH
88961 bool "Wait/wound mutex debugging: Slowpath testing"
88962- depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
88963+ depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
88964 select DEBUG_LOCK_ALLOC
88965 select DEBUG_SPINLOCK
88966 select DEBUG_MUTEXES
88967@@ -849,7 +849,7 @@ config DEBUG_WW_MUTEX_SLOWPATH
88968
88969 config DEBUG_LOCK_ALLOC
88970 bool "Lock debugging: detect incorrect freeing of live locks"
88971- depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
88972+ depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
88973 select DEBUG_SPINLOCK
88974 select DEBUG_MUTEXES
88975 select LOCKDEP
88976@@ -863,7 +863,7 @@ config DEBUG_LOCK_ALLOC
88977
88978 config PROVE_LOCKING
88979 bool "Lock debugging: prove locking correctness"
88980- depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
88981+ depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
88982 select LOCKDEP
88983 select DEBUG_SPINLOCK
88984 select DEBUG_MUTEXES
88985@@ -914,7 +914,7 @@ config LOCKDEP
88986
88987 config LOCK_STAT
88988 bool "Lock usage statistics"
88989- depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
88990+ depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
88991 select LOCKDEP
88992 select DEBUG_SPINLOCK
88993 select DEBUG_MUTEXES
88994@@ -1376,6 +1376,7 @@ config LATENCYTOP
88995 depends on DEBUG_KERNEL
88996 depends on STACKTRACE_SUPPORT
88997 depends on PROC_FS
88998+ depends on !GRKERNSEC_HIDESYM
88999 select FRAME_POINTER if !MIPS && !PPC && !S390 && !MICROBLAZE && !ARM_UNWIND && !ARC
89000 select KALLSYMS
89001 select KALLSYMS_ALL
89002@@ -1392,7 +1393,7 @@ config ARCH_HAS_DEBUG_STRICT_USER_COPY_CHECKS
89003 config DEBUG_STRICT_USER_COPY_CHECKS
89004 bool "Strict user copy size checks"
89005 depends on ARCH_HAS_DEBUG_STRICT_USER_COPY_CHECKS
89006- depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING
89007+ depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING && !PAX_SIZE_OVERFLOW
89008 help
89009 Enabling this option turns a certain set of sanity checks for user
89010 copy operations into compile time failures.
89011@@ -1502,7 +1503,7 @@ endmenu # runtime tests
89012
89013 config PROVIDE_OHCI1394_DMA_INIT
89014 bool "Remote debugging over FireWire early on boot"
89015- depends on PCI && X86
89016+ depends on PCI && X86 && !GRKERNSEC
89017 help
89018 If you want to debug problems which hang or crash the kernel early
89019 on boot and the crashing machine has a FireWire port, you can use
89020@@ -1531,7 +1532,7 @@ config PROVIDE_OHCI1394_DMA_INIT
89021
89022 config FIREWIRE_OHCI_REMOTE_DMA
89023 bool "Remote debugging over FireWire with firewire-ohci"
89024- depends on FIREWIRE_OHCI
89025+ depends on FIREWIRE_OHCI && !GRKERNSEC
89026 help
89027 This option lets you use the FireWire bus for remote debugging
89028 with help of the firewire-ohci driver. It enables unfiltered
89029diff --git a/lib/Makefile b/lib/Makefile
89030index f3bb2cb..b358ace 100644
89031--- a/lib/Makefile
89032+++ b/lib/Makefile
89033@@ -52,7 +52,7 @@ obj-$(CONFIG_GENERIC_HWEIGHT) += hweight.o
89034
89035 obj-$(CONFIG_BTREE) += btree.o
89036 obj-$(CONFIG_DEBUG_PREEMPT) += smp_processor_id.o
89037-obj-$(CONFIG_DEBUG_LIST) += list_debug.o
89038+obj-y += list_debug.o
89039 obj-$(CONFIG_DEBUG_OBJECTS) += debugobjects.o
89040
89041 ifneq ($(CONFIG_HAVE_DEC_LOCK),y)
89042diff --git a/lib/bitmap.c b/lib/bitmap.c
89043index 06f7e4f..f3cf2b0 100644
89044--- a/lib/bitmap.c
89045+++ b/lib/bitmap.c
89046@@ -422,7 +422,7 @@ int __bitmap_parse(const char *buf, unsigned int buflen,
89047 {
89048 int c, old_c, totaldigits, ndigits, nchunks, nbits;
89049 u32 chunk;
89050- const char __user __force *ubuf = (const char __user __force *)buf;
89051+ const char __user *ubuf = (const char __force_user *)buf;
89052
89053 bitmap_zero(maskp, nmaskbits);
89054
89055@@ -507,7 +507,7 @@ int bitmap_parse_user(const char __user *ubuf,
89056 {
89057 if (!access_ok(VERIFY_READ, ubuf, ulen))
89058 return -EFAULT;
89059- return __bitmap_parse((const char __force *)ubuf,
89060+ return __bitmap_parse((const char __force_kernel *)ubuf,
89061 ulen, 1, maskp, nmaskbits);
89062
89063 }
89064@@ -598,7 +598,7 @@ static int __bitmap_parselist(const char *buf, unsigned int buflen,
89065 {
89066 unsigned a, b;
89067 int c, old_c, totaldigits;
89068- const char __user __force *ubuf = (const char __user __force *)buf;
89069+ const char __user *ubuf = (const char __force_user *)buf;
89070 int exp_digit, in_range;
89071
89072 totaldigits = c = 0;
89073@@ -698,7 +698,7 @@ int bitmap_parselist_user(const char __user *ubuf,
89074 {
89075 if (!access_ok(VERIFY_READ, ubuf, ulen))
89076 return -EFAULT;
89077- return __bitmap_parselist((const char __force *)ubuf,
89078+ return __bitmap_parselist((const char __force_kernel *)ubuf,
89079 ulen, 1, maskp, nmaskbits);
89080 }
89081 EXPORT_SYMBOL(bitmap_parselist_user);
89082diff --git a/lib/bug.c b/lib/bug.c
89083index 1686034..a9c00c8 100644
89084--- a/lib/bug.c
89085+++ b/lib/bug.c
89086@@ -134,6 +134,8 @@ enum bug_trap_type report_bug(unsigned long bugaddr, struct pt_regs *regs)
89087 return BUG_TRAP_TYPE_NONE;
89088
89089 bug = find_bug(bugaddr);
89090+ if (!bug)
89091+ return BUG_TRAP_TYPE_NONE;
89092
89093 file = NULL;
89094 line = 0;
89095diff --git a/lib/debugobjects.c b/lib/debugobjects.c
89096index bf2c8b1..1d00ccf 100644
89097--- a/lib/debugobjects.c
89098+++ b/lib/debugobjects.c
89099@@ -286,7 +286,7 @@ static void debug_object_is_on_stack(void *addr, int onstack)
89100 if (limit > 4)
89101 return;
89102
89103- is_on_stack = object_is_on_stack(addr);
89104+ is_on_stack = object_starts_on_stack(addr);
89105 if (is_on_stack == onstack)
89106 return;
89107
89108diff --git a/lib/devres.c b/lib/devres.c
89109index 8235331..5881053 100644
89110--- a/lib/devres.c
89111+++ b/lib/devres.c
89112@@ -81,7 +81,7 @@ EXPORT_SYMBOL(devm_ioremap_nocache);
89113 void devm_iounmap(struct device *dev, void __iomem *addr)
89114 {
89115 WARN_ON(devres_destroy(dev, devm_ioremap_release, devm_ioremap_match,
89116- (void *)addr));
89117+ (void __force *)addr));
89118 iounmap(addr);
89119 }
89120 EXPORT_SYMBOL(devm_iounmap);
89121@@ -224,7 +224,7 @@ void devm_ioport_unmap(struct device *dev, void __iomem *addr)
89122 {
89123 ioport_unmap(addr);
89124 WARN_ON(devres_destroy(dev, devm_ioport_map_release,
89125- devm_ioport_map_match, (void *)addr));
89126+ devm_ioport_map_match, (void __force *)addr));
89127 }
89128 EXPORT_SYMBOL(devm_ioport_unmap);
89129 #endif /* CONFIG_HAS_IOPORT */
89130diff --git a/lib/div64.c b/lib/div64.c
89131index 4382ad7..08aa558 100644
89132--- a/lib/div64.c
89133+++ b/lib/div64.c
89134@@ -59,7 +59,7 @@ uint32_t __attribute__((weak)) __div64_32(uint64_t *n, uint32_t base)
89135 EXPORT_SYMBOL(__div64_32);
89136
89137 #ifndef div_s64_rem
89138-s64 div_s64_rem(s64 dividend, s32 divisor, s32 *remainder)
89139+s64 __intentional_overflow(-1) div_s64_rem(s64 dividend, s32 divisor, s32 *remainder)
89140 {
89141 u64 quotient;
89142
89143@@ -130,7 +130,7 @@ EXPORT_SYMBOL(div64_u64_rem);
89144 * 'http://www.hackersdelight.org/HDcode/newCode/divDouble.c.txt'
89145 */
89146 #ifndef div64_u64
89147-u64 div64_u64(u64 dividend, u64 divisor)
89148+u64 __intentional_overflow(-1) div64_u64(u64 dividend, u64 divisor)
89149 {
89150 u32 high = divisor >> 32;
89151 u64 quot;
89152diff --git a/lib/dma-debug.c b/lib/dma-debug.c
89153index d87a17a..ac0d79a 100644
89154--- a/lib/dma-debug.c
89155+++ b/lib/dma-debug.c
89156@@ -768,7 +768,7 @@ static int dma_debug_device_change(struct notifier_block *nb, unsigned long acti
89157
89158 void dma_debug_add_bus(struct bus_type *bus)
89159 {
89160- struct notifier_block *nb;
89161+ notifier_block_no_const *nb;
89162
89163 if (global_disable)
89164 return;
89165@@ -945,7 +945,7 @@ static void check_unmap(struct dma_debug_entry *ref)
89166
89167 static void check_for_stack(struct device *dev, void *addr)
89168 {
89169- if (object_is_on_stack(addr))
89170+ if (object_starts_on_stack(addr))
89171 err_printk(dev, NULL, "DMA-API: device driver maps memory from"
89172 "stack [addr=%p]\n", addr);
89173 }
89174diff --git a/lib/inflate.c b/lib/inflate.c
89175index 013a761..c28f3fc 100644
89176--- a/lib/inflate.c
89177+++ b/lib/inflate.c
89178@@ -269,7 +269,7 @@ static void free(void *where)
89179 malloc_ptr = free_mem_ptr;
89180 }
89181 #else
89182-#define malloc(a) kmalloc(a, GFP_KERNEL)
89183+#define malloc(a) kmalloc((a), GFP_KERNEL)
89184 #define free(a) kfree(a)
89185 #endif
89186
89187diff --git a/lib/ioremap.c b/lib/ioremap.c
89188index 0c9216c..863bd89 100644
89189--- a/lib/ioremap.c
89190+++ b/lib/ioremap.c
89191@@ -38,7 +38,7 @@ static inline int ioremap_pmd_range(pud_t *pud, unsigned long addr,
89192 unsigned long next;
89193
89194 phys_addr -= addr;
89195- pmd = pmd_alloc(&init_mm, pud, addr);
89196+ pmd = pmd_alloc_kernel(&init_mm, pud, addr);
89197 if (!pmd)
89198 return -ENOMEM;
89199 do {
89200@@ -56,7 +56,7 @@ static inline int ioremap_pud_range(pgd_t *pgd, unsigned long addr,
89201 unsigned long next;
89202
89203 phys_addr -= addr;
89204- pud = pud_alloc(&init_mm, pgd, addr);
89205+ pud = pud_alloc_kernel(&init_mm, pgd, addr);
89206 if (!pud)
89207 return -ENOMEM;
89208 do {
89209diff --git a/lib/is_single_threaded.c b/lib/is_single_threaded.c
89210index bd2bea9..6b3c95e 100644
89211--- a/lib/is_single_threaded.c
89212+++ b/lib/is_single_threaded.c
89213@@ -22,6 +22,9 @@ bool current_is_single_threaded(void)
89214 struct task_struct *p, *t;
89215 bool ret;
89216
89217+ if (!mm)
89218+ return true;
89219+
89220 if (atomic_read(&task->signal->live) != 1)
89221 return false;
89222
89223diff --git a/lib/kobject.c b/lib/kobject.c
89224index 084f7b1..d265b8a 100644
89225--- a/lib/kobject.c
89226+++ b/lib/kobject.c
89227@@ -875,9 +875,9 @@ EXPORT_SYMBOL_GPL(kset_create_and_add);
89228
89229
89230 static DEFINE_SPINLOCK(kobj_ns_type_lock);
89231-static const struct kobj_ns_type_operations *kobj_ns_ops_tbl[KOBJ_NS_TYPES];
89232+static const struct kobj_ns_type_operations *kobj_ns_ops_tbl[KOBJ_NS_TYPES] __read_only;
89233
89234-int kobj_ns_type_register(const struct kobj_ns_type_operations *ops)
89235+int __init kobj_ns_type_register(const struct kobj_ns_type_operations *ops)
89236 {
89237 enum kobj_ns_type type = ops->type;
89238 int error;
89239diff --git a/lib/list_debug.c b/lib/list_debug.c
89240index c24c2f7..f0296f4 100644
89241--- a/lib/list_debug.c
89242+++ b/lib/list_debug.c
89243@@ -11,7 +11,9 @@
89244 #include <linux/bug.h>
89245 #include <linux/kernel.h>
89246 #include <linux/rculist.h>
89247+#include <linux/mm.h>
89248
89249+#ifdef CONFIG_DEBUG_LIST
89250 /*
89251 * Insert a new entry between two known consecutive entries.
89252 *
89253@@ -19,21 +21,40 @@
89254 * the prev/next entries already!
89255 */
89256
89257+static bool __list_add_debug(struct list_head *new,
89258+ struct list_head *prev,
89259+ struct list_head *next)
89260+{
89261+ if (unlikely(next->prev != prev)) {
89262+ printk(KERN_ERR "list_add corruption. next->prev should be "
89263+ "prev (%p), but was %p. (next=%p).\n",
89264+ prev, next->prev, next);
89265+ BUG();
89266+ return false;
89267+ }
89268+ if (unlikely(prev->next != next)) {
89269+ printk(KERN_ERR "list_add corruption. prev->next should be "
89270+ "next (%p), but was %p. (prev=%p).\n",
89271+ next, prev->next, prev);
89272+ BUG();
89273+ return false;
89274+ }
89275+ if (unlikely(new == prev || new == next)) {
89276+ printk(KERN_ERR "list_add double add: new=%p, prev=%p, next=%p.\n",
89277+ new, prev, next);
89278+ BUG();
89279+ return false;
89280+ }
89281+ return true;
89282+}
89283+
89284 void __list_add(struct list_head *new,
89285- struct list_head *prev,
89286- struct list_head *next)
89287+ struct list_head *prev,
89288+ struct list_head *next)
89289 {
89290- WARN(next->prev != prev,
89291- "list_add corruption. next->prev should be "
89292- "prev (%p), but was %p. (next=%p).\n",
89293- prev, next->prev, next);
89294- WARN(prev->next != next,
89295- "list_add corruption. prev->next should be "
89296- "next (%p), but was %p. (prev=%p).\n",
89297- next, prev->next, prev);
89298- WARN(new == prev || new == next,
89299- "list_add double add: new=%p, prev=%p, next=%p.\n",
89300- new, prev, next);
89301+ if (!__list_add_debug(new, prev, next))
89302+ return;
89303+
89304 next->prev = new;
89305 new->next = next;
89306 new->prev = prev;
89307@@ -41,28 +62,46 @@ void __list_add(struct list_head *new,
89308 }
89309 EXPORT_SYMBOL(__list_add);
89310
89311-void __list_del_entry(struct list_head *entry)
89312+static bool __list_del_entry_debug(struct list_head *entry)
89313 {
89314 struct list_head *prev, *next;
89315
89316 prev = entry->prev;
89317 next = entry->next;
89318
89319- if (WARN(next == LIST_POISON1,
89320- "list_del corruption, %p->next is LIST_POISON1 (%p)\n",
89321- entry, LIST_POISON1) ||
89322- WARN(prev == LIST_POISON2,
89323- "list_del corruption, %p->prev is LIST_POISON2 (%p)\n",
89324- entry, LIST_POISON2) ||
89325- WARN(prev->next != entry,
89326- "list_del corruption. prev->next should be %p, "
89327- "but was %p\n", entry, prev->next) ||
89328- WARN(next->prev != entry,
89329- "list_del corruption. next->prev should be %p, "
89330- "but was %p\n", entry, next->prev))
89331+ if (unlikely(next == LIST_POISON1)) {
89332+ printk(KERN_ERR "list_del corruption, %p->next is LIST_POISON1 (%p)\n",
89333+ entry, LIST_POISON1);
89334+ BUG();
89335+ return false;
89336+ }
89337+ if (unlikely(prev == LIST_POISON2)) {
89338+ printk(KERN_ERR "list_del corruption, %p->prev is LIST_POISON2 (%p)\n",
89339+ entry, LIST_POISON2);
89340+ BUG();
89341+ return false;
89342+ }
89343+ if (unlikely(entry->prev->next != entry)) {
89344+ printk(KERN_ERR "list_del corruption. prev->next should be %p, "
89345+ "but was %p\n", entry, prev->next);
89346+ BUG();
89347+ return false;
89348+ }
89349+ if (unlikely(entry->next->prev != entry)) {
89350+ printk(KERN_ERR "list_del corruption. next->prev should be %p, "
89351+ "but was %p\n", entry, next->prev);
89352+ BUG();
89353+ return false;
89354+ }
89355+ return true;
89356+}
89357+
89358+void __list_del_entry(struct list_head *entry)
89359+{
89360+ if (!__list_del_entry_debug(entry))
89361 return;
89362
89363- __list_del(prev, next);
89364+ __list_del(entry->prev, entry->next);
89365 }
89366 EXPORT_SYMBOL(__list_del_entry);
89367
89368@@ -86,15 +125,85 @@ EXPORT_SYMBOL(list_del);
89369 void __list_add_rcu(struct list_head *new,
89370 struct list_head *prev, struct list_head *next)
89371 {
89372- WARN(next->prev != prev,
89373- "list_add_rcu corruption. next->prev should be prev (%p), but was %p. (next=%p).\n",
89374- prev, next->prev, next);
89375- WARN(prev->next != next,
89376- "list_add_rcu corruption. prev->next should be next (%p), but was %p. (prev=%p).\n",
89377- next, prev->next, prev);
89378+ if (!__list_add_debug(new, prev, next))
89379+ return;
89380+
89381 new->next = next;
89382 new->prev = prev;
89383 rcu_assign_pointer(list_next_rcu(prev), new);
89384 next->prev = new;
89385 }
89386 EXPORT_SYMBOL(__list_add_rcu);
89387+#endif
89388+
89389+void __pax_list_add(struct list_head *new, struct list_head *prev, struct list_head *next)
89390+{
89391+#ifdef CONFIG_DEBUG_LIST
89392+ if (!__list_add_debug(new, prev, next))
89393+ return;
89394+#endif
89395+
89396+ pax_open_kernel();
89397+ next->prev = new;
89398+ new->next = next;
89399+ new->prev = prev;
89400+ prev->next = new;
89401+ pax_close_kernel();
89402+}
89403+EXPORT_SYMBOL(__pax_list_add);
89404+
89405+void pax_list_del(struct list_head *entry)
89406+{
89407+#ifdef CONFIG_DEBUG_LIST
89408+ if (!__list_del_entry_debug(entry))
89409+ return;
89410+#endif
89411+
89412+ pax_open_kernel();
89413+ __list_del(entry->prev, entry->next);
89414+ entry->next = LIST_POISON1;
89415+ entry->prev = LIST_POISON2;
89416+ pax_close_kernel();
89417+}
89418+EXPORT_SYMBOL(pax_list_del);
89419+
89420+void pax_list_del_init(struct list_head *entry)
89421+{
89422+ pax_open_kernel();
89423+ __list_del(entry->prev, entry->next);
89424+ INIT_LIST_HEAD(entry);
89425+ pax_close_kernel();
89426+}
89427+EXPORT_SYMBOL(pax_list_del_init);
89428+
89429+void __pax_list_add_rcu(struct list_head *new,
89430+ struct list_head *prev, struct list_head *next)
89431+{
89432+#ifdef CONFIG_DEBUG_LIST
89433+ if (!__list_add_debug(new, prev, next))
89434+ return;
89435+#endif
89436+
89437+ pax_open_kernel();
89438+ new->next = next;
89439+ new->prev = prev;
89440+ rcu_assign_pointer(list_next_rcu(prev), new);
89441+ next->prev = new;
89442+ pax_close_kernel();
89443+}
89444+EXPORT_SYMBOL(__pax_list_add_rcu);
89445+
89446+void pax_list_del_rcu(struct list_head *entry)
89447+{
89448+#ifdef CONFIG_DEBUG_LIST
89449+ if (!__list_del_entry_debug(entry))
89450+ return;
89451+#endif
89452+
89453+ pax_open_kernel();
89454+ __list_del(entry->prev, entry->next);
89455+ entry->next = LIST_POISON1;
89456+ entry->prev = LIST_POISON2;
89457+ pax_close_kernel();
89458+}
89459+EXPORT_SYMBOL(pax_list_del_rcu);
89460diff --git a/lib/percpu-refcount.c b/lib/percpu-refcount.c
89461index 1a53d49..ace934c 100644
89462--- a/lib/percpu-refcount.c
89463+++ b/lib/percpu-refcount.c
89464@@ -29,7 +29,7 @@
89465 * can't hit 0 before we've added up all the percpu refs.
89466 */
89467
89468-#define PCPU_COUNT_BIAS (1U << 31)
89469+#define PCPU_COUNT_BIAS (1U << 30)
89470
89471 /**
89472 * percpu_ref_init - initialize a percpu refcount
89473diff --git a/lib/radix-tree.c b/lib/radix-tree.c
89474index 7811ed3..f80ca19 100644
89475--- a/lib/radix-tree.c
89476+++ b/lib/radix-tree.c
89477@@ -93,7 +93,7 @@ struct radix_tree_preload {
89478 int nr;
89479 struct radix_tree_node *nodes[RADIX_TREE_PRELOAD_SIZE];
89480 };
89481-static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads) = { 0, };
89482+static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads);
89483
89484 static inline void *ptr_to_indirect(void *ptr)
89485 {
89486diff --git a/lib/random32.c b/lib/random32.c
89487index 01e8890..1e5b2df 100644
89488--- a/lib/random32.c
89489+++ b/lib/random32.c
89490@@ -2,19 +2,19 @@
89491 This is a maximally equidistributed combined Tausworthe generator
89492 based on code from GNU Scientific Library 1.5 (30 Jun 2004)
89493
89494- x_n = (s1_n ^ s2_n ^ s3_n)
89495+ lfsr113 version:
89496
89497- s1_{n+1} = (((s1_n & 4294967294) <<12) ^ (((s1_n <<13) ^ s1_n) >>19))
89498- s2_{n+1} = (((s2_n & 4294967288) << 4) ^ (((s2_n << 2) ^ s2_n) >>25))
89499- s3_{n+1} = (((s3_n & 4294967280) <<17) ^ (((s3_n << 3) ^ s3_n) >>11))
89500+ x_n = (s1_n ^ s2_n ^ s3_n ^ s4_n)
89501
89502- The period of this generator is about 2^88.
89503+ s1_{n+1} = (((s1_n & 4294967294) << 18) ^ (((s1_n << 6) ^ s1_n) >> 13))
89504+ s2_{n+1} = (((s2_n & 4294967288) << 2) ^ (((s2_n << 2) ^ s2_n) >> 27))
89505+ s3_{n+1} = (((s3_n & 4294967280) << 7) ^ (((s3_n << 13) ^ s3_n) >> 21))
89506+ s4_{n+1} = (((s4_n & 4294967168) << 13) ^ (((s4_n << 3) ^ s4_n) >> 12))
89507+
89508+ The period of this generator is about 2^113 (see erratum paper).
89509
89510 From: P. L'Ecuyer, "Maximally Equidistributed Combined Tausworthe
89511- Generators", Mathematics of Computation, 65, 213 (1996), 203--213.
89512-
89513- This is available on the net from L'Ecuyer's home page,
89514-
89515+ Generators", Mathematics of Computation, 65, 213 (1996), 203--213:
89516 http://www.iro.umontreal.ca/~lecuyer/myftp/papers/tausme.ps
89517 ftp://ftp.iro.umontreal.ca/pub/simulation/lecuyer/papers/tausme.ps
89518
89519@@ -29,7 +29,7 @@
89520 that paper.)
89521
89522 This affects the seeding procedure by imposing the requirement
89523- s1 > 1, s2 > 7, s3 > 15.
89524+ s1 > 1, s2 > 7, s3 > 15, s4 > 127.
89525
89526 */
89527
89528@@ -38,6 +38,11 @@
89529 #include <linux/export.h>
89530 #include <linux/jiffies.h>
89531 #include <linux/random.h>
89532+#include <linux/sched.h>
89533+
89534+#ifdef CONFIG_RANDOM32_SELFTEST
89535+static void __init prandom_state_selftest(void);
89536+#endif
89537
89538 static DEFINE_PER_CPU(struct rnd_state, net_rand_state);
89539
89540@@ -52,11 +57,12 @@ u32 prandom_u32_state(struct rnd_state *state)
89541 {
89542 #define TAUSWORTHE(s,a,b,c,d) ((s&c)<<d) ^ (((s <<a) ^ s)>>b)
89543
89544- state->s1 = TAUSWORTHE(state->s1, 13, 19, 4294967294UL, 12);
89545- state->s2 = TAUSWORTHE(state->s2, 2, 25, 4294967288UL, 4);
89546- state->s3 = TAUSWORTHE(state->s3, 3, 11, 4294967280UL, 17);
89547+ state->s1 = TAUSWORTHE(state->s1, 6U, 13U, 4294967294U, 18U);
89548+ state->s2 = TAUSWORTHE(state->s2, 2U, 27U, 4294967288U, 2U);
89549+ state->s3 = TAUSWORTHE(state->s3, 13U, 21U, 4294967280U, 7U);
89550+ state->s4 = TAUSWORTHE(state->s4, 3U, 12U, 4294967168U, 13U);
89551
89552- return (state->s1 ^ state->s2 ^ state->s3);
89553+ return (state->s1 ^ state->s2 ^ state->s3 ^ state->s4);
89554 }
89555 EXPORT_SYMBOL(prandom_u32_state);
89556
89557@@ -126,6 +132,38 @@ void prandom_bytes(void *buf, int bytes)
89558 }
89559 EXPORT_SYMBOL(prandom_bytes);
89560
89561+static void prandom_warmup(struct rnd_state *state)
89562+{
89563+ /* Calling RNG ten times to satify recurrence condition */
89564+ prandom_u32_state(state);
89565+ prandom_u32_state(state);
89566+ prandom_u32_state(state);
89567+ prandom_u32_state(state);
89568+ prandom_u32_state(state);
89569+ prandom_u32_state(state);
89570+ prandom_u32_state(state);
89571+ prandom_u32_state(state);
89572+ prandom_u32_state(state);
89573+ prandom_u32_state(state);
89574+}
89575+
89576+static void prandom_seed_very_weak(struct rnd_state *state, u32 seed)
89577+{
89578+ /* Note: This sort of seeding is ONLY used in test cases and
89579+ * during boot at the time from core_initcall until late_initcall
89580+ * as we don't have a stronger entropy source available yet.
89581+ * After late_initcall, we reseed entire state, we have to (!),
89582+ * otherwise an attacker just needs to search 32 bit space to
89583+ * probe for our internal 128 bit state if he knows a couple
89584+ * of prandom32 outputs!
89585+ */
89586+#define LCG(x) ((x) * 69069U) /* super-duper LCG */
89587+ state->s1 = __seed(LCG(seed), 2U);
89588+ state->s2 = __seed(LCG(state->s1), 8U);
89589+ state->s3 = __seed(LCG(state->s2), 16U);
89590+ state->s4 = __seed(LCG(state->s3), 128U);
89591+}
89592+
89593 /**
89594 * prandom_seed - add entropy to pseudo random number generator
89595 * @seed: seed value
89596@@ -141,7 +179,9 @@ void prandom_seed(u32 entropy)
89597 */
89598 for_each_possible_cpu (i) {
89599 struct rnd_state *state = &per_cpu(net_rand_state, i);
89600- state->s1 = __seed(state->s1 ^ entropy, 2);
89601+
89602+ state->s1 = __seed(state->s1 ^ entropy, 2U);
89603+ prandom_warmup(state);
89604 }
89605 }
89606 EXPORT_SYMBOL(prandom_seed);
89607@@ -154,46 +194,249 @@ static int __init prandom_init(void)
89608 {
89609 int i;
89610
89611+#ifdef CONFIG_RANDOM32_SELFTEST
89612+ prandom_state_selftest();
89613+#endif
89614+
89615 for_each_possible_cpu(i) {
89616 struct rnd_state *state = &per_cpu(net_rand_state,i);
89617
89618-#define LCG(x) ((x) * 69069) /* super-duper LCG */
89619- state->s1 = __seed(LCG(i + jiffies), 2);
89620- state->s2 = __seed(LCG(state->s1), 8);
89621- state->s3 = __seed(LCG(state->s2), 16);
89622-
89623- /* "warm it up" */
89624- prandom_u32_state(state);
89625- prandom_u32_state(state);
89626- prandom_u32_state(state);
89627- prandom_u32_state(state);
89628- prandom_u32_state(state);
89629- prandom_u32_state(state);
89630+ prandom_seed_very_weak(state, (i + jiffies) ^ random_get_entropy());
89631+ prandom_warmup(state);
89632 }
89633 return 0;
89634 }
89635 core_initcall(prandom_init);
89636
89637+static void __prandom_timer(unsigned long dontcare);
89638+static DEFINE_TIMER(seed_timer, __prandom_timer, 0, 0);
89639+
89640+static void __prandom_timer(unsigned long dontcare)
89641+{
89642+ u32 entropy;
89643+ unsigned long expires;
89644+
89645+ get_random_bytes(&entropy, sizeof(entropy));
89646+ prandom_seed(entropy);
89647+
89648+ /* reseed every ~60 seconds, in [40 .. 80) interval with slack */
89649+ expires = 40 + (prandom_u32() % 40);
89650+ seed_timer.expires = jiffies + msecs_to_jiffies(expires * MSEC_PER_SEC);
89651+
89652+ add_timer(&seed_timer);
89653+}
89654+
89655+static void __init __prandom_start_seed_timer(void)
89656+{
89657+ set_timer_slack(&seed_timer, HZ);
89658+ seed_timer.expires = jiffies + msecs_to_jiffies(40 * MSEC_PER_SEC);
89659+ add_timer(&seed_timer);
89660+}
89661+
89662 /*
89663 * Generate better values after random number generator
89664 * is fully initialized.
89665 */
89666-static int __init prandom_reseed(void)
89667+static void __prandom_reseed(bool late)
89668 {
89669 int i;
89670+ unsigned long flags;
89671+ static bool latch = false;
89672+ static DEFINE_SPINLOCK(lock);
89673+
89674+ /* only allow initial seeding (late == false) once */
89675+ spin_lock_irqsave(&lock, flags);
89676+ if (latch && !late)
89677+ goto out;
89678+ latch = true;
89679
89680 for_each_possible_cpu(i) {
89681 struct rnd_state *state = &per_cpu(net_rand_state,i);
89682- u32 seeds[3];
89683+ u32 seeds[4];
89684
89685 get_random_bytes(&seeds, sizeof(seeds));
89686- state->s1 = __seed(seeds[0], 2);
89687- state->s2 = __seed(seeds[1], 8);
89688- state->s3 = __seed(seeds[2], 16);
89689+ state->s1 = __seed(seeds[0], 2U);
89690+ state->s2 = __seed(seeds[1], 8U);
89691+ state->s3 = __seed(seeds[2], 16U);
89692+ state->s4 = __seed(seeds[3], 128U);
89693
89694- /* mix it in */
89695- prandom_u32_state(state);
89696+ prandom_warmup(state);
89697 }
89698+out:
89699+ spin_unlock_irqrestore(&lock, flags);
89700+}
89701+
89702+void prandom_reseed_late(void)
89703+{
89704+ __prandom_reseed(true);
89705+}
89706+
89707+static int __init prandom_reseed(void)
89708+{
89709+ __prandom_reseed(false);
89710+ __prandom_start_seed_timer();
89711 return 0;
89712 }
89713 late_initcall(prandom_reseed);
89714+
89715+#ifdef CONFIG_RANDOM32_SELFTEST
89716+static struct prandom_test1 {
89717+ u32 seed;
89718+ u32 result;
89719+} test1[] = {
89720+ { 1U, 3484351685U },
89721+ { 2U, 2623130059U },
89722+ { 3U, 3125133893U },
89723+ { 4U, 984847254U },
89724+};
89725+
89726+static struct prandom_test2 {
89727+ u32 seed;
89728+ u32 iteration;
89729+ u32 result;
89730+} test2[] = {
89731+ /* Test cases against taus113 from GSL library. */
89732+ { 931557656U, 959U, 2975593782U },
89733+ { 1339693295U, 876U, 3887776532U },
89734+ { 1545556285U, 961U, 1615538833U },
89735+ { 601730776U, 723U, 1776162651U },
89736+ { 1027516047U, 687U, 511983079U },
89737+ { 416526298U, 700U, 916156552U },
89738+ { 1395522032U, 652U, 2222063676U },
89739+ { 366221443U, 617U, 2992857763U },
89740+ { 1539836965U, 714U, 3783265725U },
89741+ { 556206671U, 994U, 799626459U },
89742+ { 684907218U, 799U, 367789491U },
89743+ { 2121230701U, 931U, 2115467001U },
89744+ { 1668516451U, 644U, 3620590685U },
89745+ { 768046066U, 883U, 2034077390U },
89746+ { 1989159136U, 833U, 1195767305U },
89747+ { 536585145U, 996U, 3577259204U },
89748+ { 1008129373U, 642U, 1478080776U },
89749+ { 1740775604U, 939U, 1264980372U },
89750+ { 1967883163U, 508U, 10734624U },
89751+ { 1923019697U, 730U, 3821419629U },
89752+ { 442079932U, 560U, 3440032343U },
89753+ { 1961302714U, 845U, 841962572U },
89754+ { 2030205964U, 962U, 1325144227U },
89755+ { 1160407529U, 507U, 240940858U },
89756+ { 635482502U, 779U, 4200489746U },
89757+ { 1252788931U, 699U, 867195434U },
89758+ { 1961817131U, 719U, 668237657U },
89759+ { 1071468216U, 983U, 917876630U },
89760+ { 1281848367U, 932U, 1003100039U },
89761+ { 582537119U, 780U, 1127273778U },
89762+ { 1973672777U, 853U, 1071368872U },
89763+ { 1896756996U, 762U, 1127851055U },
89764+ { 847917054U, 500U, 1717499075U },
89765+ { 1240520510U, 951U, 2849576657U },
89766+ { 1685071682U, 567U, 1961810396U },
89767+ { 1516232129U, 557U, 3173877U },
89768+ { 1208118903U, 612U, 1613145022U },
89769+ { 1817269927U, 693U, 4279122573U },
89770+ { 1510091701U, 717U, 638191229U },
89771+ { 365916850U, 807U, 600424314U },
89772+ { 399324359U, 702U, 1803598116U },
89773+ { 1318480274U, 779U, 2074237022U },
89774+ { 697758115U, 840U, 1483639402U },
89775+ { 1696507773U, 840U, 577415447U },
89776+ { 2081979121U, 981U, 3041486449U },
89777+ { 955646687U, 742U, 3846494357U },
89778+ { 1250683506U, 749U, 836419859U },
89779+ { 595003102U, 534U, 366794109U },
89780+ { 47485338U, 558U, 3521120834U },
89781+ { 619433479U, 610U, 3991783875U },
89782+ { 704096520U, 518U, 4139493852U },
89783+ { 1712224984U, 606U, 2393312003U },
89784+ { 1318233152U, 922U, 3880361134U },
89785+ { 855572992U, 761U, 1472974787U },
89786+ { 64721421U, 703U, 683860550U },
89787+ { 678931758U, 840U, 380616043U },
89788+ { 692711973U, 778U, 1382361947U },
89789+ { 677703619U, 530U, 2826914161U },
89790+ { 92393223U, 586U, 1522128471U },
89791+ { 1222592920U, 743U, 3466726667U },
89792+ { 358288986U, 695U, 1091956998U },
89793+ { 1935056945U, 958U, 514864477U },
89794+ { 735675993U, 990U, 1294239989U },
89795+ { 1560089402U, 897U, 2238551287U },
89796+ { 70616361U, 829U, 22483098U },
89797+ { 368234700U, 731U, 2913875084U },
89798+ { 20221190U, 879U, 1564152970U },
89799+ { 539444654U, 682U, 1835141259U },
89800+ { 1314987297U, 840U, 1801114136U },
89801+ { 2019295544U, 645U, 3286438930U },
89802+ { 469023838U, 716U, 1637918202U },
89803+ { 1843754496U, 653U, 2562092152U },
89804+ { 400672036U, 809U, 4264212785U },
89805+ { 404722249U, 965U, 2704116999U },
89806+ { 600702209U, 758U, 584979986U },
89807+ { 519953954U, 667U, 2574436237U },
89808+ { 1658071126U, 694U, 2214569490U },
89809+ { 420480037U, 749U, 3430010866U },
89810+ { 690103647U, 969U, 3700758083U },
89811+ { 1029424799U, 937U, 3787746841U },
89812+ { 2012608669U, 506U, 3362628973U },
89813+ { 1535432887U, 998U, 42610943U },
89814+ { 1330635533U, 857U, 3040806504U },
89815+ { 1223800550U, 539U, 3954229517U },
89816+ { 1322411537U, 680U, 3223250324U },
89817+ { 1877847898U, 945U, 2915147143U },
89818+ { 1646356099U, 874U, 965988280U },
89819+ { 805687536U, 744U, 4032277920U },
89820+ { 1948093210U, 633U, 1346597684U },
89821+ { 392609744U, 783U, 1636083295U },
89822+ { 690241304U, 770U, 1201031298U },
89823+ { 1360302965U, 696U, 1665394461U },
89824+ { 1220090946U, 780U, 1316922812U },
89825+ { 447092251U, 500U, 3438743375U },
89826+ { 1613868791U, 592U, 828546883U },
89827+ { 523430951U, 548U, 2552392304U },
89828+ { 726692899U, 810U, 1656872867U },
89829+ { 1364340021U, 836U, 3710513486U },
89830+ { 1986257729U, 931U, 935013962U },
89831+ { 407983964U, 921U, 728767059U },
89832+};
89833+
89834+static void __init prandom_state_selftest(void)
89835+{
89836+ int i, j, errors = 0, runs = 0;
89837+ bool error = false;
89838+
89839+ for (i = 0; i < ARRAY_SIZE(test1); i++) {
89840+ struct rnd_state state;
89841+
89842+ prandom_seed_very_weak(&state, test1[i].seed);
89843+ prandom_warmup(&state);
89844+
89845+ if (test1[i].result != prandom_u32_state(&state))
89846+ error = true;
89847+ }
89848+
89849+ if (error)
89850+ pr_warn("prandom: seed boundary self test failed\n");
89851+ else
89852+ pr_info("prandom: seed boundary self test passed\n");
89853+
89854+ for (i = 0; i < ARRAY_SIZE(test2); i++) {
89855+ struct rnd_state state;
89856+
89857+ prandom_seed_very_weak(&state, test2[i].seed);
89858+ prandom_warmup(&state);
89859+
89860+ for (j = 0; j < test2[i].iteration - 1; j++)
89861+ prandom_u32_state(&state);
89862+
89863+ if (test2[i].result != prandom_u32_state(&state))
89864+ errors++;
89865+
89866+ runs++;
89867+ cond_resched();
89868+ }
89869+
89870+ if (errors)
89871+ pr_warn("prandom: %d/%d self tests failed\n", errors, runs);
89872+ else
89873+ pr_info("prandom: %d self tests passed\n", runs);
89874+}
89875+#endif
89876diff --git a/lib/rbtree.c b/lib/rbtree.c
89877index 65f4eff..2cfa167 100644
89878--- a/lib/rbtree.c
89879+++ b/lib/rbtree.c
89880@@ -380,7 +380,9 @@ static inline void dummy_copy(struct rb_node *old, struct rb_node *new) {}
89881 static inline void dummy_rotate(struct rb_node *old, struct rb_node *new) {}
89882
89883 static const struct rb_augment_callbacks dummy_callbacks = {
89884- dummy_propagate, dummy_copy, dummy_rotate
89885+ .propagate = dummy_propagate,
89886+ .copy = dummy_copy,
89887+ .rotate = dummy_rotate
89888 };
89889
89890 void rb_insert_color(struct rb_node *node, struct rb_root *root)
89891diff --git a/lib/strncpy_from_user.c b/lib/strncpy_from_user.c
89892index bb2b201..46abaf9 100644
89893--- a/lib/strncpy_from_user.c
89894+++ b/lib/strncpy_from_user.c
89895@@ -21,7 +21,7 @@
89896 */
89897 static inline long do_strncpy_from_user(char *dst, const char __user *src, long count, unsigned long max)
89898 {
89899- const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
89900+ static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
89901 long res = 0;
89902
89903 /*
89904diff --git a/lib/strnlen_user.c b/lib/strnlen_user.c
89905index a28df52..3d55877 100644
89906--- a/lib/strnlen_user.c
89907+++ b/lib/strnlen_user.c
89908@@ -26,7 +26,7 @@
89909 */
89910 static inline long do_strnlen_user(const char __user *src, unsigned long count, unsigned long max)
89911 {
89912- const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
89913+ static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
89914 long align, res = 0;
89915 unsigned long c;
89916
89917diff --git a/lib/swiotlb.c b/lib/swiotlb.c
89918index 4e8686c..3e8c92f 100644
89919--- a/lib/swiotlb.c
89920+++ b/lib/swiotlb.c
89921@@ -664,7 +664,7 @@ EXPORT_SYMBOL(swiotlb_alloc_coherent);
89922
89923 void
89924 swiotlb_free_coherent(struct device *hwdev, size_t size, void *vaddr,
89925- dma_addr_t dev_addr)
89926+ dma_addr_t dev_addr, struct dma_attrs *attrs)
89927 {
89928 phys_addr_t paddr = dma_to_phys(hwdev, dev_addr);
89929
89930diff --git a/lib/usercopy.c b/lib/usercopy.c
89931index 4f5b1dd..7cab418 100644
89932--- a/lib/usercopy.c
89933+++ b/lib/usercopy.c
89934@@ -7,3 +7,9 @@ void copy_from_user_overflow(void)
89935 WARN(1, "Buffer overflow detected!\n");
89936 }
89937 EXPORT_SYMBOL(copy_from_user_overflow);
89938+
89939+void copy_to_user_overflow(void)
89940+{
89941+ WARN(1, "Buffer overflow detected!\n");
89942+}
89943+EXPORT_SYMBOL(copy_to_user_overflow);
89944diff --git a/lib/vsprintf.c b/lib/vsprintf.c
89945index d76555c..62d4bfe 100644
89946--- a/lib/vsprintf.c
89947+++ b/lib/vsprintf.c
89948@@ -16,6 +16,9 @@
89949 * - scnprintf and vscnprintf
89950 */
89951
89952+#ifdef CONFIG_GRKERNSEC_HIDESYM
89953+#define __INCLUDED_BY_HIDESYM 1
89954+#endif
89955 #include <stdarg.h>
89956 #include <linux/module.h> /* for KSYM_SYMBOL_LEN */
89957 #include <linux/types.h>
89958@@ -1155,7 +1158,11 @@ char *netdev_feature_string(char *buf, char *end, const u8 *addr,
89959 return number(buf, end, *(const netdev_features_t *)addr, spec);
89960 }
89961
89962+#ifdef CONFIG_GRKERNSEC_HIDESYM
89963+int kptr_restrict __read_mostly = 2;
89964+#else
89965 int kptr_restrict __read_mostly;
89966+#endif
89967
89968 /*
89969 * Show a '%p' thing. A kernel extension is that the '%p' is followed
89970@@ -1168,6 +1175,7 @@ int kptr_restrict __read_mostly;
89971 * - 'f' For simple symbolic function names without offset
89972 * - 'S' For symbolic direct pointers with offset
89973 * - 's' For symbolic direct pointers without offset
89974+ * - 'A' For symbolic direct pointers with offset approved for use with GRKERNSEC_HIDESYM
89975 * - '[FfSs]R' as above with __builtin_extract_return_addr() translation
89976 * - 'B' For backtraced symbolic direct pointers with offset
89977 * - 'R' For decoded struct resource, e.g., [mem 0x0-0x1f 64bit pref]
89978@@ -1232,12 +1240,12 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
89979
89980 if (!ptr && *fmt != 'K') {
89981 /*
89982- * Print (null) with the same width as a pointer so it makes
89983+ * Print (nil) with the same width as a pointer so it makes
89984 * tabular output look nice.
89985 */
89986 if (spec.field_width == -1)
89987 spec.field_width = default_width;
89988- return string(buf, end, "(null)", spec);
89989+ return string(buf, end, "(nil)", spec);
89990 }
89991
89992 switch (*fmt) {
89993@@ -1247,6 +1255,12 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
89994 /* Fallthrough */
89995 case 'S':
89996 case 's':
89997+#ifdef CONFIG_GRKERNSEC_HIDESYM
89998+ break;
89999+#else
90000+ return symbol_string(buf, end, ptr, spec, fmt);
90001+#endif
90002+ case 'A':
90003 case 'B':
90004 return symbol_string(buf, end, ptr, spec, fmt);
90005 case 'R':
90006@@ -1302,6 +1316,8 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
90007 va_end(va);
90008 return buf;
90009 }
90010+ case 'P':
90011+ break;
90012 case 'K':
90013 /*
90014 * %pK cannot be used in IRQ context because its test
90015@@ -1363,6 +1379,21 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
90016 ((const struct file *)ptr)->f_path.dentry,
90017 spec, fmt);
90018 }
90019+
90020+#ifdef CONFIG_GRKERNSEC_HIDESYM
90021+ /* 'P' = approved pointers to copy to userland,
90022+ as in the /proc/kallsyms case, as we make it display nothing
90023+ for non-root users, and the real contents for root users
90024+ Also ignore 'K' pointers, since we force their NULLing for non-root users
90025+ above
90026+ */
90027+ if ((unsigned long)ptr > TASK_SIZE && *fmt != 'P' && *fmt != 'K' && is_usercopy_object(buf)) {
90028+ printk(KERN_ALERT "grsec: kernel infoleak detected! Please report this log to spender@grsecurity.net.\n");
90029+ dump_stack();
90030+ ptr = NULL;
90031+ }
90032+#endif
90033+
90034 spec.flags |= SMALL;
90035 if (spec.field_width == -1) {
90036 spec.field_width = default_width;
90037@@ -2086,11 +2117,11 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
90038 typeof(type) value; \
90039 if (sizeof(type) == 8) { \
90040 args = PTR_ALIGN(args, sizeof(u32)); \
90041- *(u32 *)&value = *(u32 *)args; \
90042- *((u32 *)&value + 1) = *(u32 *)(args + 4); \
90043+ *(u32 *)&value = *(const u32 *)args; \
90044+ *((u32 *)&value + 1) = *(const u32 *)(args + 4); \
90045 } else { \
90046 args = PTR_ALIGN(args, sizeof(type)); \
90047- value = *(typeof(type) *)args; \
90048+ value = *(const typeof(type) *)args; \
90049 } \
90050 args += sizeof(type); \
90051 value; \
90052@@ -2153,7 +2184,7 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
90053 case FORMAT_TYPE_STR: {
90054 const char *str_arg = args;
90055 args += strlen(str_arg) + 1;
90056- str = string(str, end, (char *)str_arg, spec);
90057+ str = string(str, end, str_arg, spec);
90058 break;
90059 }
90060
90061diff --git a/localversion-grsec b/localversion-grsec
90062new file mode 100644
90063index 0000000..7cd6065
90064--- /dev/null
90065+++ b/localversion-grsec
90066@@ -0,0 +1 @@
90067+-grsec
90068diff --git a/mm/Kconfig b/mm/Kconfig
90069index 394838f..0e5f816 100644
90070--- a/mm/Kconfig
90071+++ b/mm/Kconfig
90072@@ -317,10 +317,11 @@ config KSM
90073 root has set /sys/kernel/mm/ksm/run to 1 (if CONFIG_SYSFS is set).
90074
90075 config DEFAULT_MMAP_MIN_ADDR
90076- int "Low address space to protect from user allocation"
90077+ int "Low address space to protect from user allocation"
90078 depends on MMU
90079- default 4096
90080- help
90081+ default 32768 if ALPHA || ARM || PARISC || SPARC32
90082+ default 65536
90083+ help
90084 This is the portion of low virtual memory which should be protected
90085 from userspace allocation. Keeping a user from writing to low pages
90086 can help reduce the impact of kernel NULL pointer bugs.
90087@@ -351,7 +352,7 @@ config MEMORY_FAILURE
90088
90089 config HWPOISON_INJECT
90090 tristate "HWPoison pages injector"
90091- depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS
90092+ depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS && !GRKERNSEC
90093 select PROC_PAGE_MONITOR
90094
90095 config NOMMU_INITIAL_TRIM_EXCESS
90096diff --git a/mm/backing-dev.c b/mm/backing-dev.c
90097index ce682f7..1fb54f9 100644
90098--- a/mm/backing-dev.c
90099+++ b/mm/backing-dev.c
90100@@ -12,7 +12,7 @@
90101 #include <linux/device.h>
90102 #include <trace/events/writeback.h>
90103
90104-static atomic_long_t bdi_seq = ATOMIC_LONG_INIT(0);
90105+static atomic_long_unchecked_t bdi_seq = ATOMIC_LONG_INIT(0);
90106
90107 struct backing_dev_info default_backing_dev_info = {
90108 .name = "default",
90109@@ -525,7 +525,7 @@ int bdi_setup_and_register(struct backing_dev_info *bdi, char *name,
90110 return err;
90111
90112 err = bdi_register(bdi, NULL, "%.28s-%ld", name,
90113- atomic_long_inc_return(&bdi_seq));
90114+ atomic_long_inc_return_unchecked(&bdi_seq));
90115 if (err) {
90116 bdi_destroy(bdi);
90117 return err;
90118diff --git a/mm/filemap.c b/mm/filemap.c
90119index ae4846f..b0acebe 100644
90120--- a/mm/filemap.c
90121+++ b/mm/filemap.c
90122@@ -1768,7 +1768,7 @@ int generic_file_mmap(struct file * file, struct vm_area_struct * vma)
90123 struct address_space *mapping = file->f_mapping;
90124
90125 if (!mapping->a_ops->readpage)
90126- return -ENOEXEC;
90127+ return -ENODEV;
90128 file_accessed(file);
90129 vma->vm_ops = &generic_file_vm_ops;
90130 return 0;
90131@@ -1950,7 +1950,7 @@ static size_t __iovec_copy_from_user_inatomic(char *vaddr,
90132
90133 while (bytes) {
90134 char __user *buf = iov->iov_base + base;
90135- int copy = min(bytes, iov->iov_len - base);
90136+ size_t copy = min(bytes, iov->iov_len - base);
90137
90138 base = 0;
90139 left = __copy_from_user_inatomic(vaddr, buf, copy);
90140@@ -1979,7 +1979,7 @@ size_t iov_iter_copy_from_user_atomic(struct page *page,
90141 BUG_ON(!in_atomic());
90142 kaddr = kmap_atomic(page);
90143 if (likely(i->nr_segs == 1)) {
90144- int left;
90145+ size_t left;
90146 char __user *buf = i->iov->iov_base + i->iov_offset;
90147 left = __copy_from_user_inatomic(kaddr + offset, buf, bytes);
90148 copied = bytes - left;
90149@@ -2007,7 +2007,7 @@ size_t iov_iter_copy_from_user(struct page *page,
90150
90151 kaddr = kmap(page);
90152 if (likely(i->nr_segs == 1)) {
90153- int left;
90154+ size_t left;
90155 char __user *buf = i->iov->iov_base + i->iov_offset;
90156 left = __copy_from_user(kaddr + offset, buf, bytes);
90157 copied = bytes - left;
90158@@ -2037,7 +2037,7 @@ void iov_iter_advance(struct iov_iter *i, size_t bytes)
90159 * zero-length segments (without overruning the iovec).
90160 */
90161 while (bytes || unlikely(i->count && !iov->iov_len)) {
90162- int copy;
90163+ size_t copy;
90164
90165 copy = min(bytes, iov->iov_len - base);
90166 BUG_ON(!i->count || i->count < copy);
90167@@ -2108,6 +2108,7 @@ inline int generic_write_checks(struct file *file, loff_t *pos, size_t *count, i
90168 *pos = i_size_read(inode);
90169
90170 if (limit != RLIM_INFINITY) {
90171+ gr_learn_resource(current, RLIMIT_FSIZE,*pos, 0);
90172 if (*pos >= limit) {
90173 send_sig(SIGXFSZ, current, 0);
90174 return -EFBIG;
90175diff --git a/mm/fremap.c b/mm/fremap.c
90176index bbc4d66..117b798 100644
90177--- a/mm/fremap.c
90178+++ b/mm/fremap.c
90179@@ -163,6 +163,11 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
90180 retry:
90181 vma = find_vma(mm, start);
90182
90183+#ifdef CONFIG_PAX_SEGMEXEC
90184+ if (vma && (mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_MAYEXEC))
90185+ goto out;
90186+#endif
90187+
90188 /*
90189 * Make sure the vma is shared, that it supports prefaulting,
90190 * and that the remapped range is valid and fully within
90191diff --git a/mm/highmem.c b/mm/highmem.c
90192index b32b70c..e512eb0 100644
90193--- a/mm/highmem.c
90194+++ b/mm/highmem.c
90195@@ -138,8 +138,9 @@ static void flush_all_zero_pkmaps(void)
90196 * So no dangers, even with speculative execution.
90197 */
90198 page = pte_page(pkmap_page_table[i]);
90199+ pax_open_kernel();
90200 pte_clear(&init_mm, PKMAP_ADDR(i), &pkmap_page_table[i]);
90201-
90202+ pax_close_kernel();
90203 set_page_address(page, NULL);
90204 need_flush = 1;
90205 }
90206@@ -198,9 +199,11 @@ start:
90207 }
90208 }
90209 vaddr = PKMAP_ADDR(last_pkmap_nr);
90210+
90211+ pax_open_kernel();
90212 set_pte_at(&init_mm, vaddr,
90213 &(pkmap_page_table[last_pkmap_nr]), mk_pte(page, kmap_prot));
90214-
90215+ pax_close_kernel();
90216 pkmap_count[last_pkmap_nr] = 1;
90217 set_page_address(page, (void *)vaddr);
90218
90219diff --git a/mm/huge_memory.c b/mm/huge_memory.c
90220index 4796245..292a266 100644
90221--- a/mm/huge_memory.c
90222+++ b/mm/huge_memory.c
90223@@ -1154,7 +1154,7 @@ alloc:
90224 new_page = NULL;
90225
90226 if (unlikely(!new_page)) {
90227- if (is_huge_zero_pmd(orig_pmd)) {
90228+ if (!page) {
90229 ret = do_huge_pmd_wp_zero_page_fallback(mm, vma,
90230 address, pmd, orig_pmd, haddr);
90231 } else {
90232@@ -1181,7 +1181,7 @@ alloc:
90233
90234 count_vm_event(THP_FAULT_ALLOC);
90235
90236- if (is_huge_zero_pmd(orig_pmd))
90237+ if (!page)
90238 clear_huge_page(new_page, haddr, HPAGE_PMD_NR);
90239 else
90240 copy_user_huge_page(new_page, page, haddr, vma, HPAGE_PMD_NR);
90241@@ -1207,7 +1207,7 @@ alloc:
90242 page_add_new_anon_rmap(new_page, vma, haddr);
90243 set_pmd_at(mm, haddr, pmd, entry);
90244 update_mmu_cache_pmd(vma, address, pmd);
90245- if (is_huge_zero_pmd(orig_pmd)) {
90246+ if (!page) {
90247 add_mm_counter(mm, MM_ANONPAGES, HPAGE_PMD_NR);
90248 put_huge_zero_page();
90249 } else {
90250diff --git a/mm/hugetlb.c b/mm/hugetlb.c
90251index 0b7656e..d21cefc 100644
90252--- a/mm/hugetlb.c
90253+++ b/mm/hugetlb.c
90254@@ -2094,15 +2094,17 @@ static int hugetlb_sysctl_handler_common(bool obey_mempolicy,
90255 struct hstate *h = &default_hstate;
90256 unsigned long tmp;
90257 int ret;
90258+ ctl_table_no_const hugetlb_table;
90259
90260 tmp = h->max_huge_pages;
90261
90262 if (write && h->order >= MAX_ORDER)
90263 return -EINVAL;
90264
90265- table->data = &tmp;
90266- table->maxlen = sizeof(unsigned long);
90267- ret = proc_doulongvec_minmax(table, write, buffer, length, ppos);
90268+ hugetlb_table = *table;
90269+ hugetlb_table.data = &tmp;
90270+ hugetlb_table.maxlen = sizeof(unsigned long);
90271+ ret = proc_doulongvec_minmax(&hugetlb_table, write, buffer, length, ppos);
90272 if (ret)
90273 goto out;
90274
90275@@ -2147,15 +2149,17 @@ int hugetlb_overcommit_handler(struct ctl_table *table, int write,
90276 struct hstate *h = &default_hstate;
90277 unsigned long tmp;
90278 int ret;
90279+ ctl_table_no_const hugetlb_table;
90280
90281 tmp = h->nr_overcommit_huge_pages;
90282
90283 if (write && h->order >= MAX_ORDER)
90284 return -EINVAL;
90285
90286- table->data = &tmp;
90287- table->maxlen = sizeof(unsigned long);
90288- ret = proc_doulongvec_minmax(table, write, buffer, length, ppos);
90289+ hugetlb_table = *table;
90290+ hugetlb_table.data = &tmp;
90291+ hugetlb_table.maxlen = sizeof(unsigned long);
90292+ ret = proc_doulongvec_minmax(&hugetlb_table, write, buffer, length, ppos);
90293 if (ret)
90294 goto out;
90295
90296@@ -2605,6 +2609,27 @@ static int unmap_ref_private(struct mm_struct *mm, struct vm_area_struct *vma,
90297 return 1;
90298 }
90299
90300+#ifdef CONFIG_PAX_SEGMEXEC
90301+static void pax_mirror_huge_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m)
90302+{
90303+ struct mm_struct *mm = vma->vm_mm;
90304+ struct vm_area_struct *vma_m;
90305+ unsigned long address_m;
90306+ pte_t *ptep_m;
90307+
90308+ vma_m = pax_find_mirror_vma(vma);
90309+ if (!vma_m)
90310+ return;
90311+
90312+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
90313+ address_m = address + SEGMEXEC_TASK_SIZE;
90314+ ptep_m = huge_pte_offset(mm, address_m & HPAGE_MASK);
90315+ get_page(page_m);
90316+ hugepage_add_anon_rmap(page_m, vma_m, address_m);
90317+ set_huge_pte_at(mm, address_m, ptep_m, make_huge_pte(vma_m, page_m, 0));
90318+}
90319+#endif
90320+
90321 /*
90322 * Hugetlb_cow() should be called with page lock of the original hugepage held.
90323 * Called with hugetlb_instantiation_mutex held and pte_page locked so we
90324@@ -2721,6 +2746,11 @@ retry_avoidcopy:
90325 make_huge_pte(vma, new_page, 1));
90326 page_remove_rmap(old_page);
90327 hugepage_add_new_anon_rmap(new_page, vma, address);
90328+
90329+#ifdef CONFIG_PAX_SEGMEXEC
90330+ pax_mirror_huge_pte(vma, address, new_page);
90331+#endif
90332+
90333 /* Make the old page be freed below */
90334 new_page = old_page;
90335 }
90336@@ -2883,6 +2913,10 @@ retry:
90337 && (vma->vm_flags & VM_SHARED)));
90338 set_huge_pte_at(mm, address, ptep, new_pte);
90339
90340+#ifdef CONFIG_PAX_SEGMEXEC
90341+ pax_mirror_huge_pte(vma, address, page);
90342+#endif
90343+
90344 if ((flags & FAULT_FLAG_WRITE) && !(vma->vm_flags & VM_SHARED)) {
90345 /* Optimization, do the COW without a second fault */
90346 ret = hugetlb_cow(mm, vma, address, ptep, new_pte, page);
90347@@ -2912,6 +2946,10 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
90348 static DEFINE_MUTEX(hugetlb_instantiation_mutex);
90349 struct hstate *h = hstate_vma(vma);
90350
90351+#ifdef CONFIG_PAX_SEGMEXEC
90352+ struct vm_area_struct *vma_m;
90353+#endif
90354+
90355 address &= huge_page_mask(h);
90356
90357 ptep = huge_pte_offset(mm, address);
90358@@ -2925,6 +2963,26 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
90359 VM_FAULT_SET_HINDEX(hstate_index(h));
90360 }
90361
90362+#ifdef CONFIG_PAX_SEGMEXEC
90363+ vma_m = pax_find_mirror_vma(vma);
90364+ if (vma_m) {
90365+ unsigned long address_m;
90366+
90367+ if (vma->vm_start > vma_m->vm_start) {
90368+ address_m = address;
90369+ address -= SEGMEXEC_TASK_SIZE;
90370+ vma = vma_m;
90371+ h = hstate_vma(vma);
90372+ } else
90373+ address_m = address + SEGMEXEC_TASK_SIZE;
90374+
90375+ if (!huge_pte_alloc(mm, address_m, huge_page_size(h)))
90376+ return VM_FAULT_OOM;
90377+ address_m &= HPAGE_MASK;
90378+ unmap_hugepage_range(vma, address_m, address_m + HPAGE_SIZE, NULL);
90379+ }
90380+#endif
90381+
90382 ptep = huge_pte_alloc(mm, address, huge_page_size(h));
90383 if (!ptep)
90384 return VM_FAULT_OOM;
90385diff --git a/mm/internal.h b/mm/internal.h
90386index 684f7aa..9eb9edc 100644
90387--- a/mm/internal.h
90388+++ b/mm/internal.h
90389@@ -97,6 +97,7 @@ extern pmd_t *mm_find_pmd(struct mm_struct *mm, unsigned long address);
90390 * in mm/page_alloc.c
90391 */
90392 extern void __free_pages_bootmem(struct page *page, unsigned int order);
90393+extern void free_compound_page(struct page *page);
90394 extern void prep_compound_page(struct page *page, unsigned long order);
90395 #ifdef CONFIG_MEMORY_FAILURE
90396 extern bool is_free_buddy_page(struct page *page);
90397@@ -352,7 +353,7 @@ extern u32 hwpoison_filter_enable;
90398
90399 extern unsigned long vm_mmap_pgoff(struct file *, unsigned long,
90400 unsigned long, unsigned long,
90401- unsigned long, unsigned long);
90402+ unsigned long, unsigned long) __intentional_overflow(-1);
90403
90404 extern void set_pageblock_order(void);
90405 unsigned long reclaim_clean_pages_from_list(struct zone *zone,
90406diff --git a/mm/kmemleak.c b/mm/kmemleak.c
90407index e126b0e..e986018 100644
90408--- a/mm/kmemleak.c
90409+++ b/mm/kmemleak.c
90410@@ -363,7 +363,7 @@ static void print_unreferenced(struct seq_file *seq,
90411
90412 for (i = 0; i < object->trace_len; i++) {
90413 void *ptr = (void *)object->trace[i];
90414- seq_printf(seq, " [<%p>] %pS\n", ptr, ptr);
90415+ seq_printf(seq, " [<%pP>] %pA\n", ptr, ptr);
90416 }
90417 }
90418
90419@@ -1851,7 +1851,7 @@ static int __init kmemleak_late_init(void)
90420 return -ENOMEM;
90421 }
90422
90423- dentry = debugfs_create_file("kmemleak", S_IRUGO, NULL, NULL,
90424+ dentry = debugfs_create_file("kmemleak", S_IRUSR, NULL, NULL,
90425 &kmemleak_fops);
90426 if (!dentry)
90427 pr_warning("Failed to create the debugfs kmemleak file\n");
90428diff --git a/mm/maccess.c b/mm/maccess.c
90429index d53adf9..03a24bf 100644
90430--- a/mm/maccess.c
90431+++ b/mm/maccess.c
90432@@ -26,7 +26,7 @@ long __probe_kernel_read(void *dst, const void *src, size_t size)
90433 set_fs(KERNEL_DS);
90434 pagefault_disable();
90435 ret = __copy_from_user_inatomic(dst,
90436- (__force const void __user *)src, size);
90437+ (const void __force_user *)src, size);
90438 pagefault_enable();
90439 set_fs(old_fs);
90440
90441@@ -53,7 +53,7 @@ long __probe_kernel_write(void *dst, const void *src, size_t size)
90442
90443 set_fs(KERNEL_DS);
90444 pagefault_disable();
90445- ret = __copy_to_user_inatomic((__force void __user *)dst, src, size);
90446+ ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
90447 pagefault_enable();
90448 set_fs(old_fs);
90449
90450diff --git a/mm/madvise.c b/mm/madvise.c
90451index 539eeb9..e24a987 100644
90452--- a/mm/madvise.c
90453+++ b/mm/madvise.c
90454@@ -51,6 +51,10 @@ static long madvise_behavior(struct vm_area_struct *vma,
90455 pgoff_t pgoff;
90456 unsigned long new_flags = vma->vm_flags;
90457
90458+#ifdef CONFIG_PAX_SEGMEXEC
90459+ struct vm_area_struct *vma_m;
90460+#endif
90461+
90462 switch (behavior) {
90463 case MADV_NORMAL:
90464 new_flags = new_flags & ~VM_RAND_READ & ~VM_SEQ_READ;
90465@@ -126,6 +130,13 @@ success:
90466 /*
90467 * vm_flags is protected by the mmap_sem held in write mode.
90468 */
90469+
90470+#ifdef CONFIG_PAX_SEGMEXEC
90471+ vma_m = pax_find_mirror_vma(vma);
90472+ if (vma_m)
90473+ vma_m->vm_flags = new_flags & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT);
90474+#endif
90475+
90476 vma->vm_flags = new_flags;
90477
90478 out:
90479@@ -274,6 +285,11 @@ static long madvise_dontneed(struct vm_area_struct *vma,
90480 struct vm_area_struct **prev,
90481 unsigned long start, unsigned long end)
90482 {
90483+
90484+#ifdef CONFIG_PAX_SEGMEXEC
90485+ struct vm_area_struct *vma_m;
90486+#endif
90487+
90488 *prev = vma;
90489 if (vma->vm_flags & (VM_LOCKED|VM_HUGETLB|VM_PFNMAP))
90490 return -EINVAL;
90491@@ -286,6 +302,21 @@ static long madvise_dontneed(struct vm_area_struct *vma,
90492 zap_page_range(vma, start, end - start, &details);
90493 } else
90494 zap_page_range(vma, start, end - start, NULL);
90495+
90496+#ifdef CONFIG_PAX_SEGMEXEC
90497+ vma_m = pax_find_mirror_vma(vma);
90498+ if (vma_m) {
90499+ if (unlikely(vma->vm_flags & VM_NONLINEAR)) {
90500+ struct zap_details details = {
90501+ .nonlinear_vma = vma_m,
90502+ .last_index = ULONG_MAX,
90503+ };
90504+ zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, &details);
90505+ } else
90506+ zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, NULL);
90507+ }
90508+#endif
90509+
90510 return 0;
90511 }
90512
90513@@ -491,6 +522,16 @@ SYSCALL_DEFINE3(madvise, unsigned long, start, size_t, len_in, int, behavior)
90514 if (end < start)
90515 return error;
90516
90517+#ifdef CONFIG_PAX_SEGMEXEC
90518+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
90519+ if (end > SEGMEXEC_TASK_SIZE)
90520+ return error;
90521+ } else
90522+#endif
90523+
90524+ if (end > TASK_SIZE)
90525+ return error;
90526+
90527 error = 0;
90528 if (end == start)
90529 return error;
90530diff --git a/mm/memory-failure.c b/mm/memory-failure.c
90531index 9aea53f..f239c30 100644
90532--- a/mm/memory-failure.c
90533+++ b/mm/memory-failure.c
90534@@ -61,7 +61,7 @@ int sysctl_memory_failure_early_kill __read_mostly = 0;
90535
90536 int sysctl_memory_failure_recovery __read_mostly = 1;
90537
90538-atomic_long_t num_poisoned_pages __read_mostly = ATOMIC_LONG_INIT(0);
90539+atomic_long_unchecked_t num_poisoned_pages __read_mostly = ATOMIC_LONG_INIT(0);
90540
90541 #if defined(CONFIG_HWPOISON_INJECT) || defined(CONFIG_HWPOISON_INJECT_MODULE)
90542
90543@@ -202,7 +202,7 @@ static int kill_proc(struct task_struct *t, unsigned long addr, int trapno,
90544 pfn, t->comm, t->pid);
90545 si.si_signo = SIGBUS;
90546 si.si_errno = 0;
90547- si.si_addr = (void *)addr;
90548+ si.si_addr = (void __user *)addr;
90549 #ifdef __ARCH_SI_TRAPNO
90550 si.si_trapno = trapno;
90551 #endif
90552@@ -762,7 +762,7 @@ static struct page_state {
90553 unsigned long res;
90554 char *msg;
90555 int (*action)(struct page *p, unsigned long pfn);
90556-} error_states[] = {
90557+} __do_const error_states[] = {
90558 { reserved, reserved, "reserved kernel", me_kernel },
90559 /*
90560 * free pages are specially detected outside this table:
90561@@ -1063,7 +1063,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
90562 nr_pages = 1 << compound_order(hpage);
90563 else /* normal page or thp */
90564 nr_pages = 1;
90565- atomic_long_add(nr_pages, &num_poisoned_pages);
90566+ atomic_long_add_unchecked(nr_pages, &num_poisoned_pages);
90567
90568 /*
90569 * We need/can do nothing about count=0 pages.
90570@@ -1093,7 +1093,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
90571 if (!PageHWPoison(hpage)
90572 || (hwpoison_filter(p) && TestClearPageHWPoison(p))
90573 || (p != hpage && TestSetPageHWPoison(hpage))) {
90574- atomic_long_sub(nr_pages, &num_poisoned_pages);
90575+ atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
90576 return 0;
90577 }
90578 set_page_hwpoison_huge_page(hpage);
90579@@ -1162,7 +1162,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
90580 }
90581 if (hwpoison_filter(p)) {
90582 if (TestClearPageHWPoison(p))
90583- atomic_long_sub(nr_pages, &num_poisoned_pages);
90584+ atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
90585 unlock_page(hpage);
90586 put_page(hpage);
90587 return 0;
90588@@ -1380,7 +1380,7 @@ int unpoison_memory(unsigned long pfn)
90589 return 0;
90590 }
90591 if (TestClearPageHWPoison(p))
90592- atomic_long_dec(&num_poisoned_pages);
90593+ atomic_long_dec_unchecked(&num_poisoned_pages);
90594 pr_info("MCE: Software-unpoisoned free page %#lx\n", pfn);
90595 return 0;
90596 }
90597@@ -1394,7 +1394,7 @@ int unpoison_memory(unsigned long pfn)
90598 */
90599 if (TestClearPageHWPoison(page)) {
90600 pr_info("MCE: Software-unpoisoned page %#lx\n", pfn);
90601- atomic_long_sub(nr_pages, &num_poisoned_pages);
90602+ atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
90603 freeit = 1;
90604 if (PageHuge(page))
90605 clear_page_hwpoison_huge_page(page);
90606@@ -1533,11 +1533,11 @@ static int soft_offline_huge_page(struct page *page, int flags)
90607 if (PageHuge(page)) {
90608 set_page_hwpoison_huge_page(hpage);
90609 dequeue_hwpoisoned_huge_page(hpage);
90610- atomic_long_add(1 << compound_order(hpage),
90611+ atomic_long_add_unchecked(1 << compound_order(hpage),
90612 &num_poisoned_pages);
90613 } else {
90614 SetPageHWPoison(page);
90615- atomic_long_inc(&num_poisoned_pages);
90616+ atomic_long_inc_unchecked(&num_poisoned_pages);
90617 }
90618 }
90619 return ret;
90620@@ -1576,7 +1576,7 @@ static int __soft_offline_page(struct page *page, int flags)
90621 put_page(page);
90622 pr_info("soft_offline: %#lx: invalidated\n", pfn);
90623 SetPageHWPoison(page);
90624- atomic_long_inc(&num_poisoned_pages);
90625+ atomic_long_inc_unchecked(&num_poisoned_pages);
90626 return 0;
90627 }
90628
90629@@ -1621,7 +1621,7 @@ static int __soft_offline_page(struct page *page, int flags)
90630 if (!is_free_buddy_page(page))
90631 pr_info("soft offline: %#lx: page leaked\n",
90632 pfn);
90633- atomic_long_inc(&num_poisoned_pages);
90634+ atomic_long_inc_unchecked(&num_poisoned_pages);
90635 }
90636 } else {
90637 pr_info("soft offline: %#lx: isolation failed: %d, page count %d, type %lx\n",
90638@@ -1682,11 +1682,11 @@ int soft_offline_page(struct page *page, int flags)
90639 if (PageHuge(page)) {
90640 set_page_hwpoison_huge_page(hpage);
90641 dequeue_hwpoisoned_huge_page(hpage);
90642- atomic_long_add(1 << compound_order(hpage),
90643+ atomic_long_add_unchecked(1 << compound_order(hpage),
90644 &num_poisoned_pages);
90645 } else {
90646 SetPageHWPoison(page);
90647- atomic_long_inc(&num_poisoned_pages);
90648+ atomic_long_inc_unchecked(&num_poisoned_pages);
90649 }
90650 }
90651 unset:
90652diff --git a/mm/memory.c b/mm/memory.c
90653index d176154..cd1b387 100644
90654--- a/mm/memory.c
90655+++ b/mm/memory.c
90656@@ -402,6 +402,7 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
90657 free_pte_range(tlb, pmd, addr);
90658 } while (pmd++, addr = next, addr != end);
90659
90660+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_PER_CPU_PGD)
90661 start &= PUD_MASK;
90662 if (start < floor)
90663 return;
90664@@ -416,6 +417,8 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
90665 pmd = pmd_offset(pud, start);
90666 pud_clear(pud);
90667 pmd_free_tlb(tlb, pmd, start);
90668+#endif
90669+
90670 }
90671
90672 static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
90673@@ -435,6 +438,7 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
90674 free_pmd_range(tlb, pud, addr, next, floor, ceiling);
90675 } while (pud++, addr = next, addr != end);
90676
90677+#if !defined(CONFIG_X86_64) || !defined(CONFIG_PAX_PER_CPU_PGD)
90678 start &= PGDIR_MASK;
90679 if (start < floor)
90680 return;
90681@@ -449,6 +453,8 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
90682 pud = pud_offset(pgd, start);
90683 pgd_clear(pgd);
90684 pud_free_tlb(tlb, pud, start);
90685+#endif
90686+
90687 }
90688
90689 /*
90690@@ -1636,12 +1642,6 @@ no_page_table:
90691 return page;
90692 }
90693
90694-static inline int stack_guard_page(struct vm_area_struct *vma, unsigned long addr)
90695-{
90696- return stack_guard_page_start(vma, addr) ||
90697- stack_guard_page_end(vma, addr+PAGE_SIZE);
90698-}
90699-
90700 /**
90701 * __get_user_pages() - pin user pages in memory
90702 * @tsk: task_struct of target task
90703@@ -1728,10 +1728,10 @@ long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
90704
90705 i = 0;
90706
90707- do {
90708+ while (nr_pages) {
90709 struct vm_area_struct *vma;
90710
90711- vma = find_extend_vma(mm, start);
90712+ vma = find_vma(mm, start);
90713 if (!vma && in_gate_area(mm, start)) {
90714 unsigned long pg = start & PAGE_MASK;
90715 pgd_t *pgd;
90716@@ -1780,7 +1780,7 @@ long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
90717 goto next_page;
90718 }
90719
90720- if (!vma ||
90721+ if (!vma || start < vma->vm_start ||
90722 (vma->vm_flags & (VM_IO | VM_PFNMAP)) ||
90723 !(vm_flags & vma->vm_flags))
90724 return i ? : -EFAULT;
90725@@ -1809,11 +1809,6 @@ long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
90726 int ret;
90727 unsigned int fault_flags = 0;
90728
90729- /* For mlock, just skip the stack guard page. */
90730- if (foll_flags & FOLL_MLOCK) {
90731- if (stack_guard_page(vma, start))
90732- goto next_page;
90733- }
90734 if (foll_flags & FOLL_WRITE)
90735 fault_flags |= FAULT_FLAG_WRITE;
90736 if (nonblocking)
90737@@ -1893,7 +1888,7 @@ next_page:
90738 start += page_increm * PAGE_SIZE;
90739 nr_pages -= page_increm;
90740 } while (nr_pages && start < vma->vm_end);
90741- } while (nr_pages);
90742+ }
90743 return i;
90744 }
90745 EXPORT_SYMBOL(__get_user_pages);
90746@@ -2100,6 +2095,10 @@ static int insert_page(struct vm_area_struct *vma, unsigned long addr,
90747 page_add_file_rmap(page);
90748 set_pte_at(mm, addr, pte, mk_pte(page, prot));
90749
90750+#ifdef CONFIG_PAX_SEGMEXEC
90751+ pax_mirror_file_pte(vma, addr, page, ptl);
90752+#endif
90753+
90754 retval = 0;
90755 pte_unmap_unlock(pte, ptl);
90756 return retval;
90757@@ -2144,9 +2143,21 @@ int vm_insert_page(struct vm_area_struct *vma, unsigned long addr,
90758 if (!page_count(page))
90759 return -EINVAL;
90760 if (!(vma->vm_flags & VM_MIXEDMAP)) {
90761+
90762+#ifdef CONFIG_PAX_SEGMEXEC
90763+ struct vm_area_struct *vma_m;
90764+#endif
90765+
90766 BUG_ON(down_read_trylock(&vma->vm_mm->mmap_sem));
90767 BUG_ON(vma->vm_flags & VM_PFNMAP);
90768 vma->vm_flags |= VM_MIXEDMAP;
90769+
90770+#ifdef CONFIG_PAX_SEGMEXEC
90771+ vma_m = pax_find_mirror_vma(vma);
90772+ if (vma_m)
90773+ vma_m->vm_flags |= VM_MIXEDMAP;
90774+#endif
90775+
90776 }
90777 return insert_page(vma, addr, page, vma->vm_page_prot);
90778 }
90779@@ -2229,6 +2240,7 @@ int vm_insert_mixed(struct vm_area_struct *vma, unsigned long addr,
90780 unsigned long pfn)
90781 {
90782 BUG_ON(!(vma->vm_flags & VM_MIXEDMAP));
90783+ BUG_ON(vma->vm_mirror);
90784
90785 if (addr < vma->vm_start || addr >= vma->vm_end)
90786 return -EFAULT;
90787@@ -2476,7 +2488,9 @@ static int apply_to_pmd_range(struct mm_struct *mm, pud_t *pud,
90788
90789 BUG_ON(pud_huge(*pud));
90790
90791- pmd = pmd_alloc(mm, pud, addr);
90792+ pmd = (mm == &init_mm) ?
90793+ pmd_alloc_kernel(mm, pud, addr) :
90794+ pmd_alloc(mm, pud, addr);
90795 if (!pmd)
90796 return -ENOMEM;
90797 do {
90798@@ -2496,7 +2510,9 @@ static int apply_to_pud_range(struct mm_struct *mm, pgd_t *pgd,
90799 unsigned long next;
90800 int err;
90801
90802- pud = pud_alloc(mm, pgd, addr);
90803+ pud = (mm == &init_mm) ?
90804+ pud_alloc_kernel(mm, pgd, addr) :
90805+ pud_alloc(mm, pgd, addr);
90806 if (!pud)
90807 return -ENOMEM;
90808 do {
90809@@ -2584,6 +2600,186 @@ static inline void cow_user_page(struct page *dst, struct page *src, unsigned lo
90810 copy_user_highpage(dst, src, va, vma);
90811 }
90812
90813+#ifdef CONFIG_PAX_SEGMEXEC
90814+static void pax_unmap_mirror_pte(struct vm_area_struct *vma, unsigned long address, pmd_t *pmd)
90815+{
90816+ struct mm_struct *mm = vma->vm_mm;
90817+ spinlock_t *ptl;
90818+ pte_t *pte, entry;
90819+
90820+ pte = pte_offset_map_lock(mm, pmd, address, &ptl);
90821+ entry = *pte;
90822+ if (!pte_present(entry)) {
90823+ if (!pte_none(entry)) {
90824+ BUG_ON(pte_file(entry));
90825+ free_swap_and_cache(pte_to_swp_entry(entry));
90826+ pte_clear_not_present_full(mm, address, pte, 0);
90827+ }
90828+ } else {
90829+ struct page *page;
90830+
90831+ flush_cache_page(vma, address, pte_pfn(entry));
90832+ entry = ptep_clear_flush(vma, address, pte);
90833+ BUG_ON(pte_dirty(entry));
90834+ page = vm_normal_page(vma, address, entry);
90835+ if (page) {
90836+ update_hiwater_rss(mm);
90837+ if (PageAnon(page))
90838+ dec_mm_counter_fast(mm, MM_ANONPAGES);
90839+ else
90840+ dec_mm_counter_fast(mm, MM_FILEPAGES);
90841+ page_remove_rmap(page);
90842+ page_cache_release(page);
90843+ }
90844+ }
90845+ pte_unmap_unlock(pte, ptl);
90846+}
90847+
90848+/* PaX: if vma is mirrored, synchronize the mirror's PTE
90849+ *
90850+ * the ptl of the lower mapped page is held on entry and is not released on exit
90851+ * or inside to ensure atomic changes to the PTE states (swapout, mremap, munmap, etc)
90852+ */
90853+static void pax_mirror_anon_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
90854+{
90855+ struct mm_struct *mm = vma->vm_mm;
90856+ unsigned long address_m;
90857+ spinlock_t *ptl_m;
90858+ struct vm_area_struct *vma_m;
90859+ pmd_t *pmd_m;
90860+ pte_t *pte_m, entry_m;
90861+
90862+ BUG_ON(!page_m || !PageAnon(page_m));
90863+
90864+ vma_m = pax_find_mirror_vma(vma);
90865+ if (!vma_m)
90866+ return;
90867+
90868+ BUG_ON(!PageLocked(page_m));
90869+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
90870+ address_m = address + SEGMEXEC_TASK_SIZE;
90871+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
90872+ pte_m = pte_offset_map(pmd_m, address_m);
90873+ ptl_m = pte_lockptr(mm, pmd_m);
90874+ if (ptl != ptl_m) {
90875+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
90876+ if (!pte_none(*pte_m))
90877+ goto out;
90878+ }
90879+
90880+ entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
90881+ page_cache_get(page_m);
90882+ page_add_anon_rmap(page_m, vma_m, address_m);
90883+ inc_mm_counter_fast(mm, MM_ANONPAGES);
90884+ set_pte_at(mm, address_m, pte_m, entry_m);
90885+ update_mmu_cache(vma_m, address_m, pte_m);
90886+out:
90887+ if (ptl != ptl_m)
90888+ spin_unlock(ptl_m);
90889+ pte_unmap(pte_m);
90890+ unlock_page(page_m);
90891+}
90892+
90893+void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
90894+{
90895+ struct mm_struct *mm = vma->vm_mm;
90896+ unsigned long address_m;
90897+ spinlock_t *ptl_m;
90898+ struct vm_area_struct *vma_m;
90899+ pmd_t *pmd_m;
90900+ pte_t *pte_m, entry_m;
90901+
90902+ BUG_ON(!page_m || PageAnon(page_m));
90903+
90904+ vma_m = pax_find_mirror_vma(vma);
90905+ if (!vma_m)
90906+ return;
90907+
90908+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
90909+ address_m = address + SEGMEXEC_TASK_SIZE;
90910+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
90911+ pte_m = pte_offset_map(pmd_m, address_m);
90912+ ptl_m = pte_lockptr(mm, pmd_m);
90913+ if (ptl != ptl_m) {
90914+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
90915+ if (!pte_none(*pte_m))
90916+ goto out;
90917+ }
90918+
90919+ entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
90920+ page_cache_get(page_m);
90921+ page_add_file_rmap(page_m);
90922+ inc_mm_counter_fast(mm, MM_FILEPAGES);
90923+ set_pte_at(mm, address_m, pte_m, entry_m);
90924+ update_mmu_cache(vma_m, address_m, pte_m);
90925+out:
90926+ if (ptl != ptl_m)
90927+ spin_unlock(ptl_m);
90928+ pte_unmap(pte_m);
90929+}
90930+
90931+static void pax_mirror_pfn_pte(struct vm_area_struct *vma, unsigned long address, unsigned long pfn_m, spinlock_t *ptl)
90932+{
90933+ struct mm_struct *mm = vma->vm_mm;
90934+ unsigned long address_m;
90935+ spinlock_t *ptl_m;
90936+ struct vm_area_struct *vma_m;
90937+ pmd_t *pmd_m;
90938+ pte_t *pte_m, entry_m;
90939+
90940+ vma_m = pax_find_mirror_vma(vma);
90941+ if (!vma_m)
90942+ return;
90943+
90944+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
90945+ address_m = address + SEGMEXEC_TASK_SIZE;
90946+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
90947+ pte_m = pte_offset_map(pmd_m, address_m);
90948+ ptl_m = pte_lockptr(mm, pmd_m);
90949+ if (ptl != ptl_m) {
90950+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
90951+ if (!pte_none(*pte_m))
90952+ goto out;
90953+ }
90954+
90955+ entry_m = pfn_pte(pfn_m, vma_m->vm_page_prot);
90956+ set_pte_at(mm, address_m, pte_m, entry_m);
90957+out:
90958+ if (ptl != ptl_m)
90959+ spin_unlock(ptl_m);
90960+ pte_unmap(pte_m);
90961+}
90962+
90963+static void pax_mirror_pte(struct vm_area_struct *vma, unsigned long address, pte_t *pte, pmd_t *pmd, spinlock_t *ptl)
90964+{
90965+ struct page *page_m;
90966+ pte_t entry;
90967+
90968+ if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC))
90969+ goto out;
90970+
90971+ entry = *pte;
90972+ page_m = vm_normal_page(vma, address, entry);
90973+ if (!page_m)
90974+ pax_mirror_pfn_pte(vma, address, pte_pfn(entry), ptl);
90975+ else if (PageAnon(page_m)) {
90976+ if (pax_find_mirror_vma(vma)) {
90977+ pte_unmap_unlock(pte, ptl);
90978+ lock_page(page_m);
90979+ pte = pte_offset_map_lock(vma->vm_mm, pmd, address, &ptl);
90980+ if (pte_same(entry, *pte))
90981+ pax_mirror_anon_pte(vma, address, page_m, ptl);
90982+ else
90983+ unlock_page(page_m);
90984+ }
90985+ } else
90986+ pax_mirror_file_pte(vma, address, page_m, ptl);
90987+
90988+out:
90989+ pte_unmap_unlock(pte, ptl);
90990+}
90991+#endif
90992+
90993 /*
90994 * This routine handles present pages, when users try to write
90995 * to a shared page. It is done by copying the page to a new address
90996@@ -2800,6 +2996,12 @@ gotten:
90997 */
90998 page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
90999 if (likely(pte_same(*page_table, orig_pte))) {
91000+
91001+#ifdef CONFIG_PAX_SEGMEXEC
91002+ if (pax_find_mirror_vma(vma))
91003+ BUG_ON(!trylock_page(new_page));
91004+#endif
91005+
91006 if (old_page) {
91007 if (!PageAnon(old_page)) {
91008 dec_mm_counter_fast(mm, MM_FILEPAGES);
91009@@ -2851,6 +3053,10 @@ gotten:
91010 page_remove_rmap(old_page);
91011 }
91012
91013+#ifdef CONFIG_PAX_SEGMEXEC
91014+ pax_mirror_anon_pte(vma, address, new_page, ptl);
91015+#endif
91016+
91017 /* Free the old page.. */
91018 new_page = old_page;
91019 ret |= VM_FAULT_WRITE;
91020@@ -3128,6 +3334,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
91021 swap_free(entry);
91022 if (vm_swap_full() || (vma->vm_flags & VM_LOCKED) || PageMlocked(page))
91023 try_to_free_swap(page);
91024+
91025+#ifdef CONFIG_PAX_SEGMEXEC
91026+ if ((flags & FAULT_FLAG_WRITE) || !pax_find_mirror_vma(vma))
91027+#endif
91028+
91029 unlock_page(page);
91030 if (page != swapcache) {
91031 /*
91032@@ -3151,6 +3362,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
91033
91034 /* No need to invalidate - it was non-present before */
91035 update_mmu_cache(vma, address, page_table);
91036+
91037+#ifdef CONFIG_PAX_SEGMEXEC
91038+ pax_mirror_anon_pte(vma, address, page, ptl);
91039+#endif
91040+
91041 unlock:
91042 pte_unmap_unlock(page_table, ptl);
91043 out:
91044@@ -3170,40 +3386,6 @@ out_release:
91045 }
91046
91047 /*
91048- * This is like a special single-page "expand_{down|up}wards()",
91049- * except we must first make sure that 'address{-|+}PAGE_SIZE'
91050- * doesn't hit another vma.
91051- */
91052-static inline int check_stack_guard_page(struct vm_area_struct *vma, unsigned long address)
91053-{
91054- address &= PAGE_MASK;
91055- if ((vma->vm_flags & VM_GROWSDOWN) && address == vma->vm_start) {
91056- struct vm_area_struct *prev = vma->vm_prev;
91057-
91058- /*
91059- * Is there a mapping abutting this one below?
91060- *
91061- * That's only ok if it's the same stack mapping
91062- * that has gotten split..
91063- */
91064- if (prev && prev->vm_end == address)
91065- return prev->vm_flags & VM_GROWSDOWN ? 0 : -ENOMEM;
91066-
91067- expand_downwards(vma, address - PAGE_SIZE);
91068- }
91069- if ((vma->vm_flags & VM_GROWSUP) && address + PAGE_SIZE == vma->vm_end) {
91070- struct vm_area_struct *next = vma->vm_next;
91071-
91072- /* As VM_GROWSDOWN but s/below/above/ */
91073- if (next && next->vm_start == address + PAGE_SIZE)
91074- return next->vm_flags & VM_GROWSUP ? 0 : -ENOMEM;
91075-
91076- expand_upwards(vma, address + PAGE_SIZE);
91077- }
91078- return 0;
91079-}
91080-
91081-/*
91082 * We enter with non-exclusive mmap_sem (to exclude vma changes,
91083 * but allow concurrent faults), and pte mapped but not yet locked.
91084 * We return with mmap_sem still held, but pte unmapped and unlocked.
91085@@ -3212,27 +3394,23 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
91086 unsigned long address, pte_t *page_table, pmd_t *pmd,
91087 unsigned int flags)
91088 {
91089- struct page *page;
91090+ struct page *page = NULL;
91091 spinlock_t *ptl;
91092 pte_t entry;
91093
91094- pte_unmap(page_table);
91095-
91096- /* Check if we need to add a guard page to the stack */
91097- if (check_stack_guard_page(vma, address) < 0)
91098- return VM_FAULT_SIGBUS;
91099-
91100- /* Use the zero-page for reads */
91101 if (!(flags & FAULT_FLAG_WRITE)) {
91102 entry = pte_mkspecial(pfn_pte(my_zero_pfn(address),
91103 vma->vm_page_prot));
91104- page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
91105+ ptl = pte_lockptr(mm, pmd);
91106+ spin_lock(ptl);
91107 if (!pte_none(*page_table))
91108 goto unlock;
91109 goto setpte;
91110 }
91111
91112 /* Allocate our own private page. */
91113+ pte_unmap(page_table);
91114+
91115 if (unlikely(anon_vma_prepare(vma)))
91116 goto oom;
91117 page = alloc_zeroed_user_highpage_movable(vma, address);
91118@@ -3256,6 +3434,11 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
91119 if (!pte_none(*page_table))
91120 goto release;
91121
91122+#ifdef CONFIG_PAX_SEGMEXEC
91123+ if (pax_find_mirror_vma(vma))
91124+ BUG_ON(!trylock_page(page));
91125+#endif
91126+
91127 inc_mm_counter_fast(mm, MM_ANONPAGES);
91128 page_add_new_anon_rmap(page, vma, address);
91129 setpte:
91130@@ -3263,6 +3446,12 @@ setpte:
91131
91132 /* No need to invalidate - it was non-present before */
91133 update_mmu_cache(vma, address, page_table);
91134+
91135+#ifdef CONFIG_PAX_SEGMEXEC
91136+ if (page)
91137+ pax_mirror_anon_pte(vma, address, page, ptl);
91138+#endif
91139+
91140 unlock:
91141 pte_unmap_unlock(page_table, ptl);
91142 return 0;
91143@@ -3406,6 +3595,12 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
91144 */
91145 /* Only go through if we didn't race with anybody else... */
91146 if (likely(pte_same(*page_table, orig_pte))) {
91147+
91148+#ifdef CONFIG_PAX_SEGMEXEC
91149+ if (anon && pax_find_mirror_vma(vma))
91150+ BUG_ON(!trylock_page(page));
91151+#endif
91152+
91153 flush_icache_page(vma, page);
91154 entry = mk_pte(page, vma->vm_page_prot);
91155 if (flags & FAULT_FLAG_WRITE)
91156@@ -3427,6 +3622,14 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
91157
91158 /* no need to invalidate: a not-present page won't be cached */
91159 update_mmu_cache(vma, address, page_table);
91160+
91161+#ifdef CONFIG_PAX_SEGMEXEC
91162+ if (anon)
91163+ pax_mirror_anon_pte(vma, address, page, ptl);
91164+ else
91165+ pax_mirror_file_pte(vma, address, page, ptl);
91166+#endif
91167+
91168 } else {
91169 if (cow_page)
91170 mem_cgroup_uncharge_page(cow_page);
91171@@ -3737,6 +3940,12 @@ static int handle_pte_fault(struct mm_struct *mm,
91172 if (flags & FAULT_FLAG_WRITE)
91173 flush_tlb_fix_spurious_fault(vma, address);
91174 }
91175+
91176+#ifdef CONFIG_PAX_SEGMEXEC
91177+ pax_mirror_pte(vma, address, pte, pmd, ptl);
91178+ return 0;
91179+#endif
91180+
91181 unlock:
91182 pte_unmap_unlock(pte, ptl);
91183 return 0;
91184@@ -3753,9 +3962,41 @@ static int __handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
91185 pmd_t *pmd;
91186 pte_t *pte;
91187
91188+#ifdef CONFIG_PAX_SEGMEXEC
91189+ struct vm_area_struct *vma_m;
91190+#endif
91191+
91192 if (unlikely(is_vm_hugetlb_page(vma)))
91193 return hugetlb_fault(mm, vma, address, flags);
91194
91195+#ifdef CONFIG_PAX_SEGMEXEC
91196+ vma_m = pax_find_mirror_vma(vma);
91197+ if (vma_m) {
91198+ unsigned long address_m;
91199+ pgd_t *pgd_m;
91200+ pud_t *pud_m;
91201+ pmd_t *pmd_m;
91202+
91203+ if (vma->vm_start > vma_m->vm_start) {
91204+ address_m = address;
91205+ address -= SEGMEXEC_TASK_SIZE;
91206+ vma = vma_m;
91207+ } else
91208+ address_m = address + SEGMEXEC_TASK_SIZE;
91209+
91210+ pgd_m = pgd_offset(mm, address_m);
91211+ pud_m = pud_alloc(mm, pgd_m, address_m);
91212+ if (!pud_m)
91213+ return VM_FAULT_OOM;
91214+ pmd_m = pmd_alloc(mm, pud_m, address_m);
91215+ if (!pmd_m)
91216+ return VM_FAULT_OOM;
91217+ if (!pmd_present(*pmd_m) && __pte_alloc(mm, vma_m, pmd_m, address_m))
91218+ return VM_FAULT_OOM;
91219+ pax_unmap_mirror_pte(vma_m, address_m, pmd_m);
91220+ }
91221+#endif
91222+
91223 retry:
91224 pgd = pgd_offset(mm, address);
91225 pud = pud_alloc(mm, pgd, address);
91226@@ -3894,6 +4135,23 @@ int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
91227 spin_unlock(&mm->page_table_lock);
91228 return 0;
91229 }
91230+
91231+int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
91232+{
91233+ pud_t *new = pud_alloc_one(mm, address);
91234+ if (!new)
91235+ return -ENOMEM;
91236+
91237+ smp_wmb(); /* See comment in __pte_alloc */
91238+
91239+ spin_lock(&mm->page_table_lock);
91240+ if (pgd_present(*pgd)) /* Another has populated it */
91241+ pud_free(mm, new);
91242+ else
91243+ pgd_populate_kernel(mm, pgd, new);
91244+ spin_unlock(&mm->page_table_lock);
91245+ return 0;
91246+}
91247 #endif /* __PAGETABLE_PUD_FOLDED */
91248
91249 #ifndef __PAGETABLE_PMD_FOLDED
91250@@ -3924,6 +4182,30 @@ int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
91251 spin_unlock(&mm->page_table_lock);
91252 return 0;
91253 }
91254+
91255+int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
91256+{
91257+ pmd_t *new = pmd_alloc_one(mm, address);
91258+ if (!new)
91259+ return -ENOMEM;
91260+
91261+ smp_wmb(); /* See comment in __pte_alloc */
91262+
91263+ spin_lock(&mm->page_table_lock);
91264+#ifndef __ARCH_HAS_4LEVEL_HACK
91265+ if (pud_present(*pud)) /* Another has populated it */
91266+ pmd_free(mm, new);
91267+ else
91268+ pud_populate_kernel(mm, pud, new);
91269+#else
91270+ if (pgd_present(*pud)) /* Another has populated it */
91271+ pmd_free(mm, new);
91272+ else
91273+ pgd_populate_kernel(mm, pud, new);
91274+#endif /* __ARCH_HAS_4LEVEL_HACK */
91275+ spin_unlock(&mm->page_table_lock);
91276+ return 0;
91277+}
91278 #endif /* __PAGETABLE_PMD_FOLDED */
91279
91280 #if !defined(__HAVE_ARCH_GATE_AREA)
91281@@ -3937,7 +4219,7 @@ static int __init gate_vma_init(void)
91282 gate_vma.vm_start = FIXADDR_USER_START;
91283 gate_vma.vm_end = FIXADDR_USER_END;
91284 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
91285- gate_vma.vm_page_prot = __P101;
91286+ gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
91287
91288 return 0;
91289 }
91290@@ -4071,8 +4353,8 @@ out:
91291 return ret;
91292 }
91293
91294-int generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
91295- void *buf, int len, int write)
91296+ssize_t generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
91297+ void *buf, size_t len, int write)
91298 {
91299 resource_size_t phys_addr;
91300 unsigned long prot = 0;
91301@@ -4098,8 +4380,8 @@ EXPORT_SYMBOL_GPL(generic_access_phys);
91302 * Access another process' address space as given in mm. If non-NULL, use the
91303 * given task for page fault accounting.
91304 */
91305-static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
91306- unsigned long addr, void *buf, int len, int write)
91307+static ssize_t __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
91308+ unsigned long addr, void *buf, size_t len, int write)
91309 {
91310 struct vm_area_struct *vma;
91311 void *old_buf = buf;
91312@@ -4107,7 +4389,7 @@ static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
91313 down_read(&mm->mmap_sem);
91314 /* ignore errors, just check how much was successfully transferred */
91315 while (len) {
91316- int bytes, ret, offset;
91317+ ssize_t bytes, ret, offset;
91318 void *maddr;
91319 struct page *page = NULL;
91320
91321@@ -4166,8 +4448,8 @@ static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
91322 *
91323 * The caller must hold a reference on @mm.
91324 */
91325-int access_remote_vm(struct mm_struct *mm, unsigned long addr,
91326- void *buf, int len, int write)
91327+ssize_t access_remote_vm(struct mm_struct *mm, unsigned long addr,
91328+ void *buf, size_t len, int write)
91329 {
91330 return __access_remote_vm(NULL, mm, addr, buf, len, write);
91331 }
91332@@ -4177,11 +4459,11 @@ int access_remote_vm(struct mm_struct *mm, unsigned long addr,
91333 * Source/target buffer must be kernel space,
91334 * Do not walk the page table directly, use get_user_pages
91335 */
91336-int access_process_vm(struct task_struct *tsk, unsigned long addr,
91337- void *buf, int len, int write)
91338+ssize_t access_process_vm(struct task_struct *tsk, unsigned long addr,
91339+ void *buf, size_t len, int write)
91340 {
91341 struct mm_struct *mm;
91342- int ret;
91343+ ssize_t ret;
91344
91345 mm = get_task_mm(tsk);
91346 if (!mm)
91347diff --git a/mm/mempolicy.c b/mm/mempolicy.c
91348index 6b22d8f9..8b5f6cf 100644
91349--- a/mm/mempolicy.c
91350+++ b/mm/mempolicy.c
91351@@ -746,6 +746,10 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
91352 unsigned long vmstart;
91353 unsigned long vmend;
91354
91355+#ifdef CONFIG_PAX_SEGMEXEC
91356+ struct vm_area_struct *vma_m;
91357+#endif
91358+
91359 vma = find_vma(mm, start);
91360 if (!vma || vma->vm_start > start)
91361 return -EFAULT;
91362@@ -789,6 +793,16 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
91363 err = vma_replace_policy(vma, new_pol);
91364 if (err)
91365 goto out;
91366+
91367+#ifdef CONFIG_PAX_SEGMEXEC
91368+ vma_m = pax_find_mirror_vma(vma);
91369+ if (vma_m) {
91370+ err = vma_replace_policy(vma_m, new_pol);
91371+ if (err)
91372+ goto out;
91373+ }
91374+#endif
91375+
91376 }
91377
91378 out:
91379@@ -1252,6 +1266,17 @@ static long do_mbind(unsigned long start, unsigned long len,
91380
91381 if (end < start)
91382 return -EINVAL;
91383+
91384+#ifdef CONFIG_PAX_SEGMEXEC
91385+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
91386+ if (end > SEGMEXEC_TASK_SIZE)
91387+ return -EINVAL;
91388+ } else
91389+#endif
91390+
91391+ if (end > TASK_SIZE)
91392+ return -EINVAL;
91393+
91394 if (end == start)
91395 return 0;
91396
91397@@ -1480,8 +1505,7 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
91398 */
91399 tcred = __task_cred(task);
91400 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
91401- !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
91402- !capable(CAP_SYS_NICE)) {
91403+ !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
91404 rcu_read_unlock();
91405 err = -EPERM;
91406 goto out_put;
91407@@ -1512,6 +1536,15 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
91408 goto out;
91409 }
91410
91411+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
91412+ if (mm != current->mm &&
91413+ (mm->pax_flags & MF_PAX_RANDMMAP || mm->pax_flags & MF_PAX_SEGMEXEC)) {
91414+ mmput(mm);
91415+ err = -EPERM;
91416+ goto out;
91417+ }
91418+#endif
91419+
91420 err = do_migrate_pages(mm, old, new,
91421 capable(CAP_SYS_NICE) ? MPOL_MF_MOVE_ALL : MPOL_MF_MOVE);
91422
91423diff --git a/mm/migrate.c b/mm/migrate.c
91424index e3cf71d..c94506c 100644
91425--- a/mm/migrate.c
91426+++ b/mm/migrate.c
91427@@ -1406,8 +1406,7 @@ SYSCALL_DEFINE6(move_pages, pid_t, pid, unsigned long, nr_pages,
91428 */
91429 tcred = __task_cred(task);
91430 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
91431- !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
91432- !capable(CAP_SYS_NICE)) {
91433+ !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
91434 rcu_read_unlock();
91435 err = -EPERM;
91436 goto out;
91437diff --git a/mm/mlock.c b/mm/mlock.c
91438index 192e6ee..b044449 100644
91439--- a/mm/mlock.c
91440+++ b/mm/mlock.c
91441@@ -14,6 +14,7 @@
91442 #include <linux/pagevec.h>
91443 #include <linux/mempolicy.h>
91444 #include <linux/syscalls.h>
91445+#include <linux/security.h>
91446 #include <linux/sched.h>
91447 #include <linux/export.h>
91448 #include <linux/rmap.h>
91449@@ -588,7 +589,7 @@ static int do_mlock(unsigned long start, size_t len, int on)
91450 {
91451 unsigned long nstart, end, tmp;
91452 struct vm_area_struct * vma, * prev;
91453- int error;
91454+ int error = 0;
91455
91456 VM_BUG_ON(start & ~PAGE_MASK);
91457 VM_BUG_ON(len != PAGE_ALIGN(len));
91458@@ -597,6 +598,9 @@ static int do_mlock(unsigned long start, size_t len, int on)
91459 return -EINVAL;
91460 if (end == start)
91461 return 0;
91462+ if (end > TASK_SIZE)
91463+ return -EINVAL;
91464+
91465 vma = find_vma(current->mm, start);
91466 if (!vma || vma->vm_start > start)
91467 return -ENOMEM;
91468@@ -608,6 +612,11 @@ static int do_mlock(unsigned long start, size_t len, int on)
91469 for (nstart = start ; ; ) {
91470 vm_flags_t newflags;
91471
91472+#ifdef CONFIG_PAX_SEGMEXEC
91473+ if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
91474+ break;
91475+#endif
91476+
91477 /* Here we know that vma->vm_start <= nstart < vma->vm_end. */
91478
91479 newflags = vma->vm_flags & ~VM_LOCKED;
91480@@ -720,6 +729,7 @@ SYSCALL_DEFINE2(mlock, unsigned long, start, size_t, len)
91481 lock_limit >>= PAGE_SHIFT;
91482
91483 /* check against resource limits */
91484+ gr_learn_resource(current, RLIMIT_MEMLOCK, (current->mm->locked_vm << PAGE_SHIFT) + len, 1);
91485 if ((locked <= lock_limit) || capable(CAP_IPC_LOCK))
91486 error = do_mlock(start, len, 1);
91487 up_write(&current->mm->mmap_sem);
91488@@ -754,6 +764,11 @@ static int do_mlockall(int flags)
91489 for (vma = current->mm->mmap; vma ; vma = prev->vm_next) {
91490 vm_flags_t newflags;
91491
91492+#ifdef CONFIG_PAX_SEGMEXEC
91493+ if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
91494+ break;
91495+#endif
91496+
91497 newflags = vma->vm_flags & ~VM_LOCKED;
91498 if (flags & MCL_CURRENT)
91499 newflags |= VM_LOCKED;
91500@@ -787,6 +802,7 @@ SYSCALL_DEFINE1(mlockall, int, flags)
91501 lock_limit >>= PAGE_SHIFT;
91502
91503 ret = -ENOMEM;
91504+ gr_learn_resource(current, RLIMIT_MEMLOCK, current->mm->total_vm << PAGE_SHIFT, 1);
91505 if (!(flags & MCL_CURRENT) || (current->mm->total_vm <= lock_limit) ||
91506 capable(CAP_IPC_LOCK))
91507 ret = do_mlockall(flags);
91508diff --git a/mm/mmap.c b/mm/mmap.c
91509index 362e5f1..8968e02 100644
91510--- a/mm/mmap.c
91511+++ b/mm/mmap.c
91512@@ -36,6 +36,7 @@
91513 #include <linux/sched/sysctl.h>
91514 #include <linux/notifier.h>
91515 #include <linux/memory.h>
91516+#include <linux/random.h>
91517
91518 #include <asm/uaccess.h>
91519 #include <asm/cacheflush.h>
91520@@ -52,6 +53,16 @@
91521 #define arch_rebalance_pgtables(addr, len) (addr)
91522 #endif
91523
91524+static inline void verify_mm_writelocked(struct mm_struct *mm)
91525+{
91526+#if defined(CONFIG_DEBUG_VM) || defined(CONFIG_PAX)
91527+ if (unlikely(down_read_trylock(&mm->mmap_sem))) {
91528+ up_read(&mm->mmap_sem);
91529+ BUG();
91530+ }
91531+#endif
91532+}
91533+
91534 static void unmap_region(struct mm_struct *mm,
91535 struct vm_area_struct *vma, struct vm_area_struct *prev,
91536 unsigned long start, unsigned long end);
91537@@ -71,16 +82,25 @@ static void unmap_region(struct mm_struct *mm,
91538 * x: (no) no x: (no) yes x: (no) yes x: (yes) yes
91539 *
91540 */
91541-pgprot_t protection_map[16] = {
91542+pgprot_t protection_map[16] __read_only = {
91543 __P000, __P001, __P010, __P011, __P100, __P101, __P110, __P111,
91544 __S000, __S001, __S010, __S011, __S100, __S101, __S110, __S111
91545 };
91546
91547-pgprot_t vm_get_page_prot(unsigned long vm_flags)
91548+pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
91549 {
91550- return __pgprot(pgprot_val(protection_map[vm_flags &
91551+ pgprot_t prot = __pgprot(pgprot_val(protection_map[vm_flags &
91552 (VM_READ|VM_WRITE|VM_EXEC|VM_SHARED)]) |
91553 pgprot_val(arch_vm_get_page_prot(vm_flags)));
91554+
91555+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
91556+ if (!(__supported_pte_mask & _PAGE_NX) &&
91557+ (vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC &&
91558+ (vm_flags & (VM_READ | VM_WRITE)))
91559+ prot = __pgprot(pte_val(pte_exprotect(__pte(pgprot_val(prot)))));
91560+#endif
91561+
91562+ return prot;
91563 }
91564 EXPORT_SYMBOL(vm_get_page_prot);
91565
91566@@ -89,6 +109,7 @@ int sysctl_overcommit_ratio __read_mostly = 50; /* default is 50% */
91567 int sysctl_max_map_count __read_mostly = DEFAULT_MAX_MAP_COUNT;
91568 unsigned long sysctl_user_reserve_kbytes __read_mostly = 1UL << 17; /* 128MB */
91569 unsigned long sysctl_admin_reserve_kbytes __read_mostly = 1UL << 13; /* 8MB */
91570+unsigned long sysctl_heap_stack_gap __read_mostly = 64*1024;
91571 /*
91572 * Make sure vm_committed_as in one cacheline and not cacheline shared with
91573 * other variables. It can be updated by several CPUs frequently.
91574@@ -247,6 +268,7 @@ static struct vm_area_struct *remove_vma(struct vm_area_struct *vma)
91575 struct vm_area_struct *next = vma->vm_next;
91576
91577 might_sleep();
91578+ BUG_ON(vma->vm_mirror);
91579 if (vma->vm_ops && vma->vm_ops->close)
91580 vma->vm_ops->close(vma);
91581 if (vma->vm_file)
91582@@ -291,6 +313,7 @@ SYSCALL_DEFINE1(brk, unsigned long, brk)
91583 * not page aligned -Ram Gupta
91584 */
91585 rlim = rlimit(RLIMIT_DATA);
91586+ gr_learn_resource(current, RLIMIT_DATA, (brk - mm->start_brk) + (mm->end_data - mm->start_data), 1);
91587 if (rlim < RLIM_INFINITY && (brk - mm->start_brk) +
91588 (mm->end_data - mm->start_data) > rlim)
91589 goto out;
91590@@ -933,6 +956,12 @@ static int
91591 can_vma_merge_before(struct vm_area_struct *vma, unsigned long vm_flags,
91592 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
91593 {
91594+
91595+#ifdef CONFIG_PAX_SEGMEXEC
91596+ if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_start == SEGMEXEC_TASK_SIZE)
91597+ return 0;
91598+#endif
91599+
91600 if (is_mergeable_vma(vma, file, vm_flags) &&
91601 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
91602 if (vma->vm_pgoff == vm_pgoff)
91603@@ -952,6 +981,12 @@ static int
91604 can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
91605 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
91606 {
91607+
91608+#ifdef CONFIG_PAX_SEGMEXEC
91609+ if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end == SEGMEXEC_TASK_SIZE)
91610+ return 0;
91611+#endif
91612+
91613 if (is_mergeable_vma(vma, file, vm_flags) &&
91614 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
91615 pgoff_t vm_pglen;
91616@@ -994,13 +1029,20 @@ can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
91617 struct vm_area_struct *vma_merge(struct mm_struct *mm,
91618 struct vm_area_struct *prev, unsigned long addr,
91619 unsigned long end, unsigned long vm_flags,
91620- struct anon_vma *anon_vma, struct file *file,
91621+ struct anon_vma *anon_vma, struct file *file,
91622 pgoff_t pgoff, struct mempolicy *policy)
91623 {
91624 pgoff_t pglen = (end - addr) >> PAGE_SHIFT;
91625 struct vm_area_struct *area, *next;
91626 int err;
91627
91628+#ifdef CONFIG_PAX_SEGMEXEC
91629+ unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE, end_m = end + SEGMEXEC_TASK_SIZE;
91630+ struct vm_area_struct *area_m = NULL, *next_m = NULL, *prev_m = NULL;
91631+
91632+ BUG_ON((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE < end);
91633+#endif
91634+
91635 /*
91636 * We later require that vma->vm_flags == vm_flags,
91637 * so this tests vma->vm_flags & VM_SPECIAL, too.
91638@@ -1016,6 +1058,15 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
91639 if (next && next->vm_end == end) /* cases 6, 7, 8 */
91640 next = next->vm_next;
91641
91642+#ifdef CONFIG_PAX_SEGMEXEC
91643+ if (prev)
91644+ prev_m = pax_find_mirror_vma(prev);
91645+ if (area)
91646+ area_m = pax_find_mirror_vma(area);
91647+ if (next)
91648+ next_m = pax_find_mirror_vma(next);
91649+#endif
91650+
91651 /*
91652 * Can it merge with the predecessor?
91653 */
91654@@ -1035,9 +1086,24 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
91655 /* cases 1, 6 */
91656 err = vma_adjust(prev, prev->vm_start,
91657 next->vm_end, prev->vm_pgoff, NULL);
91658- } else /* cases 2, 5, 7 */
91659+
91660+#ifdef CONFIG_PAX_SEGMEXEC
91661+ if (!err && prev_m)
91662+ err = vma_adjust(prev_m, prev_m->vm_start,
91663+ next_m->vm_end, prev_m->vm_pgoff, NULL);
91664+#endif
91665+
91666+ } else { /* cases 2, 5, 7 */
91667 err = vma_adjust(prev, prev->vm_start,
91668 end, prev->vm_pgoff, NULL);
91669+
91670+#ifdef CONFIG_PAX_SEGMEXEC
91671+ if (!err && prev_m)
91672+ err = vma_adjust(prev_m, prev_m->vm_start,
91673+ end_m, prev_m->vm_pgoff, NULL);
91674+#endif
91675+
91676+ }
91677 if (err)
91678 return NULL;
91679 khugepaged_enter_vma_merge(prev);
91680@@ -1051,12 +1117,27 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
91681 mpol_equal(policy, vma_policy(next)) &&
91682 can_vma_merge_before(next, vm_flags,
91683 anon_vma, file, pgoff+pglen)) {
91684- if (prev && addr < prev->vm_end) /* case 4 */
91685+ if (prev && addr < prev->vm_end) { /* case 4 */
91686 err = vma_adjust(prev, prev->vm_start,
91687 addr, prev->vm_pgoff, NULL);
91688- else /* cases 3, 8 */
91689+
91690+#ifdef CONFIG_PAX_SEGMEXEC
91691+ if (!err && prev_m)
91692+ err = vma_adjust(prev_m, prev_m->vm_start,
91693+ addr_m, prev_m->vm_pgoff, NULL);
91694+#endif
91695+
91696+ } else { /* cases 3, 8 */
91697 err = vma_adjust(area, addr, next->vm_end,
91698 next->vm_pgoff - pglen, NULL);
91699+
91700+#ifdef CONFIG_PAX_SEGMEXEC
91701+ if (!err && area_m)
91702+ err = vma_adjust(area_m, addr_m, next_m->vm_end,
91703+ next_m->vm_pgoff - pglen, NULL);
91704+#endif
91705+
91706+ }
91707 if (err)
91708 return NULL;
91709 khugepaged_enter_vma_merge(area);
91710@@ -1165,8 +1246,10 @@ none:
91711 void vm_stat_account(struct mm_struct *mm, unsigned long flags,
91712 struct file *file, long pages)
91713 {
91714- const unsigned long stack_flags
91715- = VM_STACK_FLAGS & (VM_GROWSUP|VM_GROWSDOWN);
91716+
91717+#ifdef CONFIG_PAX_RANDMMAP
91718+ if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
91719+#endif
91720
91721 mm->total_vm += pages;
91722
91723@@ -1174,7 +1257,7 @@ void vm_stat_account(struct mm_struct *mm, unsigned long flags,
91724 mm->shared_vm += pages;
91725 if ((flags & (VM_EXEC|VM_WRITE)) == VM_EXEC)
91726 mm->exec_vm += pages;
91727- } else if (flags & stack_flags)
91728+ } else if (flags & (VM_GROWSUP|VM_GROWSDOWN))
91729 mm->stack_vm += pages;
91730 }
91731 #endif /* CONFIG_PROC_FS */
91732@@ -1212,7 +1295,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
91733 * (the exception is when the underlying filesystem is noexec
91734 * mounted, in which case we dont add PROT_EXEC.)
91735 */
91736- if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
91737+ if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
91738 if (!(file && (file->f_path.mnt->mnt_flags & MNT_NOEXEC)))
91739 prot |= PROT_EXEC;
91740
91741@@ -1238,7 +1321,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
91742 /* Obtain the address to map to. we verify (or select) it and ensure
91743 * that it represents a valid section of the address space.
91744 */
91745- addr = get_unmapped_area(file, addr, len, pgoff, flags);
91746+ addr = get_unmapped_area(file, addr, len, pgoff, flags | ((prot & PROT_EXEC) ? MAP_EXECUTABLE : 0));
91747 if (addr & ~PAGE_MASK)
91748 return addr;
91749
91750@@ -1249,6 +1332,43 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
91751 vm_flags = calc_vm_prot_bits(prot) | calc_vm_flag_bits(flags) |
91752 mm->def_flags | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC;
91753
91754+#ifdef CONFIG_PAX_MPROTECT
91755+ if (mm->pax_flags & MF_PAX_MPROTECT) {
91756+
91757+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
91758+ if (file && !pgoff && (vm_flags & VM_EXEC) && mm->binfmt &&
91759+ mm->binfmt->handle_mmap)
91760+ mm->binfmt->handle_mmap(file);
91761+#endif
91762+
91763+#ifndef CONFIG_PAX_MPROTECT_COMPAT
91764+ if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC)) {
91765+ gr_log_rwxmmap(file);
91766+
91767+#ifdef CONFIG_PAX_EMUPLT
91768+ vm_flags &= ~VM_EXEC;
91769+#else
91770+ return -EPERM;
91771+#endif
91772+
91773+ }
91774+
91775+ if (!(vm_flags & VM_EXEC))
91776+ vm_flags &= ~VM_MAYEXEC;
91777+#else
91778+ if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
91779+ vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
91780+#endif
91781+ else
91782+ vm_flags &= ~VM_MAYWRITE;
91783+ }
91784+#endif
91785+
91786+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
91787+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && file)
91788+ vm_flags &= ~VM_PAGEEXEC;
91789+#endif
91790+
91791 if (flags & MAP_LOCKED)
91792 if (!can_do_mlock())
91793 return -EPERM;
91794@@ -1260,6 +1380,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
91795 locked += mm->locked_vm;
91796 lock_limit = rlimit(RLIMIT_MEMLOCK);
91797 lock_limit >>= PAGE_SHIFT;
91798+ gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
91799 if (locked > lock_limit && !capable(CAP_IPC_LOCK))
91800 return -EAGAIN;
91801 }
91802@@ -1344,6 +1465,9 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
91803 vm_flags |= VM_NORESERVE;
91804 }
91805
91806+ if (!gr_acl_handle_mmap(file, prot))
91807+ return -EACCES;
91808+
91809 addr = mmap_region(file, addr, len, vm_flags, pgoff);
91810 if (!IS_ERR_VALUE(addr) &&
91811 ((vm_flags & VM_LOCKED) ||
91812@@ -1437,7 +1561,7 @@ int vma_wants_writenotify(struct vm_area_struct *vma)
91813 vm_flags_t vm_flags = vma->vm_flags;
91814
91815 /* If it was private or non-writable, the write bit is already clear */
91816- if ((vm_flags & (VM_WRITE|VM_SHARED)) != ((VM_WRITE|VM_SHARED)))
91817+ if ((vm_flags & (VM_WRITE|VM_SHARED)) != (VM_WRITE|VM_SHARED))
91818 return 0;
91819
91820 /* The backer wishes to know when pages are first written to? */
91821@@ -1483,7 +1607,22 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
91822 struct rb_node **rb_link, *rb_parent;
91823 unsigned long charged = 0;
91824
91825+#ifdef CONFIG_PAX_SEGMEXEC
91826+ struct vm_area_struct *vma_m = NULL;
91827+#endif
91828+
91829+ /*
91830+ * mm->mmap_sem is required to protect against another thread
91831+ * changing the mappings in case we sleep.
91832+ */
91833+ verify_mm_writelocked(mm);
91834+
91835 /* Check against address space limit. */
91836+
91837+#ifdef CONFIG_PAX_RANDMMAP
91838+ if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (vm_flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
91839+#endif
91840+
91841 if (!may_expand_vm(mm, len >> PAGE_SHIFT)) {
91842 unsigned long nr_pages;
91843
91844@@ -1502,11 +1641,10 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
91845
91846 /* Clear old maps */
91847 error = -ENOMEM;
91848-munmap_back:
91849 if (find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent)) {
91850 if (do_munmap(mm, addr, len))
91851 return -ENOMEM;
91852- goto munmap_back;
91853+ BUG_ON(find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent));
91854 }
91855
91856 /*
91857@@ -1537,6 +1675,16 @@ munmap_back:
91858 goto unacct_error;
91859 }
91860
91861+#ifdef CONFIG_PAX_SEGMEXEC
91862+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vm_flags & VM_EXEC)) {
91863+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
91864+ if (!vma_m) {
91865+ error = -ENOMEM;
91866+ goto free_vma;
91867+ }
91868+ }
91869+#endif
91870+
91871 vma->vm_mm = mm;
91872 vma->vm_start = addr;
91873 vma->vm_end = addr + len;
91874@@ -1556,6 +1704,13 @@ munmap_back:
91875 if (error)
91876 goto unmap_and_free_vma;
91877
91878+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
91879+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && !(vma->vm_flags & VM_SPECIAL)) {
91880+ vma->vm_flags |= VM_PAGEEXEC;
91881+ vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
91882+ }
91883+#endif
91884+
91885 /* Can addr have changed??
91886 *
91887 * Answer: Yes, several device drivers can do it in their
91888@@ -1589,6 +1744,12 @@ munmap_back:
91889 }
91890
91891 vma_link(mm, vma, prev, rb_link, rb_parent);
91892+
91893+#ifdef CONFIG_PAX_SEGMEXEC
91894+ if (vma_m)
91895+ BUG_ON(pax_mirror_vma(vma_m, vma));
91896+#endif
91897+
91898 /* Once vma denies write, undo our temporary denial count */
91899 if (vm_flags & VM_DENYWRITE)
91900 allow_write_access(file);
91901@@ -1597,6 +1758,7 @@ out:
91902 perf_event_mmap(vma);
91903
91904 vm_stat_account(mm, vm_flags, file, len >> PAGE_SHIFT);
91905+ track_exec_limit(mm, addr, addr + len, vm_flags);
91906 if (vm_flags & VM_LOCKED) {
91907 if (!((vm_flags & VM_SPECIAL) || is_vm_hugetlb_page(vma) ||
91908 vma == get_gate_vma(current->mm)))
91909@@ -1629,6 +1791,12 @@ unmap_and_free_vma:
91910 unmap_region(mm, vma, prev, vma->vm_start, vma->vm_end);
91911 charged = 0;
91912 free_vma:
91913+
91914+#ifdef CONFIG_PAX_SEGMEXEC
91915+ if (vma_m)
91916+ kmem_cache_free(vm_area_cachep, vma_m);
91917+#endif
91918+
91919 kmem_cache_free(vm_area_cachep, vma);
91920 unacct_error:
91921 if (charged)
91922@@ -1636,7 +1804,63 @@ unacct_error:
91923 return error;
91924 }
91925
91926-unsigned long unmapped_area(struct vm_unmapped_area_info *info)
91927+#ifdef CONFIG_GRKERNSEC_RAND_THREADSTACK
91928+unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags)
91929+{
91930+ if ((mm->pax_flags & MF_PAX_RANDMMAP) && !filp && (flags & MAP_STACK))
91931+ return ((prandom_u32() & 0xFF) + 1) << PAGE_SHIFT;
91932+
91933+ return 0;
91934+}
91935+#endif
91936+
91937+bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len, unsigned long offset)
91938+{
91939+ if (!vma) {
91940+#ifdef CONFIG_STACK_GROWSUP
91941+ if (addr > sysctl_heap_stack_gap)
91942+ vma = find_vma(current->mm, addr - sysctl_heap_stack_gap);
91943+ else
91944+ vma = find_vma(current->mm, 0);
91945+ if (vma && (vma->vm_flags & VM_GROWSUP))
91946+ return false;
91947+#endif
91948+ return true;
91949+ }
91950+
91951+ if (addr + len > vma->vm_start)
91952+ return false;
91953+
91954+ if (vma->vm_flags & VM_GROWSDOWN)
91955+ return sysctl_heap_stack_gap <= vma->vm_start - addr - len;
91956+#ifdef CONFIG_STACK_GROWSUP
91957+ else if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP))
91958+ return addr - vma->vm_prev->vm_end >= sysctl_heap_stack_gap;
91959+#endif
91960+ else if (offset)
91961+ return offset <= vma->vm_start - addr - len;
91962+
91963+ return true;
91964+}
91965+
91966+unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len, unsigned long offset)
91967+{
91968+ if (vma->vm_start < len)
91969+ return -ENOMEM;
91970+
91971+ if (!(vma->vm_flags & VM_GROWSDOWN)) {
91972+ if (offset <= vma->vm_start - len)
91973+ return vma->vm_start - len - offset;
91974+ else
91975+ return -ENOMEM;
91976+ }
91977+
91978+ if (sysctl_heap_stack_gap <= vma->vm_start - len)
91979+ return vma->vm_start - len - sysctl_heap_stack_gap;
91980+ return -ENOMEM;
91981+}
91982+
91983+unsigned long unmapped_area(const struct vm_unmapped_area_info *info)
91984 {
91985 /*
91986 * We implement the search by looking for an rbtree node that
91987@@ -1684,11 +1908,29 @@ unsigned long unmapped_area(struct vm_unmapped_area_info *info)
91988 }
91989 }
91990
91991- gap_start = vma->vm_prev ? vma->vm_prev->vm_end : 0;
91992+ gap_start = vma->vm_prev ? vma->vm_prev->vm_end: 0;
91993 check_current:
91994 /* Check if current node has a suitable gap */
91995 if (gap_start > high_limit)
91996 return -ENOMEM;
91997+
91998+ if (gap_end - gap_start > info->threadstack_offset)
91999+ gap_start += info->threadstack_offset;
92000+ else
92001+ gap_start = gap_end;
92002+
92003+ if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP)) {
92004+ if (gap_end - gap_start > sysctl_heap_stack_gap)
92005+ gap_start += sysctl_heap_stack_gap;
92006+ else
92007+ gap_start = gap_end;
92008+ }
92009+ if (vma->vm_flags & VM_GROWSDOWN) {
92010+ if (gap_end - gap_start > sysctl_heap_stack_gap)
92011+ gap_end -= sysctl_heap_stack_gap;
92012+ else
92013+ gap_end = gap_start;
92014+ }
92015 if (gap_end >= low_limit && gap_end - gap_start >= length)
92016 goto found;
92017
92018@@ -1738,7 +1980,7 @@ found:
92019 return gap_start;
92020 }
92021
92022-unsigned long unmapped_area_topdown(struct vm_unmapped_area_info *info)
92023+unsigned long unmapped_area_topdown(const struct vm_unmapped_area_info *info)
92024 {
92025 struct mm_struct *mm = current->mm;
92026 struct vm_area_struct *vma;
92027@@ -1792,6 +2034,24 @@ check_current:
92028 gap_end = vma->vm_start;
92029 if (gap_end < low_limit)
92030 return -ENOMEM;
92031+
92032+ if (gap_end - gap_start > info->threadstack_offset)
92033+ gap_end -= info->threadstack_offset;
92034+ else
92035+ gap_end = gap_start;
92036+
92037+ if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP)) {
92038+ if (gap_end - gap_start > sysctl_heap_stack_gap)
92039+ gap_start += sysctl_heap_stack_gap;
92040+ else
92041+ gap_start = gap_end;
92042+ }
92043+ if (vma->vm_flags & VM_GROWSDOWN) {
92044+ if (gap_end - gap_start > sysctl_heap_stack_gap)
92045+ gap_end -= sysctl_heap_stack_gap;
92046+ else
92047+ gap_end = gap_start;
92048+ }
92049 if (gap_start <= high_limit && gap_end - gap_start >= length)
92050 goto found;
92051
92052@@ -1855,6 +2115,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
92053 struct mm_struct *mm = current->mm;
92054 struct vm_area_struct *vma;
92055 struct vm_unmapped_area_info info;
92056+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
92057
92058 if (len > TASK_SIZE - mmap_min_addr)
92059 return -ENOMEM;
92060@@ -1862,19 +2123,30 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
92061 if (flags & MAP_FIXED)
92062 return addr;
92063
92064+#ifdef CONFIG_PAX_RANDMMAP
92065+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
92066+#endif
92067+
92068 if (addr) {
92069 addr = PAGE_ALIGN(addr);
92070 vma = find_vma(mm, addr);
92071 if (TASK_SIZE - len >= addr && addr >= mmap_min_addr &&
92072- (!vma || addr + len <= vma->vm_start))
92073+ check_heap_stack_gap(vma, addr, len, offset))
92074 return addr;
92075 }
92076
92077 info.flags = 0;
92078 info.length = len;
92079 info.low_limit = TASK_UNMAPPED_BASE;
92080+
92081+#ifdef CONFIG_PAX_RANDMMAP
92082+ if (mm->pax_flags & MF_PAX_RANDMMAP)
92083+ info.low_limit += mm->delta_mmap;
92084+#endif
92085+
92086 info.high_limit = TASK_SIZE;
92087 info.align_mask = 0;
92088+ info.threadstack_offset = offset;
92089 return vm_unmapped_area(&info);
92090 }
92091 #endif
92092@@ -1893,6 +2165,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
92093 struct mm_struct *mm = current->mm;
92094 unsigned long addr = addr0;
92095 struct vm_unmapped_area_info info;
92096+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
92097
92098 /* requested length too big for entire address space */
92099 if (len > TASK_SIZE - mmap_min_addr)
92100@@ -1901,12 +2174,16 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
92101 if (flags & MAP_FIXED)
92102 return addr;
92103
92104+#ifdef CONFIG_PAX_RANDMMAP
92105+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
92106+#endif
92107+
92108 /* requesting a specific address */
92109 if (addr) {
92110 addr = PAGE_ALIGN(addr);
92111 vma = find_vma(mm, addr);
92112 if (TASK_SIZE - len >= addr && addr >= mmap_min_addr &&
92113- (!vma || addr + len <= vma->vm_start))
92114+ check_heap_stack_gap(vma, addr, len, offset))
92115 return addr;
92116 }
92117
92118@@ -1915,6 +2192,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
92119 info.low_limit = max(PAGE_SIZE, mmap_min_addr);
92120 info.high_limit = mm->mmap_base;
92121 info.align_mask = 0;
92122+ info.threadstack_offset = offset;
92123 addr = vm_unmapped_area(&info);
92124
92125 /*
92126@@ -1927,6 +2205,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
92127 VM_BUG_ON(addr != -ENOMEM);
92128 info.flags = 0;
92129 info.low_limit = TASK_UNMAPPED_BASE;
92130+
92131+#ifdef CONFIG_PAX_RANDMMAP
92132+ if (mm->pax_flags & MF_PAX_RANDMMAP)
92133+ info.low_limit += mm->delta_mmap;
92134+#endif
92135+
92136 info.high_limit = TASK_SIZE;
92137 addr = vm_unmapped_area(&info);
92138 }
92139@@ -2028,6 +2312,28 @@ find_vma_prev(struct mm_struct *mm, unsigned long addr,
92140 return vma;
92141 }
92142
92143+#ifdef CONFIG_PAX_SEGMEXEC
92144+struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma)
92145+{
92146+ struct vm_area_struct *vma_m;
92147+
92148+ BUG_ON(!vma || vma->vm_start >= vma->vm_end);
92149+ if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC)) {
92150+ BUG_ON(vma->vm_mirror);
92151+ return NULL;
92152+ }
92153+ BUG_ON(vma->vm_start < SEGMEXEC_TASK_SIZE && SEGMEXEC_TASK_SIZE < vma->vm_end);
92154+ vma_m = vma->vm_mirror;
92155+ BUG_ON(!vma_m || vma_m->vm_mirror != vma);
92156+ BUG_ON(vma->vm_file != vma_m->vm_file);
92157+ BUG_ON(vma->vm_end - vma->vm_start != vma_m->vm_end - vma_m->vm_start);
92158+ BUG_ON(vma->vm_pgoff != vma_m->vm_pgoff);
92159+ BUG_ON(vma->anon_vma != vma_m->anon_vma && vma->anon_vma->root != vma_m->anon_vma->root);
92160+ BUG_ON((vma->vm_flags ^ vma_m->vm_flags) & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED));
92161+ return vma_m;
92162+}
92163+#endif
92164+
92165 /*
92166 * Verify that the stack growth is acceptable and
92167 * update accounting. This is shared with both the
92168@@ -2044,6 +2350,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
92169 return -ENOMEM;
92170
92171 /* Stack limit test */
92172+ gr_learn_resource(current, RLIMIT_STACK, size, 1);
92173 if (size > ACCESS_ONCE(rlim[RLIMIT_STACK].rlim_cur))
92174 return -ENOMEM;
92175
92176@@ -2054,6 +2361,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
92177 locked = mm->locked_vm + grow;
92178 limit = ACCESS_ONCE(rlim[RLIMIT_MEMLOCK].rlim_cur);
92179 limit >>= PAGE_SHIFT;
92180+ gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
92181 if (locked > limit && !capable(CAP_IPC_LOCK))
92182 return -ENOMEM;
92183 }
92184@@ -2083,37 +2391,48 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
92185 * PA-RISC uses this for its stack; IA64 for its Register Backing Store.
92186 * vma is the last one with address > vma->vm_end. Have to extend vma.
92187 */
92188+#ifndef CONFIG_IA64
92189+static
92190+#endif
92191 int expand_upwards(struct vm_area_struct *vma, unsigned long address)
92192 {
92193 int error;
92194+ bool locknext;
92195
92196 if (!(vma->vm_flags & VM_GROWSUP))
92197 return -EFAULT;
92198
92199+ /* Also guard against wrapping around to address 0. */
92200+ if (address < PAGE_ALIGN(address+1))
92201+ address = PAGE_ALIGN(address+1);
92202+ else
92203+ return -ENOMEM;
92204+
92205 /*
92206 * We must make sure the anon_vma is allocated
92207 * so that the anon_vma locking is not a noop.
92208 */
92209 if (unlikely(anon_vma_prepare(vma)))
92210 return -ENOMEM;
92211+ locknext = vma->vm_next && (vma->vm_next->vm_flags & VM_GROWSDOWN);
92212+ if (locknext && anon_vma_prepare(vma->vm_next))
92213+ return -ENOMEM;
92214 vma_lock_anon_vma(vma);
92215+ if (locknext)
92216+ vma_lock_anon_vma(vma->vm_next);
92217
92218 /*
92219 * vma->vm_start/vm_end cannot change under us because the caller
92220 * is required to hold the mmap_sem in read mode. We need the
92221- * anon_vma lock to serialize against concurrent expand_stacks.
92222- * Also guard against wrapping around to address 0.
92223+ * anon_vma locks to serialize against concurrent expand_stacks
92224+ * and expand_upwards.
92225 */
92226- if (address < PAGE_ALIGN(address+4))
92227- address = PAGE_ALIGN(address+4);
92228- else {
92229- vma_unlock_anon_vma(vma);
92230- return -ENOMEM;
92231- }
92232 error = 0;
92233
92234 /* Somebody else might have raced and expanded it already */
92235- if (address > vma->vm_end) {
92236+ 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)
92237+ error = -ENOMEM;
92238+ else if (address > vma->vm_end && (!locknext || vma->vm_next->vm_start >= address)) {
92239 unsigned long size, grow;
92240
92241 size = address - vma->vm_start;
92242@@ -2148,6 +2467,8 @@ int expand_upwards(struct vm_area_struct *vma, unsigned long address)
92243 }
92244 }
92245 }
92246+ if (locknext)
92247+ vma_unlock_anon_vma(vma->vm_next);
92248 vma_unlock_anon_vma(vma);
92249 khugepaged_enter_vma_merge(vma);
92250 validate_mm(vma->vm_mm);
92251@@ -2162,6 +2483,8 @@ int expand_downwards(struct vm_area_struct *vma,
92252 unsigned long address)
92253 {
92254 int error;
92255+ bool lockprev = false;
92256+ struct vm_area_struct *prev;
92257
92258 /*
92259 * We must make sure the anon_vma is allocated
92260@@ -2175,6 +2498,15 @@ int expand_downwards(struct vm_area_struct *vma,
92261 if (error)
92262 return error;
92263
92264+ prev = vma->vm_prev;
92265+#if defined(CONFIG_STACK_GROWSUP) || defined(CONFIG_IA64)
92266+ lockprev = prev && (prev->vm_flags & VM_GROWSUP);
92267+#endif
92268+ if (lockprev && anon_vma_prepare(prev))
92269+ return -ENOMEM;
92270+ if (lockprev)
92271+ vma_lock_anon_vma(prev);
92272+
92273 vma_lock_anon_vma(vma);
92274
92275 /*
92276@@ -2184,9 +2516,17 @@ int expand_downwards(struct vm_area_struct *vma,
92277 */
92278
92279 /* Somebody else might have raced and expanded it already */
92280- if (address < vma->vm_start) {
92281+ if (prev && (prev->vm_flags & (VM_READ | VM_WRITE | VM_EXEC)) && address - prev->vm_end < sysctl_heap_stack_gap)
92282+ error = -ENOMEM;
92283+ else if (address < vma->vm_start && (!lockprev || prev->vm_end <= address)) {
92284 unsigned long size, grow;
92285
92286+#ifdef CONFIG_PAX_SEGMEXEC
92287+ struct vm_area_struct *vma_m;
92288+
92289+ vma_m = pax_find_mirror_vma(vma);
92290+#endif
92291+
92292 size = vma->vm_end - address;
92293 grow = (vma->vm_start - address) >> PAGE_SHIFT;
92294
92295@@ -2211,13 +2551,27 @@ int expand_downwards(struct vm_area_struct *vma,
92296 vma->vm_pgoff -= grow;
92297 anon_vma_interval_tree_post_update_vma(vma);
92298 vma_gap_update(vma);
92299+
92300+#ifdef CONFIG_PAX_SEGMEXEC
92301+ if (vma_m) {
92302+ anon_vma_interval_tree_pre_update_vma(vma_m);
92303+ vma_m->vm_start -= grow << PAGE_SHIFT;
92304+ vma_m->vm_pgoff -= grow;
92305+ anon_vma_interval_tree_post_update_vma(vma_m);
92306+ vma_gap_update(vma_m);
92307+ }
92308+#endif
92309+
92310 spin_unlock(&vma->vm_mm->page_table_lock);
92311
92312+ track_exec_limit(vma->vm_mm, vma->vm_start, vma->vm_end, vma->vm_flags);
92313 perf_event_mmap(vma);
92314 }
92315 }
92316 }
92317 vma_unlock_anon_vma(vma);
92318+ if (lockprev)
92319+ vma_unlock_anon_vma(prev);
92320 khugepaged_enter_vma_merge(vma);
92321 validate_mm(vma->vm_mm);
92322 return error;
92323@@ -2315,6 +2669,13 @@ static void remove_vma_list(struct mm_struct *mm, struct vm_area_struct *vma)
92324 do {
92325 long nrpages = vma_pages(vma);
92326
92327+#ifdef CONFIG_PAX_SEGMEXEC
92328+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE)) {
92329+ vma = remove_vma(vma);
92330+ continue;
92331+ }
92332+#endif
92333+
92334 if (vma->vm_flags & VM_ACCOUNT)
92335 nr_accounted += nrpages;
92336 vm_stat_account(mm, vma->vm_flags, vma->vm_file, -nrpages);
92337@@ -2359,6 +2720,16 @@ detach_vmas_to_be_unmapped(struct mm_struct *mm, struct vm_area_struct *vma,
92338 insertion_point = (prev ? &prev->vm_next : &mm->mmap);
92339 vma->vm_prev = NULL;
92340 do {
92341+
92342+#ifdef CONFIG_PAX_SEGMEXEC
92343+ if (vma->vm_mirror) {
92344+ BUG_ON(!vma->vm_mirror->vm_mirror || vma->vm_mirror->vm_mirror != vma);
92345+ vma->vm_mirror->vm_mirror = NULL;
92346+ vma->vm_mirror->vm_flags &= ~VM_EXEC;
92347+ vma->vm_mirror = NULL;
92348+ }
92349+#endif
92350+
92351 vma_rb_erase(vma, &mm->mm_rb);
92352 mm->map_count--;
92353 tail_vma = vma;
92354@@ -2384,14 +2755,33 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
92355 struct vm_area_struct *new;
92356 int err = -ENOMEM;
92357
92358+#ifdef CONFIG_PAX_SEGMEXEC
92359+ struct vm_area_struct *vma_m, *new_m = NULL;
92360+ unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE;
92361+#endif
92362+
92363 if (is_vm_hugetlb_page(vma) && (addr &
92364 ~(huge_page_mask(hstate_vma(vma)))))
92365 return -EINVAL;
92366
92367+#ifdef CONFIG_PAX_SEGMEXEC
92368+ vma_m = pax_find_mirror_vma(vma);
92369+#endif
92370+
92371 new = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
92372 if (!new)
92373 goto out_err;
92374
92375+#ifdef CONFIG_PAX_SEGMEXEC
92376+ if (vma_m) {
92377+ new_m = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
92378+ if (!new_m) {
92379+ kmem_cache_free(vm_area_cachep, new);
92380+ goto out_err;
92381+ }
92382+ }
92383+#endif
92384+
92385 /* most fields are the same, copy all, and then fixup */
92386 *new = *vma;
92387
92388@@ -2404,6 +2794,22 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
92389 new->vm_pgoff += ((addr - vma->vm_start) >> PAGE_SHIFT);
92390 }
92391
92392+#ifdef CONFIG_PAX_SEGMEXEC
92393+ if (vma_m) {
92394+ *new_m = *vma_m;
92395+ INIT_LIST_HEAD(&new_m->anon_vma_chain);
92396+ new_m->vm_mirror = new;
92397+ new->vm_mirror = new_m;
92398+
92399+ if (new_below)
92400+ new_m->vm_end = addr_m;
92401+ else {
92402+ new_m->vm_start = addr_m;
92403+ new_m->vm_pgoff += ((addr_m - vma_m->vm_start) >> PAGE_SHIFT);
92404+ }
92405+ }
92406+#endif
92407+
92408 err = vma_dup_policy(vma, new);
92409 if (err)
92410 goto out_free_vma;
92411@@ -2423,6 +2829,38 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
92412 else
92413 err = vma_adjust(vma, vma->vm_start, addr, vma->vm_pgoff, new);
92414
92415+#ifdef CONFIG_PAX_SEGMEXEC
92416+ if (!err && vma_m) {
92417+ struct mempolicy *pol = vma_policy(new);
92418+
92419+ if (anon_vma_clone(new_m, vma_m))
92420+ goto out_free_mpol;
92421+
92422+ mpol_get(pol);
92423+ set_vma_policy(new_m, pol);
92424+
92425+ if (new_m->vm_file)
92426+ get_file(new_m->vm_file);
92427+
92428+ if (new_m->vm_ops && new_m->vm_ops->open)
92429+ new_m->vm_ops->open(new_m);
92430+
92431+ if (new_below)
92432+ err = vma_adjust(vma_m, addr_m, vma_m->vm_end, vma_m->vm_pgoff +
92433+ ((addr_m - new_m->vm_start) >> PAGE_SHIFT), new_m);
92434+ else
92435+ err = vma_adjust(vma_m, vma_m->vm_start, addr_m, vma_m->vm_pgoff, new_m);
92436+
92437+ if (err) {
92438+ if (new_m->vm_ops && new_m->vm_ops->close)
92439+ new_m->vm_ops->close(new_m);
92440+ if (new_m->vm_file)
92441+ fput(new_m->vm_file);
92442+ mpol_put(pol);
92443+ }
92444+ }
92445+#endif
92446+
92447 /* Success. */
92448 if (!err)
92449 return 0;
92450@@ -2432,10 +2870,18 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
92451 new->vm_ops->close(new);
92452 if (new->vm_file)
92453 fput(new->vm_file);
92454- unlink_anon_vmas(new);
92455 out_free_mpol:
92456 mpol_put(vma_policy(new));
92457 out_free_vma:
92458+
92459+#ifdef CONFIG_PAX_SEGMEXEC
92460+ if (new_m) {
92461+ unlink_anon_vmas(new_m);
92462+ kmem_cache_free(vm_area_cachep, new_m);
92463+ }
92464+#endif
92465+
92466+ unlink_anon_vmas(new);
92467 kmem_cache_free(vm_area_cachep, new);
92468 out_err:
92469 return err;
92470@@ -2448,6 +2894,15 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
92471 int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
92472 unsigned long addr, int new_below)
92473 {
92474+
92475+#ifdef CONFIG_PAX_SEGMEXEC
92476+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
92477+ BUG_ON(vma->vm_end > SEGMEXEC_TASK_SIZE);
92478+ if (mm->map_count >= sysctl_max_map_count-1)
92479+ return -ENOMEM;
92480+ } else
92481+#endif
92482+
92483 if (mm->map_count >= sysctl_max_map_count)
92484 return -ENOMEM;
92485
92486@@ -2459,11 +2914,30 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
92487 * work. This now handles partial unmappings.
92488 * Jeremy Fitzhardinge <jeremy@goop.org>
92489 */
92490+#ifdef CONFIG_PAX_SEGMEXEC
92491 int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
92492 {
92493+ int ret = __do_munmap(mm, start, len);
92494+ if (ret || !(mm->pax_flags & MF_PAX_SEGMEXEC))
92495+ return ret;
92496+
92497+ return __do_munmap(mm, start + SEGMEXEC_TASK_SIZE, len);
92498+}
92499+
92500+int __do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
92501+#else
92502+int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
92503+#endif
92504+{
92505 unsigned long end;
92506 struct vm_area_struct *vma, *prev, *last;
92507
92508+ /*
92509+ * mm->mmap_sem is required to protect against another thread
92510+ * changing the mappings in case we sleep.
92511+ */
92512+ verify_mm_writelocked(mm);
92513+
92514 if ((start & ~PAGE_MASK) || start > TASK_SIZE || len > TASK_SIZE-start)
92515 return -EINVAL;
92516
92517@@ -2538,6 +3012,8 @@ int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
92518 /* Fix up all other VM information */
92519 remove_vma_list(mm, vma);
92520
92521+ track_exec_limit(mm, start, end, 0UL);
92522+
92523 return 0;
92524 }
92525
92526@@ -2546,6 +3022,13 @@ int vm_munmap(unsigned long start, size_t len)
92527 int ret;
92528 struct mm_struct *mm = current->mm;
92529
92530+
92531+#ifdef CONFIG_PAX_SEGMEXEC
92532+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) &&
92533+ (len > SEGMEXEC_TASK_SIZE || start > SEGMEXEC_TASK_SIZE-len))
92534+ return -EINVAL;
92535+#endif
92536+
92537 down_write(&mm->mmap_sem);
92538 ret = do_munmap(mm, start, len);
92539 up_write(&mm->mmap_sem);
92540@@ -2559,16 +3042,6 @@ SYSCALL_DEFINE2(munmap, unsigned long, addr, size_t, len)
92541 return vm_munmap(addr, len);
92542 }
92543
92544-static inline void verify_mm_writelocked(struct mm_struct *mm)
92545-{
92546-#ifdef CONFIG_DEBUG_VM
92547- if (unlikely(down_read_trylock(&mm->mmap_sem))) {
92548- WARN_ON(1);
92549- up_read(&mm->mmap_sem);
92550- }
92551-#endif
92552-}
92553-
92554 /*
92555 * this is really a simplified "do_mmap". it only handles
92556 * anonymous maps. eventually we may be able to do some
92557@@ -2582,6 +3055,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
92558 struct rb_node ** rb_link, * rb_parent;
92559 pgoff_t pgoff = addr >> PAGE_SHIFT;
92560 int error;
92561+ unsigned long charged;
92562
92563 len = PAGE_ALIGN(len);
92564 if (!len)
92565@@ -2589,16 +3063,30 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
92566
92567 flags = VM_DATA_DEFAULT_FLAGS | VM_ACCOUNT | mm->def_flags;
92568
92569+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
92570+ if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
92571+ flags &= ~VM_EXEC;
92572+
92573+#ifdef CONFIG_PAX_MPROTECT
92574+ if (mm->pax_flags & MF_PAX_MPROTECT)
92575+ flags &= ~VM_MAYEXEC;
92576+#endif
92577+
92578+ }
92579+#endif
92580+
92581 error = get_unmapped_area(NULL, addr, len, 0, MAP_FIXED);
92582 if (error & ~PAGE_MASK)
92583 return error;
92584
92585+ charged = len >> PAGE_SHIFT;
92586+
92587 /*
92588 * mlock MCL_FUTURE?
92589 */
92590 if (mm->def_flags & VM_LOCKED) {
92591 unsigned long locked, lock_limit;
92592- locked = len >> PAGE_SHIFT;
92593+ locked = charged;
92594 locked += mm->locked_vm;
92595 lock_limit = rlimit(RLIMIT_MEMLOCK);
92596 lock_limit >>= PAGE_SHIFT;
92597@@ -2615,21 +3103,20 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
92598 /*
92599 * Clear old maps. this also does some error checking for us
92600 */
92601- munmap_back:
92602 if (find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent)) {
92603 if (do_munmap(mm, addr, len))
92604 return -ENOMEM;
92605- goto munmap_back;
92606+ BUG_ON(find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent));
92607 }
92608
92609 /* Check against address space limits *after* clearing old maps... */
92610- if (!may_expand_vm(mm, len >> PAGE_SHIFT))
92611+ if (!may_expand_vm(mm, charged))
92612 return -ENOMEM;
92613
92614 if (mm->map_count > sysctl_max_map_count)
92615 return -ENOMEM;
92616
92617- if (security_vm_enough_memory_mm(mm, len >> PAGE_SHIFT))
92618+ if (security_vm_enough_memory_mm(mm, charged))
92619 return -ENOMEM;
92620
92621 /* Can we just expand an old private anonymous mapping? */
92622@@ -2643,7 +3130,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
92623 */
92624 vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
92625 if (!vma) {
92626- vm_unacct_memory(len >> PAGE_SHIFT);
92627+ vm_unacct_memory(charged);
92628 return -ENOMEM;
92629 }
92630
92631@@ -2657,10 +3144,11 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
92632 vma_link(mm, vma, prev, rb_link, rb_parent);
92633 out:
92634 perf_event_mmap(vma);
92635- mm->total_vm += len >> PAGE_SHIFT;
92636+ mm->total_vm += charged;
92637 if (flags & VM_LOCKED)
92638- mm->locked_vm += (len >> PAGE_SHIFT);
92639+ mm->locked_vm += charged;
92640 vma->vm_flags |= VM_SOFTDIRTY;
92641+ track_exec_limit(mm, addr, addr + len, flags);
92642 return addr;
92643 }
92644
92645@@ -2722,6 +3210,7 @@ void exit_mmap(struct mm_struct *mm)
92646 while (vma) {
92647 if (vma->vm_flags & VM_ACCOUNT)
92648 nr_accounted += vma_pages(vma);
92649+ vma->vm_mirror = NULL;
92650 vma = remove_vma(vma);
92651 }
92652 vm_unacct_memory(nr_accounted);
92653@@ -2738,6 +3227,13 @@ int insert_vm_struct(struct mm_struct *mm, struct vm_area_struct *vma)
92654 struct vm_area_struct *prev;
92655 struct rb_node **rb_link, *rb_parent;
92656
92657+#ifdef CONFIG_PAX_SEGMEXEC
92658+ struct vm_area_struct *vma_m = NULL;
92659+#endif
92660+
92661+ if (security_mmap_addr(vma->vm_start))
92662+ return -EPERM;
92663+
92664 /*
92665 * The vm_pgoff of a purely anonymous vma should be irrelevant
92666 * until its first write fault, when page's anon_vma and index
92667@@ -2761,7 +3257,21 @@ int insert_vm_struct(struct mm_struct *mm, struct vm_area_struct *vma)
92668 security_vm_enough_memory_mm(mm, vma_pages(vma)))
92669 return -ENOMEM;
92670
92671+#ifdef CONFIG_PAX_SEGMEXEC
92672+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_EXEC)) {
92673+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
92674+ if (!vma_m)
92675+ return -ENOMEM;
92676+ }
92677+#endif
92678+
92679 vma_link(mm, vma, prev, rb_link, rb_parent);
92680+
92681+#ifdef CONFIG_PAX_SEGMEXEC
92682+ if (vma_m)
92683+ BUG_ON(pax_mirror_vma(vma_m, vma));
92684+#endif
92685+
92686 return 0;
92687 }
92688
92689@@ -2780,6 +3290,8 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
92690 struct rb_node **rb_link, *rb_parent;
92691 bool faulted_in_anon_vma = true;
92692
92693+ BUG_ON(vma->vm_mirror);
92694+
92695 /*
92696 * If anonymous vma has not yet been faulted, update new pgoff
92697 * to match new location, to increase its chance of merging.
92698@@ -2844,6 +3356,39 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
92699 return NULL;
92700 }
92701
92702+#ifdef CONFIG_PAX_SEGMEXEC
92703+long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma)
92704+{
92705+ struct vm_area_struct *prev_m;
92706+ struct rb_node **rb_link_m, *rb_parent_m;
92707+ struct mempolicy *pol_m;
92708+
92709+ BUG_ON(!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC));
92710+ BUG_ON(vma->vm_mirror || vma_m->vm_mirror);
92711+ BUG_ON(!mpol_equal(vma_policy(vma), vma_policy(vma_m)));
92712+ *vma_m = *vma;
92713+ INIT_LIST_HEAD(&vma_m->anon_vma_chain);
92714+ if (anon_vma_clone(vma_m, vma))
92715+ return -ENOMEM;
92716+ pol_m = vma_policy(vma_m);
92717+ mpol_get(pol_m);
92718+ set_vma_policy(vma_m, pol_m);
92719+ vma_m->vm_start += SEGMEXEC_TASK_SIZE;
92720+ vma_m->vm_end += SEGMEXEC_TASK_SIZE;
92721+ vma_m->vm_flags &= ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED);
92722+ vma_m->vm_page_prot = vm_get_page_prot(vma_m->vm_flags);
92723+ if (vma_m->vm_file)
92724+ get_file(vma_m->vm_file);
92725+ if (vma_m->vm_ops && vma_m->vm_ops->open)
92726+ vma_m->vm_ops->open(vma_m);
92727+ BUG_ON(find_vma_links(vma->vm_mm, vma_m->vm_start, vma_m->vm_end, &prev_m, &rb_link_m, &rb_parent_m));
92728+ vma_link(vma->vm_mm, vma_m, prev_m, rb_link_m, rb_parent_m);
92729+ vma_m->vm_mirror = vma;
92730+ vma->vm_mirror = vma_m;
92731+ return 0;
92732+}
92733+#endif
92734+
92735 /*
92736 * Return true if the calling process may expand its vm space by the passed
92737 * number of pages
92738@@ -2855,6 +3400,7 @@ int may_expand_vm(struct mm_struct *mm, unsigned long npages)
92739
92740 lim = rlimit(RLIMIT_AS) >> PAGE_SHIFT;
92741
92742+ gr_learn_resource(current, RLIMIT_AS, (cur + npages) << PAGE_SHIFT, 1);
92743 if (cur + npages > lim)
92744 return 0;
92745 return 1;
92746@@ -2925,6 +3471,22 @@ int install_special_mapping(struct mm_struct *mm,
92747 vma->vm_start = addr;
92748 vma->vm_end = addr + len;
92749
92750+#ifdef CONFIG_PAX_MPROTECT
92751+ if (mm->pax_flags & MF_PAX_MPROTECT) {
92752+#ifndef CONFIG_PAX_MPROTECT_COMPAT
92753+ if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC))
92754+ return -EPERM;
92755+ if (!(vm_flags & VM_EXEC))
92756+ vm_flags &= ~VM_MAYEXEC;
92757+#else
92758+ if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
92759+ vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
92760+#endif
92761+ else
92762+ vm_flags &= ~VM_MAYWRITE;
92763+ }
92764+#endif
92765+
92766 vma->vm_flags = vm_flags | mm->def_flags | VM_DONTEXPAND | VM_SOFTDIRTY;
92767 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
92768
92769diff --git a/mm/mprotect.c b/mm/mprotect.c
92770index 7651a57..d761c62 100644
92771--- a/mm/mprotect.c
92772+++ b/mm/mprotect.c
92773@@ -23,10 +23,18 @@
92774 #include <linux/mmu_notifier.h>
92775 #include <linux/migrate.h>
92776 #include <linux/perf_event.h>
92777+#include <linux/sched/sysctl.h>
92778+
92779+#ifdef CONFIG_PAX_MPROTECT
92780+#include <linux/elf.h>
92781+#include <linux/binfmts.h>
92782+#endif
92783+
92784 #include <asm/uaccess.h>
92785 #include <asm/pgtable.h>
92786 #include <asm/cacheflush.h>
92787 #include <asm/tlbflush.h>
92788+#include <asm/mmu_context.h>
92789
92790 #ifndef pgprot_modify
92791 static inline pgprot_t pgprot_modify(pgprot_t oldprot, pgprot_t newprot)
92792@@ -250,6 +258,48 @@ unsigned long change_protection(struct vm_area_struct *vma, unsigned long start,
92793 return pages;
92794 }
92795
92796+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
92797+/* called while holding the mmap semaphor for writing except stack expansion */
92798+void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot)
92799+{
92800+ unsigned long oldlimit, newlimit = 0UL;
92801+
92802+ if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || (__supported_pte_mask & _PAGE_NX))
92803+ return;
92804+
92805+ spin_lock(&mm->page_table_lock);
92806+ oldlimit = mm->context.user_cs_limit;
92807+ if ((prot & VM_EXEC) && oldlimit < end)
92808+ /* USER_CS limit moved up */
92809+ newlimit = end;
92810+ else if (!(prot & VM_EXEC) && start < oldlimit && oldlimit <= end)
92811+ /* USER_CS limit moved down */
92812+ newlimit = start;
92813+
92814+ if (newlimit) {
92815+ mm->context.user_cs_limit = newlimit;
92816+
92817+#ifdef CONFIG_SMP
92818+ wmb();
92819+ cpus_clear(mm->context.cpu_user_cs_mask);
92820+ cpu_set(smp_processor_id(), mm->context.cpu_user_cs_mask);
92821+#endif
92822+
92823+ set_user_cs(mm->context.user_cs_base, mm->context.user_cs_limit, smp_processor_id());
92824+ }
92825+ spin_unlock(&mm->page_table_lock);
92826+ if (newlimit == end) {
92827+ struct vm_area_struct *vma = find_vma(mm, oldlimit);
92828+
92829+ for (; vma && vma->vm_start < end; vma = vma->vm_next)
92830+ if (is_vm_hugetlb_page(vma))
92831+ hugetlb_change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot);
92832+ else
92833+ change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot, vma_wants_writenotify(vma), 0);
92834+ }
92835+}
92836+#endif
92837+
92838 int
92839 mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
92840 unsigned long start, unsigned long end, unsigned long newflags)
92841@@ -262,11 +312,29 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
92842 int error;
92843 int dirty_accountable = 0;
92844
92845+#ifdef CONFIG_PAX_SEGMEXEC
92846+ struct vm_area_struct *vma_m = NULL;
92847+ unsigned long start_m, end_m;
92848+
92849+ start_m = start + SEGMEXEC_TASK_SIZE;
92850+ end_m = end + SEGMEXEC_TASK_SIZE;
92851+#endif
92852+
92853 if (newflags == oldflags) {
92854 *pprev = vma;
92855 return 0;
92856 }
92857
92858+ if (newflags & (VM_READ | VM_WRITE | VM_EXEC)) {
92859+ struct vm_area_struct *prev = vma->vm_prev, *next = vma->vm_next;
92860+
92861+ if (next && (next->vm_flags & VM_GROWSDOWN) && sysctl_heap_stack_gap > next->vm_start - end)
92862+ return -ENOMEM;
92863+
92864+ if (prev && (prev->vm_flags & VM_GROWSUP) && sysctl_heap_stack_gap > start - prev->vm_end)
92865+ return -ENOMEM;
92866+ }
92867+
92868 /*
92869 * If we make a private mapping writable we increase our commit;
92870 * but (without finer accounting) cannot reduce our commit if we
92871@@ -283,6 +351,42 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
92872 }
92873 }
92874
92875+#ifdef CONFIG_PAX_SEGMEXEC
92876+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && ((oldflags ^ newflags) & VM_EXEC)) {
92877+ if (start != vma->vm_start) {
92878+ error = split_vma(mm, vma, start, 1);
92879+ if (error)
92880+ goto fail;
92881+ BUG_ON(!*pprev || (*pprev)->vm_next == vma);
92882+ *pprev = (*pprev)->vm_next;
92883+ }
92884+
92885+ if (end != vma->vm_end) {
92886+ error = split_vma(mm, vma, end, 0);
92887+ if (error)
92888+ goto fail;
92889+ }
92890+
92891+ if (pax_find_mirror_vma(vma)) {
92892+ error = __do_munmap(mm, start_m, end_m - start_m);
92893+ if (error)
92894+ goto fail;
92895+ } else {
92896+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
92897+ if (!vma_m) {
92898+ error = -ENOMEM;
92899+ goto fail;
92900+ }
92901+ vma->vm_flags = newflags;
92902+ error = pax_mirror_vma(vma_m, vma);
92903+ if (error) {
92904+ vma->vm_flags = oldflags;
92905+ goto fail;
92906+ }
92907+ }
92908+ }
92909+#endif
92910+
92911 /*
92912 * First try to merge with previous and/or next vma.
92913 */
92914@@ -313,9 +417,21 @@ success:
92915 * vm_flags and vm_page_prot are protected by the mmap_sem
92916 * held in write mode.
92917 */
92918+
92919+#ifdef CONFIG_PAX_SEGMEXEC
92920+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (newflags & VM_EXEC) && ((vma->vm_flags ^ newflags) & VM_READ))
92921+ pax_find_mirror_vma(vma)->vm_flags ^= VM_READ;
92922+#endif
92923+
92924 vma->vm_flags = newflags;
92925+
92926+#ifdef CONFIG_PAX_MPROTECT
92927+ if (mm->binfmt && mm->binfmt->handle_mprotect)
92928+ mm->binfmt->handle_mprotect(vma, newflags);
92929+#endif
92930+
92931 vma->vm_page_prot = pgprot_modify(vma->vm_page_prot,
92932- vm_get_page_prot(newflags));
92933+ vm_get_page_prot(vma->vm_flags));
92934
92935 if (vma_wants_writenotify(vma)) {
92936 vma->vm_page_prot = vm_get_page_prot(newflags & ~VM_SHARED);
92937@@ -354,6 +470,17 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
92938 end = start + len;
92939 if (end <= start)
92940 return -ENOMEM;
92941+
92942+#ifdef CONFIG_PAX_SEGMEXEC
92943+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
92944+ if (end > SEGMEXEC_TASK_SIZE)
92945+ return -EINVAL;
92946+ } else
92947+#endif
92948+
92949+ if (end > TASK_SIZE)
92950+ return -EINVAL;
92951+
92952 if (!arch_validate_prot(prot))
92953 return -EINVAL;
92954
92955@@ -361,7 +488,7 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
92956 /*
92957 * Does the application expect PROT_READ to imply PROT_EXEC:
92958 */
92959- if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
92960+ if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
92961 prot |= PROT_EXEC;
92962
92963 vm_flags = calc_vm_prot_bits(prot);
92964@@ -393,6 +520,11 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
92965 if (start > vma->vm_start)
92966 prev = vma;
92967
92968+#ifdef CONFIG_PAX_MPROTECT
92969+ if (current->mm->binfmt && current->mm->binfmt->handle_mprotect)
92970+ current->mm->binfmt->handle_mprotect(vma, vm_flags);
92971+#endif
92972+
92973 for (nstart = start ; ; ) {
92974 unsigned long newflags;
92975
92976@@ -403,6 +535,14 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
92977
92978 /* newflags >> 4 shift VM_MAY% in place of VM_% */
92979 if ((newflags & ~(newflags >> 4)) & (VM_READ | VM_WRITE | VM_EXEC)) {
92980+ if (prot & (PROT_WRITE | PROT_EXEC))
92981+ gr_log_rwxmprotect(vma);
92982+
92983+ error = -EACCES;
92984+ goto out;
92985+ }
92986+
92987+ if (!gr_acl_handle_mprotect(vma->vm_file, prot)) {
92988 error = -EACCES;
92989 goto out;
92990 }
92991@@ -417,6 +557,9 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
92992 error = mprotect_fixup(vma, &prev, nstart, tmp, newflags);
92993 if (error)
92994 goto out;
92995+
92996+ track_exec_limit(current->mm, nstart, tmp, vm_flags);
92997+
92998 nstart = tmp;
92999
93000 if (nstart < prev->vm_end)
93001diff --git a/mm/mremap.c b/mm/mremap.c
93002index 0843feb..4f5b2e6 100644
93003--- a/mm/mremap.c
93004+++ b/mm/mremap.c
93005@@ -144,6 +144,12 @@ static void move_ptes(struct vm_area_struct *vma, pmd_t *old_pmd,
93006 continue;
93007 pte = ptep_get_and_clear(mm, old_addr, old_pte);
93008 pte = move_pte(pte, new_vma->vm_page_prot, old_addr, new_addr);
93009+
93010+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
93011+ if (!(__supported_pte_mask & _PAGE_NX) && pte_present(pte) && (new_vma->vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC)
93012+ pte = pte_exprotect(pte);
93013+#endif
93014+
93015 pte = move_soft_dirty_pte(pte);
93016 set_pte_at(mm, new_addr, new_pte, pte);
93017 }
93018@@ -337,6 +343,11 @@ static struct vm_area_struct *vma_to_resize(unsigned long addr,
93019 if (is_vm_hugetlb_page(vma))
93020 goto Einval;
93021
93022+#ifdef CONFIG_PAX_SEGMEXEC
93023+ if (pax_find_mirror_vma(vma))
93024+ goto Einval;
93025+#endif
93026+
93027 /* We can't remap across vm area boundaries */
93028 if (old_len > vma->vm_end - addr)
93029 goto Efault;
93030@@ -392,20 +403,25 @@ static unsigned long mremap_to(unsigned long addr, unsigned long old_len,
93031 unsigned long ret = -EINVAL;
93032 unsigned long charged = 0;
93033 unsigned long map_flags;
93034+ unsigned long pax_task_size = TASK_SIZE;
93035
93036 if (new_addr & ~PAGE_MASK)
93037 goto out;
93038
93039- if (new_len > TASK_SIZE || new_addr > TASK_SIZE - new_len)
93040+#ifdef CONFIG_PAX_SEGMEXEC
93041+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
93042+ pax_task_size = SEGMEXEC_TASK_SIZE;
93043+#endif
93044+
93045+ pax_task_size -= PAGE_SIZE;
93046+
93047+ if (new_len > TASK_SIZE || new_addr > pax_task_size - new_len)
93048 goto out;
93049
93050 /* Check if the location we're moving into overlaps the
93051 * old location at all, and fail if it does.
93052 */
93053- if ((new_addr <= addr) && (new_addr+new_len) > addr)
93054- goto out;
93055-
93056- if ((addr <= new_addr) && (addr+old_len) > new_addr)
93057+ if (addr + old_len > new_addr && new_addr + new_len > addr)
93058 goto out;
93059
93060 ret = do_munmap(mm, new_addr, new_len);
93061@@ -474,6 +490,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
93062 unsigned long ret = -EINVAL;
93063 unsigned long charged = 0;
93064 bool locked = false;
93065+ unsigned long pax_task_size = TASK_SIZE;
93066
93067 if (flags & ~(MREMAP_FIXED | MREMAP_MAYMOVE))
93068 return ret;
93069@@ -495,6 +512,17 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
93070 if (!new_len)
93071 return ret;
93072
93073+#ifdef CONFIG_PAX_SEGMEXEC
93074+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
93075+ pax_task_size = SEGMEXEC_TASK_SIZE;
93076+#endif
93077+
93078+ pax_task_size -= PAGE_SIZE;
93079+
93080+ if (new_len > pax_task_size || addr > pax_task_size-new_len ||
93081+ old_len > pax_task_size || addr > pax_task_size-old_len)
93082+ return ret;
93083+
93084 down_write(&current->mm->mmap_sem);
93085
93086 if (flags & MREMAP_FIXED) {
93087@@ -545,6 +573,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
93088 new_addr = addr;
93089 }
93090 ret = addr;
93091+ track_exec_limit(vma->vm_mm, vma->vm_start, addr + new_len, vma->vm_flags);
93092 goto out;
93093 }
93094 }
93095@@ -568,7 +597,12 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
93096 goto out;
93097 }
93098
93099+ map_flags = vma->vm_flags;
93100 ret = move_vma(vma, addr, old_len, new_len, new_addr, &locked);
93101+ if (!(ret & ~PAGE_MASK)) {
93102+ track_exec_limit(current->mm, addr, addr + old_len, 0UL);
93103+ track_exec_limit(current->mm, new_addr, new_addr + new_len, map_flags);
93104+ }
93105 }
93106 out:
93107 if (ret & ~PAGE_MASK)
93108diff --git a/mm/nommu.c b/mm/nommu.c
93109index ecd1f15..77039bd 100644
93110--- a/mm/nommu.c
93111+++ b/mm/nommu.c
93112@@ -64,7 +64,6 @@ int sysctl_max_map_count = DEFAULT_MAX_MAP_COUNT;
93113 int sysctl_nr_trim_pages = CONFIG_NOMMU_INITIAL_TRIM_EXCESS;
93114 unsigned long sysctl_user_reserve_kbytes __read_mostly = 1UL << 17; /* 128MB */
93115 unsigned long sysctl_admin_reserve_kbytes __read_mostly = 1UL << 13; /* 8MB */
93116-int heap_stack_gap = 0;
93117
93118 atomic_long_t mmap_pages_allocated;
93119
93120@@ -844,15 +843,6 @@ struct vm_area_struct *find_vma(struct mm_struct *mm, unsigned long addr)
93121 EXPORT_SYMBOL(find_vma);
93122
93123 /*
93124- * find a VMA
93125- * - we don't extend stack VMAs under NOMMU conditions
93126- */
93127-struct vm_area_struct *find_extend_vma(struct mm_struct *mm, unsigned long addr)
93128-{
93129- return find_vma(mm, addr);
93130-}
93131-
93132-/*
93133 * expand a stack to a given address
93134 * - not supported under NOMMU conditions
93135 */
93136@@ -1563,6 +1553,7 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
93137
93138 /* most fields are the same, copy all, and then fixup */
93139 *new = *vma;
93140+ INIT_LIST_HEAD(&new->anon_vma_chain);
93141 *region = *vma->vm_region;
93142 new->vm_region = region;
93143
93144@@ -1993,8 +1984,8 @@ int generic_file_remap_pages(struct vm_area_struct *vma, unsigned long addr,
93145 }
93146 EXPORT_SYMBOL(generic_file_remap_pages);
93147
93148-static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
93149- unsigned long addr, void *buf, int len, int write)
93150+static ssize_t __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
93151+ unsigned long addr, void *buf, size_t len, int write)
93152 {
93153 struct vm_area_struct *vma;
93154
93155@@ -2035,8 +2026,8 @@ static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
93156 *
93157 * The caller must hold a reference on @mm.
93158 */
93159-int access_remote_vm(struct mm_struct *mm, unsigned long addr,
93160- void *buf, int len, int write)
93161+ssize_t access_remote_vm(struct mm_struct *mm, unsigned long addr,
93162+ void *buf, size_t len, int write)
93163 {
93164 return __access_remote_vm(NULL, mm, addr, buf, len, write);
93165 }
93166@@ -2045,7 +2036,7 @@ int access_remote_vm(struct mm_struct *mm, unsigned long addr,
93167 * Access another process' address space.
93168 * - source/target buffer must be kernel space
93169 */
93170-int access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, int len, int write)
93171+ssize_t access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, size_t len, int write)
93172 {
93173 struct mm_struct *mm;
93174
93175diff --git a/mm/page-writeback.c b/mm/page-writeback.c
93176index 6380758..4064aec 100644
93177--- a/mm/page-writeback.c
93178+++ b/mm/page-writeback.c
93179@@ -690,7 +690,7 @@ static inline long long pos_ratio_polynom(unsigned long setpoint,
93180 * card's bdi_dirty may rush to many times higher than bdi_setpoint.
93181 * - the bdi dirty thresh drops quickly due to change of JBOD workload
93182 */
93183-static unsigned long bdi_position_ratio(struct backing_dev_info *bdi,
93184+static unsigned long __intentional_overflow(-1) bdi_position_ratio(struct backing_dev_info *bdi,
93185 unsigned long thresh,
93186 unsigned long bg_thresh,
93187 unsigned long dirty,
93188diff --git a/mm/page_alloc.c b/mm/page_alloc.c
93189index 317ea74..a4a1977 100644
93190--- a/mm/page_alloc.c
93191+++ b/mm/page_alloc.c
93192@@ -61,6 +61,7 @@
93193 #include <linux/page-debug-flags.h>
93194 #include <linux/hugetlb.h>
93195 #include <linux/sched/rt.h>
93196+#include <linux/random.h>
93197
93198 #include <asm/sections.h>
93199 #include <asm/tlbflush.h>
93200@@ -354,7 +355,7 @@ out:
93201 * This usage means that zero-order pages may not be compound.
93202 */
93203
93204-static void free_compound_page(struct page *page)
93205+void free_compound_page(struct page *page)
93206 {
93207 __free_pages_ok(page, compound_order(page));
93208 }
93209@@ -712,6 +713,10 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
93210 int i;
93211 int bad = 0;
93212
93213+#ifdef CONFIG_PAX_MEMORY_SANITIZE
93214+ unsigned long index = 1UL << order;
93215+#endif
93216+
93217 trace_mm_page_free(page, order);
93218 kmemcheck_free_shadow(page, order);
93219
93220@@ -728,6 +733,12 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
93221 debug_check_no_obj_freed(page_address(page),
93222 PAGE_SIZE << order);
93223 }
93224+
93225+#ifdef CONFIG_PAX_MEMORY_SANITIZE
93226+ for (; index; --index)
93227+ sanitize_highpage(page + index - 1);
93228+#endif
93229+
93230 arch_free_page(page, order);
93231 kernel_map_pages(page, 1 << order, 0);
93232
93233@@ -750,6 +761,20 @@ static void __free_pages_ok(struct page *page, unsigned int order)
93234 local_irq_restore(flags);
93235 }
93236
93237+#ifdef CONFIG_PAX_LATENT_ENTROPY
93238+bool __meminitdata extra_latent_entropy;
93239+
93240+static int __init setup_pax_extra_latent_entropy(char *str)
93241+{
93242+ extra_latent_entropy = true;
93243+ return 0;
93244+}
93245+early_param("pax_extra_latent_entropy", setup_pax_extra_latent_entropy);
93246+
93247+volatile u64 latent_entropy __latent_entropy;
93248+EXPORT_SYMBOL(latent_entropy);
93249+#endif
93250+
93251 void __init __free_pages_bootmem(struct page *page, unsigned int order)
93252 {
93253 unsigned int nr_pages = 1 << order;
93254@@ -765,6 +790,19 @@ void __init __free_pages_bootmem(struct page *page, unsigned int order)
93255 __ClearPageReserved(p);
93256 set_page_count(p, 0);
93257
93258+#ifdef CONFIG_PAX_LATENT_ENTROPY
93259+ if (extra_latent_entropy && !PageHighMem(page) && page_to_pfn(page) < 0x100000) {
93260+ u64 hash = 0;
93261+ size_t index, end = PAGE_SIZE * nr_pages / sizeof hash;
93262+ const u64 *data = lowmem_page_address(page);
93263+
93264+ for (index = 0; index < end; index++)
93265+ hash ^= hash + data[index];
93266+ latent_entropy ^= hash;
93267+ add_device_randomness((const void *)&latent_entropy, sizeof(latent_entropy));
93268+ }
93269+#endif
93270+
93271 page_zone(page)->managed_pages += nr_pages;
93272 set_page_refcounted(page);
93273 __free_pages(page, order);
93274@@ -870,8 +908,10 @@ static int prep_new_page(struct page *page, int order, gfp_t gfp_flags)
93275 arch_alloc_page(page, order);
93276 kernel_map_pages(page, 1 << order, 1);
93277
93278+#ifndef CONFIG_PAX_MEMORY_SANITIZE
93279 if (gfp_flags & __GFP_ZERO)
93280 prep_zero_page(page, order, gfp_flags);
93281+#endif
93282
93283 if (order && (gfp_flags & __GFP_COMP))
93284 prep_compound_page(page, order);
93285diff --git a/mm/page_io.c b/mm/page_io.c
93286index 8c79a47..a689e0d 100644
93287--- a/mm/page_io.c
93288+++ b/mm/page_io.c
93289@@ -260,7 +260,7 @@ int __swap_writepage(struct page *page, struct writeback_control *wbc,
93290 struct file *swap_file = sis->swap_file;
93291 struct address_space *mapping = swap_file->f_mapping;
93292 struct iovec iov = {
93293- .iov_base = kmap(page),
93294+ .iov_base = (void __force_user *)kmap(page),
93295 .iov_len = PAGE_SIZE,
93296 };
93297
93298diff --git a/mm/percpu.c b/mm/percpu.c
93299index 8c8e08f..73a5cda 100644
93300--- a/mm/percpu.c
93301+++ b/mm/percpu.c
93302@@ -122,7 +122,7 @@ static unsigned int pcpu_low_unit_cpu __read_mostly;
93303 static unsigned int pcpu_high_unit_cpu __read_mostly;
93304
93305 /* the address of the first chunk which starts with the kernel static area */
93306-void *pcpu_base_addr __read_mostly;
93307+void *pcpu_base_addr __read_only;
93308 EXPORT_SYMBOL_GPL(pcpu_base_addr);
93309
93310 static const int *pcpu_unit_map __read_mostly; /* cpu -> unit */
93311diff --git a/mm/process_vm_access.c b/mm/process_vm_access.c
93312index fd26d04..0cea1b0 100644
93313--- a/mm/process_vm_access.c
93314+++ b/mm/process_vm_access.c
93315@@ -13,6 +13,7 @@
93316 #include <linux/uio.h>
93317 #include <linux/sched.h>
93318 #include <linux/highmem.h>
93319+#include <linux/security.h>
93320 #include <linux/ptrace.h>
93321 #include <linux/slab.h>
93322 #include <linux/syscalls.h>
93323@@ -258,19 +259,19 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
93324 size_t iov_l_curr_offset = 0;
93325 ssize_t iov_len;
93326
93327+ return -ENOSYS; // PaX: until properly audited
93328+
93329 /*
93330 * Work out how many pages of struct pages we're going to need
93331 * when eventually calling get_user_pages
93332 */
93333 for (i = 0; i < riovcnt; i++) {
93334 iov_len = rvec[i].iov_len;
93335- if (iov_len > 0) {
93336- nr_pages_iov = ((unsigned long)rvec[i].iov_base
93337- + iov_len)
93338- / PAGE_SIZE - (unsigned long)rvec[i].iov_base
93339- / PAGE_SIZE + 1;
93340- nr_pages = max(nr_pages, nr_pages_iov);
93341- }
93342+ if (iov_len <= 0)
93343+ continue;
93344+ nr_pages_iov = ((unsigned long)rvec[i].iov_base + iov_len) / PAGE_SIZE -
93345+ (unsigned long)rvec[i].iov_base / PAGE_SIZE + 1;
93346+ nr_pages = max(nr_pages, nr_pages_iov);
93347 }
93348
93349 if (nr_pages == 0)
93350@@ -298,6 +299,11 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
93351 goto free_proc_pages;
93352 }
93353
93354+ if (gr_handle_ptrace(task, vm_write ? PTRACE_POKETEXT : PTRACE_ATTACH)) {
93355+ rc = -EPERM;
93356+ goto put_task_struct;
93357+ }
93358+
93359 mm = mm_access(task, PTRACE_MODE_ATTACH);
93360 if (!mm || IS_ERR(mm)) {
93361 rc = IS_ERR(mm) ? PTR_ERR(mm) : -ESRCH;
93362diff --git a/mm/rmap.c b/mm/rmap.c
93363index b9d2222..e4baa1f 100644
93364--- a/mm/rmap.c
93365+++ b/mm/rmap.c
93366@@ -163,6 +163,10 @@ int anon_vma_prepare(struct vm_area_struct *vma)
93367 struct anon_vma *anon_vma = vma->anon_vma;
93368 struct anon_vma_chain *avc;
93369
93370+#ifdef CONFIG_PAX_SEGMEXEC
93371+ struct anon_vma_chain *avc_m = NULL;
93372+#endif
93373+
93374 might_sleep();
93375 if (unlikely(!anon_vma)) {
93376 struct mm_struct *mm = vma->vm_mm;
93377@@ -172,6 +176,12 @@ int anon_vma_prepare(struct vm_area_struct *vma)
93378 if (!avc)
93379 goto out_enomem;
93380
93381+#ifdef CONFIG_PAX_SEGMEXEC
93382+ avc_m = anon_vma_chain_alloc(GFP_KERNEL);
93383+ if (!avc_m)
93384+ goto out_enomem_free_avc;
93385+#endif
93386+
93387 anon_vma = find_mergeable_anon_vma(vma);
93388 allocated = NULL;
93389 if (!anon_vma) {
93390@@ -185,6 +195,18 @@ int anon_vma_prepare(struct vm_area_struct *vma)
93391 /* page_table_lock to protect against threads */
93392 spin_lock(&mm->page_table_lock);
93393 if (likely(!vma->anon_vma)) {
93394+
93395+#ifdef CONFIG_PAX_SEGMEXEC
93396+ struct vm_area_struct *vma_m = pax_find_mirror_vma(vma);
93397+
93398+ if (vma_m) {
93399+ BUG_ON(vma_m->anon_vma);
93400+ vma_m->anon_vma = anon_vma;
93401+ anon_vma_chain_link(vma_m, avc_m, anon_vma);
93402+ avc_m = NULL;
93403+ }
93404+#endif
93405+
93406 vma->anon_vma = anon_vma;
93407 anon_vma_chain_link(vma, avc, anon_vma);
93408 allocated = NULL;
93409@@ -195,12 +217,24 @@ int anon_vma_prepare(struct vm_area_struct *vma)
93410
93411 if (unlikely(allocated))
93412 put_anon_vma(allocated);
93413+
93414+#ifdef CONFIG_PAX_SEGMEXEC
93415+ if (unlikely(avc_m))
93416+ anon_vma_chain_free(avc_m);
93417+#endif
93418+
93419 if (unlikely(avc))
93420 anon_vma_chain_free(avc);
93421 }
93422 return 0;
93423
93424 out_enomem_free_avc:
93425+
93426+#ifdef CONFIG_PAX_SEGMEXEC
93427+ if (avc_m)
93428+ anon_vma_chain_free(avc_m);
93429+#endif
93430+
93431 anon_vma_chain_free(avc);
93432 out_enomem:
93433 return -ENOMEM;
93434@@ -236,7 +270,7 @@ static inline void unlock_anon_vma_root(struct anon_vma *root)
93435 * Attach the anon_vmas from src to dst.
93436 * Returns 0 on success, -ENOMEM on failure.
93437 */
93438-int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
93439+int anon_vma_clone(struct vm_area_struct *dst, const struct vm_area_struct *src)
93440 {
93441 struct anon_vma_chain *avc, *pavc;
93442 struct anon_vma *root = NULL;
93443@@ -269,7 +303,7 @@ int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
93444 * the corresponding VMA in the parent process is attached to.
93445 * Returns 0 on success, non-zero on failure.
93446 */
93447-int anon_vma_fork(struct vm_area_struct *vma, struct vm_area_struct *pvma)
93448+int anon_vma_fork(struct vm_area_struct *vma, const struct vm_area_struct *pvma)
93449 {
93450 struct anon_vma_chain *avc;
93451 struct anon_vma *anon_vma;
93452@@ -373,8 +407,10 @@ static void anon_vma_ctor(void *data)
93453 void __init anon_vma_init(void)
93454 {
93455 anon_vma_cachep = kmem_cache_create("anon_vma", sizeof(struct anon_vma),
93456- 0, SLAB_DESTROY_BY_RCU|SLAB_PANIC, anon_vma_ctor);
93457- anon_vma_chain_cachep = KMEM_CACHE(anon_vma_chain, SLAB_PANIC);
93458+ 0, SLAB_DESTROY_BY_RCU|SLAB_PANIC|SLAB_NO_SANITIZE,
93459+ anon_vma_ctor);
93460+ anon_vma_chain_cachep = KMEM_CACHE(anon_vma_chain,
93461+ SLAB_PANIC|SLAB_NO_SANITIZE);
93462 }
93463
93464 /*
93465diff --git a/mm/shmem.c b/mm/shmem.c
93466index 8297623..6b9dfe9 100644
93467--- a/mm/shmem.c
93468+++ b/mm/shmem.c
93469@@ -33,7 +33,7 @@
93470 #include <linux/swap.h>
93471 #include <linux/aio.h>
93472
93473-static struct vfsmount *shm_mnt;
93474+struct vfsmount *shm_mnt;
93475
93476 #ifdef CONFIG_SHMEM
93477 /*
93478@@ -77,7 +77,7 @@ static struct vfsmount *shm_mnt;
93479 #define BOGO_DIRENT_SIZE 20
93480
93481 /* Symlink up to this size is kmalloc'ed instead of using a swappable page */
93482-#define SHORT_SYMLINK_LEN 128
93483+#define SHORT_SYMLINK_LEN 64
93484
93485 /*
93486 * shmem_fallocate and shmem_writepage communicate via inode->i_private
93487@@ -2232,6 +2232,11 @@ static const struct xattr_handler *shmem_xattr_handlers[] = {
93488 static int shmem_xattr_validate(const char *name)
93489 {
93490 struct { const char *prefix; size_t len; } arr[] = {
93491+
93492+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
93493+ { XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN},
93494+#endif
93495+
93496 { XATTR_SECURITY_PREFIX, XATTR_SECURITY_PREFIX_LEN },
93497 { XATTR_TRUSTED_PREFIX, XATTR_TRUSTED_PREFIX_LEN }
93498 };
93499@@ -2287,6 +2292,15 @@ static int shmem_setxattr(struct dentry *dentry, const char *name,
93500 if (err)
93501 return err;
93502
93503+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
93504+ if (!strncmp(name, XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN)) {
93505+ if (strcmp(name, XATTR_NAME_PAX_FLAGS))
93506+ return -EOPNOTSUPP;
93507+ if (size > 8)
93508+ return -EINVAL;
93509+ }
93510+#endif
93511+
93512 return simple_xattr_set(&info->xattrs, name, value, size, flags);
93513 }
93514
93515@@ -2599,8 +2613,7 @@ int shmem_fill_super(struct super_block *sb, void *data, int silent)
93516 int err = -ENOMEM;
93517
93518 /* Round up to L1_CACHE_BYTES to resist false sharing */
93519- sbinfo = kzalloc(max((int)sizeof(struct shmem_sb_info),
93520- L1_CACHE_BYTES), GFP_KERNEL);
93521+ sbinfo = kzalloc(max(sizeof(struct shmem_sb_info), L1_CACHE_BYTES), GFP_KERNEL);
93522 if (!sbinfo)
93523 return -ENOMEM;
93524
93525diff --git a/mm/slab.c b/mm/slab.c
93526index 2580db0..0523956 100644
93527--- a/mm/slab.c
93528+++ b/mm/slab.c
93529@@ -366,10 +366,12 @@ static void kmem_cache_node_init(struct kmem_cache_node *parent)
93530 if ((x)->max_freeable < i) \
93531 (x)->max_freeable = i; \
93532 } while (0)
93533-#define STATS_INC_ALLOCHIT(x) atomic_inc(&(x)->allochit)
93534-#define STATS_INC_ALLOCMISS(x) atomic_inc(&(x)->allocmiss)
93535-#define STATS_INC_FREEHIT(x) atomic_inc(&(x)->freehit)
93536-#define STATS_INC_FREEMISS(x) atomic_inc(&(x)->freemiss)
93537+#define STATS_INC_ALLOCHIT(x) atomic_inc_unchecked(&(x)->allochit)
93538+#define STATS_INC_ALLOCMISS(x) atomic_inc_unchecked(&(x)->allocmiss)
93539+#define STATS_INC_FREEHIT(x) atomic_inc_unchecked(&(x)->freehit)
93540+#define STATS_INC_FREEMISS(x) atomic_inc_unchecked(&(x)->freemiss)
93541+#define STATS_INC_SANITIZED(x) atomic_inc_unchecked(&(x)->sanitized)
93542+#define STATS_INC_NOT_SANITIZED(x) atomic_inc_unchecked(&(x)->not_sanitized)
93543 #else
93544 #define STATS_INC_ACTIVE(x) do { } while (0)
93545 #define STATS_DEC_ACTIVE(x) do { } while (0)
93546@@ -386,6 +388,8 @@ static void kmem_cache_node_init(struct kmem_cache_node *parent)
93547 #define STATS_INC_ALLOCMISS(x) do { } while (0)
93548 #define STATS_INC_FREEHIT(x) do { } while (0)
93549 #define STATS_INC_FREEMISS(x) do { } while (0)
93550+#define STATS_INC_SANITIZED(x) do { } while (0)
93551+#define STATS_INC_NOT_SANITIZED(x) do { } while (0)
93552 #endif
93553
93554 #if DEBUG
93555@@ -477,7 +481,7 @@ static inline void *index_to_obj(struct kmem_cache *cache, struct slab *slab,
93556 * reciprocal_divide(offset, cache->reciprocal_buffer_size)
93557 */
93558 static inline unsigned int obj_to_index(const struct kmem_cache *cache,
93559- const struct slab *slab, void *obj)
93560+ const struct slab *slab, const void *obj)
93561 {
93562 u32 offset = (obj - slab->s_mem);
93563 return reciprocal_divide(offset, cache->reciprocal_buffer_size);
93564@@ -1571,12 +1575,12 @@ void __init kmem_cache_init(void)
93565 */
93566
93567 kmalloc_caches[INDEX_AC] = create_kmalloc_cache("kmalloc-ac",
93568- kmalloc_size(INDEX_AC), ARCH_KMALLOC_FLAGS);
93569+ kmalloc_size(INDEX_AC), SLAB_USERCOPY | ARCH_KMALLOC_FLAGS);
93570
93571 if (INDEX_AC != INDEX_NODE)
93572 kmalloc_caches[INDEX_NODE] =
93573 create_kmalloc_cache("kmalloc-node",
93574- kmalloc_size(INDEX_NODE), ARCH_KMALLOC_FLAGS);
93575+ kmalloc_size(INDEX_NODE), SLAB_USERCOPY | ARCH_KMALLOC_FLAGS);
93576
93577 slab_early_init = 0;
93578
93579@@ -3577,6 +3581,21 @@ static inline void __cache_free(struct kmem_cache *cachep, void *objp,
93580 struct array_cache *ac = cpu_cache_get(cachep);
93581
93582 check_irq_off();
93583+
93584+#ifdef CONFIG_PAX_MEMORY_SANITIZE
93585+ if (pax_sanitize_slab) {
93586+ if (!(cachep->flags & (SLAB_POISON | SLAB_NO_SANITIZE))) {
93587+ memset(objp, PAX_MEMORY_SANITIZE_VALUE, cachep->object_size);
93588+
93589+ if (cachep->ctor)
93590+ cachep->ctor(objp);
93591+
93592+ STATS_INC_SANITIZED(cachep);
93593+ } else
93594+ STATS_INC_NOT_SANITIZED(cachep);
93595+ }
93596+#endif
93597+
93598 kmemleak_free_recursive(objp, cachep->flags);
93599 objp = cache_free_debugcheck(cachep, objp, caller);
93600
93601@@ -3805,6 +3824,7 @@ void kfree(const void *objp)
93602
93603 if (unlikely(ZERO_OR_NULL_PTR(objp)))
93604 return;
93605+ VM_BUG_ON(!virt_addr_valid(objp));
93606 local_irq_save(flags);
93607 kfree_debugcheck(objp);
93608 c = virt_to_cache(objp);
93609@@ -4246,14 +4266,22 @@ void slabinfo_show_stats(struct seq_file *m, struct kmem_cache *cachep)
93610 }
93611 /* cpu stats */
93612 {
93613- unsigned long allochit = atomic_read(&cachep->allochit);
93614- unsigned long allocmiss = atomic_read(&cachep->allocmiss);
93615- unsigned long freehit = atomic_read(&cachep->freehit);
93616- unsigned long freemiss = atomic_read(&cachep->freemiss);
93617+ unsigned long allochit = atomic_read_unchecked(&cachep->allochit);
93618+ unsigned long allocmiss = atomic_read_unchecked(&cachep->allocmiss);
93619+ unsigned long freehit = atomic_read_unchecked(&cachep->freehit);
93620+ unsigned long freemiss = atomic_read_unchecked(&cachep->freemiss);
93621
93622 seq_printf(m, " : cpustat %6lu %6lu %6lu %6lu",
93623 allochit, allocmiss, freehit, freemiss);
93624 }
93625+#ifdef CONFIG_PAX_MEMORY_SANITIZE
93626+ {
93627+ unsigned long sanitized = atomic_read_unchecked(&cachep->sanitized);
93628+ unsigned long not_sanitized = atomic_read_unchecked(&cachep->not_sanitized);
93629+
93630+ seq_printf(m, " : pax %6lu %6lu", sanitized, not_sanitized);
93631+ }
93632+#endif
93633 #endif
93634 }
93635
93636@@ -4471,13 +4499,71 @@ static const struct file_operations proc_slabstats_operations = {
93637 static int __init slab_proc_init(void)
93638 {
93639 #ifdef CONFIG_DEBUG_SLAB_LEAK
93640- proc_create("slab_allocators", 0, NULL, &proc_slabstats_operations);
93641+ proc_create("slab_allocators", S_IRUSR, NULL, &proc_slabstats_operations);
93642 #endif
93643 return 0;
93644 }
93645 module_init(slab_proc_init);
93646 #endif
93647
93648+bool is_usercopy_object(const void *ptr)
93649+{
93650+ struct page *page;
93651+ struct kmem_cache *cachep;
93652+
93653+ if (ZERO_OR_NULL_PTR(ptr))
93654+ return false;
93655+
93656+ if (!slab_is_available())
93657+ return false;
93658+
93659+ if (!virt_addr_valid(ptr))
93660+ return false;
93661+
93662+ page = virt_to_head_page(ptr);
93663+
93664+ if (!PageSlab(page))
93665+ return false;
93666+
93667+ cachep = page->slab_cache;
93668+ return cachep->flags & SLAB_USERCOPY;
93669+}
93670+
93671+#ifdef CONFIG_PAX_USERCOPY
93672+const char *check_heap_object(const void *ptr, unsigned long n)
93673+{
93674+ struct page *page;
93675+ struct kmem_cache *cachep;
93676+ struct slab *slabp;
93677+ unsigned int objnr;
93678+ unsigned long offset;
93679+
93680+ if (ZERO_OR_NULL_PTR(ptr))
93681+ return "<null>";
93682+
93683+ if (!virt_addr_valid(ptr))
93684+ return NULL;
93685+
93686+ page = virt_to_head_page(ptr);
93687+
93688+ if (!PageSlab(page))
93689+ return NULL;
93690+
93691+ cachep = page->slab_cache;
93692+ if (!(cachep->flags & SLAB_USERCOPY))
93693+ return cachep->name;
93694+
93695+ slabp = page->slab_page;
93696+ objnr = obj_to_index(cachep, slabp, ptr);
93697+ BUG_ON(objnr >= cachep->num);
93698+ offset = ptr - index_to_obj(cachep, slabp, objnr) - obj_offset(cachep);
93699+ if (offset <= cachep->object_size && n <= cachep->object_size - offset)
93700+ return NULL;
93701+
93702+ return cachep->name;
93703+}
93704+#endif
93705+
93706 /**
93707 * ksize - get the actual amount of memory allocated for a given object
93708 * @objp: Pointer to the object
93709diff --git a/mm/slab.h b/mm/slab.h
93710index a535033..2f98fe5 100644
93711--- a/mm/slab.h
93712+++ b/mm/slab.h
93713@@ -32,6 +32,15 @@ extern struct list_head slab_caches;
93714 /* The slab cache that manages slab cache information */
93715 extern struct kmem_cache *kmem_cache;
93716
93717+#ifdef CONFIG_PAX_MEMORY_SANITIZE
93718+#ifdef CONFIG_X86_64
93719+#define PAX_MEMORY_SANITIZE_VALUE '\xfe'
93720+#else
93721+#define PAX_MEMORY_SANITIZE_VALUE '\xff'
93722+#endif
93723+extern bool pax_sanitize_slab;
93724+#endif
93725+
93726 unsigned long calculate_alignment(unsigned long flags,
93727 unsigned long align, unsigned long size);
93728
93729@@ -67,7 +76,8 @@ __kmem_cache_alias(struct mem_cgroup *memcg, const char *name, size_t size,
93730
93731 /* Legal flag mask for kmem_cache_create(), for various configurations */
93732 #define SLAB_CORE_FLAGS (SLAB_HWCACHE_ALIGN | SLAB_CACHE_DMA | SLAB_PANIC | \
93733- SLAB_DESTROY_BY_RCU | SLAB_DEBUG_OBJECTS )
93734+ SLAB_DESTROY_BY_RCU | SLAB_DEBUG_OBJECTS | \
93735+ SLAB_USERCOPY | SLAB_NO_SANITIZE)
93736
93737 #if defined(CONFIG_DEBUG_SLAB)
93738 #define SLAB_DEBUG_FLAGS (SLAB_RED_ZONE | SLAB_POISON | SLAB_STORE_USER)
93739@@ -231,6 +241,9 @@ static inline struct kmem_cache *cache_from_obj(struct kmem_cache *s, void *x)
93740 return s;
93741
93742 page = virt_to_head_page(x);
93743+
93744+ BUG_ON(!PageSlab(page));
93745+
93746 cachep = page->slab_cache;
93747 if (slab_equal_or_root(cachep, s))
93748 return cachep;
93749diff --git a/mm/slab_common.c b/mm/slab_common.c
93750index e2e98af..3b1a163 100644
93751--- a/mm/slab_common.c
93752+++ b/mm/slab_common.c
93753@@ -23,11 +23,22 @@
93754
93755 #include "slab.h"
93756
93757-enum slab_state slab_state;
93758+enum slab_state slab_state __read_only;
93759 LIST_HEAD(slab_caches);
93760 DEFINE_MUTEX(slab_mutex);
93761 struct kmem_cache *kmem_cache;
93762
93763+#ifdef CONFIG_PAX_MEMORY_SANITIZE
93764+bool pax_sanitize_slab __read_only = true;
93765+static int __init pax_sanitize_slab_setup(char *str)
93766+{
93767+ pax_sanitize_slab = !!simple_strtol(str, NULL, 0);
93768+ printk("%sabled PaX slab sanitization\n", pax_sanitize_slab ? "En" : "Dis");
93769+ return 1;
93770+}
93771+__setup("pax_sanitize_slab=", pax_sanitize_slab_setup);
93772+#endif
93773+
93774 #ifdef CONFIG_DEBUG_VM
93775 static int kmem_cache_sanity_check(struct mem_cgroup *memcg, const char *name,
93776 size_t size)
93777@@ -212,7 +223,7 @@ kmem_cache_create_memcg(struct mem_cgroup *memcg, const char *name, size_t size,
93778
93779 err = __kmem_cache_create(s, flags);
93780 if (!err) {
93781- s->refcount = 1;
93782+ atomic_set(&s->refcount, 1);
93783 list_add(&s->list, &slab_caches);
93784 memcg_cache_list_add(memcg, s);
93785 } else {
93786@@ -258,8 +269,7 @@ void kmem_cache_destroy(struct kmem_cache *s)
93787
93788 get_online_cpus();
93789 mutex_lock(&slab_mutex);
93790- s->refcount--;
93791- if (!s->refcount) {
93792+ if (atomic_dec_and_test(&s->refcount)) {
93793 list_del(&s->list);
93794
93795 if (!__kmem_cache_shutdown(s)) {
93796@@ -305,7 +315,7 @@ void __init create_boot_cache(struct kmem_cache *s, const char *name, size_t siz
93797 panic("Creation of kmalloc slab %s size=%zu failed. Reason %d\n",
93798 name, size, err);
93799
93800- s->refcount = -1; /* Exempt from merging for now */
93801+ atomic_set(&s->refcount, -1); /* Exempt from merging for now */
93802 }
93803
93804 struct kmem_cache *__init create_kmalloc_cache(const char *name, size_t size,
93805@@ -318,7 +328,7 @@ struct kmem_cache *__init create_kmalloc_cache(const char *name, size_t size,
93806
93807 create_boot_cache(s, name, size, flags);
93808 list_add(&s->list, &slab_caches);
93809- s->refcount = 1;
93810+ atomic_set(&s->refcount, 1);
93811 return s;
93812 }
93813
93814@@ -330,6 +340,11 @@ struct kmem_cache *kmalloc_dma_caches[KMALLOC_SHIFT_HIGH + 1];
93815 EXPORT_SYMBOL(kmalloc_dma_caches);
93816 #endif
93817
93818+#ifdef CONFIG_PAX_USERCOPY_SLABS
93819+struct kmem_cache *kmalloc_usercopy_caches[KMALLOC_SHIFT_HIGH + 1];
93820+EXPORT_SYMBOL(kmalloc_usercopy_caches);
93821+#endif
93822+
93823 /*
93824 * Conversion table for small slabs sizes / 8 to the index in the
93825 * kmalloc array. This is necessary for slabs < 192 since we have non power
93826@@ -394,6 +409,13 @@ struct kmem_cache *kmalloc_slab(size_t size, gfp_t flags)
93827 return kmalloc_dma_caches[index];
93828
93829 #endif
93830+
93831+#ifdef CONFIG_PAX_USERCOPY_SLABS
93832+ if (unlikely((flags & GFP_USERCOPY)))
93833+ return kmalloc_usercopy_caches[index];
93834+
93835+#endif
93836+
93837 return kmalloc_caches[index];
93838 }
93839
93840@@ -450,7 +472,7 @@ void __init create_kmalloc_caches(unsigned long flags)
93841 for (i = KMALLOC_SHIFT_LOW; i <= KMALLOC_SHIFT_HIGH; i++) {
93842 if (!kmalloc_caches[i]) {
93843 kmalloc_caches[i] = create_kmalloc_cache(NULL,
93844- 1 << i, flags);
93845+ 1 << i, SLAB_USERCOPY | flags);
93846 }
93847
93848 /*
93849@@ -459,10 +481,10 @@ void __init create_kmalloc_caches(unsigned long flags)
93850 * earlier power of two caches
93851 */
93852 if (KMALLOC_MIN_SIZE <= 32 && !kmalloc_caches[1] && i == 6)
93853- kmalloc_caches[1] = create_kmalloc_cache(NULL, 96, flags);
93854+ kmalloc_caches[1] = create_kmalloc_cache(NULL, 96, SLAB_USERCOPY | flags);
93855
93856 if (KMALLOC_MIN_SIZE <= 64 && !kmalloc_caches[2] && i == 7)
93857- kmalloc_caches[2] = create_kmalloc_cache(NULL, 192, flags);
93858+ kmalloc_caches[2] = create_kmalloc_cache(NULL, 192, SLAB_USERCOPY | flags);
93859 }
93860
93861 /* Kmalloc array is now usable */
93862@@ -495,6 +517,23 @@ void __init create_kmalloc_caches(unsigned long flags)
93863 }
93864 }
93865 #endif
93866+
93867+#ifdef CONFIG_PAX_USERCOPY_SLABS
93868+ for (i = 0; i <= KMALLOC_SHIFT_HIGH; i++) {
93869+ struct kmem_cache *s = kmalloc_caches[i];
93870+
93871+ if (s) {
93872+ int size = kmalloc_size(i);
93873+ char *n = kasprintf(GFP_NOWAIT,
93874+ "usercopy-kmalloc-%d", size);
93875+
93876+ BUG_ON(!n);
93877+ kmalloc_usercopy_caches[i] = create_kmalloc_cache(n,
93878+ size, SLAB_USERCOPY | flags);
93879+ }
93880+ }
93881+#endif
93882+
93883 }
93884 #endif /* !CONFIG_SLOB */
93885
93886@@ -535,6 +574,9 @@ void print_slabinfo_header(struct seq_file *m)
93887 seq_puts(m, " : globalstat <listallocs> <maxobjs> <grown> <reaped> "
93888 "<error> <maxfreeable> <nodeallocs> <remotefrees> <alienoverflow>");
93889 seq_puts(m, " : cpustat <allochit> <allocmiss> <freehit> <freemiss>");
93890+#ifdef CONFIG_PAX_MEMORY_SANITIZE
93891+ seq_puts(m, " : pax <sanitized> <not_sanitized>");
93892+#endif
93893 #endif
93894 seq_putc(m, '\n');
93895 }
93896diff --git a/mm/slob.c b/mm/slob.c
93897index 4bf8809..98a6914 100644
93898--- a/mm/slob.c
93899+++ b/mm/slob.c
93900@@ -157,7 +157,7 @@ static void set_slob(slob_t *s, slobidx_t size, slob_t *next)
93901 /*
93902 * Return the size of a slob block.
93903 */
93904-static slobidx_t slob_units(slob_t *s)
93905+static slobidx_t slob_units(const slob_t *s)
93906 {
93907 if (s->units > 0)
93908 return s->units;
93909@@ -167,7 +167,7 @@ static slobidx_t slob_units(slob_t *s)
93910 /*
93911 * Return the next free slob block pointer after this one.
93912 */
93913-static slob_t *slob_next(slob_t *s)
93914+static slob_t *slob_next(const slob_t *s)
93915 {
93916 slob_t *base = (slob_t *)((unsigned long)s & PAGE_MASK);
93917 slobidx_t next;
93918@@ -182,14 +182,14 @@ static slob_t *slob_next(slob_t *s)
93919 /*
93920 * Returns true if s is the last free block in its page.
93921 */
93922-static int slob_last(slob_t *s)
93923+static int slob_last(const slob_t *s)
93924 {
93925 return !((unsigned long)slob_next(s) & ~PAGE_MASK);
93926 }
93927
93928-static void *slob_new_pages(gfp_t gfp, int order, int node)
93929+static struct page *slob_new_pages(gfp_t gfp, unsigned int order, int node)
93930 {
93931- void *page;
93932+ struct page *page;
93933
93934 #ifdef CONFIG_NUMA
93935 if (node != NUMA_NO_NODE)
93936@@ -201,14 +201,18 @@ static void *slob_new_pages(gfp_t gfp, int order, int node)
93937 if (!page)
93938 return NULL;
93939
93940- return page_address(page);
93941+ __SetPageSlab(page);
93942+ return page;
93943 }
93944
93945-static void slob_free_pages(void *b, int order)
93946+static void slob_free_pages(struct page *sp, int order)
93947 {
93948 if (current->reclaim_state)
93949 current->reclaim_state->reclaimed_slab += 1 << order;
93950- free_pages((unsigned long)b, order);
93951+ __ClearPageSlab(sp);
93952+ page_mapcount_reset(sp);
93953+ sp->private = 0;
93954+ __free_pages(sp, order);
93955 }
93956
93957 /*
93958@@ -313,15 +317,15 @@ static void *slob_alloc(size_t size, gfp_t gfp, int align, int node)
93959
93960 /* Not enough space: must allocate a new page */
93961 if (!b) {
93962- b = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
93963- if (!b)
93964+ sp = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
93965+ if (!sp)
93966 return NULL;
93967- sp = virt_to_page(b);
93968- __SetPageSlab(sp);
93969+ b = page_address(sp);
93970
93971 spin_lock_irqsave(&slob_lock, flags);
93972 sp->units = SLOB_UNITS(PAGE_SIZE);
93973 sp->freelist = b;
93974+ sp->private = 0;
93975 INIT_LIST_HEAD(&sp->list);
93976 set_slob(b, SLOB_UNITS(PAGE_SIZE), b + SLOB_UNITS(PAGE_SIZE));
93977 set_slob_page_free(sp, slob_list);
93978@@ -359,12 +363,15 @@ static void slob_free(void *block, int size)
93979 if (slob_page_free(sp))
93980 clear_slob_page_free(sp);
93981 spin_unlock_irqrestore(&slob_lock, flags);
93982- __ClearPageSlab(sp);
93983- page_mapcount_reset(sp);
93984- slob_free_pages(b, 0);
93985+ slob_free_pages(sp, 0);
93986 return;
93987 }
93988
93989+#ifdef CONFIG_PAX_MEMORY_SANITIZE
93990+ if (pax_sanitize_slab)
93991+ memset(block, PAX_MEMORY_SANITIZE_VALUE, size);
93992+#endif
93993+
93994 if (!slob_page_free(sp)) {
93995 /* This slob page is about to become partially free. Easy! */
93996 sp->units = units;
93997@@ -424,11 +431,10 @@ out:
93998 */
93999
94000 static __always_inline void *
94001-__do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
94002+__do_kmalloc_node_align(size_t size, gfp_t gfp, int node, unsigned long caller, int align)
94003 {
94004- unsigned int *m;
94005- int align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
94006- void *ret;
94007+ slob_t *m;
94008+ void *ret = NULL;
94009
94010 gfp &= gfp_allowed_mask;
94011
94012@@ -442,23 +448,41 @@ __do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
94013
94014 if (!m)
94015 return NULL;
94016- *m = size;
94017+ BUILD_BUG_ON(ARCH_KMALLOC_MINALIGN < 2 * SLOB_UNIT);
94018+ BUILD_BUG_ON(ARCH_SLAB_MINALIGN < 2 * SLOB_UNIT);
94019+ m[0].units = size;
94020+ m[1].units = align;
94021 ret = (void *)m + align;
94022
94023 trace_kmalloc_node(caller, ret,
94024 size, size + align, gfp, node);
94025 } else {
94026 unsigned int order = get_order(size);
94027+ struct page *page;
94028
94029 if (likely(order))
94030 gfp |= __GFP_COMP;
94031- ret = slob_new_pages(gfp, order, node);
94032+ page = slob_new_pages(gfp, order, node);
94033+ if (page) {
94034+ ret = page_address(page);
94035+ page->private = size;
94036+ }
94037
94038 trace_kmalloc_node(caller, ret,
94039 size, PAGE_SIZE << order, gfp, node);
94040 }
94041
94042- kmemleak_alloc(ret, size, 1, gfp);
94043+ return ret;
94044+}
94045+
94046+static __always_inline void *
94047+__do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
94048+{
94049+ int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
94050+ void *ret = __do_kmalloc_node_align(size, gfp, node, caller, align);
94051+
94052+ if (!ZERO_OR_NULL_PTR(ret))
94053+ kmemleak_alloc(ret, size, 1, gfp);
94054 return ret;
94055 }
94056
94057@@ -493,34 +517,112 @@ void kfree(const void *block)
94058 return;
94059 kmemleak_free(block);
94060
94061+ VM_BUG_ON(!virt_addr_valid(block));
94062 sp = virt_to_page(block);
94063- if (PageSlab(sp)) {
94064+ VM_BUG_ON(!PageSlab(sp));
94065+ if (!sp->private) {
94066 int align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
94067- unsigned int *m = (unsigned int *)(block - align);
94068- slob_free(m, *m + align);
94069- } else
94070+ slob_t *m = (slob_t *)(block - align);
94071+ slob_free(m, m[0].units + align);
94072+ } else {
94073+ __ClearPageSlab(sp);
94074+ page_mapcount_reset(sp);
94075+ sp->private = 0;
94076 __free_pages(sp, compound_order(sp));
94077+ }
94078 }
94079 EXPORT_SYMBOL(kfree);
94080
94081+bool is_usercopy_object(const void *ptr)
94082+{
94083+ if (!slab_is_available())
94084+ return false;
94085+
94086+ // PAX: TODO
94087+
94088+ return false;
94089+}
94090+
94091+#ifdef CONFIG_PAX_USERCOPY
94092+const char *check_heap_object(const void *ptr, unsigned long n)
94093+{
94094+ struct page *page;
94095+ const slob_t *free;
94096+ const void *base;
94097+ unsigned long flags;
94098+
94099+ if (ZERO_OR_NULL_PTR(ptr))
94100+ return "<null>";
94101+
94102+ if (!virt_addr_valid(ptr))
94103+ return NULL;
94104+
94105+ page = virt_to_head_page(ptr);
94106+ if (!PageSlab(page))
94107+ return NULL;
94108+
94109+ if (page->private) {
94110+ base = page;
94111+ if (base <= ptr && n <= page->private - (ptr - base))
94112+ return NULL;
94113+ return "<slob>";
94114+ }
94115+
94116+ /* some tricky double walking to find the chunk */
94117+ spin_lock_irqsave(&slob_lock, flags);
94118+ base = (void *)((unsigned long)ptr & PAGE_MASK);
94119+ free = page->freelist;
94120+
94121+ while (!slob_last(free) && (void *)free <= ptr) {
94122+ base = free + slob_units(free);
94123+ free = slob_next(free);
94124+ }
94125+
94126+ while (base < (void *)free) {
94127+ slobidx_t m = ((slob_t *)base)[0].units, align = ((slob_t *)base)[1].units;
94128+ int size = SLOB_UNIT * SLOB_UNITS(m + align);
94129+ int offset;
94130+
94131+ if (ptr < base + align)
94132+ break;
94133+
94134+ offset = ptr - base - align;
94135+ if (offset >= m) {
94136+ base += size;
94137+ continue;
94138+ }
94139+
94140+ if (n > m - offset)
94141+ break;
94142+
94143+ spin_unlock_irqrestore(&slob_lock, flags);
94144+ return NULL;
94145+ }
94146+
94147+ spin_unlock_irqrestore(&slob_lock, flags);
94148+ return "<slob>";
94149+}
94150+#endif
94151+
94152 /* can't use ksize for kmem_cache_alloc memory, only kmalloc */
94153 size_t ksize(const void *block)
94154 {
94155 struct page *sp;
94156 int align;
94157- unsigned int *m;
94158+ slob_t *m;
94159
94160 BUG_ON(!block);
94161 if (unlikely(block == ZERO_SIZE_PTR))
94162 return 0;
94163
94164 sp = virt_to_page(block);
94165- if (unlikely(!PageSlab(sp)))
94166- return PAGE_SIZE << compound_order(sp);
94167+ VM_BUG_ON(!PageSlab(sp));
94168+ if (sp->private)
94169+ return sp->private;
94170
94171 align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
94172- m = (unsigned int *)(block - align);
94173- return SLOB_UNITS(*m) * SLOB_UNIT;
94174+ m = (slob_t *)(block - align);
94175+ return SLOB_UNITS(m[0].units) * SLOB_UNIT;
94176 }
94177 EXPORT_SYMBOL(ksize);
94178
94179@@ -536,23 +638,33 @@ int __kmem_cache_create(struct kmem_cache *c, unsigned long flags)
94180
94181 void *slob_alloc_node(struct kmem_cache *c, gfp_t flags, int node)
94182 {
94183- void *b;
94184+ void *b = NULL;
94185
94186 flags &= gfp_allowed_mask;
94187
94188 lockdep_trace_alloc(flags);
94189
94190+#ifdef CONFIG_PAX_USERCOPY_SLABS
94191+ b = __do_kmalloc_node_align(c->size, flags, node, _RET_IP_, c->align);
94192+#else
94193 if (c->size < PAGE_SIZE) {
94194 b = slob_alloc(c->size, flags, c->align, node);
94195 trace_kmem_cache_alloc_node(_RET_IP_, b, c->object_size,
94196 SLOB_UNITS(c->size) * SLOB_UNIT,
94197 flags, node);
94198 } else {
94199- b = slob_new_pages(flags, get_order(c->size), node);
94200+ struct page *sp;
94201+
94202+ sp = slob_new_pages(flags, get_order(c->size), node);
94203+ if (sp) {
94204+ b = page_address(sp);
94205+ sp->private = c->size;
94206+ }
94207 trace_kmem_cache_alloc_node(_RET_IP_, b, c->object_size,
94208 PAGE_SIZE << get_order(c->size),
94209 flags, node);
94210 }
94211+#endif
94212
94213 if (b && c->ctor)
94214 c->ctor(b);
94215@@ -584,10 +696,14 @@ EXPORT_SYMBOL(kmem_cache_alloc_node);
94216
94217 static void __kmem_cache_free(void *b, int size)
94218 {
94219- if (size < PAGE_SIZE)
94220+ struct page *sp;
94221+
94222+ sp = virt_to_page(b);
94223+ BUG_ON(!PageSlab(sp));
94224+ if (!sp->private)
94225 slob_free(b, size);
94226 else
94227- slob_free_pages(b, get_order(size));
94228+ slob_free_pages(sp, get_order(size));
94229 }
94230
94231 static void kmem_rcu_free(struct rcu_head *head)
94232@@ -600,17 +716,31 @@ static void kmem_rcu_free(struct rcu_head *head)
94233
94234 void kmem_cache_free(struct kmem_cache *c, void *b)
94235 {
94236+ int size = c->size;
94237+
94238+#ifdef CONFIG_PAX_USERCOPY_SLABS
94239+ if (size + c->align < PAGE_SIZE) {
94240+ size += c->align;
94241+ b -= c->align;
94242+ }
94243+#endif
94244+
94245 kmemleak_free_recursive(b, c->flags);
94246 if (unlikely(c->flags & SLAB_DESTROY_BY_RCU)) {
94247 struct slob_rcu *slob_rcu;
94248- slob_rcu = b + (c->size - sizeof(struct slob_rcu));
94249- slob_rcu->size = c->size;
94250+ slob_rcu = b + (size - sizeof(struct slob_rcu));
94251+ slob_rcu->size = size;
94252 call_rcu(&slob_rcu->head, kmem_rcu_free);
94253 } else {
94254- __kmem_cache_free(b, c->size);
94255+ __kmem_cache_free(b, size);
94256 }
94257
94258+#ifdef CONFIG_PAX_USERCOPY_SLABS
94259+ trace_kfree(_RET_IP_, b);
94260+#else
94261 trace_kmem_cache_free(_RET_IP_, b);
94262+#endif
94263+
94264 }
94265 EXPORT_SYMBOL(kmem_cache_free);
94266
94267diff --git a/mm/slub.c b/mm/slub.c
94268index 96f2169..9111a59 100644
94269--- a/mm/slub.c
94270+++ b/mm/slub.c
94271@@ -207,7 +207,7 @@ struct track {
94272
94273 enum track_item { TRACK_ALLOC, TRACK_FREE };
94274
94275-#ifdef CONFIG_SYSFS
94276+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
94277 static int sysfs_slab_add(struct kmem_cache *);
94278 static int sysfs_slab_alias(struct kmem_cache *, const char *);
94279 static void sysfs_slab_remove(struct kmem_cache *);
94280@@ -530,7 +530,7 @@ static void print_track(const char *s, struct track *t)
94281 if (!t->addr)
94282 return;
94283
94284- printk(KERN_ERR "INFO: %s in %pS age=%lu cpu=%u pid=%d\n",
94285+ printk(KERN_ERR "INFO: %s in %pA age=%lu cpu=%u pid=%d\n",
94286 s, (void *)t->addr, jiffies - t->when, t->cpu, t->pid);
94287 #ifdef CONFIG_STACKTRACE
94288 {
94289@@ -2616,6 +2616,14 @@ static __always_inline void slab_free(struct kmem_cache *s,
94290
94291 slab_free_hook(s, x);
94292
94293+#ifdef CONFIG_PAX_MEMORY_SANITIZE
94294+ if (pax_sanitize_slab && !(s->flags & SLAB_NO_SANITIZE)) {
94295+ memset(x, PAX_MEMORY_SANITIZE_VALUE, s->object_size);
94296+ if (s->ctor)
94297+ s->ctor(x);
94298+ }
94299+#endif
94300+
94301 redo:
94302 /*
94303 * Determine the currently cpus per cpu slab.
94304@@ -2683,7 +2691,7 @@ static int slub_min_objects;
94305 * Merge control. If this is set then no merging of slab caches will occur.
94306 * (Could be removed. This was introduced to pacify the merge skeptics.)
94307 */
94308-static int slub_nomerge;
94309+static int slub_nomerge = 1;
94310
94311 /*
94312 * Calculate the order of allocation given an slab object size.
94313@@ -2960,6 +2968,9 @@ static int calculate_sizes(struct kmem_cache *s, int forced_order)
94314 s->inuse = size;
94315
94316 if (((flags & (SLAB_DESTROY_BY_RCU | SLAB_POISON)) ||
94317+#ifdef CONFIG_PAX_MEMORY_SANITIZE
94318+ (pax_sanitize_slab && !(flags & SLAB_NO_SANITIZE)) ||
94319+#endif
94320 s->ctor)) {
94321 /*
94322 * Relocate free pointer after the object if it is not
94323@@ -3305,6 +3316,59 @@ void *__kmalloc_node(size_t size, gfp_t flags, int node)
94324 EXPORT_SYMBOL(__kmalloc_node);
94325 #endif
94326
94327+bool is_usercopy_object(const void *ptr)
94328+{
94329+ struct page *page;
94330+ struct kmem_cache *s;
94331+
94332+ if (ZERO_OR_NULL_PTR(ptr))
94333+ return false;
94334+
94335+ if (!slab_is_available())
94336+ return false;
94337+
94338+ if (!virt_addr_valid(ptr))
94339+ return false;
94340+
94341+ page = virt_to_head_page(ptr);
94342+
94343+ if (!PageSlab(page))
94344+ return false;
94345+
94346+ s = page->slab_cache;
94347+ return s->flags & SLAB_USERCOPY;
94348+}
94349+
94350+#ifdef CONFIG_PAX_USERCOPY
94351+const char *check_heap_object(const void *ptr, unsigned long n)
94352+{
94353+ struct page *page;
94354+ struct kmem_cache *s;
94355+ unsigned long offset;
94356+
94357+ if (ZERO_OR_NULL_PTR(ptr))
94358+ return "<null>";
94359+
94360+ if (!virt_addr_valid(ptr))
94361+ return NULL;
94362+
94363+ page = virt_to_head_page(ptr);
94364+
94365+ if (!PageSlab(page))
94366+ return NULL;
94367+
94368+ s = page->slab_cache;
94369+ if (!(s->flags & SLAB_USERCOPY))
94370+ return s->name;
94371+
94372+ offset = (ptr - page_address(page)) % s->size;
94373+ if (offset <= s->object_size && n <= s->object_size - offset)
94374+ return NULL;
94375+
94376+ return s->name;
94377+}
94378+#endif
94379+
94380 size_t ksize(const void *object)
94381 {
94382 struct page *page;
94383@@ -3333,6 +3397,7 @@ void kfree(const void *x)
94384 if (unlikely(ZERO_OR_NULL_PTR(x)))
94385 return;
94386
94387+ VM_BUG_ON(!virt_addr_valid(x));
94388 page = virt_to_head_page(x);
94389 if (unlikely(!PageSlab(page))) {
94390 BUG_ON(!PageCompound(page));
94391@@ -3638,7 +3703,7 @@ static int slab_unmergeable(struct kmem_cache *s)
94392 /*
94393 * We may have set a slab to be unmergeable during bootstrap.
94394 */
94395- if (s->refcount < 0)
94396+ if (atomic_read(&s->refcount) < 0)
94397 return 1;
94398
94399 return 0;
94400@@ -3696,7 +3761,7 @@ __kmem_cache_alias(struct mem_cgroup *memcg, const char *name, size_t size,
94401
94402 s = find_mergeable(memcg, size, align, flags, name, ctor);
94403 if (s) {
94404- s->refcount++;
94405+ atomic_inc(&s->refcount);
94406 /*
94407 * Adjust the object sizes so that we clear
94408 * the complete object on kzalloc.
94409@@ -3705,7 +3770,7 @@ __kmem_cache_alias(struct mem_cgroup *memcg, const char *name, size_t size,
94410 s->inuse = max_t(int, s->inuse, ALIGN(size, sizeof(void *)));
94411
94412 if (sysfs_slab_alias(s, name)) {
94413- s->refcount--;
94414+ atomic_dec(&s->refcount);
94415 s = NULL;
94416 }
94417 }
94418@@ -3825,7 +3890,7 @@ void *__kmalloc_node_track_caller(size_t size, gfp_t gfpflags,
94419 }
94420 #endif
94421
94422-#ifdef CONFIG_SYSFS
94423+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
94424 static int count_inuse(struct page *page)
94425 {
94426 return page->inuse;
94427@@ -4214,12 +4279,12 @@ static void resiliency_test(void)
94428 validate_slab_cache(kmalloc_caches[9]);
94429 }
94430 #else
94431-#ifdef CONFIG_SYSFS
94432+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
94433 static void resiliency_test(void) {};
94434 #endif
94435 #endif
94436
94437-#ifdef CONFIG_SYSFS
94438+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
94439 enum slab_stat_type {
94440 SL_ALL, /* All slabs */
94441 SL_PARTIAL, /* Only partially allocated slabs */
94442@@ -4459,7 +4524,7 @@ SLAB_ATTR_RO(ctor);
94443
94444 static ssize_t aliases_show(struct kmem_cache *s, char *buf)
94445 {
94446- return sprintf(buf, "%d\n", s->refcount - 1);
94447+ return sprintf(buf, "%d\n", atomic_read(&s->refcount) - 1);
94448 }
94449 SLAB_ATTR_RO(aliases);
94450
94451@@ -4547,6 +4612,14 @@ static ssize_t cache_dma_show(struct kmem_cache *s, char *buf)
94452 SLAB_ATTR_RO(cache_dma);
94453 #endif
94454
94455+#ifdef CONFIG_PAX_USERCOPY_SLABS
94456+static ssize_t usercopy_show(struct kmem_cache *s, char *buf)
94457+{
94458+ return sprintf(buf, "%d\n", !!(s->flags & SLAB_USERCOPY));
94459+}
94460+SLAB_ATTR_RO(usercopy);
94461+#endif
94462+
94463 static ssize_t destroy_by_rcu_show(struct kmem_cache *s, char *buf)
94464 {
94465 return sprintf(buf, "%d\n", !!(s->flags & SLAB_DESTROY_BY_RCU));
94466@@ -4881,6 +4954,9 @@ static struct attribute *slab_attrs[] = {
94467 #ifdef CONFIG_ZONE_DMA
94468 &cache_dma_attr.attr,
94469 #endif
94470+#ifdef CONFIG_PAX_USERCOPY_SLABS
94471+ &usercopy_attr.attr,
94472+#endif
94473 #ifdef CONFIG_NUMA
94474 &remote_node_defrag_ratio_attr.attr,
94475 #endif
94476@@ -5113,6 +5189,7 @@ static char *create_unique_id(struct kmem_cache *s)
94477 return name;
94478 }
94479
94480+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
94481 static int sysfs_slab_add(struct kmem_cache *s)
94482 {
94483 int err;
94484@@ -5136,7 +5213,7 @@ static int sysfs_slab_add(struct kmem_cache *s)
94485 }
94486
94487 s->kobj.kset = slab_kset;
94488- err = kobject_init_and_add(&s->kobj, &slab_ktype, NULL, name);
94489+ err = kobject_init_and_add(&s->kobj, &slab_ktype, NULL, "%s", name);
94490 if (err) {
94491 kobject_put(&s->kobj);
94492 return err;
94493@@ -5170,6 +5247,7 @@ static void sysfs_slab_remove(struct kmem_cache *s)
94494 kobject_del(&s->kobj);
94495 kobject_put(&s->kobj);
94496 }
94497+#endif
94498
94499 /*
94500 * Need to buffer aliases during bootup until sysfs becomes
94501@@ -5183,6 +5261,7 @@ struct saved_alias {
94502
94503 static struct saved_alias *alias_list;
94504
94505+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
94506 static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
94507 {
94508 struct saved_alias *al;
94509@@ -5205,6 +5284,7 @@ static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
94510 alias_list = al;
94511 return 0;
94512 }
94513+#endif
94514
94515 static int __init slab_sysfs_init(void)
94516 {
94517diff --git a/mm/sparse-vmemmap.c b/mm/sparse-vmemmap.c
94518index 27eeab3..7c3f7f2 100644
94519--- a/mm/sparse-vmemmap.c
94520+++ b/mm/sparse-vmemmap.c
94521@@ -130,7 +130,7 @@ pud_t * __meminit vmemmap_pud_populate(pgd_t *pgd, unsigned long addr, int node)
94522 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
94523 if (!p)
94524 return NULL;
94525- pud_populate(&init_mm, pud, p);
94526+ pud_populate_kernel(&init_mm, pud, p);
94527 }
94528 return pud;
94529 }
94530@@ -142,7 +142,7 @@ pgd_t * __meminit vmemmap_pgd_populate(unsigned long addr, int node)
94531 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
94532 if (!p)
94533 return NULL;
94534- pgd_populate(&init_mm, pgd, p);
94535+ pgd_populate_kernel(&init_mm, pgd, p);
94536 }
94537 return pgd;
94538 }
94539diff --git a/mm/sparse.c b/mm/sparse.c
94540index 4ac1d7e..bbfcb1f 100644
94541--- a/mm/sparse.c
94542+++ b/mm/sparse.c
94543@@ -745,7 +745,7 @@ static void clear_hwpoisoned_pages(struct page *memmap, int nr_pages)
94544
94545 for (i = 0; i < PAGES_PER_SECTION; i++) {
94546 if (PageHWPoison(&memmap[i])) {
94547- atomic_long_sub(1, &num_poisoned_pages);
94548+ atomic_long_sub_unchecked(1, &num_poisoned_pages);
94549 ClearPageHWPoison(&memmap[i]);
94550 }
94551 }
94552diff --git a/mm/swap.c b/mm/swap.c
94553index 759c3ca..7c1a5b4 100644
94554--- a/mm/swap.c
94555+++ b/mm/swap.c
94556@@ -77,6 +77,8 @@ static void __put_compound_page(struct page *page)
94557
94558 __page_cache_release(page);
94559 dtor = get_compound_page_dtor(page);
94560+ if (!PageHuge(page))
94561+ BUG_ON(dtor != free_compound_page);
94562 (*dtor)(page);
94563 }
94564
94565diff --git a/mm/swapfile.c b/mm/swapfile.c
94566index de7c904..c84bf11 100644
94567--- a/mm/swapfile.c
94568+++ b/mm/swapfile.c
94569@@ -66,7 +66,7 @@ static DEFINE_MUTEX(swapon_mutex);
94570
94571 static DECLARE_WAIT_QUEUE_HEAD(proc_poll_wait);
94572 /* Activity counter to indicate that a swapon or swapoff has occurred */
94573-static atomic_t proc_poll_event = ATOMIC_INIT(0);
94574+static atomic_unchecked_t proc_poll_event = ATOMIC_INIT(0);
94575
94576 static inline unsigned char swap_count(unsigned char ent)
94577 {
94578@@ -1949,7 +1949,7 @@ SYSCALL_DEFINE1(swapoff, const char __user *, specialfile)
94579 }
94580 filp_close(swap_file, NULL);
94581 err = 0;
94582- atomic_inc(&proc_poll_event);
94583+ atomic_inc_unchecked(&proc_poll_event);
94584 wake_up_interruptible(&proc_poll_wait);
94585
94586 out_dput:
94587@@ -1966,8 +1966,8 @@ static unsigned swaps_poll(struct file *file, poll_table *wait)
94588
94589 poll_wait(file, &proc_poll_wait, wait);
94590
94591- if (seq->poll_event != atomic_read(&proc_poll_event)) {
94592- seq->poll_event = atomic_read(&proc_poll_event);
94593+ if (seq->poll_event != atomic_read_unchecked(&proc_poll_event)) {
94594+ seq->poll_event = atomic_read_unchecked(&proc_poll_event);
94595 return POLLIN | POLLRDNORM | POLLERR | POLLPRI;
94596 }
94597
94598@@ -2065,7 +2065,7 @@ static int swaps_open(struct inode *inode, struct file *file)
94599 return ret;
94600
94601 seq = file->private_data;
94602- seq->poll_event = atomic_read(&proc_poll_event);
94603+ seq->poll_event = atomic_read_unchecked(&proc_poll_event);
94604 return 0;
94605 }
94606
94607@@ -2524,7 +2524,7 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags)
94608 (frontswap_map) ? "FS" : "");
94609
94610 mutex_unlock(&swapon_mutex);
94611- atomic_inc(&proc_poll_event);
94612+ atomic_inc_unchecked(&proc_poll_event);
94613 wake_up_interruptible(&proc_poll_wait);
94614
94615 if (S_ISREG(inode->i_mode))
94616diff --git a/mm/util.c b/mm/util.c
94617index eaf63fc2..c6952b2 100644
94618--- a/mm/util.c
94619+++ b/mm/util.c
94620@@ -294,6 +294,12 @@ done:
94621 void arch_pick_mmap_layout(struct mm_struct *mm)
94622 {
94623 mm->mmap_base = TASK_UNMAPPED_BASE;
94624+
94625+#ifdef CONFIG_PAX_RANDMMAP
94626+ if (mm->pax_flags & MF_PAX_RANDMMAP)
94627+ mm->mmap_base += mm->delta_mmap;
94628+#endif
94629+
94630 mm->get_unmapped_area = arch_get_unmapped_area;
94631 }
94632 #endif
94633@@ -387,7 +393,10 @@ struct address_space *page_mapping(struct page *page)
94634 {
94635 struct address_space *mapping = page->mapping;
94636
94637- VM_BUG_ON(PageSlab(page));
94638+ /* This happens if someone calls flush_dcache_page on slab page */
94639+ if (unlikely(PageSlab(page)))
94640+ return NULL;
94641+
94642 if (unlikely(PageSwapCache(page))) {
94643 swp_entry_t entry;
94644
94645diff --git a/mm/vmalloc.c b/mm/vmalloc.c
94646index 1074543..136dbe0 100644
94647--- a/mm/vmalloc.c
94648+++ b/mm/vmalloc.c
94649@@ -59,8 +59,19 @@ static void vunmap_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end)
94650
94651 pte = pte_offset_kernel(pmd, addr);
94652 do {
94653- pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
94654- WARN_ON(!pte_none(ptent) && !pte_present(ptent));
94655+
94656+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
94657+ if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr < (unsigned long)MODULES_EXEC_END) {
94658+ BUG_ON(!pte_exec(*pte));
94659+ set_pte_at(&init_mm, addr, pte, pfn_pte(__pa(addr) >> PAGE_SHIFT, PAGE_KERNEL_EXEC));
94660+ continue;
94661+ }
94662+#endif
94663+
94664+ {
94665+ pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
94666+ WARN_ON(!pte_none(ptent) && !pte_present(ptent));
94667+ }
94668 } while (pte++, addr += PAGE_SIZE, addr != end);
94669 }
94670
94671@@ -120,16 +131,29 @@ static int vmap_pte_range(pmd_t *pmd, unsigned long addr,
94672 pte = pte_alloc_kernel(pmd, addr);
94673 if (!pte)
94674 return -ENOMEM;
94675+
94676+ pax_open_kernel();
94677 do {
94678 struct page *page = pages[*nr];
94679
94680- if (WARN_ON(!pte_none(*pte)))
94681+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
94682+ if (pgprot_val(prot) & _PAGE_NX)
94683+#endif
94684+
94685+ if (!pte_none(*pte)) {
94686+ pax_close_kernel();
94687+ WARN_ON(1);
94688 return -EBUSY;
94689- if (WARN_ON(!page))
94690+ }
94691+ if (!page) {
94692+ pax_close_kernel();
94693+ WARN_ON(1);
94694 return -ENOMEM;
94695+ }
94696 set_pte_at(&init_mm, addr, pte, mk_pte(page, prot));
94697 (*nr)++;
94698 } while (pte++, addr += PAGE_SIZE, addr != end);
94699+ pax_close_kernel();
94700 return 0;
94701 }
94702
94703@@ -139,7 +163,7 @@ static int vmap_pmd_range(pud_t *pud, unsigned long addr,
94704 pmd_t *pmd;
94705 unsigned long next;
94706
94707- pmd = pmd_alloc(&init_mm, pud, addr);
94708+ pmd = pmd_alloc_kernel(&init_mm, pud, addr);
94709 if (!pmd)
94710 return -ENOMEM;
94711 do {
94712@@ -156,7 +180,7 @@ static int vmap_pud_range(pgd_t *pgd, unsigned long addr,
94713 pud_t *pud;
94714 unsigned long next;
94715
94716- pud = pud_alloc(&init_mm, pgd, addr);
94717+ pud = pud_alloc_kernel(&init_mm, pgd, addr);
94718 if (!pud)
94719 return -ENOMEM;
94720 do {
94721@@ -216,6 +240,12 @@ int is_vmalloc_or_module_addr(const void *x)
94722 if (addr >= MODULES_VADDR && addr < MODULES_END)
94723 return 1;
94724 #endif
94725+
94726+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
94727+ if (x >= (const void *)MODULES_EXEC_VADDR && x < (const void *)MODULES_EXEC_END)
94728+ return 1;
94729+#endif
94730+
94731 return is_vmalloc_addr(x);
94732 }
94733
94734@@ -236,8 +266,14 @@ struct page *vmalloc_to_page(const void *vmalloc_addr)
94735
94736 if (!pgd_none(*pgd)) {
94737 pud_t *pud = pud_offset(pgd, addr);
94738+#ifdef CONFIG_X86
94739+ if (!pud_large(*pud))
94740+#endif
94741 if (!pud_none(*pud)) {
94742 pmd_t *pmd = pmd_offset(pud, addr);
94743+#ifdef CONFIG_X86
94744+ if (!pmd_large(*pmd))
94745+#endif
94746 if (!pmd_none(*pmd)) {
94747 pte_t *ptep, pte;
94748
94749@@ -1303,6 +1339,16 @@ static struct vm_struct *__get_vm_area_node(unsigned long size,
94750 struct vm_struct *area;
94751
94752 BUG_ON(in_interrupt());
94753+
94754+#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
94755+ if (flags & VM_KERNEXEC) {
94756+ if (start != VMALLOC_START || end != VMALLOC_END)
94757+ return NULL;
94758+ start = (unsigned long)MODULES_EXEC_VADDR;
94759+ end = (unsigned long)MODULES_EXEC_END;
94760+ }
94761+#endif
94762+
94763 if (flags & VM_IOREMAP)
94764 align = 1ul << clamp(fls(size), PAGE_SHIFT, IOREMAP_MAX_ORDER);
94765
94766@@ -1528,6 +1574,11 @@ void *vmap(struct page **pages, unsigned int count,
94767 if (count > totalram_pages)
94768 return NULL;
94769
94770+#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
94771+ if (!(pgprot_val(prot) & _PAGE_NX))
94772+ flags |= VM_KERNEXEC;
94773+#endif
94774+
94775 area = get_vm_area_caller((count << PAGE_SHIFT), flags,
94776 __builtin_return_address(0));
94777 if (!area)
94778@@ -1629,6 +1680,13 @@ void *__vmalloc_node_range(unsigned long size, unsigned long align,
94779 if (!size || (size >> PAGE_SHIFT) > totalram_pages)
94780 goto fail;
94781
94782+#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
94783+ if (!(pgprot_val(prot) & _PAGE_NX))
94784+ area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNINITIALIZED | VM_KERNEXEC,
94785+ VMALLOC_START, VMALLOC_END, node, gfp_mask, caller);
94786+ else
94787+#endif
94788+
94789 area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNINITIALIZED,
94790 start, end, node, gfp_mask, caller);
94791 if (!area)
94792@@ -1805,10 +1863,9 @@ EXPORT_SYMBOL(vzalloc_node);
94793 * For tight control over page level allocator and protection flags
94794 * use __vmalloc() instead.
94795 */
94796-
94797 void *vmalloc_exec(unsigned long size)
94798 {
94799- return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
94800+ return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, PAGE_KERNEL_EXEC,
94801 NUMA_NO_NODE, __builtin_return_address(0));
94802 }
94803
94804@@ -2115,6 +2172,8 @@ int remap_vmalloc_range_partial(struct vm_area_struct *vma, unsigned long uaddr,
94805 {
94806 struct vm_struct *area;
94807
94808+ BUG_ON(vma->vm_mirror);
94809+
94810 size = PAGE_ALIGN(size);
94811
94812 if (!PAGE_ALIGNED(uaddr) || !PAGE_ALIGNED(kaddr))
94813@@ -2600,7 +2659,11 @@ static int s_show(struct seq_file *m, void *p)
94814 v->addr, v->addr + v->size, v->size);
94815
94816 if (v->caller)
94817+#ifdef CONFIG_GRKERNSEC_HIDESYM
94818+ seq_printf(m, " %pK", v->caller);
94819+#else
94820 seq_printf(m, " %pS", v->caller);
94821+#endif
94822
94823 if (v->nr_pages)
94824 seq_printf(m, " pages=%d", v->nr_pages);
94825diff --git a/mm/vmstat.c b/mm/vmstat.c
94826index 5a442a7..dbbda4a 100644
94827--- a/mm/vmstat.c
94828+++ b/mm/vmstat.c
94829@@ -20,6 +20,7 @@
94830 #include <linux/writeback.h>
94831 #include <linux/compaction.h>
94832 #include <linux/mm_inline.h>
94833+#include <linux/grsecurity.h>
94834
94835 #include "internal.h"
94836
94837@@ -79,7 +80,7 @@ void vm_events_fold_cpu(int cpu)
94838 *
94839 * vm_stat contains the global counters
94840 */
94841-atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
94842+atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
94843 EXPORT_SYMBOL(vm_stat);
94844
94845 #ifdef CONFIG_SMP
94846@@ -423,7 +424,7 @@ static inline void fold_diff(int *diff)
94847
94848 for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)
94849 if (diff[i])
94850- atomic_long_add(diff[i], &vm_stat[i]);
94851+ atomic_long_add_unchecked(diff[i], &vm_stat[i]);
94852 }
94853
94854 /*
94855@@ -455,7 +456,7 @@ static void refresh_cpu_vm_stats(void)
94856 v = this_cpu_xchg(p->vm_stat_diff[i], 0);
94857 if (v) {
94858
94859- atomic_long_add(v, &zone->vm_stat[i]);
94860+ atomic_long_add_unchecked(v, &zone->vm_stat[i]);
94861 global_diff[i] += v;
94862 #ifdef CONFIG_NUMA
94863 /* 3 seconds idle till flush */
94864@@ -517,7 +518,7 @@ void cpu_vm_stats_fold(int cpu)
94865
94866 v = p->vm_stat_diff[i];
94867 p->vm_stat_diff[i] = 0;
94868- atomic_long_add(v, &zone->vm_stat[i]);
94869+ atomic_long_add_unchecked(v, &zone->vm_stat[i]);
94870 global_diff[i] += v;
94871 }
94872 }
94873@@ -537,8 +538,8 @@ void drain_zonestat(struct zone *zone, struct per_cpu_pageset *pset)
94874 if (pset->vm_stat_diff[i]) {
94875 int v = pset->vm_stat_diff[i];
94876 pset->vm_stat_diff[i] = 0;
94877- atomic_long_add(v, &zone->vm_stat[i]);
94878- atomic_long_add(v, &vm_stat[i]);
94879+ atomic_long_add_unchecked(v, &zone->vm_stat[i]);
94880+ atomic_long_add_unchecked(v, &vm_stat[i]);
94881 }
94882 }
94883 #endif
94884@@ -1148,10 +1149,22 @@ static void *vmstat_start(struct seq_file *m, loff_t *pos)
94885 stat_items_size += sizeof(struct vm_event_state);
94886 #endif
94887
94888- v = kmalloc(stat_items_size, GFP_KERNEL);
94889+ v = kzalloc(stat_items_size, GFP_KERNEL);
94890 m->private = v;
94891 if (!v)
94892 return ERR_PTR(-ENOMEM);
94893+
94894+#ifdef CONFIG_GRKERNSEC_PROC_ADD
94895+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
94896+ if (!uid_eq(current_uid(), GLOBAL_ROOT_UID)
94897+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
94898+ && !in_group_p(grsec_proc_gid)
94899+#endif
94900+ )
94901+ return (unsigned long *)m->private + *pos;
94902+#endif
94903+#endif
94904+
94905 for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)
94906 v[i] = global_page_state(i);
94907 v += NR_VM_ZONE_STAT_ITEMS;
94908@@ -1281,10 +1294,16 @@ static int __init setup_vmstat(void)
94909 start_cpu_timer(cpu);
94910 #endif
94911 #ifdef CONFIG_PROC_FS
94912- proc_create("buddyinfo", S_IRUGO, NULL, &fragmentation_file_operations);
94913- proc_create("pagetypeinfo", S_IRUGO, NULL, &pagetypeinfo_file_ops);
94914- proc_create("vmstat", S_IRUGO, NULL, &proc_vmstat_file_operations);
94915- proc_create("zoneinfo", S_IRUGO, NULL, &proc_zoneinfo_file_operations);
94916+ {
94917+ mode_t gr_mode = S_IRUGO;
94918+#ifdef CONFIG_GRKERNSEC_PROC_ADD
94919+ gr_mode = S_IRUSR;
94920+#endif
94921+ proc_create("buddyinfo", gr_mode, NULL, &fragmentation_file_operations);
94922+ proc_create("pagetypeinfo", gr_mode, NULL, &pagetypeinfo_file_ops);
94923+ proc_create("vmstat", S_IRUGO, NULL, &proc_vmstat_file_operations);
94924+ proc_create("zoneinfo", gr_mode, NULL, &proc_zoneinfo_file_operations);
94925+ }
94926 #endif
94927 return 0;
94928 }
94929diff --git a/net/8021q/vlan.c b/net/8021q/vlan.c
94930index 61fc573..b5e47d0 100644
94931--- a/net/8021q/vlan.c
94932+++ b/net/8021q/vlan.c
94933@@ -472,7 +472,7 @@ out:
94934 return NOTIFY_DONE;
94935 }
94936
94937-static struct notifier_block vlan_notifier_block __read_mostly = {
94938+static struct notifier_block vlan_notifier_block = {
94939 .notifier_call = vlan_device_event,
94940 };
94941
94942@@ -547,8 +547,7 @@ static int vlan_ioctl_handler(struct net *net, void __user *arg)
94943 err = -EPERM;
94944 if (!ns_capable(net->user_ns, CAP_NET_ADMIN))
94945 break;
94946- if ((args.u.name_type >= 0) &&
94947- (args.u.name_type < VLAN_NAME_TYPE_HIGHEST)) {
94948+ if (args.u.name_type < VLAN_NAME_TYPE_HIGHEST) {
94949 struct vlan_net *vn;
94950
94951 vn = net_generic(net, vlan_net_id);
94952diff --git a/net/9p/mod.c b/net/9p/mod.c
94953index 6ab36ae..6f1841b 100644
94954--- a/net/9p/mod.c
94955+++ b/net/9p/mod.c
94956@@ -84,7 +84,7 @@ static LIST_HEAD(v9fs_trans_list);
94957 void v9fs_register_trans(struct p9_trans_module *m)
94958 {
94959 spin_lock(&v9fs_trans_lock);
94960- list_add_tail(&m->list, &v9fs_trans_list);
94961+ pax_list_add_tail((struct list_head *)&m->list, &v9fs_trans_list);
94962 spin_unlock(&v9fs_trans_lock);
94963 }
94964 EXPORT_SYMBOL(v9fs_register_trans);
94965@@ -97,7 +97,7 @@ EXPORT_SYMBOL(v9fs_register_trans);
94966 void v9fs_unregister_trans(struct p9_trans_module *m)
94967 {
94968 spin_lock(&v9fs_trans_lock);
94969- list_del_init(&m->list);
94970+ pax_list_del_init((struct list_head *)&m->list);
94971 spin_unlock(&v9fs_trans_lock);
94972 }
94973 EXPORT_SYMBOL(v9fs_unregister_trans);
94974diff --git a/net/9p/trans_fd.c b/net/9p/trans_fd.c
94975index 3ffda1b..fceac96 100644
94976--- a/net/9p/trans_fd.c
94977+++ b/net/9p/trans_fd.c
94978@@ -432,7 +432,7 @@ static int p9_fd_write(struct p9_client *client, void *v, int len)
94979 oldfs = get_fs();
94980 set_fs(get_ds());
94981 /* The cast to a user pointer is valid due to the set_fs() */
94982- ret = vfs_write(ts->wr, (__force void __user *)v, len, &ts->wr->f_pos);
94983+ ret = vfs_write(ts->wr, (void __force_user *)v, len, &ts->wr->f_pos);
94984 set_fs(oldfs);
94985
94986 if (ret <= 0 && ret != -ERESTARTSYS && ret != -EAGAIN)
94987diff --git a/net/atm/atm_misc.c b/net/atm/atm_misc.c
94988index 876fbe8..8bbea9f 100644
94989--- a/net/atm/atm_misc.c
94990+++ b/net/atm/atm_misc.c
94991@@ -17,7 +17,7 @@ int atm_charge(struct atm_vcc *vcc, int truesize)
94992 if (atomic_read(&sk_atm(vcc)->sk_rmem_alloc) <= sk_atm(vcc)->sk_rcvbuf)
94993 return 1;
94994 atm_return(vcc, truesize);
94995- atomic_inc(&vcc->stats->rx_drop);
94996+ atomic_inc_unchecked(&vcc->stats->rx_drop);
94997 return 0;
94998 }
94999 EXPORT_SYMBOL(atm_charge);
95000@@ -39,7 +39,7 @@ struct sk_buff *atm_alloc_charge(struct atm_vcc *vcc, int pdu_size,
95001 }
95002 }
95003 atm_return(vcc, guess);
95004- atomic_inc(&vcc->stats->rx_drop);
95005+ atomic_inc_unchecked(&vcc->stats->rx_drop);
95006 return NULL;
95007 }
95008 EXPORT_SYMBOL(atm_alloc_charge);
95009@@ -86,7 +86,7 @@ EXPORT_SYMBOL(atm_pcr_goal);
95010
95011 void sonet_copy_stats(struct k_sonet_stats *from, struct sonet_stats *to)
95012 {
95013-#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
95014+#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
95015 __SONET_ITEMS
95016 #undef __HANDLE_ITEM
95017 }
95018@@ -94,7 +94,7 @@ EXPORT_SYMBOL(sonet_copy_stats);
95019
95020 void sonet_subtract_stats(struct k_sonet_stats *from, struct sonet_stats *to)
95021 {
95022-#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
95023+#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i,&from->i)
95024 __SONET_ITEMS
95025 #undef __HANDLE_ITEM
95026 }
95027diff --git a/net/atm/lec.c b/net/atm/lec.c
95028index f23916b..dd4d26b 100644
95029--- a/net/atm/lec.c
95030+++ b/net/atm/lec.c
95031@@ -111,9 +111,9 @@ static inline void lec_arp_put(struct lec_arp_table *entry)
95032 }
95033
95034 static struct lane2_ops lane2_ops = {
95035- lane2_resolve, /* resolve, spec 3.1.3 */
95036- lane2_associate_req, /* associate_req, spec 3.1.4 */
95037- NULL /* associate indicator, spec 3.1.5 */
95038+ .resolve = lane2_resolve,
95039+ .associate_req = lane2_associate_req,
95040+ .associate_indicator = NULL
95041 };
95042
95043 static unsigned char bus_mac[ETH_ALEN] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
95044diff --git a/net/atm/lec.h b/net/atm/lec.h
95045index 4149db1..f2ab682 100644
95046--- a/net/atm/lec.h
95047+++ b/net/atm/lec.h
95048@@ -48,7 +48,7 @@ struct lane2_ops {
95049 const u8 *tlvs, u32 sizeoftlvs);
95050 void (*associate_indicator) (struct net_device *dev, const u8 *mac_addr,
95051 const u8 *tlvs, u32 sizeoftlvs);
95052-};
95053+} __no_const;
95054
95055 /*
95056 * ATM LAN Emulation supports both LLC & Dix Ethernet EtherType
95057diff --git a/net/atm/mpoa_caches.c b/net/atm/mpoa_caches.c
95058index d1b2d9a..d549f7f 100644
95059--- a/net/atm/mpoa_caches.c
95060+++ b/net/atm/mpoa_caches.c
95061@@ -535,30 +535,30 @@ static void eg_destroy_cache(struct mpoa_client *mpc)
95062
95063
95064 static struct in_cache_ops ingress_ops = {
95065- in_cache_add_entry, /* add_entry */
95066- in_cache_get, /* get */
95067- in_cache_get_with_mask, /* get_with_mask */
95068- in_cache_get_by_vcc, /* get_by_vcc */
95069- in_cache_put, /* put */
95070- in_cache_remove_entry, /* remove_entry */
95071- cache_hit, /* cache_hit */
95072- clear_count_and_expired, /* clear_count */
95073- check_resolving_entries, /* check_resolving */
95074- refresh_entries, /* refresh */
95075- in_destroy_cache /* destroy_cache */
95076+ .add_entry = in_cache_add_entry,
95077+ .get = in_cache_get,
95078+ .get_with_mask = in_cache_get_with_mask,
95079+ .get_by_vcc = in_cache_get_by_vcc,
95080+ .put = in_cache_put,
95081+ .remove_entry = in_cache_remove_entry,
95082+ .cache_hit = cache_hit,
95083+ .clear_count = clear_count_and_expired,
95084+ .check_resolving = check_resolving_entries,
95085+ .refresh = refresh_entries,
95086+ .destroy_cache = in_destroy_cache
95087 };
95088
95089 static struct eg_cache_ops egress_ops = {
95090- eg_cache_add_entry, /* add_entry */
95091- eg_cache_get_by_cache_id, /* get_by_cache_id */
95092- eg_cache_get_by_tag, /* get_by_tag */
95093- eg_cache_get_by_vcc, /* get_by_vcc */
95094- eg_cache_get_by_src_ip, /* get_by_src_ip */
95095- eg_cache_put, /* put */
95096- eg_cache_remove_entry, /* remove_entry */
95097- update_eg_cache_entry, /* update */
95098- clear_expired, /* clear_expired */
95099- eg_destroy_cache /* destroy_cache */
95100+ .add_entry = eg_cache_add_entry,
95101+ .get_by_cache_id = eg_cache_get_by_cache_id,
95102+ .get_by_tag = eg_cache_get_by_tag,
95103+ .get_by_vcc = eg_cache_get_by_vcc,
95104+ .get_by_src_ip = eg_cache_get_by_src_ip,
95105+ .put = eg_cache_put,
95106+ .remove_entry = eg_cache_remove_entry,
95107+ .update = update_eg_cache_entry,
95108+ .clear_expired = clear_expired,
95109+ .destroy_cache = eg_destroy_cache
95110 };
95111
95112
95113diff --git a/net/atm/proc.c b/net/atm/proc.c
95114index bbb6461..cf04016 100644
95115--- a/net/atm/proc.c
95116+++ b/net/atm/proc.c
95117@@ -45,9 +45,9 @@ static void add_stats(struct seq_file *seq, const char *aal,
95118 const struct k_atm_aal_stats *stats)
95119 {
95120 seq_printf(seq, "%s ( %d %d %d %d %d )", aal,
95121- atomic_read(&stats->tx), atomic_read(&stats->tx_err),
95122- atomic_read(&stats->rx), atomic_read(&stats->rx_err),
95123- atomic_read(&stats->rx_drop));
95124+ atomic_read_unchecked(&stats->tx),atomic_read_unchecked(&stats->tx_err),
95125+ atomic_read_unchecked(&stats->rx),atomic_read_unchecked(&stats->rx_err),
95126+ atomic_read_unchecked(&stats->rx_drop));
95127 }
95128
95129 static void atm_dev_info(struct seq_file *seq, const struct atm_dev *dev)
95130diff --git a/net/atm/resources.c b/net/atm/resources.c
95131index 0447d5d..3cf4728 100644
95132--- a/net/atm/resources.c
95133+++ b/net/atm/resources.c
95134@@ -160,7 +160,7 @@ EXPORT_SYMBOL(atm_dev_deregister);
95135 static void copy_aal_stats(struct k_atm_aal_stats *from,
95136 struct atm_aal_stats *to)
95137 {
95138-#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
95139+#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
95140 __AAL_STAT_ITEMS
95141 #undef __HANDLE_ITEM
95142 }
95143@@ -168,7 +168,7 @@ static void copy_aal_stats(struct k_atm_aal_stats *from,
95144 static void subtract_aal_stats(struct k_atm_aal_stats *from,
95145 struct atm_aal_stats *to)
95146 {
95147-#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
95148+#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i, &from->i)
95149 __AAL_STAT_ITEMS
95150 #undef __HANDLE_ITEM
95151 }
95152diff --git a/net/ax25/sysctl_net_ax25.c b/net/ax25/sysctl_net_ax25.c
95153index 919a5ce..cc6b444 100644
95154--- a/net/ax25/sysctl_net_ax25.c
95155+++ b/net/ax25/sysctl_net_ax25.c
95156@@ -152,7 +152,7 @@ int ax25_register_dev_sysctl(ax25_dev *ax25_dev)
95157 {
95158 char path[sizeof("net/ax25/") + IFNAMSIZ];
95159 int k;
95160- struct ctl_table *table;
95161+ ctl_table_no_const *table;
95162
95163 table = kmemdup(ax25_param_table, sizeof(ax25_param_table), GFP_KERNEL);
95164 if (!table)
95165diff --git a/net/batman-adv/bat_iv_ogm.c b/net/batman-adv/bat_iv_ogm.c
95166index 0a8a80c..f7e89aa 100644
95167--- a/net/batman-adv/bat_iv_ogm.c
95168+++ b/net/batman-adv/bat_iv_ogm.c
95169@@ -121,7 +121,7 @@ static int batadv_iv_ogm_iface_enable(struct batadv_hard_iface *hard_iface)
95170
95171 /* randomize initial seqno to avoid collision */
95172 get_random_bytes(&random_seqno, sizeof(random_seqno));
95173- atomic_set(&hard_iface->bat_iv.ogm_seqno, random_seqno);
95174+ atomic_set_unchecked(&hard_iface->bat_iv.ogm_seqno, random_seqno);
95175
95176 hard_iface->bat_iv.ogm_buff_len = BATADV_OGM_HLEN;
95177 ogm_buff = kmalloc(hard_iface->bat_iv.ogm_buff_len, GFP_ATOMIC);
95178@@ -703,9 +703,9 @@ static void batadv_iv_ogm_schedule(struct batadv_hard_iface *hard_iface)
95179 batadv_ogm_packet = (struct batadv_ogm_packet *)(*ogm_buff);
95180
95181 /* change sequence number to network order */
95182- seqno = (uint32_t)atomic_read(&hard_iface->bat_iv.ogm_seqno);
95183+ seqno = (uint32_t)atomic_read_unchecked(&hard_iface->bat_iv.ogm_seqno);
95184 batadv_ogm_packet->seqno = htonl(seqno);
95185- atomic_inc(&hard_iface->bat_iv.ogm_seqno);
95186+ atomic_inc_unchecked(&hard_iface->bat_iv.ogm_seqno);
95187
95188 batadv_ogm_packet->ttvn = atomic_read(&bat_priv->tt.vn);
95189 batadv_ogm_packet->tt_crc = htons(bat_priv->tt.local_crc);
95190@@ -1111,7 +1111,7 @@ static void batadv_iv_ogm_process(const struct ethhdr *ethhdr,
95191 return;
95192
95193 /* could be changed by schedule_own_packet() */
95194- if_incoming_seqno = atomic_read(&if_incoming->bat_iv.ogm_seqno);
95195+ if_incoming_seqno = atomic_read_unchecked(&if_incoming->bat_iv.ogm_seqno);
95196
95197 if (batadv_ogm_packet->flags & BATADV_DIRECTLINK)
95198 has_directlink_flag = 1;
95199diff --git a/net/batman-adv/hard-interface.c b/net/batman-adv/hard-interface.c
95200index c478e6b..469fd2f 100644
95201--- a/net/batman-adv/hard-interface.c
95202+++ b/net/batman-adv/hard-interface.c
95203@@ -453,7 +453,7 @@ int batadv_hardif_enable_interface(struct batadv_hard_iface *hard_iface,
95204 hard_iface->batman_adv_ptype.dev = hard_iface->net_dev;
95205 dev_add_pack(&hard_iface->batman_adv_ptype);
95206
95207- atomic_set(&hard_iface->frag_seqno, 1);
95208+ atomic_set_unchecked(&hard_iface->frag_seqno, 1);
95209 batadv_info(hard_iface->soft_iface, "Adding interface: %s\n",
95210 hard_iface->net_dev->name);
95211
95212diff --git a/net/batman-adv/soft-interface.c b/net/batman-adv/soft-interface.c
95213index 813db4e..847edac 100644
95214--- a/net/batman-adv/soft-interface.c
95215+++ b/net/batman-adv/soft-interface.c
95216@@ -263,7 +263,7 @@ static int batadv_interface_tx(struct sk_buff *skb,
95217 primary_if->net_dev->dev_addr, ETH_ALEN);
95218
95219 /* set broadcast sequence number */
95220- seqno = atomic_inc_return(&bat_priv->bcast_seqno);
95221+ seqno = atomic_inc_return_unchecked(&bat_priv->bcast_seqno);
95222 bcast_packet->seqno = htonl(seqno);
95223
95224 batadv_add_bcast_packet_to_list(bat_priv, skb, brd_delay);
95225@@ -483,7 +483,7 @@ static int batadv_softif_init_late(struct net_device *dev)
95226 atomic_set(&bat_priv->batman_queue_left, BATADV_BATMAN_QUEUE_LEN);
95227
95228 atomic_set(&bat_priv->mesh_state, BATADV_MESH_INACTIVE);
95229- atomic_set(&bat_priv->bcast_seqno, 1);
95230+ atomic_set_unchecked(&bat_priv->bcast_seqno, 1);
95231 atomic_set(&bat_priv->tt.vn, 0);
95232 atomic_set(&bat_priv->tt.local_changes, 0);
95233 atomic_set(&bat_priv->tt.ogm_append_cnt, 0);
95234diff --git a/net/batman-adv/types.h b/net/batman-adv/types.h
95235index b2c94e1..3d47e07 100644
95236--- a/net/batman-adv/types.h
95237+++ b/net/batman-adv/types.h
95238@@ -51,7 +51,7 @@
95239 struct batadv_hard_iface_bat_iv {
95240 unsigned char *ogm_buff;
95241 int ogm_buff_len;
95242- atomic_t ogm_seqno;
95243+ atomic_unchecked_t ogm_seqno;
95244 };
95245
95246 /**
95247@@ -76,7 +76,7 @@ struct batadv_hard_iface {
95248 int16_t if_num;
95249 char if_status;
95250 struct net_device *net_dev;
95251- atomic_t frag_seqno;
95252+ atomic_unchecked_t frag_seqno;
95253 uint8_t num_bcasts;
95254 struct kobject *hardif_obj;
95255 atomic_t refcount;
95256@@ -560,7 +560,7 @@ struct batadv_priv {
95257 #ifdef CONFIG_BATMAN_ADV_DEBUG
95258 atomic_t log_level;
95259 #endif
95260- atomic_t bcast_seqno;
95261+ atomic_unchecked_t bcast_seqno;
95262 atomic_t bcast_queue_left;
95263 atomic_t batman_queue_left;
95264 char num_ifaces;
95265diff --git a/net/batman-adv/unicast.c b/net/batman-adv/unicast.c
95266index 48b31d3..62a0bcb 100644
95267--- a/net/batman-adv/unicast.c
95268+++ b/net/batman-adv/unicast.c
95269@@ -272,7 +272,7 @@ int batadv_frag_send_skb(struct sk_buff *skb, struct batadv_priv *bat_priv,
95270 frag1->flags = BATADV_UNI_FRAG_HEAD | large_tail;
95271 frag2->flags = large_tail;
95272
95273- seqno = atomic_add_return(2, &hard_iface->frag_seqno);
95274+ seqno = atomic_add_return_unchecked(2, &hard_iface->frag_seqno);
95275 frag1->seqno = htons(seqno - 1);
95276 frag2->seqno = htons(seqno);
95277
95278diff --git a/net/bluetooth/hci_sock.c b/net/bluetooth/hci_sock.c
95279index fa4bf66..e92948f 100644
95280--- a/net/bluetooth/hci_sock.c
95281+++ b/net/bluetooth/hci_sock.c
95282@@ -932,7 +932,7 @@ static int hci_sock_setsockopt(struct socket *sock, int level, int optname,
95283 uf.event_mask[1] = *((u32 *) f->event_mask + 1);
95284 }
95285
95286- len = min_t(unsigned int, len, sizeof(uf));
95287+ len = min((size_t)len, sizeof(uf));
95288 if (copy_from_user(&uf, optval, len)) {
95289 err = -EFAULT;
95290 break;
95291diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
95292index 63fa111..b166ec6 100644
95293--- a/net/bluetooth/l2cap_core.c
95294+++ b/net/bluetooth/l2cap_core.c
95295@@ -3511,8 +3511,10 @@ static int l2cap_parse_conf_rsp(struct l2cap_chan *chan, void *rsp, int len,
95296 break;
95297
95298 case L2CAP_CONF_RFC:
95299- if (olen == sizeof(rfc))
95300- memcpy(&rfc, (void *)val, olen);
95301+ if (olen != sizeof(rfc))
95302+ break;
95303+
95304+ memcpy(&rfc, (void *)val, olen);
95305
95306 if (test_bit(CONF_STATE2_DEVICE, &chan->conf_state) &&
95307 rfc.mode != chan->mode)
95308diff --git a/net/bluetooth/l2cap_sock.c b/net/bluetooth/l2cap_sock.c
95309index 0098af8..fb5a31f 100644
95310--- a/net/bluetooth/l2cap_sock.c
95311+++ b/net/bluetooth/l2cap_sock.c
95312@@ -485,7 +485,8 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname,
95313 struct sock *sk = sock->sk;
95314 struct l2cap_chan *chan = l2cap_pi(sk)->chan;
95315 struct l2cap_options opts;
95316- int len, err = 0;
95317+ int err = 0;
95318+ size_t len = optlen;
95319 u32 opt;
95320
95321 BT_DBG("sk %p", sk);
95322@@ -507,7 +508,7 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname,
95323 opts.max_tx = chan->max_tx;
95324 opts.txwin_size = chan->tx_win;
95325
95326- len = min_t(unsigned int, sizeof(opts), optlen);
95327+ len = min(sizeof(opts), len);
95328 if (copy_from_user((char *) &opts, optval, len)) {
95329 err = -EFAULT;
95330 break;
95331@@ -587,7 +588,8 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
95332 struct bt_security sec;
95333 struct bt_power pwr;
95334 struct l2cap_conn *conn;
95335- int len, err = 0;
95336+ int err = 0;
95337+ size_t len = optlen;
95338 u32 opt;
95339
95340 BT_DBG("sk %p", sk);
95341@@ -610,7 +612,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
95342
95343 sec.level = BT_SECURITY_LOW;
95344
95345- len = min_t(unsigned int, sizeof(sec), optlen);
95346+ len = min(sizeof(sec), len);
95347 if (copy_from_user((char *) &sec, optval, len)) {
95348 err = -EFAULT;
95349 break;
95350@@ -707,7 +709,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
95351
95352 pwr.force_active = BT_POWER_FORCE_ACTIVE_ON;
95353
95354- len = min_t(unsigned int, sizeof(pwr), optlen);
95355+ len = min(sizeof(pwr), len);
95356 if (copy_from_user((char *) &pwr, optval, len)) {
95357 err = -EFAULT;
95358 break;
95359diff --git a/net/bluetooth/rfcomm/sock.c b/net/bluetooth/rfcomm/sock.c
95360index c1c6028..17e8dcc 100644
95361--- a/net/bluetooth/rfcomm/sock.c
95362+++ b/net/bluetooth/rfcomm/sock.c
95363@@ -665,7 +665,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
95364 struct sock *sk = sock->sk;
95365 struct bt_security sec;
95366 int err = 0;
95367- size_t len;
95368+ size_t len = optlen;
95369 u32 opt;
95370
95371 BT_DBG("sk %p", sk);
95372@@ -687,7 +687,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
95373
95374 sec.level = BT_SECURITY_LOW;
95375
95376- len = min_t(unsigned int, sizeof(sec), optlen);
95377+ len = min(sizeof(sec), len);
95378 if (copy_from_user((char *) &sec, optval, len)) {
95379 err = -EFAULT;
95380 break;
95381diff --git a/net/bluetooth/rfcomm/tty.c b/net/bluetooth/rfcomm/tty.c
95382index 84fcf9f..e389b27 100644
95383--- a/net/bluetooth/rfcomm/tty.c
95384+++ b/net/bluetooth/rfcomm/tty.c
95385@@ -684,7 +684,7 @@ static int rfcomm_tty_open(struct tty_struct *tty, struct file *filp)
95386 BT_DBG("tty %p id %d", tty, tty->index);
95387
95388 BT_DBG("dev %p dst %pMR channel %d opened %d", dev, &dev->dst,
95389- dev->channel, dev->port.count);
95390+ dev->channel, atomic_read(&dev->port.count));
95391
95392 err = tty_port_open(&dev->port, tty, filp);
95393 if (err)
95394@@ -707,7 +707,7 @@ static void rfcomm_tty_close(struct tty_struct *tty, struct file *filp)
95395 struct rfcomm_dev *dev = (struct rfcomm_dev *) tty->driver_data;
95396
95397 BT_DBG("tty %p dev %p dlc %p opened %d", tty, dev, dev->dlc,
95398- dev->port.count);
95399+ atomic_read(&dev->port.count));
95400
95401 tty_port_close(&dev->port, tty, filp);
95402 }
95403diff --git a/net/bridge/netfilter/ebt_ulog.c b/net/bridge/netfilter/ebt_ulog.c
95404index 5180938..7c470c3 100644
95405--- a/net/bridge/netfilter/ebt_ulog.c
95406+++ b/net/bridge/netfilter/ebt_ulog.c
95407@@ -181,6 +181,7 @@ static void ebt_ulog_packet(struct net *net, unsigned int hooknr,
95408 ub->qlen++;
95409
95410 pm = nlmsg_data(nlh);
95411+ memset(pm, 0, sizeof(*pm));
95412
95413 /* Fill in the ulog data */
95414 pm->version = EBT_ULOG_VERSION;
95415@@ -193,8 +194,6 @@ static void ebt_ulog_packet(struct net *net, unsigned int hooknr,
95416 pm->hook = hooknr;
95417 if (uloginfo->prefix != NULL)
95418 strcpy(pm->prefix, uloginfo->prefix);
95419- else
95420- *(pm->prefix) = '\0';
95421
95422 if (in) {
95423 strcpy(pm->physindev, in->name);
95424@@ -204,16 +203,14 @@ static void ebt_ulog_packet(struct net *net, unsigned int hooknr,
95425 strcpy(pm->indev, br_port_get_rcu(in)->br->dev->name);
95426 else
95427 strcpy(pm->indev, in->name);
95428- } else
95429- pm->indev[0] = pm->physindev[0] = '\0';
95430+ }
95431
95432 if (out) {
95433 /* If out exists, then out is a bridge port */
95434 strcpy(pm->physoutdev, out->name);
95435 /* rcu_read_lock()ed by nf_hook_slow */
95436 strcpy(pm->outdev, br_port_get_rcu(out)->br->dev->name);
95437- } else
95438- pm->outdev[0] = pm->physoutdev[0] = '\0';
95439+ }
95440
95441 if (skb_copy_bits(skb, -ETH_HLEN, pm->data, copy_len) < 0)
95442 BUG();
95443diff --git a/net/bridge/netfilter/ebtables.c b/net/bridge/netfilter/ebtables.c
95444index ac78024..161a80c 100644
95445--- a/net/bridge/netfilter/ebtables.c
95446+++ b/net/bridge/netfilter/ebtables.c
95447@@ -1525,7 +1525,7 @@ static int do_ebt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
95448 tmp.valid_hooks = t->table->valid_hooks;
95449 }
95450 mutex_unlock(&ebt_mutex);
95451- if (copy_to_user(user, &tmp, *len) != 0){
95452+ if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0){
95453 BUGPRINT("c2u Didn't work\n");
95454 ret = -EFAULT;
95455 break;
95456@@ -2331,7 +2331,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
95457 goto out;
95458 tmp.valid_hooks = t->valid_hooks;
95459
95460- if (copy_to_user(user, &tmp, *len) != 0) {
95461+ if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
95462 ret = -EFAULT;
95463 break;
95464 }
95465@@ -2342,7 +2342,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
95466 tmp.entries_size = t->table->entries_size;
95467 tmp.valid_hooks = t->table->valid_hooks;
95468
95469- if (copy_to_user(user, &tmp, *len) != 0) {
95470+ if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
95471 ret = -EFAULT;
95472 break;
95473 }
95474diff --git a/net/caif/cfctrl.c b/net/caif/cfctrl.c
95475index 0f45522..dab651f 100644
95476--- a/net/caif/cfctrl.c
95477+++ b/net/caif/cfctrl.c
95478@@ -10,6 +10,7 @@
95479 #include <linux/spinlock.h>
95480 #include <linux/slab.h>
95481 #include <linux/pkt_sched.h>
95482+#include <linux/sched.h>
95483 #include <net/caif/caif_layer.h>
95484 #include <net/caif/cfpkt.h>
95485 #include <net/caif/cfctrl.h>
95486@@ -43,8 +44,8 @@ struct cflayer *cfctrl_create(void)
95487 memset(&dev_info, 0, sizeof(dev_info));
95488 dev_info.id = 0xff;
95489 cfsrvl_init(&this->serv, 0, &dev_info, false);
95490- atomic_set(&this->req_seq_no, 1);
95491- atomic_set(&this->rsp_seq_no, 1);
95492+ atomic_set_unchecked(&this->req_seq_no, 1);
95493+ atomic_set_unchecked(&this->rsp_seq_no, 1);
95494 this->serv.layer.receive = cfctrl_recv;
95495 sprintf(this->serv.layer.name, "ctrl");
95496 this->serv.layer.ctrlcmd = cfctrl_ctrlcmd;
95497@@ -130,8 +131,8 @@ static void cfctrl_insert_req(struct cfctrl *ctrl,
95498 struct cfctrl_request_info *req)
95499 {
95500 spin_lock_bh(&ctrl->info_list_lock);
95501- atomic_inc(&ctrl->req_seq_no);
95502- req->sequence_no = atomic_read(&ctrl->req_seq_no);
95503+ atomic_inc_unchecked(&ctrl->req_seq_no);
95504+ req->sequence_no = atomic_read_unchecked(&ctrl->req_seq_no);
95505 list_add_tail(&req->list, &ctrl->list);
95506 spin_unlock_bh(&ctrl->info_list_lock);
95507 }
95508@@ -149,7 +150,7 @@ static struct cfctrl_request_info *cfctrl_remove_req(struct cfctrl *ctrl,
95509 if (p != first)
95510 pr_warn("Requests are not received in order\n");
95511
95512- atomic_set(&ctrl->rsp_seq_no,
95513+ atomic_set_unchecked(&ctrl->rsp_seq_no,
95514 p->sequence_no);
95515 list_del(&p->list);
95516 goto out;
95517diff --git a/net/can/af_can.c b/net/can/af_can.c
95518index 3ab8dd2..b9aef13 100644
95519--- a/net/can/af_can.c
95520+++ b/net/can/af_can.c
95521@@ -862,7 +862,7 @@ static const struct net_proto_family can_family_ops = {
95522 };
95523
95524 /* notifier block for netdevice event */
95525-static struct notifier_block can_netdev_notifier __read_mostly = {
95526+static struct notifier_block can_netdev_notifier = {
95527 .notifier_call = can_notifier,
95528 };
95529
95530diff --git a/net/can/gw.c b/net/can/gw.c
95531index 3f9b0f3..fc6d4fa 100644
95532--- a/net/can/gw.c
95533+++ b/net/can/gw.c
95534@@ -80,7 +80,6 @@ MODULE_PARM_DESC(max_hops,
95535 "default: " __stringify(CGW_DEFAULT_HOPS) ")");
95536
95537 static HLIST_HEAD(cgw_list);
95538-static struct notifier_block notifier;
95539
95540 static struct kmem_cache *cgw_cache __read_mostly;
95541
95542@@ -954,6 +953,10 @@ static int cgw_remove_job(struct sk_buff *skb, struct nlmsghdr *nlh)
95543 return err;
95544 }
95545
95546+static struct notifier_block notifier = {
95547+ .notifier_call = cgw_notifier
95548+};
95549+
95550 static __init int cgw_module_init(void)
95551 {
95552 /* sanitize given module parameter */
95553@@ -969,7 +972,6 @@ static __init int cgw_module_init(void)
95554 return -ENOMEM;
95555
95556 /* set notifier */
95557- notifier.notifier_call = cgw_notifier;
95558 register_netdevice_notifier(&notifier);
95559
95560 if (__rtnl_register(PF_CAN, RTM_GETROUTE, NULL, cgw_dump_jobs, NULL)) {
95561diff --git a/net/ceph/messenger.c b/net/ceph/messenger.c
95562index 4a5df7b..9ad1f1d 100644
95563--- a/net/ceph/messenger.c
95564+++ b/net/ceph/messenger.c
95565@@ -186,7 +186,7 @@ static void con_fault(struct ceph_connection *con);
95566 #define MAX_ADDR_STR_LEN 64 /* 54 is enough */
95567
95568 static char addr_str[ADDR_STR_COUNT][MAX_ADDR_STR_LEN];
95569-static atomic_t addr_str_seq = ATOMIC_INIT(0);
95570+static atomic_unchecked_t addr_str_seq = ATOMIC_INIT(0);
95571
95572 static struct page *zero_page; /* used in certain error cases */
95573
95574@@ -197,7 +197,7 @@ const char *ceph_pr_addr(const struct sockaddr_storage *ss)
95575 struct sockaddr_in *in4 = (struct sockaddr_in *) ss;
95576 struct sockaddr_in6 *in6 = (struct sockaddr_in6 *) ss;
95577
95578- i = atomic_inc_return(&addr_str_seq) & ADDR_STR_COUNT_MASK;
95579+ i = atomic_inc_return_unchecked(&addr_str_seq) & ADDR_STR_COUNT_MASK;
95580 s = addr_str[i];
95581
95582 switch (ss->ss_family) {
95583diff --git a/net/compat.c b/net/compat.c
95584index dd32e34..6066f87 100644
95585--- a/net/compat.c
95586+++ b/net/compat.c
95587@@ -73,9 +73,9 @@ int get_compat_msghdr(struct msghdr *kmsg, struct compat_msghdr __user *umsg)
95588 return -EFAULT;
95589 if (kmsg->msg_namelen > sizeof(struct sockaddr_storage))
95590 kmsg->msg_namelen = sizeof(struct sockaddr_storage);
95591- kmsg->msg_name = compat_ptr(tmp1);
95592- kmsg->msg_iov = compat_ptr(tmp2);
95593- kmsg->msg_control = compat_ptr(tmp3);
95594+ kmsg->msg_name = (void __force_kernel *)compat_ptr(tmp1);
95595+ kmsg->msg_iov = (void __force_kernel *)compat_ptr(tmp2);
95596+ kmsg->msg_control = (void __force_kernel *)compat_ptr(tmp3);
95597 return 0;
95598 }
95599
95600@@ -87,7 +87,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
95601
95602 if (kern_msg->msg_namelen) {
95603 if (mode == VERIFY_READ) {
95604- int err = move_addr_to_kernel(kern_msg->msg_name,
95605+ int err = move_addr_to_kernel((void __force_user *)kern_msg->msg_name,
95606 kern_msg->msg_namelen,
95607 kern_address);
95608 if (err < 0)
95609@@ -99,7 +99,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
95610 kern_msg->msg_name = NULL;
95611
95612 tot_len = iov_from_user_compat_to_kern(kern_iov,
95613- (struct compat_iovec __user *)kern_msg->msg_iov,
95614+ (struct compat_iovec __force_user *)kern_msg->msg_iov,
95615 kern_msg->msg_iovlen);
95616 if (tot_len >= 0)
95617 kern_msg->msg_iov = kern_iov;
95618@@ -119,20 +119,20 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
95619
95620 #define CMSG_COMPAT_FIRSTHDR(msg) \
95621 (((msg)->msg_controllen) >= sizeof(struct compat_cmsghdr) ? \
95622- (struct compat_cmsghdr __user *)((msg)->msg_control) : \
95623+ (struct compat_cmsghdr __force_user *)((msg)->msg_control) : \
95624 (struct compat_cmsghdr __user *)NULL)
95625
95626 #define CMSG_COMPAT_OK(ucmlen, ucmsg, mhdr) \
95627 ((ucmlen) >= sizeof(struct compat_cmsghdr) && \
95628 (ucmlen) <= (unsigned long) \
95629 ((mhdr)->msg_controllen - \
95630- ((char *)(ucmsg) - (char *)(mhdr)->msg_control)))
95631+ ((char __force_kernel *)(ucmsg) - (char *)(mhdr)->msg_control)))
95632
95633 static inline struct compat_cmsghdr __user *cmsg_compat_nxthdr(struct msghdr *msg,
95634 struct compat_cmsghdr __user *cmsg, int cmsg_len)
95635 {
95636 char __user *ptr = (char __user *)cmsg + CMSG_COMPAT_ALIGN(cmsg_len);
95637- if ((unsigned long)(ptr + 1 - (char __user *)msg->msg_control) >
95638+ if ((unsigned long)(ptr + 1 - (char __force_user *)msg->msg_control) >
95639 msg->msg_controllen)
95640 return NULL;
95641 return (struct compat_cmsghdr __user *)ptr;
95642@@ -222,7 +222,7 @@ Efault:
95643
95644 int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *data)
95645 {
95646- struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
95647+ struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
95648 struct compat_cmsghdr cmhdr;
95649 struct compat_timeval ctv;
95650 struct compat_timespec cts[3];
95651@@ -278,7 +278,7 @@ int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *dat
95652
95653 void scm_detach_fds_compat(struct msghdr *kmsg, struct scm_cookie *scm)
95654 {
95655- struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
95656+ struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
95657 int fdmax = (kmsg->msg_controllen - sizeof(struct compat_cmsghdr)) / sizeof(int);
95658 int fdnum = scm->fp->count;
95659 struct file **fp = scm->fp->fp;
95660@@ -366,7 +366,7 @@ static int do_set_sock_timeout(struct socket *sock, int level,
95661 return -EFAULT;
95662 old_fs = get_fs();
95663 set_fs(KERNEL_DS);
95664- err = sock_setsockopt(sock, level, optname, (char *)&ktime, sizeof(ktime));
95665+ err = sock_setsockopt(sock, level, optname, (char __force_user *)&ktime, sizeof(ktime));
95666 set_fs(old_fs);
95667
95668 return err;
95669@@ -427,7 +427,7 @@ static int do_get_sock_timeout(struct socket *sock, int level, int optname,
95670 len = sizeof(ktime);
95671 old_fs = get_fs();
95672 set_fs(KERNEL_DS);
95673- err = sock_getsockopt(sock, level, optname, (char *) &ktime, &len);
95674+ err = sock_getsockopt(sock, level, optname, (char __force_user *) &ktime, (int __force_user *)&len);
95675 set_fs(old_fs);
95676
95677 if (!err) {
95678@@ -570,7 +570,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
95679 case MCAST_JOIN_GROUP:
95680 case MCAST_LEAVE_GROUP:
95681 {
95682- struct compat_group_req __user *gr32 = (void *)optval;
95683+ struct compat_group_req __user *gr32 = (void __user *)optval;
95684 struct group_req __user *kgr =
95685 compat_alloc_user_space(sizeof(struct group_req));
95686 u32 interface;
95687@@ -591,7 +591,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
95688 case MCAST_BLOCK_SOURCE:
95689 case MCAST_UNBLOCK_SOURCE:
95690 {
95691- struct compat_group_source_req __user *gsr32 = (void *)optval;
95692+ struct compat_group_source_req __user *gsr32 = (void __user *)optval;
95693 struct group_source_req __user *kgsr = compat_alloc_user_space(
95694 sizeof(struct group_source_req));
95695 u32 interface;
95696@@ -612,7 +612,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
95697 }
95698 case MCAST_MSFILTER:
95699 {
95700- struct compat_group_filter __user *gf32 = (void *)optval;
95701+ struct compat_group_filter __user *gf32 = (void __user *)optval;
95702 struct group_filter __user *kgf;
95703 u32 interface, fmode, numsrc;
95704
95705@@ -650,7 +650,7 @@ int compat_mc_getsockopt(struct sock *sock, int level, int optname,
95706 char __user *optval, int __user *optlen,
95707 int (*getsockopt)(struct sock *, int, int, char __user *, int __user *))
95708 {
95709- struct compat_group_filter __user *gf32 = (void *)optval;
95710+ struct compat_group_filter __user *gf32 = (void __user *)optval;
95711 struct group_filter __user *kgf;
95712 int __user *koptlen;
95713 u32 interface, fmode, numsrc;
95714@@ -808,7 +808,7 @@ asmlinkage long compat_sys_socketcall(int call, u32 __user *args)
95715
95716 if (call < SYS_SOCKET || call > SYS_SENDMMSG)
95717 return -EINVAL;
95718- if (copy_from_user(a, args, nas[call]))
95719+ if (nas[call] > sizeof a || copy_from_user(a, args, nas[call]))
95720 return -EFAULT;
95721 a0 = a[0];
95722 a1 = a[1];
95723diff --git a/net/core/datagram.c b/net/core/datagram.c
95724index af814e7..3d761de 100644
95725--- a/net/core/datagram.c
95726+++ b/net/core/datagram.c
95727@@ -301,7 +301,7 @@ int skb_kill_datagram(struct sock *sk, struct sk_buff *skb, unsigned int flags)
95728 }
95729
95730 kfree_skb(skb);
95731- atomic_inc(&sk->sk_drops);
95732+ atomic_inc_unchecked(&sk->sk_drops);
95733 sk_mem_reclaim_partial(sk);
95734
95735 return err;
95736diff --git a/net/core/dev.c b/net/core/dev.c
95737index 3d13874..6e78dc7 100644
95738--- a/net/core/dev.c
95739+++ b/net/core/dev.c
95740@@ -1680,14 +1680,14 @@ int dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
95741 {
95742 if (skb_shinfo(skb)->tx_flags & SKBTX_DEV_ZEROCOPY) {
95743 if (skb_copy_ubufs(skb, GFP_ATOMIC)) {
95744- atomic_long_inc(&dev->rx_dropped);
95745+ atomic_long_inc_unchecked(&dev->rx_dropped);
95746 kfree_skb(skb);
95747 return NET_RX_DROP;
95748 }
95749 }
95750
95751 if (unlikely(!is_skb_forwardable(dev, skb))) {
95752- atomic_long_inc(&dev->rx_dropped);
95753+ atomic_long_inc_unchecked(&dev->rx_dropped);
95754 kfree_skb(skb);
95755 return NET_RX_DROP;
95756 }
95757@@ -2428,7 +2428,7 @@ static int illegal_highdma(struct net_device *dev, struct sk_buff *skb)
95758
95759 struct dev_gso_cb {
95760 void (*destructor)(struct sk_buff *skb);
95761-};
95762+} __no_const;
95763
95764 #define DEV_GSO_CB(skb) ((struct dev_gso_cb *)(skb)->cb)
95765
95766@@ -3203,7 +3203,7 @@ enqueue:
95767
95768 local_irq_restore(flags);
95769
95770- atomic_long_inc(&skb->dev->rx_dropped);
95771+ atomic_long_inc_unchecked(&skb->dev->rx_dropped);
95772 kfree_skb(skb);
95773 return NET_RX_DROP;
95774 }
95775@@ -3275,7 +3275,7 @@ int netif_rx_ni(struct sk_buff *skb)
95776 }
95777 EXPORT_SYMBOL(netif_rx_ni);
95778
95779-static void net_tx_action(struct softirq_action *h)
95780+static __latent_entropy void net_tx_action(void)
95781 {
95782 struct softnet_data *sd = &__get_cpu_var(softnet_data);
95783
95784@@ -3609,7 +3609,7 @@ ncls:
95785 ret = pt_prev->func(skb, skb->dev, pt_prev, orig_dev);
95786 } else {
95787 drop:
95788- atomic_long_inc(&skb->dev->rx_dropped);
95789+ atomic_long_inc_unchecked(&skb->dev->rx_dropped);
95790 kfree_skb(skb);
95791 /* Jamal, now you will not able to escape explaining
95792 * me how you were going to use this. :-)
95793@@ -4269,7 +4269,7 @@ void netif_napi_del(struct napi_struct *napi)
95794 }
95795 EXPORT_SYMBOL(netif_napi_del);
95796
95797-static void net_rx_action(struct softirq_action *h)
95798+static __latent_entropy void net_rx_action(void)
95799 {
95800 struct softnet_data *sd = &__get_cpu_var(softnet_data);
95801 unsigned long time_limit = jiffies + 2;
95802@@ -5973,7 +5973,7 @@ struct rtnl_link_stats64 *dev_get_stats(struct net_device *dev,
95803 } else {
95804 netdev_stats_to_stats64(storage, &dev->stats);
95805 }
95806- storage->rx_dropped += atomic_long_read(&dev->rx_dropped);
95807+ storage->rx_dropped += atomic_long_read_unchecked(&dev->rx_dropped);
95808 return storage;
95809 }
95810 EXPORT_SYMBOL(dev_get_stats);
95811diff --git a/net/core/dev_ioctl.c b/net/core/dev_ioctl.c
95812index 5b7d0e1..cb960fc 100644
95813--- a/net/core/dev_ioctl.c
95814+++ b/net/core/dev_ioctl.c
95815@@ -365,9 +365,13 @@ void dev_load(struct net *net, const char *name)
95816 if (no_module && capable(CAP_NET_ADMIN))
95817 no_module = request_module("netdev-%s", name);
95818 if (no_module && capable(CAP_SYS_MODULE)) {
95819+#ifdef CONFIG_GRKERNSEC_MODHARDEN
95820+ ___request_module(true, "grsec_modharden_netdev", "%s", name);
95821+#else
95822 if (!request_module("%s", name))
95823 pr_warn("Loading kernel module for a network device with CAP_SYS_MODULE (deprecated). Use CAP_NET_ADMIN and alias netdev-%s instead.\n",
95824 name);
95825+#endif
95826 }
95827 }
95828 EXPORT_SYMBOL(dev_load);
95829diff --git a/net/core/filter.c b/net/core/filter.c
95830index 01b7808..ad30d62 100644
95831--- a/net/core/filter.c
95832+++ b/net/core/filter.c
95833@@ -36,7 +36,6 @@
95834 #include <asm/uaccess.h>
95835 #include <asm/unaligned.h>
95836 #include <linux/filter.h>
95837-#include <linux/reciprocal_div.h>
95838 #include <linux/ratelimit.h>
95839 #include <linux/seccomp.h>
95840 #include <linux/if_vlan.h>
95841@@ -166,7 +165,7 @@ unsigned int sk_run_filter(const struct sk_buff *skb,
95842 A /= X;
95843 continue;
95844 case BPF_S_ALU_DIV_K:
95845- A = reciprocal_divide(A, K);
95846+ A /= K;
95847 continue;
95848 case BPF_S_ALU_MOD_X:
95849 if (X == 0)
95850@@ -553,11 +552,6 @@ int sk_chk_filter(struct sock_filter *filter, unsigned int flen)
95851 /* Some instructions need special checks */
95852 switch (code) {
95853 case BPF_S_ALU_DIV_K:
95854- /* check for division by zero */
95855- if (ftest->k == 0)
95856- return -EINVAL;
95857- ftest->k = reciprocal_value(ftest->k);
95858- break;
95859 case BPF_S_ALU_MOD_K:
95860 /* check for division by zero */
95861 if (ftest->k == 0)
95862@@ -853,27 +847,7 @@ void sk_decode_filter(struct sock_filter *filt, struct sock_filter *to)
95863 to->code = decodes[code];
95864 to->jt = filt->jt;
95865 to->jf = filt->jf;
95866-
95867- if (code == BPF_S_ALU_DIV_K) {
95868- /*
95869- * When loaded this rule user gave us X, which was
95870- * translated into R = r(X). Now we calculate the
95871- * RR = r(R) and report it back. If next time this
95872- * value is loaded and RRR = r(RR) is calculated
95873- * then the R == RRR will be true.
95874- *
95875- * One exception. X == 1 translates into R == 0 and
95876- * we can't calculate RR out of it with r().
95877- */
95878-
95879- if (filt->k == 0)
95880- to->k = 1;
95881- else
95882- to->k = reciprocal_value(filt->k);
95883-
95884- BUG_ON(reciprocal_value(to->k) != filt->k);
95885- } else
95886- to->k = filt->k;
95887+ to->k = filt->k;
95888 }
95889
95890 int sk_get_filter(struct sock *sk, struct sock_filter __user *ubuf, unsigned int len)
95891diff --git a/net/core/flow.c b/net/core/flow.c
95892index dfa602c..3103d88 100644
95893--- a/net/core/flow.c
95894+++ b/net/core/flow.c
95895@@ -61,7 +61,7 @@ struct flow_cache {
95896 struct timer_list rnd_timer;
95897 };
95898
95899-atomic_t flow_cache_genid = ATOMIC_INIT(0);
95900+atomic_unchecked_t flow_cache_genid = ATOMIC_INIT(0);
95901 EXPORT_SYMBOL(flow_cache_genid);
95902 static struct flow_cache flow_cache_global;
95903 static struct kmem_cache *flow_cachep __read_mostly;
95904@@ -86,7 +86,7 @@ static void flow_cache_new_hashrnd(unsigned long arg)
95905
95906 static int flow_entry_valid(struct flow_cache_entry *fle)
95907 {
95908- if (atomic_read(&flow_cache_genid) != fle->genid)
95909+ if (atomic_read_unchecked(&flow_cache_genid) != fle->genid)
95910 return 0;
95911 if (fle->object && !fle->object->ops->check(fle->object))
95912 return 0;
95913@@ -258,7 +258,7 @@ flow_cache_lookup(struct net *net, const struct flowi *key, u16 family, u8 dir,
95914 hlist_add_head(&fle->u.hlist, &fcp->hash_table[hash]);
95915 fcp->hash_count++;
95916 }
95917- } else if (likely(fle->genid == atomic_read(&flow_cache_genid))) {
95918+ } else if (likely(fle->genid == atomic_read_unchecked(&flow_cache_genid))) {
95919 flo = fle->object;
95920 if (!flo)
95921 goto ret_object;
95922@@ -279,7 +279,7 @@ nocache:
95923 }
95924 flo = resolver(net, key, family, dir, flo, ctx);
95925 if (fle) {
95926- fle->genid = atomic_read(&flow_cache_genid);
95927+ fle->genid = atomic_read_unchecked(&flow_cache_genid);
95928 if (!IS_ERR(flo))
95929 fle->object = flo;
95930 else
95931diff --git a/net/core/iovec.c b/net/core/iovec.c
95932index 7d84ea1..55385ae 100644
95933--- a/net/core/iovec.c
95934+++ b/net/core/iovec.c
95935@@ -42,7 +42,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
95936 if (m->msg_namelen) {
95937 if (mode == VERIFY_READ) {
95938 void __user *namep;
95939- namep = (void __user __force *) m->msg_name;
95940+ namep = (void __force_user *) m->msg_name;
95941 err = move_addr_to_kernel(namep, m->msg_namelen,
95942 address);
95943 if (err < 0)
95944@@ -55,7 +55,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
95945 }
95946
95947 size = m->msg_iovlen * sizeof(struct iovec);
95948- if (copy_from_user(iov, (void __user __force *) m->msg_iov, size))
95949+ if (copy_from_user(iov, (void __force_user *) m->msg_iov, size))
95950 return -EFAULT;
95951
95952 m->msg_iov = iov;
95953diff --git a/net/core/neighbour.c b/net/core/neighbour.c
95954index 11af243..7357d84 100644
95955--- a/net/core/neighbour.c
95956+++ b/net/core/neighbour.c
95957@@ -2774,7 +2774,7 @@ static int proc_unres_qlen(struct ctl_table *ctl, int write,
95958 void __user *buffer, size_t *lenp, loff_t *ppos)
95959 {
95960 int size, ret;
95961- struct ctl_table tmp = *ctl;
95962+ ctl_table_no_const tmp = *ctl;
95963
95964 tmp.extra1 = &zero;
95965 tmp.extra2 = &unres_qlen_max;
95966diff --git a/net/core/net-procfs.c b/net/core/net-procfs.c
95967index 2bf8329..7960607 100644
95968--- a/net/core/net-procfs.c
95969+++ b/net/core/net-procfs.c
95970@@ -283,8 +283,13 @@ static int ptype_seq_show(struct seq_file *seq, void *v)
95971 else
95972 seq_printf(seq, "%04x", ntohs(pt->type));
95973
95974+#ifdef CONFIG_GRKERNSEC_HIDESYM
95975+ seq_printf(seq, " %-8s %pf\n",
95976+ pt->dev ? pt->dev->name : "", NULL);
95977+#else
95978 seq_printf(seq, " %-8s %pf\n",
95979 pt->dev ? pt->dev->name : "", pt->func);
95980+#endif
95981 }
95982
95983 return 0;
95984diff --git a/net/core/net-sysfs.c b/net/core/net-sysfs.c
95985index d954b56..b0a0f7a 100644
95986--- a/net/core/net-sysfs.c
95987+++ b/net/core/net-sysfs.c
95988@@ -1356,7 +1356,7 @@ void netdev_class_remove_file(struct class_attribute *class_attr)
95989 }
95990 EXPORT_SYMBOL(netdev_class_remove_file);
95991
95992-int netdev_kobject_init(void)
95993+int __init netdev_kobject_init(void)
95994 {
95995 kobj_ns_type_register(&net_ns_type_operations);
95996 return class_register(&net_class);
95997diff --git a/net/core/net_namespace.c b/net/core/net_namespace.c
95998index 81d3a9a..a0bd7a8 100644
95999--- a/net/core/net_namespace.c
96000+++ b/net/core/net_namespace.c
96001@@ -443,7 +443,7 @@ static int __register_pernet_operations(struct list_head *list,
96002 int error;
96003 LIST_HEAD(net_exit_list);
96004
96005- list_add_tail(&ops->list, list);
96006+ pax_list_add_tail((struct list_head *)&ops->list, list);
96007 if (ops->init || (ops->id && ops->size)) {
96008 for_each_net(net) {
96009 error = ops_init(ops, net);
96010@@ -456,7 +456,7 @@ static int __register_pernet_operations(struct list_head *list,
96011
96012 out_undo:
96013 /* If I have an error cleanup all namespaces I initialized */
96014- list_del(&ops->list);
96015+ pax_list_del((struct list_head *)&ops->list);
96016 ops_exit_list(ops, &net_exit_list);
96017 ops_free_list(ops, &net_exit_list);
96018 return error;
96019@@ -467,7 +467,7 @@ static void __unregister_pernet_operations(struct pernet_operations *ops)
96020 struct net *net;
96021 LIST_HEAD(net_exit_list);
96022
96023- list_del(&ops->list);
96024+ pax_list_del((struct list_head *)&ops->list);
96025 for_each_net(net)
96026 list_add_tail(&net->exit_list, &net_exit_list);
96027 ops_exit_list(ops, &net_exit_list);
96028@@ -601,7 +601,7 @@ int register_pernet_device(struct pernet_operations *ops)
96029 mutex_lock(&net_mutex);
96030 error = register_pernet_operations(&pernet_list, ops);
96031 if (!error && (first_device == &pernet_list))
96032- first_device = &ops->list;
96033+ first_device = (struct list_head *)&ops->list;
96034 mutex_unlock(&net_mutex);
96035 return error;
96036 }
96037diff --git a/net/core/netpoll.c b/net/core/netpoll.c
96038index 0c1482c..f7ae314 100644
96039--- a/net/core/netpoll.c
96040+++ b/net/core/netpoll.c
96041@@ -435,7 +435,7 @@ void netpoll_send_udp(struct netpoll *np, const char *msg, int len)
96042 struct udphdr *udph;
96043 struct iphdr *iph;
96044 struct ethhdr *eth;
96045- static atomic_t ip_ident;
96046+ static atomic_unchecked_t ip_ident;
96047 struct ipv6hdr *ip6h;
96048
96049 udp_len = len + sizeof(*udph);
96050@@ -506,7 +506,7 @@ void netpoll_send_udp(struct netpoll *np, const char *msg, int len)
96051 put_unaligned(0x45, (unsigned char *)iph);
96052 iph->tos = 0;
96053 put_unaligned(htons(ip_len), &(iph->tot_len));
96054- iph->id = htons(atomic_inc_return(&ip_ident));
96055+ iph->id = htons(atomic_inc_return_unchecked(&ip_ident));
96056 iph->frag_off = 0;
96057 iph->ttl = 64;
96058 iph->protocol = IPPROTO_UDP;
96059diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
96060index 2a0e21d..6ad7642 100644
96061--- a/net/core/rtnetlink.c
96062+++ b/net/core/rtnetlink.c
96063@@ -58,7 +58,7 @@ struct rtnl_link {
96064 rtnl_doit_func doit;
96065 rtnl_dumpit_func dumpit;
96066 rtnl_calcit_func calcit;
96067-};
96068+} __no_const;
96069
96070 static DEFINE_MUTEX(rtnl_mutex);
96071
96072@@ -299,10 +299,13 @@ int __rtnl_link_register(struct rtnl_link_ops *ops)
96073 if (rtnl_link_ops_get(ops->kind))
96074 return -EEXIST;
96075
96076- if (!ops->dellink)
96077- ops->dellink = unregister_netdevice_queue;
96078+ if (!ops->dellink) {
96079+ pax_open_kernel();
96080+ *(void **)&ops->dellink = unregister_netdevice_queue;
96081+ pax_close_kernel();
96082+ }
96083
96084- list_add_tail(&ops->list, &link_ops);
96085+ pax_list_add_tail((struct list_head *)&ops->list, &link_ops);
96086 return 0;
96087 }
96088 EXPORT_SYMBOL_GPL(__rtnl_link_register);
96089@@ -349,7 +352,7 @@ void __rtnl_link_unregister(struct rtnl_link_ops *ops)
96090 for_each_net(net) {
96091 __rtnl_kill_links(net, ops);
96092 }
96093- list_del(&ops->list);
96094+ pax_list_del((struct list_head *)&ops->list);
96095 }
96096 EXPORT_SYMBOL_GPL(__rtnl_link_unregister);
96097
96098diff --git a/net/core/scm.c b/net/core/scm.c
96099index b442e7e..6f5b5a2 100644
96100--- a/net/core/scm.c
96101+++ b/net/core/scm.c
96102@@ -210,7 +210,7 @@ EXPORT_SYMBOL(__scm_send);
96103 int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
96104 {
96105 struct cmsghdr __user *cm
96106- = (__force struct cmsghdr __user *)msg->msg_control;
96107+ = (struct cmsghdr __force_user *)msg->msg_control;
96108 struct cmsghdr cmhdr;
96109 int cmlen = CMSG_LEN(len);
96110 int err;
96111@@ -233,7 +233,7 @@ int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
96112 err = -EFAULT;
96113 if (copy_to_user(cm, &cmhdr, sizeof cmhdr))
96114 goto out;
96115- if (copy_to_user(CMSG_DATA(cm), data, cmlen - sizeof(struct cmsghdr)))
96116+ if (copy_to_user((void __force_user *)CMSG_DATA((void __force_kernel *)cm), data, cmlen - sizeof(struct cmsghdr)))
96117 goto out;
96118 cmlen = CMSG_SPACE(len);
96119 if (msg->msg_controllen < cmlen)
96120@@ -249,7 +249,7 @@ EXPORT_SYMBOL(put_cmsg);
96121 void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
96122 {
96123 struct cmsghdr __user *cm
96124- = (__force struct cmsghdr __user*)msg->msg_control;
96125+ = (struct cmsghdr __force_user *)msg->msg_control;
96126
96127 int fdmax = 0;
96128 int fdnum = scm->fp->count;
96129@@ -269,7 +269,7 @@ void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
96130 if (fdnum < fdmax)
96131 fdmax = fdnum;
96132
96133- for (i=0, cmfptr=(__force int __user *)CMSG_DATA(cm); i<fdmax;
96134+ for (i=0, cmfptr=(int __force_user *)CMSG_DATA((void __force_kernel *)cm); i<fdmax;
96135 i++, cmfptr++)
96136 {
96137 struct socket *sock;
96138diff --git a/net/core/skbuff.c b/net/core/skbuff.c
96139index 743e6eb..a399a6d 100644
96140--- a/net/core/skbuff.c
96141+++ b/net/core/skbuff.c
96142@@ -3104,13 +3104,15 @@ void __init skb_init(void)
96143 skbuff_head_cache = kmem_cache_create("skbuff_head_cache",
96144 sizeof(struct sk_buff),
96145 0,
96146- SLAB_HWCACHE_ALIGN|SLAB_PANIC,
96147+ SLAB_HWCACHE_ALIGN|SLAB_PANIC|
96148+ SLAB_NO_SANITIZE,
96149 NULL);
96150 skbuff_fclone_cache = kmem_cache_create("skbuff_fclone_cache",
96151 (2*sizeof(struct sk_buff)) +
96152 sizeof(atomic_t),
96153 0,
96154- SLAB_HWCACHE_ALIGN|SLAB_PANIC,
96155+ SLAB_HWCACHE_ALIGN|SLAB_PANIC|
96156+ SLAB_NO_SANITIZE,
96157 NULL);
96158 }
96159
96160diff --git a/net/core/sock.c b/net/core/sock.c
96161index 5cec994..81aa1dd 100644
96162--- a/net/core/sock.c
96163+++ b/net/core/sock.c
96164@@ -393,7 +393,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
96165 struct sk_buff_head *list = &sk->sk_receive_queue;
96166
96167 if (atomic_read(&sk->sk_rmem_alloc) >= sk->sk_rcvbuf) {
96168- atomic_inc(&sk->sk_drops);
96169+ atomic_inc_unchecked(&sk->sk_drops);
96170 trace_sock_rcvqueue_full(sk, skb);
96171 return -ENOMEM;
96172 }
96173@@ -403,7 +403,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
96174 return err;
96175
96176 if (!sk_rmem_schedule(sk, skb, skb->truesize)) {
96177- atomic_inc(&sk->sk_drops);
96178+ atomic_inc_unchecked(&sk->sk_drops);
96179 return -ENOBUFS;
96180 }
96181
96182@@ -423,7 +423,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
96183 skb_dst_force(skb);
96184
96185 spin_lock_irqsave(&list->lock, flags);
96186- skb->dropcount = atomic_read(&sk->sk_drops);
96187+ skb->dropcount = atomic_read_unchecked(&sk->sk_drops);
96188 __skb_queue_tail(list, skb);
96189 spin_unlock_irqrestore(&list->lock, flags);
96190
96191@@ -443,7 +443,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
96192 skb->dev = NULL;
96193
96194 if (sk_rcvqueues_full(sk, skb, sk->sk_rcvbuf)) {
96195- atomic_inc(&sk->sk_drops);
96196+ atomic_inc_unchecked(&sk->sk_drops);
96197 goto discard_and_relse;
96198 }
96199 if (nested)
96200@@ -461,7 +461,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
96201 mutex_release(&sk->sk_lock.dep_map, 1, _RET_IP_);
96202 } else if (sk_add_backlog(sk, skb, sk->sk_rcvbuf)) {
96203 bh_unlock_sock(sk);
96204- atomic_inc(&sk->sk_drops);
96205+ atomic_inc_unchecked(&sk->sk_drops);
96206 goto discard_and_relse;
96207 }
96208
96209@@ -949,12 +949,12 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
96210 struct timeval tm;
96211 } v;
96212
96213- int lv = sizeof(int);
96214- int len;
96215+ unsigned int lv = sizeof(int);
96216+ unsigned int len;
96217
96218 if (get_user(len, optlen))
96219 return -EFAULT;
96220- if (len < 0)
96221+ if (len > INT_MAX)
96222 return -EINVAL;
96223
96224 memset(&v, 0, sizeof(v));
96225@@ -1106,11 +1106,11 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
96226
96227 case SO_PEERNAME:
96228 {
96229- char address[128];
96230+ char address[_K_SS_MAXSIZE];
96231
96232 if (sock->ops->getname(sock, (struct sockaddr *)address, &lv, 2))
96233 return -ENOTCONN;
96234- if (lv < len)
96235+ if (lv < len || sizeof address < len)
96236 return -EINVAL;
96237 if (copy_to_user(optval, address, len))
96238 return -EFAULT;
96239@@ -1183,7 +1183,7 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
96240
96241 if (len > lv)
96242 len = lv;
96243- if (copy_to_user(optval, &v, len))
96244+ if (len > sizeof(v) || copy_to_user(optval, &v, len))
96245 return -EFAULT;
96246 lenout:
96247 if (put_user(len, optlen))
96248@@ -2326,7 +2326,7 @@ void sock_init_data(struct socket *sock, struct sock *sk)
96249 */
96250 smp_wmb();
96251 atomic_set(&sk->sk_refcnt, 1);
96252- atomic_set(&sk->sk_drops, 0);
96253+ atomic_set_unchecked(&sk->sk_drops, 0);
96254 }
96255 EXPORT_SYMBOL(sock_init_data);
96256
96257@@ -2451,6 +2451,7 @@ void sock_enable_timestamp(struct sock *sk, int flag)
96258 int sock_recv_errqueue(struct sock *sk, struct msghdr *msg, int len,
96259 int level, int type)
96260 {
96261+ struct sock_extended_err ee;
96262 struct sock_exterr_skb *serr;
96263 struct sk_buff *skb, *skb2;
96264 int copied, err;
96265@@ -2472,7 +2473,8 @@ int sock_recv_errqueue(struct sock *sk, struct msghdr *msg, int len,
96266 sock_recv_timestamp(msg, sk, skb);
96267
96268 serr = SKB_EXT_ERR(skb);
96269- put_cmsg(msg, level, type, sizeof(serr->ee), &serr->ee);
96270+ ee = serr->ee;
96271+ put_cmsg(msg, level, type, sizeof ee, &ee);
96272
96273 msg->msg_flags |= MSG_ERRQUEUE;
96274 err = copied;
96275diff --git a/net/core/sock_diag.c b/net/core/sock_diag.c
96276index a0e9cf6..ef7f9ed 100644
96277--- a/net/core/sock_diag.c
96278+++ b/net/core/sock_diag.c
96279@@ -9,26 +9,33 @@
96280 #include <linux/inet_diag.h>
96281 #include <linux/sock_diag.h>
96282
96283-static const struct sock_diag_handler *sock_diag_handlers[AF_MAX];
96284+static const struct sock_diag_handler *sock_diag_handlers[AF_MAX] __read_only;
96285 static int (*inet_rcv_compat)(struct sk_buff *skb, struct nlmsghdr *nlh);
96286 static DEFINE_MUTEX(sock_diag_table_mutex);
96287
96288 int sock_diag_check_cookie(void *sk, __u32 *cookie)
96289 {
96290+#ifndef CONFIG_GRKERNSEC_HIDESYM
96291 if ((cookie[0] != INET_DIAG_NOCOOKIE ||
96292 cookie[1] != INET_DIAG_NOCOOKIE) &&
96293 ((u32)(unsigned long)sk != cookie[0] ||
96294 (u32)((((unsigned long)sk) >> 31) >> 1) != cookie[1]))
96295 return -ESTALE;
96296 else
96297+#endif
96298 return 0;
96299 }
96300 EXPORT_SYMBOL_GPL(sock_diag_check_cookie);
96301
96302 void sock_diag_save_cookie(void *sk, __u32 *cookie)
96303 {
96304+#ifdef CONFIG_GRKERNSEC_HIDESYM
96305+ cookie[0] = 0;
96306+ cookie[1] = 0;
96307+#else
96308 cookie[0] = (u32)(unsigned long)sk;
96309 cookie[1] = (u32)(((unsigned long)sk >> 31) >> 1);
96310+#endif
96311 }
96312 EXPORT_SYMBOL_GPL(sock_diag_save_cookie);
96313
96314@@ -113,8 +120,11 @@ int sock_diag_register(const struct sock_diag_handler *hndl)
96315 mutex_lock(&sock_diag_table_mutex);
96316 if (sock_diag_handlers[hndl->family])
96317 err = -EBUSY;
96318- else
96319+ else {
96320+ pax_open_kernel();
96321 sock_diag_handlers[hndl->family] = hndl;
96322+ pax_close_kernel();
96323+ }
96324 mutex_unlock(&sock_diag_table_mutex);
96325
96326 return err;
96327@@ -130,7 +140,9 @@ void sock_diag_unregister(const struct sock_diag_handler *hnld)
96328
96329 mutex_lock(&sock_diag_table_mutex);
96330 BUG_ON(sock_diag_handlers[family] != hnld);
96331+ pax_open_kernel();
96332 sock_diag_handlers[family] = NULL;
96333+ pax_close_kernel();
96334 mutex_unlock(&sock_diag_table_mutex);
96335 }
96336 EXPORT_SYMBOL_GPL(sock_diag_unregister);
96337diff --git a/net/core/sysctl_net_core.c b/net/core/sysctl_net_core.c
96338index cca4441..5e616de 100644
96339--- a/net/core/sysctl_net_core.c
96340+++ b/net/core/sysctl_net_core.c
96341@@ -32,7 +32,7 @@ static int rps_sock_flow_sysctl(struct ctl_table *table, int write,
96342 {
96343 unsigned int orig_size, size;
96344 int ret, i;
96345- struct ctl_table tmp = {
96346+ ctl_table_no_const tmp = {
96347 .data = &size,
96348 .maxlen = sizeof(size),
96349 .mode = table->mode
96350@@ -199,7 +199,7 @@ static int set_default_qdisc(struct ctl_table *table, int write,
96351 void __user *buffer, size_t *lenp, loff_t *ppos)
96352 {
96353 char id[IFNAMSIZ];
96354- struct ctl_table tbl = {
96355+ ctl_table_no_const tbl = {
96356 .data = id,
96357 .maxlen = IFNAMSIZ,
96358 };
96359@@ -378,13 +378,12 @@ static struct ctl_table netns_core_table[] = {
96360
96361 static __net_init int sysctl_core_net_init(struct net *net)
96362 {
96363- struct ctl_table *tbl;
96364+ ctl_table_no_const *tbl = NULL;
96365
96366 net->core.sysctl_somaxconn = SOMAXCONN;
96367
96368- tbl = netns_core_table;
96369 if (!net_eq(net, &init_net)) {
96370- tbl = kmemdup(tbl, sizeof(netns_core_table), GFP_KERNEL);
96371+ tbl = kmemdup(netns_core_table, sizeof(netns_core_table), GFP_KERNEL);
96372 if (tbl == NULL)
96373 goto err_dup;
96374
96375@@ -394,17 +393,16 @@ static __net_init int sysctl_core_net_init(struct net *net)
96376 if (net->user_ns != &init_user_ns) {
96377 tbl[0].procname = NULL;
96378 }
96379- }
96380-
96381- net->core.sysctl_hdr = register_net_sysctl(net, "net/core", tbl);
96382+ net->core.sysctl_hdr = register_net_sysctl(net, "net/core", tbl);
96383+ } else
96384+ net->core.sysctl_hdr = register_net_sysctl(net, "net/core", netns_core_table);
96385 if (net->core.sysctl_hdr == NULL)
96386 goto err_reg;
96387
96388 return 0;
96389
96390 err_reg:
96391- if (tbl != netns_core_table)
96392- kfree(tbl);
96393+ kfree(tbl);
96394 err_dup:
96395 return -ENOMEM;
96396 }
96397@@ -419,7 +417,7 @@ static __net_exit void sysctl_core_net_exit(struct net *net)
96398 kfree(tbl);
96399 }
96400
96401-static __net_initdata struct pernet_operations sysctl_core_ops = {
96402+static __net_initconst struct pernet_operations sysctl_core_ops = {
96403 .init = sysctl_core_net_init,
96404 .exit = sysctl_core_net_exit,
96405 };
96406diff --git a/net/decnet/af_decnet.c b/net/decnet/af_decnet.c
96407index dd4d506..fb2fb87 100644
96408--- a/net/decnet/af_decnet.c
96409+++ b/net/decnet/af_decnet.c
96410@@ -465,6 +465,7 @@ static struct proto dn_proto = {
96411 .sysctl_rmem = sysctl_decnet_rmem,
96412 .max_header = DN_MAX_NSP_DATA_HEADER + 64,
96413 .obj_size = sizeof(struct dn_sock),
96414+ .slab_flags = SLAB_USERCOPY,
96415 };
96416
96417 static struct sock *dn_alloc_sock(struct net *net, struct socket *sock, gfp_t gfp)
96418diff --git a/net/decnet/dn_dev.c b/net/decnet/dn_dev.c
96419index dd0dfb2..fdbc764 100644
96420--- a/net/decnet/dn_dev.c
96421+++ b/net/decnet/dn_dev.c
96422@@ -200,7 +200,7 @@ static struct dn_dev_sysctl_table {
96423 .extra1 = &min_t3,
96424 .extra2 = &max_t3
96425 },
96426- {0}
96427+ { }
96428 },
96429 };
96430
96431diff --git a/net/decnet/sysctl_net_decnet.c b/net/decnet/sysctl_net_decnet.c
96432index 5325b54..a0d4d69 100644
96433--- a/net/decnet/sysctl_net_decnet.c
96434+++ b/net/decnet/sysctl_net_decnet.c
96435@@ -174,7 +174,7 @@ static int dn_node_address_handler(struct ctl_table *table, int write,
96436
96437 if (len > *lenp) len = *lenp;
96438
96439- if (copy_to_user(buffer, addr, len))
96440+ if (len > sizeof addr || copy_to_user(buffer, addr, len))
96441 return -EFAULT;
96442
96443 *lenp = len;
96444@@ -237,7 +237,7 @@ static int dn_def_dev_handler(struct ctl_table *table, int write,
96445
96446 if (len > *lenp) len = *lenp;
96447
96448- if (copy_to_user(buffer, devname, len))
96449+ if (len > sizeof devname || copy_to_user(buffer, devname, len))
96450 return -EFAULT;
96451
96452 *lenp = len;
96453diff --git a/net/ieee802154/6lowpan.c b/net/ieee802154/6lowpan.c
96454index 008f337..b03b8c9 100644
96455--- a/net/ieee802154/6lowpan.c
96456+++ b/net/ieee802154/6lowpan.c
96457@@ -548,7 +548,7 @@ static int lowpan_header_create(struct sk_buff *skb,
96458 hc06_ptr += 3;
96459 } else {
96460 /* compress nothing */
96461- memcpy(hc06_ptr, &hdr, 4);
96462+ memcpy(hc06_ptr, hdr, 4);
96463 /* replace the top byte with new ECN | DSCP format */
96464 *hc06_ptr = tmp;
96465 hc06_ptr += 4;
96466diff --git a/net/ieee802154/nl-phy.c b/net/ieee802154/nl-phy.c
96467index 22b1a70..4efd237 100644
96468--- a/net/ieee802154/nl-phy.c
96469+++ b/net/ieee802154/nl-phy.c
96470@@ -224,8 +224,10 @@ static int ieee802154_add_iface(struct sk_buff *skb,
96471
96472 if (info->attrs[IEEE802154_ATTR_DEV_TYPE]) {
96473 type = nla_get_u8(info->attrs[IEEE802154_ATTR_DEV_TYPE]);
96474- if (type >= __IEEE802154_DEV_MAX)
96475- return -EINVAL;
96476+ if (type >= __IEEE802154_DEV_MAX) {
96477+ rc = -EINVAL;
96478+ goto nla_put_failure;
96479+ }
96480 }
96481
96482 dev = phy->add_iface(phy, devname, type);
96483diff --git a/net/ipv4/af_inet.c b/net/ipv4/af_inet.c
96484index cfeb85c..385989a 100644
96485--- a/net/ipv4/af_inet.c
96486+++ b/net/ipv4/af_inet.c
96487@@ -1675,13 +1675,9 @@ static int __init inet_init(void)
96488
96489 BUILD_BUG_ON(sizeof(struct inet_skb_parm) > FIELD_SIZEOF(struct sk_buff, cb));
96490
96491- sysctl_local_reserved_ports = kzalloc(65536 / 8, GFP_KERNEL);
96492- if (!sysctl_local_reserved_ports)
96493- goto out;
96494-
96495 rc = proto_register(&tcp_prot, 1);
96496 if (rc)
96497- goto out_free_reserved_ports;
96498+ goto out;
96499
96500 rc = proto_register(&udp_prot, 1);
96501 if (rc)
96502@@ -1790,8 +1786,6 @@ out_unregister_udp_proto:
96503 proto_unregister(&udp_prot);
96504 out_unregister_tcp_proto:
96505 proto_unregister(&tcp_prot);
96506-out_free_reserved_ports:
96507- kfree(sysctl_local_reserved_ports);
96508 goto out;
96509 }
96510
96511diff --git a/net/ipv4/devinet.c b/net/ipv4/devinet.c
96512index a1b5bcb..62ec5c6 100644
96513--- a/net/ipv4/devinet.c
96514+++ b/net/ipv4/devinet.c
96515@@ -1533,7 +1533,7 @@ static int inet_dump_ifaddr(struct sk_buff *skb, struct netlink_callback *cb)
96516 idx = 0;
96517 head = &net->dev_index_head[h];
96518 rcu_read_lock();
96519- cb->seq = atomic_read(&net->ipv4.dev_addr_genid) ^
96520+ cb->seq = atomic_read_unchecked(&net->ipv4.dev_addr_genid) ^
96521 net->dev_base_seq;
96522 hlist_for_each_entry_rcu(dev, head, index_hlist) {
96523 if (idx < s_idx)
96524@@ -1844,7 +1844,7 @@ static int inet_netconf_dump_devconf(struct sk_buff *skb,
96525 idx = 0;
96526 head = &net->dev_index_head[h];
96527 rcu_read_lock();
96528- cb->seq = atomic_read(&net->ipv4.dev_addr_genid) ^
96529+ cb->seq = atomic_read_unchecked(&net->ipv4.dev_addr_genid) ^
96530 net->dev_base_seq;
96531 hlist_for_each_entry_rcu(dev, head, index_hlist) {
96532 if (idx < s_idx)
96533@@ -2069,7 +2069,7 @@ static int ipv4_doint_and_flush(struct ctl_table *ctl, int write,
96534 #define DEVINET_SYSCTL_FLUSHING_ENTRY(attr, name) \
96535 DEVINET_SYSCTL_COMPLEX_ENTRY(attr, name, ipv4_doint_and_flush)
96536
96537-static struct devinet_sysctl_table {
96538+static const struct devinet_sysctl_table {
96539 struct ctl_table_header *sysctl_header;
96540 struct ctl_table devinet_vars[__IPV4_DEVCONF_MAX];
96541 } devinet_sysctl = {
96542@@ -2191,7 +2191,7 @@ static __net_init int devinet_init_net(struct net *net)
96543 int err;
96544 struct ipv4_devconf *all, *dflt;
96545 #ifdef CONFIG_SYSCTL
96546- struct ctl_table *tbl = ctl_forward_entry;
96547+ ctl_table_no_const *tbl = NULL;
96548 struct ctl_table_header *forw_hdr;
96549 #endif
96550
96551@@ -2209,7 +2209,7 @@ static __net_init int devinet_init_net(struct net *net)
96552 goto err_alloc_dflt;
96553
96554 #ifdef CONFIG_SYSCTL
96555- tbl = kmemdup(tbl, sizeof(ctl_forward_entry), GFP_KERNEL);
96556+ tbl = kmemdup(ctl_forward_entry, sizeof(ctl_forward_entry), GFP_KERNEL);
96557 if (tbl == NULL)
96558 goto err_alloc_ctl;
96559
96560@@ -2229,7 +2229,10 @@ static __net_init int devinet_init_net(struct net *net)
96561 goto err_reg_dflt;
96562
96563 err = -ENOMEM;
96564- forw_hdr = register_net_sysctl(net, "net/ipv4", tbl);
96565+ if (!net_eq(net, &init_net))
96566+ forw_hdr = register_net_sysctl(net, "net/ipv4", tbl);
96567+ else
96568+ forw_hdr = register_net_sysctl(net, "net/ipv4", ctl_forward_entry);
96569 if (forw_hdr == NULL)
96570 goto err_reg_ctl;
96571 net->ipv4.forw_hdr = forw_hdr;
96572@@ -2245,8 +2248,7 @@ err_reg_ctl:
96573 err_reg_dflt:
96574 __devinet_sysctl_unregister(all);
96575 err_reg_all:
96576- if (tbl != ctl_forward_entry)
96577- kfree(tbl);
96578+ kfree(tbl);
96579 err_alloc_ctl:
96580 #endif
96581 if (dflt != &ipv4_devconf_dflt)
96582diff --git a/net/ipv4/fib_frontend.c b/net/ipv4/fib_frontend.c
96583index b3f627a..b0f3e99 100644
96584--- a/net/ipv4/fib_frontend.c
96585+++ b/net/ipv4/fib_frontend.c
96586@@ -1017,12 +1017,12 @@ static int fib_inetaddr_event(struct notifier_block *this, unsigned long event,
96587 #ifdef CONFIG_IP_ROUTE_MULTIPATH
96588 fib_sync_up(dev);
96589 #endif
96590- atomic_inc(&net->ipv4.dev_addr_genid);
96591+ atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
96592 rt_cache_flush(dev_net(dev));
96593 break;
96594 case NETDEV_DOWN:
96595 fib_del_ifaddr(ifa, NULL);
96596- atomic_inc(&net->ipv4.dev_addr_genid);
96597+ atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
96598 if (ifa->ifa_dev->ifa_list == NULL) {
96599 /* Last address was deleted from this interface.
96600 * Disable IP.
96601@@ -1058,7 +1058,7 @@ static int fib_netdev_event(struct notifier_block *this, unsigned long event, vo
96602 #ifdef CONFIG_IP_ROUTE_MULTIPATH
96603 fib_sync_up(dev);
96604 #endif
96605- atomic_inc(&net->ipv4.dev_addr_genid);
96606+ atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
96607 rt_cache_flush(net);
96608 break;
96609 case NETDEV_DOWN:
96610diff --git a/net/ipv4/fib_semantics.c b/net/ipv4/fib_semantics.c
96611index d5dbca5..6251d5f 100644
96612--- a/net/ipv4/fib_semantics.c
96613+++ b/net/ipv4/fib_semantics.c
96614@@ -766,7 +766,7 @@ __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh)
96615 nh->nh_saddr = inet_select_addr(nh->nh_dev,
96616 nh->nh_gw,
96617 nh->nh_parent->fib_scope);
96618- nh->nh_saddr_genid = atomic_read(&net->ipv4.dev_addr_genid);
96619+ nh->nh_saddr_genid = atomic_read_unchecked(&net->ipv4.dev_addr_genid);
96620
96621 return nh->nh_saddr;
96622 }
96623diff --git a/net/ipv4/inet_connection_sock.c b/net/ipv4/inet_connection_sock.c
96624index 6acb541..9ea617d 100644
96625--- a/net/ipv4/inet_connection_sock.c
96626+++ b/net/ipv4/inet_connection_sock.c
96627@@ -37,7 +37,7 @@ struct local_ports sysctl_local_ports __read_mostly = {
96628 .range = { 32768, 61000 },
96629 };
96630
96631-unsigned long *sysctl_local_reserved_ports;
96632+unsigned long sysctl_local_reserved_ports[65536 / 8 / sizeof(unsigned long)];
96633 EXPORT_SYMBOL(sysctl_local_reserved_ports);
96634
96635 void inet_get_local_port_range(int *low, int *high)
96636diff --git a/net/ipv4/inet_hashtables.c b/net/ipv4/inet_hashtables.c
96637index 96da9c7..b956690 100644
96638--- a/net/ipv4/inet_hashtables.c
96639+++ b/net/ipv4/inet_hashtables.c
96640@@ -18,12 +18,15 @@
96641 #include <linux/sched.h>
96642 #include <linux/slab.h>
96643 #include <linux/wait.h>
96644+#include <linux/security.h>
96645
96646 #include <net/inet_connection_sock.h>
96647 #include <net/inet_hashtables.h>
96648 #include <net/secure_seq.h>
96649 #include <net/ip.h>
96650
96651+extern void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet);
96652+
96653 /*
96654 * Allocate and initialize a new local port bind bucket.
96655 * The bindhash mutex for snum's hash chain must be held here.
96656@@ -554,6 +557,8 @@ ok:
96657 twrefcnt += inet_twsk_bind_unhash(tw, hinfo);
96658 spin_unlock(&head->lock);
96659
96660+ gr_update_task_in_ip_table(current, inet_sk(sk));
96661+
96662 if (tw) {
96663 inet_twsk_deschedule(tw, death_row);
96664 while (twrefcnt) {
96665diff --git a/net/ipv4/inetpeer.c b/net/ipv4/inetpeer.c
96666index 33d5537..da337a4 100644
96667--- a/net/ipv4/inetpeer.c
96668+++ b/net/ipv4/inetpeer.c
96669@@ -503,8 +503,8 @@ relookup:
96670 if (p) {
96671 p->daddr = *daddr;
96672 atomic_set(&p->refcnt, 1);
96673- atomic_set(&p->rid, 0);
96674- atomic_set(&p->ip_id_count,
96675+ atomic_set_unchecked(&p->rid, 0);
96676+ atomic_set_unchecked(&p->ip_id_count,
96677 (daddr->family == AF_INET) ?
96678 secure_ip_id(daddr->addr.a4) :
96679 secure_ipv6_id(daddr->addr.a6));
96680diff --git a/net/ipv4/ip_fragment.c b/net/ipv4/ip_fragment.c
96681index b66910a..cfe416e 100644
96682--- a/net/ipv4/ip_fragment.c
96683+++ b/net/ipv4/ip_fragment.c
96684@@ -282,7 +282,7 @@ static inline int ip_frag_too_far(struct ipq *qp)
96685 return 0;
96686
96687 start = qp->rid;
96688- end = atomic_inc_return(&peer->rid);
96689+ end = atomic_inc_return_unchecked(&peer->rid);
96690 qp->rid = end;
96691
96692 rc = qp->q.fragments && (end - start) > max;
96693@@ -759,12 +759,11 @@ static struct ctl_table ip4_frags_ctl_table[] = {
96694
96695 static int __net_init ip4_frags_ns_ctl_register(struct net *net)
96696 {
96697- struct ctl_table *table;
96698+ ctl_table_no_const *table = NULL;
96699 struct ctl_table_header *hdr;
96700
96701- table = ip4_frags_ns_ctl_table;
96702 if (!net_eq(net, &init_net)) {
96703- table = kmemdup(table, sizeof(ip4_frags_ns_ctl_table), GFP_KERNEL);
96704+ table = kmemdup(ip4_frags_ns_ctl_table, sizeof(ip4_frags_ns_ctl_table), GFP_KERNEL);
96705 if (table == NULL)
96706 goto err_alloc;
96707
96708@@ -775,9 +774,10 @@ static int __net_init ip4_frags_ns_ctl_register(struct net *net)
96709 /* Don't export sysctls to unprivileged users */
96710 if (net->user_ns != &init_user_ns)
96711 table[0].procname = NULL;
96712- }
96713+ hdr = register_net_sysctl(net, "net/ipv4", table);
96714+ } else
96715+ hdr = register_net_sysctl(net, "net/ipv4", ip4_frags_ns_ctl_table);
96716
96717- hdr = register_net_sysctl(net, "net/ipv4", table);
96718 if (hdr == NULL)
96719 goto err_reg;
96720
96721@@ -785,8 +785,7 @@ static int __net_init ip4_frags_ns_ctl_register(struct net *net)
96722 return 0;
96723
96724 err_reg:
96725- if (!net_eq(net, &init_net))
96726- kfree(table);
96727+ kfree(table);
96728 err_alloc:
96729 return -ENOMEM;
96730 }
96731diff --git a/net/ipv4/ip_gre.c b/net/ipv4/ip_gre.c
96732index e560ef3..218c5c5 100644
96733--- a/net/ipv4/ip_gre.c
96734+++ b/net/ipv4/ip_gre.c
96735@@ -115,7 +115,7 @@ static bool log_ecn_error = true;
96736 module_param(log_ecn_error, bool, 0644);
96737 MODULE_PARM_DESC(log_ecn_error, "Log packets received with corrupted ECN");
96738
96739-static struct rtnl_link_ops ipgre_link_ops __read_mostly;
96740+static struct rtnl_link_ops ipgre_link_ops;
96741 static int ipgre_tunnel_init(struct net_device *dev);
96742
96743 static int ipgre_net_id __read_mostly;
96744@@ -732,7 +732,7 @@ static const struct nla_policy ipgre_policy[IFLA_GRE_MAX + 1] = {
96745 [IFLA_GRE_PMTUDISC] = { .type = NLA_U8 },
96746 };
96747
96748-static struct rtnl_link_ops ipgre_link_ops __read_mostly = {
96749+static struct rtnl_link_ops ipgre_link_ops = {
96750 .kind = "gre",
96751 .maxtype = IFLA_GRE_MAX,
96752 .policy = ipgre_policy,
96753@@ -746,7 +746,7 @@ static struct rtnl_link_ops ipgre_link_ops __read_mostly = {
96754 .fill_info = ipgre_fill_info,
96755 };
96756
96757-static struct rtnl_link_ops ipgre_tap_ops __read_mostly = {
96758+static struct rtnl_link_ops ipgre_tap_ops = {
96759 .kind = "gretap",
96760 .maxtype = IFLA_GRE_MAX,
96761 .policy = ipgre_policy,
96762diff --git a/net/ipv4/ip_sockglue.c b/net/ipv4/ip_sockglue.c
96763index 23e6ab0..be67a57 100644
96764--- a/net/ipv4/ip_sockglue.c
96765+++ b/net/ipv4/ip_sockglue.c
96766@@ -1153,7 +1153,8 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
96767 len = min_t(unsigned int, len, opt->optlen);
96768 if (put_user(len, optlen))
96769 return -EFAULT;
96770- if (copy_to_user(optval, opt->__data, len))
96771+ if ((len > (sizeof(optbuf) - sizeof(struct ip_options))) ||
96772+ copy_to_user(optval, opt->__data, len))
96773 return -EFAULT;
96774 return 0;
96775 }
96776@@ -1284,7 +1285,7 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
96777 if (sk->sk_type != SOCK_STREAM)
96778 return -ENOPROTOOPT;
96779
96780- msg.msg_control = optval;
96781+ msg.msg_control = (void __force_kernel *)optval;
96782 msg.msg_controllen = len;
96783 msg.msg_flags = flags;
96784
96785diff --git a/net/ipv4/ip_vti.c b/net/ipv4/ip_vti.c
96786index 26847e1..75d2d2f 100644
96787--- a/net/ipv4/ip_vti.c
96788+++ b/net/ipv4/ip_vti.c
96789@@ -44,7 +44,7 @@
96790 #include <net/net_namespace.h>
96791 #include <net/netns/generic.h>
96792
96793-static struct rtnl_link_ops vti_link_ops __read_mostly;
96794+static struct rtnl_link_ops vti_link_ops;
96795
96796 static int vti_net_id __read_mostly;
96797 static int vti_tunnel_init(struct net_device *dev);
96798@@ -425,7 +425,7 @@ static const struct nla_policy vti_policy[IFLA_VTI_MAX + 1] = {
96799 [IFLA_VTI_REMOTE] = { .len = FIELD_SIZEOF(struct iphdr, daddr) },
96800 };
96801
96802-static struct rtnl_link_ops vti_link_ops __read_mostly = {
96803+static struct rtnl_link_ops vti_link_ops = {
96804 .kind = "vti",
96805 .maxtype = IFLA_VTI_MAX,
96806 .policy = vti_policy,
96807diff --git a/net/ipv4/ipconfig.c b/net/ipv4/ipconfig.c
96808index efa1138..20dbba0 100644
96809--- a/net/ipv4/ipconfig.c
96810+++ b/net/ipv4/ipconfig.c
96811@@ -334,7 +334,7 @@ static int __init ic_devinet_ioctl(unsigned int cmd, struct ifreq *arg)
96812
96813 mm_segment_t oldfs = get_fs();
96814 set_fs(get_ds());
96815- res = devinet_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
96816+ res = devinet_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
96817 set_fs(oldfs);
96818 return res;
96819 }
96820@@ -345,7 +345,7 @@ static int __init ic_dev_ioctl(unsigned int cmd, struct ifreq *arg)
96821
96822 mm_segment_t oldfs = get_fs();
96823 set_fs(get_ds());
96824- res = dev_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
96825+ res = dev_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
96826 set_fs(oldfs);
96827 return res;
96828 }
96829@@ -356,7 +356,7 @@ static int __init ic_route_ioctl(unsigned int cmd, struct rtentry *arg)
96830
96831 mm_segment_t oldfs = get_fs();
96832 set_fs(get_ds());
96833- res = ip_rt_ioctl(&init_net, cmd, (void __user *) arg);
96834+ res = ip_rt_ioctl(&init_net, cmd, (void __force_user *) arg);
96835 set_fs(oldfs);
96836 return res;
96837 }
96838diff --git a/net/ipv4/ipip.c b/net/ipv4/ipip.c
96839index 7f80fb4..b0328f6 100644
96840--- a/net/ipv4/ipip.c
96841+++ b/net/ipv4/ipip.c
96842@@ -124,7 +124,7 @@ MODULE_PARM_DESC(log_ecn_error, "Log packets received with corrupted ECN");
96843 static int ipip_net_id __read_mostly;
96844
96845 static int ipip_tunnel_init(struct net_device *dev);
96846-static struct rtnl_link_ops ipip_link_ops __read_mostly;
96847+static struct rtnl_link_ops ipip_link_ops;
96848
96849 static int ipip_err(struct sk_buff *skb, u32 info)
96850 {
96851@@ -408,7 +408,7 @@ static const struct nla_policy ipip_policy[IFLA_IPTUN_MAX + 1] = {
96852 [IFLA_IPTUN_PMTUDISC] = { .type = NLA_U8 },
96853 };
96854
96855-static struct rtnl_link_ops ipip_link_ops __read_mostly = {
96856+static struct rtnl_link_ops ipip_link_ops = {
96857 .kind = "ipip",
96858 .maxtype = IFLA_IPTUN_MAX,
96859 .policy = ipip_policy,
96860diff --git a/net/ipv4/ipmr.c b/net/ipv4/ipmr.c
96861index 62212c7..1672409 100644
96862--- a/net/ipv4/ipmr.c
96863+++ b/net/ipv4/ipmr.c
96864@@ -157,9 +157,12 @@ static struct mr_table *ipmr_get_table(struct net *net, u32 id)
96865 static int ipmr_fib_lookup(struct net *net, struct flowi4 *flp4,
96866 struct mr_table **mrt)
96867 {
96868+ int err;
96869 struct ipmr_result res;
96870- struct fib_lookup_arg arg = { .result = &res, };
96871- int err;
96872+ struct fib_lookup_arg arg = {
96873+ .result = &res,
96874+ .flags = FIB_LOOKUP_NOREF,
96875+ };
96876
96877 err = fib_rules_lookup(net->ipv4.mr_rules_ops,
96878 flowi4_to_flowi(flp4), 0, &arg);
96879diff --git a/net/ipv4/netfilter/arp_tables.c b/net/ipv4/netfilter/arp_tables.c
96880index 85a4f21..1beb1f5 100644
96881--- a/net/ipv4/netfilter/arp_tables.c
96882+++ b/net/ipv4/netfilter/arp_tables.c
96883@@ -880,14 +880,14 @@ static int compat_table_info(const struct xt_table_info *info,
96884 #endif
96885
96886 static int get_info(struct net *net, void __user *user,
96887- const int *len, int compat)
96888+ int len, int compat)
96889 {
96890 char name[XT_TABLE_MAXNAMELEN];
96891 struct xt_table *t;
96892 int ret;
96893
96894- if (*len != sizeof(struct arpt_getinfo)) {
96895- duprintf("length %u != %Zu\n", *len,
96896+ if (len != sizeof(struct arpt_getinfo)) {
96897+ duprintf("length %u != %Zu\n", len,
96898 sizeof(struct arpt_getinfo));
96899 return -EINVAL;
96900 }
96901@@ -924,7 +924,7 @@ static int get_info(struct net *net, void __user *user,
96902 info.size = private->size;
96903 strcpy(info.name, name);
96904
96905- if (copy_to_user(user, &info, *len) != 0)
96906+ if (copy_to_user(user, &info, len) != 0)
96907 ret = -EFAULT;
96908 else
96909 ret = 0;
96910@@ -1683,7 +1683,7 @@ static int compat_do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user,
96911
96912 switch (cmd) {
96913 case ARPT_SO_GET_INFO:
96914- ret = get_info(sock_net(sk), user, len, 1);
96915+ ret = get_info(sock_net(sk), user, *len, 1);
96916 break;
96917 case ARPT_SO_GET_ENTRIES:
96918 ret = compat_get_entries(sock_net(sk), user, len);
96919@@ -1728,7 +1728,7 @@ static int do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len
96920
96921 switch (cmd) {
96922 case ARPT_SO_GET_INFO:
96923- ret = get_info(sock_net(sk), user, len, 0);
96924+ ret = get_info(sock_net(sk), user, *len, 0);
96925 break;
96926
96927 case ARPT_SO_GET_ENTRIES:
96928diff --git a/net/ipv4/netfilter/ip_tables.c b/net/ipv4/netfilter/ip_tables.c
96929index d23118d..6ad7277 100644
96930--- a/net/ipv4/netfilter/ip_tables.c
96931+++ b/net/ipv4/netfilter/ip_tables.c
96932@@ -1068,14 +1068,14 @@ static int compat_table_info(const struct xt_table_info *info,
96933 #endif
96934
96935 static int get_info(struct net *net, void __user *user,
96936- const int *len, int compat)
96937+ int len, int compat)
96938 {
96939 char name[XT_TABLE_MAXNAMELEN];
96940 struct xt_table *t;
96941 int ret;
96942
96943- if (*len != sizeof(struct ipt_getinfo)) {
96944- duprintf("length %u != %zu\n", *len,
96945+ if (len != sizeof(struct ipt_getinfo)) {
96946+ duprintf("length %u != %zu\n", len,
96947 sizeof(struct ipt_getinfo));
96948 return -EINVAL;
96949 }
96950@@ -1112,7 +1112,7 @@ static int get_info(struct net *net, void __user *user,
96951 info.size = private->size;
96952 strcpy(info.name, name);
96953
96954- if (copy_to_user(user, &info, *len) != 0)
96955+ if (copy_to_user(user, &info, len) != 0)
96956 ret = -EFAULT;
96957 else
96958 ret = 0;
96959@@ -1966,7 +1966,7 @@ compat_do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
96960
96961 switch (cmd) {
96962 case IPT_SO_GET_INFO:
96963- ret = get_info(sock_net(sk), user, len, 1);
96964+ ret = get_info(sock_net(sk), user, *len, 1);
96965 break;
96966 case IPT_SO_GET_ENTRIES:
96967 ret = compat_get_entries(sock_net(sk), user, len);
96968@@ -2013,7 +2013,7 @@ do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
96969
96970 switch (cmd) {
96971 case IPT_SO_GET_INFO:
96972- ret = get_info(sock_net(sk), user, len, 0);
96973+ ret = get_info(sock_net(sk), user, *len, 0);
96974 break;
96975
96976 case IPT_SO_GET_ENTRIES:
96977diff --git a/net/ipv4/netfilter/ipt_ULOG.c b/net/ipv4/netfilter/ipt_ULOG.c
96978index cbc2215..9cb993c 100644
96979--- a/net/ipv4/netfilter/ipt_ULOG.c
96980+++ b/net/ipv4/netfilter/ipt_ULOG.c
96981@@ -220,6 +220,7 @@ static void ipt_ulog_packet(struct net *net,
96982 ub->qlen++;
96983
96984 pm = nlmsg_data(nlh);
96985+ memset(pm, 0, sizeof(*pm));
96986
96987 /* We might not have a timestamp, get one */
96988 if (skb->tstamp.tv64 == 0)
96989@@ -238,8 +239,6 @@ static void ipt_ulog_packet(struct net *net,
96990 }
96991 else if (loginfo->prefix[0] != '\0')
96992 strncpy(pm->prefix, loginfo->prefix, sizeof(pm->prefix));
96993- else
96994- *(pm->prefix) = '\0';
96995
96996 if (in && in->hard_header_len > 0 &&
96997 skb->mac_header != skb->network_header &&
96998@@ -251,13 +250,9 @@ static void ipt_ulog_packet(struct net *net,
96999
97000 if (in)
97001 strncpy(pm->indev_name, in->name, sizeof(pm->indev_name));
97002- else
97003- pm->indev_name[0] = '\0';
97004
97005 if (out)
97006 strncpy(pm->outdev_name, out->name, sizeof(pm->outdev_name));
97007- else
97008- pm->outdev_name[0] = '\0';
97009
97010 /* copy_len <= skb->len, so can't fail. */
97011 if (skb_copy_bits(skb, 0, pm->payload, copy_len) < 0)
97012diff --git a/net/ipv4/ping.c b/net/ipv4/ping.c
97013index c482f7c..2784262 100644
97014--- a/net/ipv4/ping.c
97015+++ b/net/ipv4/ping.c
97016@@ -55,7 +55,7 @@
97017
97018
97019 struct ping_table ping_table;
97020-struct pingv6_ops pingv6_ops;
97021+struct pingv6_ops *pingv6_ops;
97022 EXPORT_SYMBOL_GPL(pingv6_ops);
97023
97024 static u16 ping_port_rover;
97025@@ -335,7 +335,7 @@ static int ping_check_bind_addr(struct sock *sk, struct inet_sock *isk,
97026 return -ENODEV;
97027 }
97028 }
97029- has_addr = pingv6_ops.ipv6_chk_addr(net, &addr->sin6_addr, dev,
97030+ has_addr = pingv6_ops->ipv6_chk_addr(net, &addr->sin6_addr, dev,
97031 scoped);
97032 rcu_read_unlock();
97033
97034@@ -541,7 +541,7 @@ void ping_err(struct sk_buff *skb, int offset, u32 info)
97035 }
97036 #if IS_ENABLED(CONFIG_IPV6)
97037 } else if (skb->protocol == htons(ETH_P_IPV6)) {
97038- harderr = pingv6_ops.icmpv6_err_convert(type, code, &err);
97039+ harderr = pingv6_ops->icmpv6_err_convert(type, code, &err);
97040 #endif
97041 }
97042
97043@@ -559,7 +559,7 @@ void ping_err(struct sk_buff *skb, int offset, u32 info)
97044 info, (u8 *)icmph);
97045 #if IS_ENABLED(CONFIG_IPV6)
97046 } else if (family == AF_INET6) {
97047- pingv6_ops.ipv6_icmp_error(sk, skb, err, 0,
97048+ pingv6_ops->ipv6_icmp_error(sk, skb, err, 0,
97049 info, (u8 *)icmph);
97050 #endif
97051 }
97052@@ -841,7 +841,7 @@ int ping_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
97053 return ip_recv_error(sk, msg, len, addr_len);
97054 #if IS_ENABLED(CONFIG_IPV6)
97055 } else if (family == AF_INET6) {
97056- return pingv6_ops.ipv6_recv_error(sk, msg, len,
97057+ return pingv6_ops->ipv6_recv_error(sk, msg, len,
97058 addr_len);
97059 #endif
97060 }
97061@@ -900,7 +900,7 @@ int ping_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
97062 }
97063
97064 if (inet6_sk(sk)->rxopt.all)
97065- pingv6_ops.ip6_datagram_recv_ctl(sk, msg, skb);
97066+ pingv6_ops->ip6_datagram_recv_ctl(sk, msg, skb);
97067 #endif
97068 } else {
97069 BUG();
97070@@ -1090,7 +1090,7 @@ static void ping_v4_format_sock(struct sock *sp, struct seq_file *f,
97071 from_kuid_munged(seq_user_ns(f), sock_i_uid(sp)),
97072 0, sock_i_ino(sp),
97073 atomic_read(&sp->sk_refcnt), sp,
97074- atomic_read(&sp->sk_drops), len);
97075+ atomic_read_unchecked(&sp->sk_drops), len);
97076 }
97077
97078 static int ping_v4_seq_show(struct seq_file *seq, void *v)
97079diff --git a/net/ipv4/raw.c b/net/ipv4/raw.c
97080index 7d3db78..9fd511d 100644
97081--- a/net/ipv4/raw.c
97082+++ b/net/ipv4/raw.c
97083@@ -311,7 +311,7 @@ static int raw_rcv_skb(struct sock *sk, struct sk_buff *skb)
97084 int raw_rcv(struct sock *sk, struct sk_buff *skb)
97085 {
97086 if (!xfrm4_policy_check(sk, XFRM_POLICY_IN, skb)) {
97087- atomic_inc(&sk->sk_drops);
97088+ atomic_inc_unchecked(&sk->sk_drops);
97089 kfree_skb(skb);
97090 return NET_RX_DROP;
97091 }
97092@@ -746,16 +746,20 @@ static int raw_init(struct sock *sk)
97093
97094 static int raw_seticmpfilter(struct sock *sk, char __user *optval, int optlen)
97095 {
97096+ struct icmp_filter filter;
97097+
97098 if (optlen > sizeof(struct icmp_filter))
97099 optlen = sizeof(struct icmp_filter);
97100- if (copy_from_user(&raw_sk(sk)->filter, optval, optlen))
97101+ if (copy_from_user(&filter, optval, optlen))
97102 return -EFAULT;
97103+ raw_sk(sk)->filter = filter;
97104 return 0;
97105 }
97106
97107 static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *optlen)
97108 {
97109 int len, ret = -EFAULT;
97110+ struct icmp_filter filter;
97111
97112 if (get_user(len, optlen))
97113 goto out;
97114@@ -765,8 +769,8 @@ static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *o
97115 if (len > sizeof(struct icmp_filter))
97116 len = sizeof(struct icmp_filter);
97117 ret = -EFAULT;
97118- if (put_user(len, optlen) ||
97119- copy_to_user(optval, &raw_sk(sk)->filter, len))
97120+ filter = raw_sk(sk)->filter;
97121+ if (put_user(len, optlen) || len > sizeof filter || copy_to_user(optval, &filter, len))
97122 goto out;
97123 ret = 0;
97124 out: return ret;
97125@@ -995,7 +999,7 @@ static void raw_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
97126 0, 0L, 0,
97127 from_kuid_munged(seq_user_ns(seq), sock_i_uid(sp)),
97128 0, sock_i_ino(sp),
97129- atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
97130+ atomic_read(&sp->sk_refcnt), sp, atomic_read_unchecked(&sp->sk_drops));
97131 }
97132
97133 static int raw_seq_show(struct seq_file *seq, void *v)
97134diff --git a/net/ipv4/route.c b/net/ipv4/route.c
97135index 62290b5..f0d944f 100644
97136--- a/net/ipv4/route.c
97137+++ b/net/ipv4/route.c
97138@@ -2617,34 +2617,34 @@ static struct ctl_table ipv4_route_flush_table[] = {
97139 .maxlen = sizeof(int),
97140 .mode = 0200,
97141 .proc_handler = ipv4_sysctl_rtcache_flush,
97142+ .extra1 = &init_net,
97143 },
97144 { },
97145 };
97146
97147 static __net_init int sysctl_route_net_init(struct net *net)
97148 {
97149- struct ctl_table *tbl;
97150+ ctl_table_no_const *tbl = NULL;
97151
97152- tbl = ipv4_route_flush_table;
97153 if (!net_eq(net, &init_net)) {
97154- tbl = kmemdup(tbl, sizeof(ipv4_route_flush_table), GFP_KERNEL);
97155+ tbl = kmemdup(ipv4_route_flush_table, sizeof(ipv4_route_flush_table), GFP_KERNEL);
97156 if (tbl == NULL)
97157 goto err_dup;
97158
97159 /* Don't export sysctls to unprivileged users */
97160 if (net->user_ns != &init_user_ns)
97161 tbl[0].procname = NULL;
97162- }
97163- tbl[0].extra1 = net;
97164+ tbl[0].extra1 = net;
97165+ net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", tbl);
97166+ } else
97167+ net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", ipv4_route_flush_table);
97168
97169- net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", tbl);
97170 if (net->ipv4.route_hdr == NULL)
97171 goto err_reg;
97172 return 0;
97173
97174 err_reg:
97175- if (tbl != ipv4_route_flush_table)
97176- kfree(tbl);
97177+ kfree(tbl);
97178 err_dup:
97179 return -ENOMEM;
97180 }
97181@@ -2667,8 +2667,8 @@ static __net_initdata struct pernet_operations sysctl_route_ops = {
97182
97183 static __net_init int rt_genid_init(struct net *net)
97184 {
97185- atomic_set(&net->ipv4.rt_genid, 0);
97186- atomic_set(&net->fnhe_genid, 0);
97187+ atomic_set_unchecked(&net->ipv4.rt_genid, 0);
97188+ atomic_set_unchecked(&net->fnhe_genid, 0);
97189 get_random_bytes(&net->ipv4.dev_addr_genid,
97190 sizeof(net->ipv4.dev_addr_genid));
97191 return 0;
97192diff --git a/net/ipv4/sysctl_net_ipv4.c b/net/ipv4/sysctl_net_ipv4.c
97193index 540279f..9855b16 100644
97194--- a/net/ipv4/sysctl_net_ipv4.c
97195+++ b/net/ipv4/sysctl_net_ipv4.c
97196@@ -58,7 +58,7 @@ static int ipv4_local_port_range(struct ctl_table *table, int write,
97197 {
97198 int ret;
97199 int range[2];
97200- struct ctl_table tmp = {
97201+ ctl_table_no_const tmp = {
97202 .data = &range,
97203 .maxlen = sizeof(range),
97204 .mode = table->mode,
97205@@ -111,7 +111,7 @@ static int ipv4_ping_group_range(struct ctl_table *table, int write,
97206 int ret;
97207 gid_t urange[2];
97208 kgid_t low, high;
97209- struct ctl_table tmp = {
97210+ ctl_table_no_const tmp = {
97211 .data = &urange,
97212 .maxlen = sizeof(urange),
97213 .mode = table->mode,
97214@@ -142,7 +142,7 @@ static int proc_tcp_congestion_control(struct ctl_table *ctl, int write,
97215 void __user *buffer, size_t *lenp, loff_t *ppos)
97216 {
97217 char val[TCP_CA_NAME_MAX];
97218- struct ctl_table tbl = {
97219+ ctl_table_no_const tbl = {
97220 .data = val,
97221 .maxlen = TCP_CA_NAME_MAX,
97222 };
97223@@ -161,7 +161,7 @@ static int proc_tcp_available_congestion_control(struct ctl_table *ctl,
97224 void __user *buffer, size_t *lenp,
97225 loff_t *ppos)
97226 {
97227- struct ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX, };
97228+ ctl_table_no_const tbl = { .maxlen = TCP_CA_BUF_MAX, };
97229 int ret;
97230
97231 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
97232@@ -178,7 +178,7 @@ static int proc_allowed_congestion_control(struct ctl_table *ctl,
97233 void __user *buffer, size_t *lenp,
97234 loff_t *ppos)
97235 {
97236- struct ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX };
97237+ ctl_table_no_const tbl = { .maxlen = TCP_CA_BUF_MAX };
97238 int ret;
97239
97240 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
97241@@ -204,15 +204,17 @@ static int ipv4_tcp_mem(struct ctl_table *ctl, int write,
97242 struct mem_cgroup *memcg;
97243 #endif
97244
97245- struct ctl_table tmp = {
97246+ ctl_table_no_const tmp = {
97247 .data = &vec,
97248 .maxlen = sizeof(vec),
97249 .mode = ctl->mode,
97250 };
97251
97252 if (!write) {
97253- ctl->data = &net->ipv4.sysctl_tcp_mem;
97254- return proc_doulongvec_minmax(ctl, write, buffer, lenp, ppos);
97255+ ctl_table_no_const tcp_mem = *ctl;
97256+
97257+ tcp_mem.data = &net->ipv4.sysctl_tcp_mem;
97258+ return proc_doulongvec_minmax(&tcp_mem, write, buffer, lenp, ppos);
97259 }
97260
97261 ret = proc_doulongvec_minmax(&tmp, write, buffer, lenp, ppos);
97262@@ -240,7 +242,7 @@ static int proc_tcp_fastopen_key(struct ctl_table *ctl, int write,
97263 void __user *buffer, size_t *lenp,
97264 loff_t *ppos)
97265 {
97266- struct ctl_table tbl = { .maxlen = (TCP_FASTOPEN_KEY_LENGTH * 2 + 10) };
97267+ ctl_table_no_const tbl = { .maxlen = (TCP_FASTOPEN_KEY_LENGTH * 2 + 10) };
97268 struct tcp_fastopen_context *ctxt;
97269 int ret;
97270 u32 user_key[4]; /* 16 bytes, matching TCP_FASTOPEN_KEY_LENGTH */
97271@@ -483,7 +485,7 @@ static struct ctl_table ipv4_table[] = {
97272 },
97273 {
97274 .procname = "ip_local_reserved_ports",
97275- .data = NULL, /* initialized in sysctl_ipv4_init */
97276+ .data = sysctl_local_reserved_ports,
97277 .maxlen = 65536,
97278 .mode = 0644,
97279 .proc_handler = proc_do_large_bitmap,
97280@@ -864,11 +866,10 @@ static struct ctl_table ipv4_net_table[] = {
97281
97282 static __net_init int ipv4_sysctl_init_net(struct net *net)
97283 {
97284- struct ctl_table *table;
97285+ ctl_table_no_const *table = NULL;
97286
97287- table = ipv4_net_table;
97288 if (!net_eq(net, &init_net)) {
97289- table = kmemdup(table, sizeof(ipv4_net_table), GFP_KERNEL);
97290+ table = kmemdup(ipv4_net_table, sizeof(ipv4_net_table), GFP_KERNEL);
97291 if (table == NULL)
97292 goto err_alloc;
97293
97294@@ -903,15 +904,17 @@ static __net_init int ipv4_sysctl_init_net(struct net *net)
97295
97296 tcp_init_mem(net);
97297
97298- net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", table);
97299+ if (!net_eq(net, &init_net))
97300+ net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", table);
97301+ else
97302+ net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", ipv4_net_table);
97303 if (net->ipv4.ipv4_hdr == NULL)
97304 goto err_reg;
97305
97306 return 0;
97307
97308 err_reg:
97309- if (!net_eq(net, &init_net))
97310- kfree(table);
97311+ kfree(table);
97312 err_alloc:
97313 return -ENOMEM;
97314 }
97315@@ -933,16 +936,6 @@ static __net_initdata struct pernet_operations ipv4_sysctl_ops = {
97316 static __init int sysctl_ipv4_init(void)
97317 {
97318 struct ctl_table_header *hdr;
97319- struct ctl_table *i;
97320-
97321- for (i = ipv4_table; i->procname; i++) {
97322- if (strcmp(i->procname, "ip_local_reserved_ports") == 0) {
97323- i->data = sysctl_local_reserved_ports;
97324- break;
97325- }
97326- }
97327- if (!i->procname)
97328- return -EINVAL;
97329
97330 hdr = register_net_sysctl(&init_net, "net/ipv4", ipv4_table);
97331 if (hdr == NULL)
97332diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c
97333index 068c8fb..a755c52 100644
97334--- a/net/ipv4/tcp_input.c
97335+++ b/net/ipv4/tcp_input.c
97336@@ -4435,7 +4435,7 @@ static struct sk_buff *tcp_collapse_one(struct sock *sk, struct sk_buff *skb,
97337 * simplifies code)
97338 */
97339 static void
97340-tcp_collapse(struct sock *sk, struct sk_buff_head *list,
97341+__intentional_overflow(5,6) tcp_collapse(struct sock *sk, struct sk_buff_head *list,
97342 struct sk_buff *head, struct sk_buff *tail,
97343 u32 start, u32 end)
97344 {
97345@@ -5520,6 +5520,7 @@ discard:
97346 tcp_paws_reject(&tp->rx_opt, 0))
97347 goto discard_and_undo;
97348
97349+#ifndef CONFIG_GRKERNSEC_NO_SIMULT_CONNECT
97350 if (th->syn) {
97351 /* We see SYN without ACK. It is attempt of
97352 * simultaneous connect with crossed SYNs.
97353@@ -5570,6 +5571,7 @@ discard:
97354 goto discard;
97355 #endif
97356 }
97357+#endif
97358 /* "fifth, if neither of the SYN or RST bits is set then
97359 * drop the segment and return."
97360 */
97361@@ -5616,7 +5618,7 @@ int tcp_rcv_state_process(struct sock *sk, struct sk_buff *skb,
97362 goto discard;
97363
97364 if (th->syn) {
97365- if (th->fin)
97366+ if (th->fin || th->urg || th->psh)
97367 goto discard;
97368 if (icsk->icsk_af_ops->conn_request(sk, skb) < 0)
97369 return 1;
97370diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
97371index 5031f68..91569e2 100644
97372--- a/net/ipv4/tcp_ipv4.c
97373+++ b/net/ipv4/tcp_ipv4.c
97374@@ -91,6 +91,10 @@ int sysctl_tcp_low_latency __read_mostly;
97375 EXPORT_SYMBOL(sysctl_tcp_low_latency);
97376
97377
97378+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
97379+extern int grsec_enable_blackhole;
97380+#endif
97381+
97382 #ifdef CONFIG_TCP_MD5SIG
97383 static int tcp_v4_md5_hash_hdr(char *md5_hash, const struct tcp_md5sig_key *key,
97384 __be32 daddr, __be32 saddr, const struct tcphdr *th);
97385@@ -1829,6 +1833,9 @@ int tcp_v4_do_rcv(struct sock *sk, struct sk_buff *skb)
97386 return 0;
97387
97388 reset:
97389+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
97390+ if (!grsec_enable_blackhole)
97391+#endif
97392 tcp_v4_send_reset(rsk, skb);
97393 discard:
97394 kfree_skb(skb);
97395@@ -1974,12 +1981,19 @@ int tcp_v4_rcv(struct sk_buff *skb)
97396 TCP_SKB_CB(skb)->sacked = 0;
97397
97398 sk = __inet_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
97399- if (!sk)
97400+ if (!sk) {
97401+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
97402+ ret = 1;
97403+#endif
97404 goto no_tcp_socket;
97405-
97406+ }
97407 process:
97408- if (sk->sk_state == TCP_TIME_WAIT)
97409+ if (sk->sk_state == TCP_TIME_WAIT) {
97410+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
97411+ ret = 2;
97412+#endif
97413 goto do_time_wait;
97414+ }
97415
97416 if (unlikely(iph->ttl < inet_sk(sk)->min_ttl)) {
97417 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
97418@@ -2033,6 +2047,10 @@ csum_error:
97419 bad_packet:
97420 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
97421 } else {
97422+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
97423+ if (!grsec_enable_blackhole || (ret == 1 &&
97424+ (skb->dev->flags & IFF_LOOPBACK)))
97425+#endif
97426 tcp_v4_send_reset(NULL, skb);
97427 }
97428
97429diff --git a/net/ipv4/tcp_minisocks.c b/net/ipv4/tcp_minisocks.c
97430index 58a3e69..7f0626e 100644
97431--- a/net/ipv4/tcp_minisocks.c
97432+++ b/net/ipv4/tcp_minisocks.c
97433@@ -27,6 +27,10 @@
97434 #include <net/inet_common.h>
97435 #include <net/xfrm.h>
97436
97437+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
97438+extern int grsec_enable_blackhole;
97439+#endif
97440+
97441 int sysctl_tcp_syncookies __read_mostly = 1;
97442 EXPORT_SYMBOL(sysctl_tcp_syncookies);
97443
97444@@ -711,7 +715,10 @@ embryonic_reset:
97445 * avoid becoming vulnerable to outside attack aiming at
97446 * resetting legit local connections.
97447 */
97448- req->rsk_ops->send_reset(sk, skb);
97449+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
97450+ if (!grsec_enable_blackhole)
97451+#endif
97452+ req->rsk_ops->send_reset(sk, skb);
97453 } else if (fastopen) { /* received a valid RST pkt */
97454 reqsk_fastopen_remove(sk, req, true);
97455 tcp_reset(sk);
97456diff --git a/net/ipv4/tcp_probe.c b/net/ipv4/tcp_probe.c
97457index 611beab..c4b6e1d 100644
97458--- a/net/ipv4/tcp_probe.c
97459+++ b/net/ipv4/tcp_probe.c
97460@@ -245,7 +245,7 @@ static ssize_t tcpprobe_read(struct file *file, char __user *buf,
97461 if (cnt + width >= len)
97462 break;
97463
97464- if (copy_to_user(buf + cnt, tbuf, width))
97465+ if (width > sizeof tbuf || copy_to_user(buf + cnt, tbuf, width))
97466 return -EFAULT;
97467 cnt += width;
97468 }
97469diff --git a/net/ipv4/tcp_timer.c b/net/ipv4/tcp_timer.c
97470index 4b85e6f..22f9ac9 100644
97471--- a/net/ipv4/tcp_timer.c
97472+++ b/net/ipv4/tcp_timer.c
97473@@ -22,6 +22,10 @@
97474 #include <linux/gfp.h>
97475 #include <net/tcp.h>
97476
97477+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
97478+extern int grsec_lastack_retries;
97479+#endif
97480+
97481 int sysctl_tcp_syn_retries __read_mostly = TCP_SYN_RETRIES;
97482 int sysctl_tcp_synack_retries __read_mostly = TCP_SYNACK_RETRIES;
97483 int sysctl_tcp_keepalive_time __read_mostly = TCP_KEEPALIVE_TIME;
97484@@ -185,6 +189,13 @@ static int tcp_write_timeout(struct sock *sk)
97485 }
97486 }
97487
97488+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
97489+ if ((sk->sk_state == TCP_LAST_ACK) &&
97490+ (grsec_lastack_retries > 0) &&
97491+ (grsec_lastack_retries < retry_until))
97492+ retry_until = grsec_lastack_retries;
97493+#endif
97494+
97495 if (retransmits_timed_out(sk, retry_until,
97496 syn_set ? 0 : icsk->icsk_user_timeout, syn_set)) {
97497 /* Has it gone just too far? */
97498diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c
97499index 6ca9907..a1e6c00 100644
97500--- a/net/ipv4/udp.c
97501+++ b/net/ipv4/udp.c
97502@@ -87,6 +87,7 @@
97503 #include <linux/types.h>
97504 #include <linux/fcntl.h>
97505 #include <linux/module.h>
97506+#include <linux/security.h>
97507 #include <linux/socket.h>
97508 #include <linux/sockios.h>
97509 #include <linux/igmp.h>
97510@@ -112,6 +113,10 @@
97511 #include <net/busy_poll.h>
97512 #include "udp_impl.h"
97513
97514+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
97515+extern int grsec_enable_blackhole;
97516+#endif
97517+
97518 struct udp_table udp_table __read_mostly;
97519 EXPORT_SYMBOL(udp_table);
97520
97521@@ -595,6 +600,9 @@ found:
97522 return s;
97523 }
97524
97525+extern int gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb);
97526+extern int gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr);
97527+
97528 /*
97529 * This routine is called by the ICMP module when it gets some
97530 * sort of error condition. If err < 0 then the socket should
97531@@ -892,9 +900,18 @@ int udp_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
97532 dport = usin->sin_port;
97533 if (dport == 0)
97534 return -EINVAL;
97535+
97536+ err = gr_search_udp_sendmsg(sk, usin);
97537+ if (err)
97538+ return err;
97539 } else {
97540 if (sk->sk_state != TCP_ESTABLISHED)
97541 return -EDESTADDRREQ;
97542+
97543+ err = gr_search_udp_sendmsg(sk, NULL);
97544+ if (err)
97545+ return err;
97546+
97547 daddr = inet->inet_daddr;
97548 dport = inet->inet_dport;
97549 /* Open fast path for connected socket.
97550@@ -1141,7 +1158,7 @@ static unsigned int first_packet_length(struct sock *sk)
97551 IS_UDPLITE(sk));
97552 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
97553 IS_UDPLITE(sk));
97554- atomic_inc(&sk->sk_drops);
97555+ atomic_inc_unchecked(&sk->sk_drops);
97556 __skb_unlink(skb, rcvq);
97557 __skb_queue_tail(&list_kill, skb);
97558 }
97559@@ -1221,6 +1238,10 @@ try_again:
97560 if (!skb)
97561 goto out;
97562
97563+ err = gr_search_udp_recvmsg(sk, skb);
97564+ if (err)
97565+ goto out_free;
97566+
97567 ulen = skb->len - sizeof(struct udphdr);
97568 copied = len;
97569 if (copied > ulen)
97570@@ -1254,7 +1275,7 @@ try_again:
97571 if (unlikely(err)) {
97572 trace_kfree_skb(skb, udp_recvmsg);
97573 if (!peeked) {
97574- atomic_inc(&sk->sk_drops);
97575+ atomic_inc_unchecked(&sk->sk_drops);
97576 UDP_INC_STATS_USER(sock_net(sk),
97577 UDP_MIB_INERRORS, is_udplite);
97578 }
97579@@ -1542,7 +1563,7 @@ csum_error:
97580 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_CSUMERRORS, is_udplite);
97581 drop:
97582 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
97583- atomic_inc(&sk->sk_drops);
97584+ atomic_inc_unchecked(&sk->sk_drops);
97585 kfree_skb(skb);
97586 return -1;
97587 }
97588@@ -1561,7 +1582,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
97589 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
97590
97591 if (!skb1) {
97592- atomic_inc(&sk->sk_drops);
97593+ atomic_inc_unchecked(&sk->sk_drops);
97594 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
97595 IS_UDPLITE(sk));
97596 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
97597@@ -1733,6 +1754,9 @@ int __udp4_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
97598 goto csum_error;
97599
97600 UDP_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
97601+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
97602+ if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
97603+#endif
97604 icmp_send(skb, ICMP_DEST_UNREACH, ICMP_PORT_UNREACH, 0);
97605
97606 /*
97607@@ -2165,7 +2189,7 @@ static void udp4_format_sock(struct sock *sp, struct seq_file *f,
97608 from_kuid_munged(seq_user_ns(f), sock_i_uid(sp)),
97609 0, sock_i_ino(sp),
97610 atomic_read(&sp->sk_refcnt), sp,
97611- atomic_read(&sp->sk_drops), len);
97612+ atomic_read_unchecked(&sp->sk_drops), len);
97613 }
97614
97615 int udp4_seq_show(struct seq_file *seq, void *v)
97616diff --git a/net/ipv4/xfrm4_policy.c b/net/ipv4/xfrm4_policy.c
97617index adf9983..8e45d0a 100644
97618--- a/net/ipv4/xfrm4_policy.c
97619+++ b/net/ipv4/xfrm4_policy.c
97620@@ -186,11 +186,11 @@ _decode_session4(struct sk_buff *skb, struct flowi *fl, int reverse)
97621 fl4->flowi4_tos = iph->tos;
97622 }
97623
97624-static inline int xfrm4_garbage_collect(struct dst_ops *ops)
97625+static int xfrm4_garbage_collect(struct dst_ops *ops)
97626 {
97627 struct net *net = container_of(ops, struct net, xfrm.xfrm4_dst_ops);
97628
97629- xfrm4_policy_afinfo.garbage_collect(net);
97630+ xfrm_garbage_collect_deferred(net);
97631 return (dst_entries_get_slow(ops) > ops->gc_thresh * 2);
97632 }
97633
97634@@ -269,19 +269,18 @@ static struct ctl_table xfrm4_policy_table[] = {
97635
97636 static int __net_init xfrm4_net_init(struct net *net)
97637 {
97638- struct ctl_table *table;
97639+ ctl_table_no_const *table = NULL;
97640 struct ctl_table_header *hdr;
97641
97642- table = xfrm4_policy_table;
97643 if (!net_eq(net, &init_net)) {
97644- table = kmemdup(table, sizeof(xfrm4_policy_table), GFP_KERNEL);
97645+ table = kmemdup(xfrm4_policy_table, sizeof(xfrm4_policy_table), GFP_KERNEL);
97646 if (!table)
97647 goto err_alloc;
97648
97649 table[0].data = &net->xfrm.xfrm4_dst_ops.gc_thresh;
97650- }
97651-
97652- hdr = register_net_sysctl(net, "net/ipv4", table);
97653+ hdr = register_net_sysctl(net, "net/ipv4", table);
97654+ } else
97655+ hdr = register_net_sysctl(net, "net/ipv4", xfrm4_policy_table);
97656 if (!hdr)
97657 goto err_reg;
97658
97659@@ -289,8 +288,7 @@ static int __net_init xfrm4_net_init(struct net *net)
97660 return 0;
97661
97662 err_reg:
97663- if (!net_eq(net, &init_net))
97664- kfree(table);
97665+ kfree(table);
97666 err_alloc:
97667 return -ENOMEM;
97668 }
97669diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
97670index cd3fb30..b7dfef7 100644
97671--- a/net/ipv6/addrconf.c
97672+++ b/net/ipv6/addrconf.c
97673@@ -586,7 +586,7 @@ static int inet6_netconf_dump_devconf(struct sk_buff *skb,
97674 idx = 0;
97675 head = &net->dev_index_head[h];
97676 rcu_read_lock();
97677- cb->seq = atomic_read(&net->ipv6.dev_addr_genid) ^
97678+ cb->seq = atomic_read_unchecked(&net->ipv6.dev_addr_genid) ^
97679 net->dev_base_seq;
97680 hlist_for_each_entry_rcu(dev, head, index_hlist) {
97681 if (idx < s_idx)
97682@@ -2364,7 +2364,7 @@ int addrconf_set_dstaddr(struct net *net, void __user *arg)
97683 p.iph.ihl = 5;
97684 p.iph.protocol = IPPROTO_IPV6;
97685 p.iph.ttl = 64;
97686- ifr.ifr_ifru.ifru_data = (__force void __user *)&p;
97687+ ifr.ifr_ifru.ifru_data = (void __force_user *)&p;
97688
97689 if (ops->ndo_do_ioctl) {
97690 mm_segment_t oldfs = get_fs();
97691@@ -3977,7 +3977,7 @@ static int inet6_dump_addr(struct sk_buff *skb, struct netlink_callback *cb,
97692 s_ip_idx = ip_idx = cb->args[2];
97693
97694 rcu_read_lock();
97695- cb->seq = atomic_read(&net->ipv6.dev_addr_genid) ^ net->dev_base_seq;
97696+ cb->seq = atomic_read_unchecked(&net->ipv6.dev_addr_genid) ^ net->dev_base_seq;
97697 for (h = s_h; h < NETDEV_HASHENTRIES; h++, s_idx = 0) {
97698 idx = 0;
97699 head = &net->dev_index_head[h];
97700@@ -4603,7 +4603,7 @@ static void __ipv6_ifa_notify(int event, struct inet6_ifaddr *ifp)
97701 dst_free(&ifp->rt->dst);
97702 break;
97703 }
97704- atomic_inc(&net->ipv6.dev_addr_genid);
97705+ atomic_inc_unchecked(&net->ipv6.dev_addr_genid);
97706 rt_genid_bump_ipv6(net);
97707 }
97708
97709@@ -4624,7 +4624,7 @@ int addrconf_sysctl_forward(struct ctl_table *ctl, int write,
97710 int *valp = ctl->data;
97711 int val = *valp;
97712 loff_t pos = *ppos;
97713- struct ctl_table lctl;
97714+ ctl_table_no_const lctl;
97715 int ret;
97716
97717 /*
97718@@ -4709,7 +4709,7 @@ int addrconf_sysctl_disable(struct ctl_table *ctl, int write,
97719 int *valp = ctl->data;
97720 int val = *valp;
97721 loff_t pos = *ppos;
97722- struct ctl_table lctl;
97723+ ctl_table_no_const lctl;
97724 int ret;
97725
97726 /*
97727diff --git a/net/ipv6/af_inet6.c b/net/ipv6/af_inet6.c
97728index 8132b44..b8eca70 100644
97729--- a/net/ipv6/af_inet6.c
97730+++ b/net/ipv6/af_inet6.c
97731@@ -767,7 +767,7 @@ static int __net_init inet6_net_init(struct net *net)
97732
97733 net->ipv6.sysctl.bindv6only = 0;
97734 net->ipv6.sysctl.icmpv6_time = 1*HZ;
97735- atomic_set(&net->ipv6.rt_genid, 0);
97736+ atomic_set_unchecked(&net->ipv6.rt_genid, 0);
97737
97738 err = ipv6_init_mibs(net);
97739 if (err)
97740diff --git a/net/ipv6/datagram.c b/net/ipv6/datagram.c
97741index c66c6df..f375d3c 100644
97742--- a/net/ipv6/datagram.c
97743+++ b/net/ipv6/datagram.c
97744@@ -908,5 +908,5 @@ void ip6_dgram_sock_seq_show(struct seq_file *seq, struct sock *sp,
97745 0,
97746 sock_i_ino(sp),
97747 atomic_read(&sp->sk_refcnt), sp,
97748- atomic_read(&sp->sk_drops));
97749+ atomic_read_unchecked(&sp->sk_drops));
97750 }
97751diff --git a/net/ipv6/icmp.c b/net/ipv6/icmp.c
97752index eef8d94..cfa1852 100644
97753--- a/net/ipv6/icmp.c
97754+++ b/net/ipv6/icmp.c
97755@@ -997,7 +997,7 @@ struct ctl_table ipv6_icmp_table_template[] = {
97756
97757 struct ctl_table * __net_init ipv6_icmp_sysctl_init(struct net *net)
97758 {
97759- struct ctl_table *table;
97760+ ctl_table_no_const *table;
97761
97762 table = kmemdup(ipv6_icmp_table_template,
97763 sizeof(ipv6_icmp_table_template),
97764diff --git a/net/ipv6/ip6_gre.c b/net/ipv6/ip6_gre.c
97765index bf4a9a0..e5f6ac5 100644
97766--- a/net/ipv6/ip6_gre.c
97767+++ b/net/ipv6/ip6_gre.c
97768@@ -74,7 +74,7 @@ struct ip6gre_net {
97769 struct net_device *fb_tunnel_dev;
97770 };
97771
97772-static struct rtnl_link_ops ip6gre_link_ops __read_mostly;
97773+static struct rtnl_link_ops ip6gre_link_ops;
97774 static int ip6gre_tunnel_init(struct net_device *dev);
97775 static void ip6gre_tunnel_setup(struct net_device *dev);
97776 static void ip6gre_tunnel_link(struct ip6gre_net *ign, struct ip6_tnl *t);
97777@@ -1286,7 +1286,7 @@ static void ip6gre_fb_tunnel_init(struct net_device *dev)
97778 }
97779
97780
97781-static struct inet6_protocol ip6gre_protocol __read_mostly = {
97782+static struct inet6_protocol ip6gre_protocol = {
97783 .handler = ip6gre_rcv,
97784 .err_handler = ip6gre_err,
97785 .flags = INET6_PROTO_NOPOLICY|INET6_PROTO_FINAL,
97786@@ -1622,7 +1622,7 @@ static const struct nla_policy ip6gre_policy[IFLA_GRE_MAX + 1] = {
97787 [IFLA_GRE_FLAGS] = { .type = NLA_U32 },
97788 };
97789
97790-static struct rtnl_link_ops ip6gre_link_ops __read_mostly = {
97791+static struct rtnl_link_ops ip6gre_link_ops = {
97792 .kind = "ip6gre",
97793 .maxtype = IFLA_GRE_MAX,
97794 .policy = ip6gre_policy,
97795@@ -1635,7 +1635,7 @@ static struct rtnl_link_ops ip6gre_link_ops __read_mostly = {
97796 .fill_info = ip6gre_fill_info,
97797 };
97798
97799-static struct rtnl_link_ops ip6gre_tap_ops __read_mostly = {
97800+static struct rtnl_link_ops ip6gre_tap_ops = {
97801 .kind = "ip6gretap",
97802 .maxtype = IFLA_GRE_MAX,
97803 .policy = ip6gre_policy,
97804diff --git a/net/ipv6/ip6_tunnel.c b/net/ipv6/ip6_tunnel.c
97805index c1e11b5..568e633 100644
97806--- a/net/ipv6/ip6_tunnel.c
97807+++ b/net/ipv6/ip6_tunnel.c
97808@@ -89,7 +89,7 @@ static u32 HASH(const struct in6_addr *addr1, const struct in6_addr *addr2)
97809
97810 static int ip6_tnl_dev_init(struct net_device *dev);
97811 static void ip6_tnl_dev_setup(struct net_device *dev);
97812-static struct rtnl_link_ops ip6_link_ops __read_mostly;
97813+static struct rtnl_link_ops ip6_link_ops;
97814
97815 static int ip6_tnl_net_id __read_mostly;
97816 struct ip6_tnl_net {
97817@@ -1699,7 +1699,7 @@ static const struct nla_policy ip6_tnl_policy[IFLA_IPTUN_MAX + 1] = {
97818 [IFLA_IPTUN_PROTO] = { .type = NLA_U8 },
97819 };
97820
97821-static struct rtnl_link_ops ip6_link_ops __read_mostly = {
97822+static struct rtnl_link_ops ip6_link_ops = {
97823 .kind = "ip6tnl",
97824 .maxtype = IFLA_IPTUN_MAX,
97825 .policy = ip6_tnl_policy,
97826diff --git a/net/ipv6/ip6mr.c b/net/ipv6/ip6mr.c
97827index f365310..0eb4038 100644
97828--- a/net/ipv6/ip6mr.c
97829+++ b/net/ipv6/ip6mr.c
97830@@ -141,9 +141,12 @@ static struct mr6_table *ip6mr_get_table(struct net *net, u32 id)
97831 static int ip6mr_fib_lookup(struct net *net, struct flowi6 *flp6,
97832 struct mr6_table **mrt)
97833 {
97834+ int err;
97835 struct ip6mr_result res;
97836- struct fib_lookup_arg arg = { .result = &res, };
97837- int err;
97838+ struct fib_lookup_arg arg = {
97839+ .result = &res,
97840+ .flags = FIB_LOOKUP_NOREF,
97841+ };
97842
97843 err = fib_rules_lookup(net->ipv6.mr6_rules_ops,
97844 flowi6_to_flowi(flp6), 0, &arg);
97845diff --git a/net/ipv6/ipv6_sockglue.c b/net/ipv6/ipv6_sockglue.c
97846index d1e2e8e..51c19ae 100644
97847--- a/net/ipv6/ipv6_sockglue.c
97848+++ b/net/ipv6/ipv6_sockglue.c
97849@@ -991,7 +991,7 @@ static int do_ipv6_getsockopt(struct sock *sk, int level, int optname,
97850 if (sk->sk_type != SOCK_STREAM)
97851 return -ENOPROTOOPT;
97852
97853- msg.msg_control = optval;
97854+ msg.msg_control = (void __force_kernel *)optval;
97855 msg.msg_controllen = len;
97856 msg.msg_flags = flags;
97857
97858diff --git a/net/ipv6/netfilter/ip6_tables.c b/net/ipv6/netfilter/ip6_tables.c
97859index 44400c2..8e11f52 100644
97860--- a/net/ipv6/netfilter/ip6_tables.c
97861+++ b/net/ipv6/netfilter/ip6_tables.c
97862@@ -1078,14 +1078,14 @@ static int compat_table_info(const struct xt_table_info *info,
97863 #endif
97864
97865 static int get_info(struct net *net, void __user *user,
97866- const int *len, int compat)
97867+ int len, int compat)
97868 {
97869 char name[XT_TABLE_MAXNAMELEN];
97870 struct xt_table *t;
97871 int ret;
97872
97873- if (*len != sizeof(struct ip6t_getinfo)) {
97874- duprintf("length %u != %zu\n", *len,
97875+ if (len != sizeof(struct ip6t_getinfo)) {
97876+ duprintf("length %u != %zu\n", len,
97877 sizeof(struct ip6t_getinfo));
97878 return -EINVAL;
97879 }
97880@@ -1122,7 +1122,7 @@ static int get_info(struct net *net, void __user *user,
97881 info.size = private->size;
97882 strcpy(info.name, name);
97883
97884- if (copy_to_user(user, &info, *len) != 0)
97885+ if (copy_to_user(user, &info, len) != 0)
97886 ret = -EFAULT;
97887 else
97888 ret = 0;
97889@@ -1976,7 +1976,7 @@ compat_do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
97890
97891 switch (cmd) {
97892 case IP6T_SO_GET_INFO:
97893- ret = get_info(sock_net(sk), user, len, 1);
97894+ ret = get_info(sock_net(sk), user, *len, 1);
97895 break;
97896 case IP6T_SO_GET_ENTRIES:
97897 ret = compat_get_entries(sock_net(sk), user, len);
97898@@ -2023,7 +2023,7 @@ do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
97899
97900 switch (cmd) {
97901 case IP6T_SO_GET_INFO:
97902- ret = get_info(sock_net(sk), user, len, 0);
97903+ ret = get_info(sock_net(sk), user, *len, 0);
97904 break;
97905
97906 case IP6T_SO_GET_ENTRIES:
97907diff --git a/net/ipv6/netfilter/nf_conntrack_reasm.c b/net/ipv6/netfilter/nf_conntrack_reasm.c
97908index 253566a..9fa50c7 100644
97909--- a/net/ipv6/netfilter/nf_conntrack_reasm.c
97910+++ b/net/ipv6/netfilter/nf_conntrack_reasm.c
97911@@ -90,12 +90,11 @@ static struct ctl_table nf_ct_frag6_sysctl_table[] = {
97912
97913 static int nf_ct_frag6_sysctl_register(struct net *net)
97914 {
97915- struct ctl_table *table;
97916+ ctl_table_no_const *table = NULL;
97917 struct ctl_table_header *hdr;
97918
97919- table = nf_ct_frag6_sysctl_table;
97920 if (!net_eq(net, &init_net)) {
97921- table = kmemdup(table, sizeof(nf_ct_frag6_sysctl_table),
97922+ table = kmemdup(nf_ct_frag6_sysctl_table, sizeof(nf_ct_frag6_sysctl_table),
97923 GFP_KERNEL);
97924 if (table == NULL)
97925 goto err_alloc;
97926@@ -103,9 +102,9 @@ static int nf_ct_frag6_sysctl_register(struct net *net)
97927 table[0].data = &net->nf_frag.frags.timeout;
97928 table[1].data = &net->nf_frag.frags.low_thresh;
97929 table[2].data = &net->nf_frag.frags.high_thresh;
97930- }
97931-
97932- hdr = register_net_sysctl(net, "net/netfilter", table);
97933+ hdr = register_net_sysctl(net, "net/netfilter", table);
97934+ } else
97935+ hdr = register_net_sysctl(net, "net/netfilter", nf_ct_frag6_sysctl_table);
97936 if (hdr == NULL)
97937 goto err_reg;
97938
97939@@ -113,8 +112,7 @@ static int nf_ct_frag6_sysctl_register(struct net *net)
97940 return 0;
97941
97942 err_reg:
97943- if (!net_eq(net, &init_net))
97944- kfree(table);
97945+ kfree(table);
97946 err_alloc:
97947 return -ENOMEM;
97948 }
97949diff --git a/net/ipv6/output_core.c b/net/ipv6/output_core.c
97950index 827f795..7e28e82 100644
97951--- a/net/ipv6/output_core.c
97952+++ b/net/ipv6/output_core.c
97953@@ -9,8 +9,8 @@
97954
97955 void ipv6_select_ident(struct frag_hdr *fhdr, struct rt6_info *rt)
97956 {
97957- static atomic_t ipv6_fragmentation_id;
97958- int old, new;
97959+ static atomic_unchecked_t ipv6_fragmentation_id;
97960+ int id;
97961
97962 #if IS_ENABLED(CONFIG_IPV6)
97963 if (rt && !(rt->dst.flags & DST_NOPEER)) {
97964@@ -26,13 +26,10 @@ void ipv6_select_ident(struct frag_hdr *fhdr, struct rt6_info *rt)
97965 }
97966 }
97967 #endif
97968- do {
97969- old = atomic_read(&ipv6_fragmentation_id);
97970- new = old + 1;
97971- if (!new)
97972- new = 1;
97973- } while (atomic_cmpxchg(&ipv6_fragmentation_id, old, new) != old);
97974- fhdr->identification = htonl(new);
97975+ id = atomic_inc_return_unchecked(&ipv6_fragmentation_id);
97976+ if (!id)
97977+ id = atomic_inc_return_unchecked(&ipv6_fragmentation_id);
97978+ fhdr->identification = htonl(id);
97979 }
97980 EXPORT_SYMBOL(ipv6_select_ident);
97981
97982diff --git a/net/ipv6/ping.c b/net/ipv6/ping.c
97983index 7856e96..75ebc7f 100644
97984--- a/net/ipv6/ping.c
97985+++ b/net/ipv6/ping.c
97986@@ -246,6 +246,22 @@ static struct pernet_operations ping_v6_net_ops = {
97987 };
97988 #endif
97989
97990+static struct pingv6_ops real_pingv6_ops = {
97991+ .ipv6_recv_error = ipv6_recv_error,
97992+ .ip6_datagram_recv_ctl = ip6_datagram_recv_ctl,
97993+ .icmpv6_err_convert = icmpv6_err_convert,
97994+ .ipv6_icmp_error = ipv6_icmp_error,
97995+ .ipv6_chk_addr = ipv6_chk_addr,
97996+};
97997+
97998+static struct pingv6_ops dummy_pingv6_ops = {
97999+ .ipv6_recv_error = dummy_ipv6_recv_error,
98000+ .ip6_datagram_recv_ctl = dummy_ip6_datagram_recv_ctl,
98001+ .icmpv6_err_convert = dummy_icmpv6_err_convert,
98002+ .ipv6_icmp_error = dummy_ipv6_icmp_error,
98003+ .ipv6_chk_addr = dummy_ipv6_chk_addr,
98004+};
98005+
98006 int __init pingv6_init(void)
98007 {
98008 #ifdef CONFIG_PROC_FS
98009@@ -253,11 +269,7 @@ int __init pingv6_init(void)
98010 if (ret)
98011 return ret;
98012 #endif
98013- pingv6_ops.ipv6_recv_error = ipv6_recv_error;
98014- pingv6_ops.ip6_datagram_recv_ctl = ip6_datagram_recv_ctl;
98015- pingv6_ops.icmpv6_err_convert = icmpv6_err_convert;
98016- pingv6_ops.ipv6_icmp_error = ipv6_icmp_error;
98017- pingv6_ops.ipv6_chk_addr = ipv6_chk_addr;
98018+ pingv6_ops = &real_pingv6_ops;
98019 return inet6_register_protosw(&pingv6_protosw);
98020 }
98021
98022@@ -266,11 +278,7 @@ int __init pingv6_init(void)
98023 */
98024 void pingv6_exit(void)
98025 {
98026- pingv6_ops.ipv6_recv_error = dummy_ipv6_recv_error;
98027- pingv6_ops.ip6_datagram_recv_ctl = dummy_ip6_datagram_recv_ctl;
98028- pingv6_ops.icmpv6_err_convert = dummy_icmpv6_err_convert;
98029- pingv6_ops.ipv6_icmp_error = dummy_ipv6_icmp_error;
98030- pingv6_ops.ipv6_chk_addr = dummy_ipv6_chk_addr;
98031+ pingv6_ops = &dummy_pingv6_ops;
98032 #ifdef CONFIG_PROC_FS
98033 unregister_pernet_subsys(&ping_v6_net_ops);
98034 #endif
98035diff --git a/net/ipv6/raw.c b/net/ipv6/raw.c
98036index 430067c..4adf088 100644
98037--- a/net/ipv6/raw.c
98038+++ b/net/ipv6/raw.c
98039@@ -385,7 +385,7 @@ static inline int rawv6_rcv_skb(struct sock *sk, struct sk_buff *skb)
98040 {
98041 if ((raw6_sk(sk)->checksum || rcu_access_pointer(sk->sk_filter)) &&
98042 skb_checksum_complete(skb)) {
98043- atomic_inc(&sk->sk_drops);
98044+ atomic_inc_unchecked(&sk->sk_drops);
98045 kfree_skb(skb);
98046 return NET_RX_DROP;
98047 }
98048@@ -413,7 +413,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
98049 struct raw6_sock *rp = raw6_sk(sk);
98050
98051 if (!xfrm6_policy_check(sk, XFRM_POLICY_IN, skb)) {
98052- atomic_inc(&sk->sk_drops);
98053+ atomic_inc_unchecked(&sk->sk_drops);
98054 kfree_skb(skb);
98055 return NET_RX_DROP;
98056 }
98057@@ -437,7 +437,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
98058
98059 if (inet->hdrincl) {
98060 if (skb_checksum_complete(skb)) {
98061- atomic_inc(&sk->sk_drops);
98062+ atomic_inc_unchecked(&sk->sk_drops);
98063 kfree_skb(skb);
98064 return NET_RX_DROP;
98065 }
98066@@ -607,7 +607,7 @@ out:
98067 return err;
98068 }
98069
98070-static int rawv6_send_hdrinc(struct sock *sk, void *from, int length,
98071+static int rawv6_send_hdrinc(struct sock *sk, void *from, unsigned int length,
98072 struct flowi6 *fl6, struct dst_entry **dstp,
98073 unsigned int flags)
98074 {
98075@@ -920,12 +920,15 @@ do_confirm:
98076 static int rawv6_seticmpfilter(struct sock *sk, int level, int optname,
98077 char __user *optval, int optlen)
98078 {
98079+ struct icmp6_filter filter;
98080+
98081 switch (optname) {
98082 case ICMPV6_FILTER:
98083 if (optlen > sizeof(struct icmp6_filter))
98084 optlen = sizeof(struct icmp6_filter);
98085- if (copy_from_user(&raw6_sk(sk)->filter, optval, optlen))
98086+ if (copy_from_user(&filter, optval, optlen))
98087 return -EFAULT;
98088+ raw6_sk(sk)->filter = filter;
98089 return 0;
98090 default:
98091 return -ENOPROTOOPT;
98092@@ -938,6 +941,7 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
98093 char __user *optval, int __user *optlen)
98094 {
98095 int len;
98096+ struct icmp6_filter filter;
98097
98098 switch (optname) {
98099 case ICMPV6_FILTER:
98100@@ -949,7 +953,8 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
98101 len = sizeof(struct icmp6_filter);
98102 if (put_user(len, optlen))
98103 return -EFAULT;
98104- if (copy_to_user(optval, &raw6_sk(sk)->filter, len))
98105+ filter = raw6_sk(sk)->filter;
98106+ if (len > sizeof filter || copy_to_user(optval, &filter, len))
98107 return -EFAULT;
98108 return 0;
98109 default:
98110diff --git a/net/ipv6/reassembly.c b/net/ipv6/reassembly.c
98111index 1aeb473..bea761c 100644
98112--- a/net/ipv6/reassembly.c
98113+++ b/net/ipv6/reassembly.c
98114@@ -626,12 +626,11 @@ static struct ctl_table ip6_frags_ctl_table[] = {
98115
98116 static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
98117 {
98118- struct ctl_table *table;
98119+ ctl_table_no_const *table = NULL;
98120 struct ctl_table_header *hdr;
98121
98122- table = ip6_frags_ns_ctl_table;
98123 if (!net_eq(net, &init_net)) {
98124- table = kmemdup(table, sizeof(ip6_frags_ns_ctl_table), GFP_KERNEL);
98125+ table = kmemdup(ip6_frags_ns_ctl_table, sizeof(ip6_frags_ns_ctl_table), GFP_KERNEL);
98126 if (table == NULL)
98127 goto err_alloc;
98128
98129@@ -642,9 +641,10 @@ static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
98130 /* Don't export sysctls to unprivileged users */
98131 if (net->user_ns != &init_user_ns)
98132 table[0].procname = NULL;
98133- }
98134+ hdr = register_net_sysctl(net, "net/ipv6", table);
98135+ } else
98136+ hdr = register_net_sysctl(net, "net/ipv6", ip6_frags_ns_ctl_table);
98137
98138- hdr = register_net_sysctl(net, "net/ipv6", table);
98139 if (hdr == NULL)
98140 goto err_reg;
98141
98142@@ -652,8 +652,7 @@ static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
98143 return 0;
98144
98145 err_reg:
98146- if (!net_eq(net, &init_net))
98147- kfree(table);
98148+ kfree(table);
98149 err_alloc:
98150 return -ENOMEM;
98151 }
98152diff --git a/net/ipv6/route.c b/net/ipv6/route.c
98153index 0accb13..f793130 100644
98154--- a/net/ipv6/route.c
98155+++ b/net/ipv6/route.c
98156@@ -3003,7 +3003,7 @@ struct ctl_table ipv6_route_table_template[] = {
98157
98158 struct ctl_table * __net_init ipv6_route_sysctl_init(struct net *net)
98159 {
98160- struct ctl_table *table;
98161+ ctl_table_no_const *table;
98162
98163 table = kmemdup(ipv6_route_table_template,
98164 sizeof(ipv6_route_table_template),
98165diff --git a/net/ipv6/sit.c b/net/ipv6/sit.c
98166index b433884..3875266 100644
98167--- a/net/ipv6/sit.c
98168+++ b/net/ipv6/sit.c
98169@@ -74,7 +74,7 @@ static void ipip6_tunnel_setup(struct net_device *dev);
98170 static void ipip6_dev_free(struct net_device *dev);
98171 static bool check_6rd(struct ip_tunnel *tunnel, const struct in6_addr *v6dst,
98172 __be32 *v4dst);
98173-static struct rtnl_link_ops sit_link_ops __read_mostly;
98174+static struct rtnl_link_ops sit_link_ops;
98175
98176 static int sit_net_id __read_mostly;
98177 struct sit_net {
98178@@ -1603,7 +1603,7 @@ static void ipip6_dellink(struct net_device *dev, struct list_head *head)
98179 unregister_netdevice_queue(dev, head);
98180 }
98181
98182-static struct rtnl_link_ops sit_link_ops __read_mostly = {
98183+static struct rtnl_link_ops sit_link_ops = {
98184 .kind = "sit",
98185 .maxtype = IFLA_IPTUN_MAX,
98186 .policy = ipip6_policy,
98187diff --git a/net/ipv6/sysctl_net_ipv6.c b/net/ipv6/sysctl_net_ipv6.c
98188index 107b2f1..72741a9 100644
98189--- a/net/ipv6/sysctl_net_ipv6.c
98190+++ b/net/ipv6/sysctl_net_ipv6.c
98191@@ -40,7 +40,7 @@ static struct ctl_table ipv6_rotable[] = {
98192
98193 static int __net_init ipv6_sysctl_net_init(struct net *net)
98194 {
98195- struct ctl_table *ipv6_table;
98196+ ctl_table_no_const *ipv6_table;
98197 struct ctl_table *ipv6_route_table;
98198 struct ctl_table *ipv6_icmp_table;
98199 int err;
98200diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c
98201index 5c71501..7e8d5d3 100644
98202--- a/net/ipv6/tcp_ipv6.c
98203+++ b/net/ipv6/tcp_ipv6.c
98204@@ -104,6 +104,10 @@ static void inet6_sk_rx_dst_set(struct sock *sk, const struct sk_buff *skb)
98205 inet6_sk(sk)->rx_dst_cookie = rt->rt6i_node->fn_sernum;
98206 }
98207
98208+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
98209+extern int grsec_enable_blackhole;
98210+#endif
98211+
98212 static void tcp_v6_hash(struct sock *sk)
98213 {
98214 if (sk->sk_state != TCP_CLOSE) {
98215@@ -1397,6 +1401,9 @@ static int tcp_v6_do_rcv(struct sock *sk, struct sk_buff *skb)
98216 return 0;
98217
98218 reset:
98219+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
98220+ if (!grsec_enable_blackhole)
98221+#endif
98222 tcp_v6_send_reset(sk, skb);
98223 discard:
98224 if (opt_skb)
98225@@ -1479,12 +1486,20 @@ static int tcp_v6_rcv(struct sk_buff *skb)
98226 TCP_SKB_CB(skb)->sacked = 0;
98227
98228 sk = __inet6_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
98229- if (!sk)
98230+ if (!sk) {
98231+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
98232+ ret = 1;
98233+#endif
98234 goto no_tcp_socket;
98235+ }
98236
98237 process:
98238- if (sk->sk_state == TCP_TIME_WAIT)
98239+ if (sk->sk_state == TCP_TIME_WAIT) {
98240+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
98241+ ret = 2;
98242+#endif
98243 goto do_time_wait;
98244+ }
98245
98246 if (hdr->hop_limit < inet6_sk(sk)->min_hopcount) {
98247 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
98248@@ -1536,6 +1551,10 @@ csum_error:
98249 bad_packet:
98250 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
98251 } else {
98252+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
98253+ if (!grsec_enable_blackhole || (ret == 1 &&
98254+ (skb->dev->flags & IFF_LOOPBACK)))
98255+#endif
98256 tcp_v6_send_reset(NULL, skb);
98257 }
98258
98259diff --git a/net/ipv6/udp.c b/net/ipv6/udp.c
98260index 3d2758d..626c422 100644
98261--- a/net/ipv6/udp.c
98262+++ b/net/ipv6/udp.c
98263@@ -53,6 +53,10 @@
98264 #include <trace/events/skb.h>
98265 #include "udp_impl.h"
98266
98267+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
98268+extern int grsec_enable_blackhole;
98269+#endif
98270+
98271 int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
98272 {
98273 const struct in6_addr *sk_rcv_saddr6 = &inet6_sk(sk)->rcv_saddr;
98274@@ -417,7 +421,7 @@ try_again:
98275 if (unlikely(err)) {
98276 trace_kfree_skb(skb, udpv6_recvmsg);
98277 if (!peeked) {
98278- atomic_inc(&sk->sk_drops);
98279+ atomic_inc_unchecked(&sk->sk_drops);
98280 if (is_udp4)
98281 UDP_INC_STATS_USER(sock_net(sk),
98282 UDP_MIB_INERRORS,
98283@@ -665,7 +669,7 @@ csum_error:
98284 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_CSUMERRORS, is_udplite);
98285 drop:
98286 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
98287- atomic_inc(&sk->sk_drops);
98288+ atomic_inc_unchecked(&sk->sk_drops);
98289 kfree_skb(skb);
98290 return -1;
98291 }
98292@@ -723,7 +727,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
98293 if (likely(skb1 == NULL))
98294 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
98295 if (!skb1) {
98296- atomic_inc(&sk->sk_drops);
98297+ atomic_inc_unchecked(&sk->sk_drops);
98298 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
98299 IS_UDPLITE(sk));
98300 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
98301@@ -863,6 +867,9 @@ int __udp6_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
98302 goto csum_error;
98303
98304 UDP6_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
98305+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
98306+ if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
98307+#endif
98308 icmpv6_send(skb, ICMPV6_DEST_UNREACH, ICMPV6_PORT_UNREACH, 0);
98309
98310 kfree_skb(skb);
98311diff --git a/net/ipv6/xfrm6_policy.c b/net/ipv6/xfrm6_policy.c
98312index 550b195..6acea83 100644
98313--- a/net/ipv6/xfrm6_policy.c
98314+++ b/net/ipv6/xfrm6_policy.c
98315@@ -212,11 +212,11 @@ _decode_session6(struct sk_buff *skb, struct flowi *fl, int reverse)
98316 }
98317 }
98318
98319-static inline int xfrm6_garbage_collect(struct dst_ops *ops)
98320+static int xfrm6_garbage_collect(struct dst_ops *ops)
98321 {
98322 struct net *net = container_of(ops, struct net, xfrm.xfrm6_dst_ops);
98323
98324- xfrm6_policy_afinfo.garbage_collect(net);
98325+ xfrm_garbage_collect_deferred(net);
98326 return dst_entries_get_fast(ops) > ops->gc_thresh * 2;
98327 }
98328
98329@@ -329,19 +329,19 @@ static struct ctl_table xfrm6_policy_table[] = {
98330
98331 static int __net_init xfrm6_net_init(struct net *net)
98332 {
98333- struct ctl_table *table;
98334+ ctl_table_no_const *table = NULL;
98335 struct ctl_table_header *hdr;
98336
98337- table = xfrm6_policy_table;
98338 if (!net_eq(net, &init_net)) {
98339- table = kmemdup(table, sizeof(xfrm6_policy_table), GFP_KERNEL);
98340+ table = kmemdup(xfrm6_policy_table, sizeof(xfrm6_policy_table), GFP_KERNEL);
98341 if (!table)
98342 goto err_alloc;
98343
98344 table[0].data = &net->xfrm.xfrm6_dst_ops.gc_thresh;
98345- }
98346+ hdr = register_net_sysctl(net, "net/ipv6", table);
98347+ } else
98348+ hdr = register_net_sysctl(net, "net/ipv6", xfrm6_policy_table);
98349
98350- hdr = register_net_sysctl(net, "net/ipv6", table);
98351 if (!hdr)
98352 goto err_reg;
98353
98354@@ -349,8 +349,7 @@ static int __net_init xfrm6_net_init(struct net *net)
98355 return 0;
98356
98357 err_reg:
98358- if (!net_eq(net, &init_net))
98359- kfree(table);
98360+ kfree(table);
98361 err_alloc:
98362 return -ENOMEM;
98363 }
98364diff --git a/net/irda/ircomm/ircomm_tty.c b/net/irda/ircomm/ircomm_tty.c
98365index 41ac7938..75e3bb1 100644
98366--- a/net/irda/ircomm/ircomm_tty.c
98367+++ b/net/irda/ircomm/ircomm_tty.c
98368@@ -319,11 +319,11 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
98369 add_wait_queue(&port->open_wait, &wait);
98370
98371 IRDA_DEBUG(2, "%s(%d):block_til_ready before block on %s open_count=%d\n",
98372- __FILE__, __LINE__, tty->driver->name, port->count);
98373+ __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
98374
98375 spin_lock_irqsave(&port->lock, flags);
98376 if (!tty_hung_up_p(filp))
98377- port->count--;
98378+ atomic_dec(&port->count);
98379 port->blocked_open++;
98380 spin_unlock_irqrestore(&port->lock, flags);
98381
98382@@ -358,7 +358,7 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
98383 }
98384
98385 IRDA_DEBUG(1, "%s(%d):block_til_ready blocking on %s open_count=%d\n",
98386- __FILE__, __LINE__, tty->driver->name, port->count);
98387+ __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
98388
98389 schedule();
98390 }
98391@@ -368,12 +368,12 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
98392
98393 spin_lock_irqsave(&port->lock, flags);
98394 if (!tty_hung_up_p(filp))
98395- port->count++;
98396+ atomic_inc(&port->count);
98397 port->blocked_open--;
98398 spin_unlock_irqrestore(&port->lock, flags);
98399
98400 IRDA_DEBUG(1, "%s(%d):block_til_ready after blocking on %s open_count=%d\n",
98401- __FILE__, __LINE__, tty->driver->name, port->count);
98402+ __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
98403
98404 if (!retval)
98405 port->flags |= ASYNC_NORMAL_ACTIVE;
98406@@ -447,12 +447,12 @@ static int ircomm_tty_open(struct tty_struct *tty, struct file *filp)
98407
98408 /* ++ is not atomic, so this should be protected - Jean II */
98409 spin_lock_irqsave(&self->port.lock, flags);
98410- self->port.count++;
98411+ atomic_inc(&self->port.count);
98412 spin_unlock_irqrestore(&self->port.lock, flags);
98413 tty_port_tty_set(&self->port, tty);
98414
98415 IRDA_DEBUG(1, "%s(), %s%d, count = %d\n", __func__ , tty->driver->name,
98416- self->line, self->port.count);
98417+ self->line, atomic_read(&self->port.count));
98418
98419 /* Not really used by us, but lets do it anyway */
98420 self->port.low_latency = (self->port.flags & ASYNC_LOW_LATENCY) ? 1 : 0;
98421@@ -989,7 +989,7 @@ static void ircomm_tty_hangup(struct tty_struct *tty)
98422 tty_kref_put(port->tty);
98423 }
98424 port->tty = NULL;
98425- port->count = 0;
98426+ atomic_set(&port->count, 0);
98427 spin_unlock_irqrestore(&port->lock, flags);
98428
98429 wake_up_interruptible(&port->open_wait);
98430@@ -1346,7 +1346,7 @@ static void ircomm_tty_line_info(struct ircomm_tty_cb *self, struct seq_file *m)
98431 seq_putc(m, '\n');
98432
98433 seq_printf(m, "Role: %s\n", self->client ? "client" : "server");
98434- seq_printf(m, "Open count: %d\n", self->port.count);
98435+ seq_printf(m, "Open count: %d\n", atomic_read(&self->port.count));
98436 seq_printf(m, "Max data size: %d\n", self->max_data_size);
98437 seq_printf(m, "Max header size: %d\n", self->max_header_size);
98438
98439diff --git a/net/iucv/af_iucv.c b/net/iucv/af_iucv.c
98440index c4b7218..3e83259 100644
98441--- a/net/iucv/af_iucv.c
98442+++ b/net/iucv/af_iucv.c
98443@@ -773,10 +773,10 @@ static int iucv_sock_autobind(struct sock *sk)
98444
98445 write_lock_bh(&iucv_sk_list.lock);
98446
98447- sprintf(name, "%08x", atomic_inc_return(&iucv_sk_list.autobind_name));
98448+ sprintf(name, "%08x", atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
98449 while (__iucv_get_sock_by_name(name)) {
98450 sprintf(name, "%08x",
98451- atomic_inc_return(&iucv_sk_list.autobind_name));
98452+ atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
98453 }
98454
98455 write_unlock_bh(&iucv_sk_list.lock);
98456diff --git a/net/iucv/iucv.c b/net/iucv/iucv.c
98457index cd5b8ec..f205e6b 100644
98458--- a/net/iucv/iucv.c
98459+++ b/net/iucv/iucv.c
98460@@ -690,7 +690,7 @@ static int iucv_cpu_notify(struct notifier_block *self,
98461 return NOTIFY_OK;
98462 }
98463
98464-static struct notifier_block __refdata iucv_cpu_notifier = {
98465+static struct notifier_block iucv_cpu_notifier = {
98466 .notifier_call = iucv_cpu_notify,
98467 };
98468
98469diff --git a/net/key/af_key.c b/net/key/af_key.c
98470index 545f047..9757a9d 100644
98471--- a/net/key/af_key.c
98472+++ b/net/key/af_key.c
98473@@ -3041,10 +3041,10 @@ static int pfkey_send_policy_notify(struct xfrm_policy *xp, int dir, const struc
98474 static u32 get_acqseq(void)
98475 {
98476 u32 res;
98477- static atomic_t acqseq;
98478+ static atomic_unchecked_t acqseq;
98479
98480 do {
98481- res = atomic_inc_return(&acqseq);
98482+ res = atomic_inc_return_unchecked(&acqseq);
98483 } while (!res);
98484 return res;
98485 }
98486diff --git a/net/mac80211/cfg.c b/net/mac80211/cfg.c
98487index 9903ee5..18978be 100644
98488--- a/net/mac80211/cfg.c
98489+++ b/net/mac80211/cfg.c
98490@@ -826,7 +826,7 @@ static int ieee80211_set_monitor_channel(struct wiphy *wiphy,
98491 ret = ieee80211_vif_use_channel(sdata, chandef,
98492 IEEE80211_CHANCTX_EXCLUSIVE);
98493 }
98494- } else if (local->open_count == local->monitors) {
98495+ } else if (local_read(&local->open_count) == local->monitors) {
98496 local->_oper_chandef = *chandef;
98497 ieee80211_hw_config(local, 0);
98498 }
98499@@ -3124,7 +3124,7 @@ static void ieee80211_mgmt_frame_register(struct wiphy *wiphy,
98500 else
98501 local->probe_req_reg--;
98502
98503- if (!local->open_count)
98504+ if (!local_read(&local->open_count))
98505 break;
98506
98507 ieee80211_queue_work(&local->hw, &local->reconfig_filter);
98508@@ -3587,8 +3587,8 @@ static int ieee80211_cfg_get_channel(struct wiphy *wiphy,
98509 if (chanctx_conf) {
98510 *chandef = chanctx_conf->def;
98511 ret = 0;
98512- } else if (local->open_count > 0 &&
98513- local->open_count == local->monitors &&
98514+ } else if (local_read(&local->open_count) > 0 &&
98515+ local_read(&local->open_count) == local->monitors &&
98516 sdata->vif.type == NL80211_IFTYPE_MONITOR) {
98517 if (local->use_chanctx)
98518 *chandef = local->monitor_chandef;
98519diff --git a/net/mac80211/ieee80211_i.h b/net/mac80211/ieee80211_i.h
98520index 611abfc..8c2c7e4 100644
98521--- a/net/mac80211/ieee80211_i.h
98522+++ b/net/mac80211/ieee80211_i.h
98523@@ -28,6 +28,7 @@
98524 #include <net/ieee80211_radiotap.h>
98525 #include <net/cfg80211.h>
98526 #include <net/mac80211.h>
98527+#include <asm/local.h>
98528 #include "key.h"
98529 #include "sta_info.h"
98530 #include "debug.h"
98531@@ -945,7 +946,7 @@ struct ieee80211_local {
98532 /* also used to protect ampdu_ac_queue and amdpu_ac_stop_refcnt */
98533 spinlock_t queue_stop_reason_lock;
98534
98535- int open_count;
98536+ local_t open_count;
98537 int monitors, cooked_mntrs;
98538 /* number of interfaces with corresponding FIF_ flags */
98539 int fif_fcsfail, fif_plcpfail, fif_control, fif_other_bss, fif_pspoll,
98540diff --git a/net/mac80211/iface.c b/net/mac80211/iface.c
98541index fcecd63..a404454 100644
98542--- a/net/mac80211/iface.c
98543+++ b/net/mac80211/iface.c
98544@@ -519,7 +519,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
98545 break;
98546 }
98547
98548- if (local->open_count == 0) {
98549+ if (local_read(&local->open_count) == 0) {
98550 res = drv_start(local);
98551 if (res)
98552 goto err_del_bss;
98553@@ -566,7 +566,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
98554 res = drv_add_interface(local, sdata);
98555 if (res)
98556 goto err_stop;
98557- } else if (local->monitors == 0 && local->open_count == 0) {
98558+ } else if (local->monitors == 0 && local_read(&local->open_count) == 0) {
98559 res = ieee80211_add_virtual_monitor(local);
98560 if (res)
98561 goto err_stop;
98562@@ -675,7 +675,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
98563 atomic_inc(&local->iff_promiscs);
98564
98565 if (coming_up)
98566- local->open_count++;
98567+ local_inc(&local->open_count);
98568
98569 if (hw_reconf_flags)
98570 ieee80211_hw_config(local, hw_reconf_flags);
98571@@ -713,7 +713,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
98572 err_del_interface:
98573 drv_remove_interface(local, sdata);
98574 err_stop:
98575- if (!local->open_count)
98576+ if (!local_read(&local->open_count))
98577 drv_stop(local);
98578 err_del_bss:
98579 sdata->bss = NULL;
98580@@ -852,7 +852,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
98581 }
98582
98583 if (going_down)
98584- local->open_count--;
98585+ local_dec(&local->open_count);
98586
98587 switch (sdata->vif.type) {
98588 case NL80211_IFTYPE_AP_VLAN:
98589@@ -919,7 +919,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
98590 }
98591 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
98592
98593- if (local->open_count == 0)
98594+ if (local_read(&local->open_count) == 0)
98595 ieee80211_clear_tx_pending(local);
98596
98597 /*
98598@@ -959,7 +959,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
98599
98600 ieee80211_recalc_ps(local, -1);
98601
98602- if (local->open_count == 0) {
98603+ if (local_read(&local->open_count) == 0) {
98604 ieee80211_stop_device(local);
98605
98606 /* no reconfiguring after stop! */
98607@@ -970,7 +970,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
98608 ieee80211_configure_filter(local);
98609 ieee80211_hw_config(local, hw_reconf_flags);
98610
98611- if (local->monitors == local->open_count)
98612+ if (local->monitors == local_read(&local->open_count))
98613 ieee80211_add_virtual_monitor(local);
98614 }
98615
98616diff --git a/net/mac80211/main.c b/net/mac80211/main.c
98617index e765f77..dfd72e7 100644
98618--- a/net/mac80211/main.c
98619+++ b/net/mac80211/main.c
98620@@ -172,7 +172,7 @@ int ieee80211_hw_config(struct ieee80211_local *local, u32 changed)
98621 changed &= ~(IEEE80211_CONF_CHANGE_CHANNEL |
98622 IEEE80211_CONF_CHANGE_POWER);
98623
98624- if (changed && local->open_count) {
98625+ if (changed && local_read(&local->open_count)) {
98626 ret = drv_config(local, changed);
98627 /*
98628 * Goal:
98629diff --git a/net/mac80211/pm.c b/net/mac80211/pm.c
98630index 3401262..d5cd68d 100644
98631--- a/net/mac80211/pm.c
98632+++ b/net/mac80211/pm.c
98633@@ -12,7 +12,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
98634 struct ieee80211_sub_if_data *sdata;
98635 struct sta_info *sta;
98636
98637- if (!local->open_count)
98638+ if (!local_read(&local->open_count))
98639 goto suspend;
98640
98641 ieee80211_scan_cancel(local);
98642@@ -59,7 +59,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
98643 cancel_work_sync(&local->dynamic_ps_enable_work);
98644 del_timer_sync(&local->dynamic_ps_timer);
98645
98646- local->wowlan = wowlan && local->open_count;
98647+ local->wowlan = wowlan && local_read(&local->open_count);
98648 if (local->wowlan) {
98649 int err = drv_suspend(local, wowlan);
98650 if (err < 0) {
98651@@ -116,7 +116,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
98652 WARN_ON(!list_empty(&local->chanctx_list));
98653
98654 /* stop hardware - this must stop RX */
98655- if (local->open_count)
98656+ if (local_read(&local->open_count))
98657 ieee80211_stop_device(local);
98658
98659 suspend:
98660diff --git a/net/mac80211/rate.c b/net/mac80211/rate.c
98661index e126605..73d2c39 100644
98662--- a/net/mac80211/rate.c
98663+++ b/net/mac80211/rate.c
98664@@ -725,7 +725,7 @@ int ieee80211_init_rate_ctrl_alg(struct ieee80211_local *local,
98665
98666 ASSERT_RTNL();
98667
98668- if (local->open_count)
98669+ if (local_read(&local->open_count))
98670 return -EBUSY;
98671
98672 if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL) {
98673diff --git a/net/mac80211/rc80211_pid_debugfs.c b/net/mac80211/rc80211_pid_debugfs.c
98674index c97a065..ff61928 100644
98675--- a/net/mac80211/rc80211_pid_debugfs.c
98676+++ b/net/mac80211/rc80211_pid_debugfs.c
98677@@ -193,7 +193,7 @@ static ssize_t rate_control_pid_events_read(struct file *file, char __user *buf,
98678
98679 spin_unlock_irqrestore(&events->lock, status);
98680
98681- if (copy_to_user(buf, pb, p))
98682+ if (p > sizeof(pb) || copy_to_user(buf, pb, p))
98683 return -EFAULT;
98684
98685 return p;
98686diff --git a/net/mac80211/util.c b/net/mac80211/util.c
98687index 69e4ef5..e8e4b92 100644
98688--- a/net/mac80211/util.c
98689+++ b/net/mac80211/util.c
98690@@ -1470,7 +1470,7 @@ int ieee80211_reconfig(struct ieee80211_local *local)
98691 }
98692 #endif
98693 /* everything else happens only if HW was up & running */
98694- if (!local->open_count)
98695+ if (!local_read(&local->open_count))
98696 goto wake_up;
98697
98698 /*
98699@@ -1695,7 +1695,7 @@ int ieee80211_reconfig(struct ieee80211_local *local)
98700 local->in_reconfig = false;
98701 barrier();
98702
98703- if (local->monitors == local->open_count && local->monitors > 0)
98704+ if (local->monitors == local_read(&local->open_count) && local->monitors > 0)
98705 ieee80211_add_virtual_monitor(local);
98706
98707 /*
98708diff --git a/net/netfilter/Kconfig b/net/netfilter/Kconfig
98709index 6e839b6..002a233 100644
98710--- a/net/netfilter/Kconfig
98711+++ b/net/netfilter/Kconfig
98712@@ -950,6 +950,16 @@ config NETFILTER_XT_MATCH_ESP
98713
98714 To compile it as a module, choose M here. If unsure, say N.
98715
98716+config NETFILTER_XT_MATCH_GRADM
98717+ tristate '"gradm" match support'
98718+ depends on NETFILTER_XTABLES && NETFILTER_ADVANCED
98719+ depends on GRKERNSEC && !GRKERNSEC_NO_RBAC
98720+ ---help---
98721+ The gradm match allows to match on grsecurity RBAC being enabled.
98722+ It is useful when iptables rules are applied early on bootup to
98723+ prevent connections to the machine (except from a trusted host)
98724+ while the RBAC system is disabled.
98725+
98726 config NETFILTER_XT_MATCH_HASHLIMIT
98727 tristate '"hashlimit" match support'
98728 depends on (IP6_NF_IPTABLES || IP6_NF_IPTABLES=n)
98729diff --git a/net/netfilter/Makefile b/net/netfilter/Makefile
98730index c3a0a12..90b587f 100644
98731--- a/net/netfilter/Makefile
98732+++ b/net/netfilter/Makefile
98733@@ -112,6 +112,7 @@ obj-$(CONFIG_NETFILTER_XT_MATCH_DEVGROUP) += xt_devgroup.o
98734 obj-$(CONFIG_NETFILTER_XT_MATCH_DSCP) += xt_dscp.o
98735 obj-$(CONFIG_NETFILTER_XT_MATCH_ECN) += xt_ecn.o
98736 obj-$(CONFIG_NETFILTER_XT_MATCH_ESP) += xt_esp.o
98737+obj-$(CONFIG_NETFILTER_XT_MATCH_GRADM) += xt_gradm.o
98738 obj-$(CONFIG_NETFILTER_XT_MATCH_HASHLIMIT) += xt_hashlimit.o
98739 obj-$(CONFIG_NETFILTER_XT_MATCH_HELPER) += xt_helper.o
98740 obj-$(CONFIG_NETFILTER_XT_MATCH_HL) += xt_hl.o
98741diff --git a/net/netfilter/ipset/ip_set_core.c b/net/netfilter/ipset/ip_set_core.c
98742index f2e30fb..f131862 100644
98743--- a/net/netfilter/ipset/ip_set_core.c
98744+++ b/net/netfilter/ipset/ip_set_core.c
98745@@ -1819,7 +1819,7 @@ done:
98746 return ret;
98747 }
98748
98749-static struct nf_sockopt_ops so_set __read_mostly = {
98750+static struct nf_sockopt_ops so_set = {
98751 .pf = PF_INET,
98752 .get_optmin = SO_IP_SET,
98753 .get_optmax = SO_IP_SET + 1,
98754diff --git a/net/netfilter/ipvs/ip_vs_conn.c b/net/netfilter/ipvs/ip_vs_conn.c
98755index 4c8e5c0..5a79b4d 100644
98756--- a/net/netfilter/ipvs/ip_vs_conn.c
98757+++ b/net/netfilter/ipvs/ip_vs_conn.c
98758@@ -556,7 +556,7 @@ ip_vs_bind_dest(struct ip_vs_conn *cp, struct ip_vs_dest *dest)
98759 /* Increase the refcnt counter of the dest */
98760 ip_vs_dest_hold(dest);
98761
98762- conn_flags = atomic_read(&dest->conn_flags);
98763+ conn_flags = atomic_read_unchecked(&dest->conn_flags);
98764 if (cp->protocol != IPPROTO_UDP)
98765 conn_flags &= ~IP_VS_CONN_F_ONE_PACKET;
98766 flags = cp->flags;
98767@@ -900,7 +900,7 @@ ip_vs_conn_new(const struct ip_vs_conn_param *p,
98768
98769 cp->control = NULL;
98770 atomic_set(&cp->n_control, 0);
98771- atomic_set(&cp->in_pkts, 0);
98772+ atomic_set_unchecked(&cp->in_pkts, 0);
98773
98774 cp->packet_xmit = NULL;
98775 cp->app = NULL;
98776@@ -1188,7 +1188,7 @@ static inline int todrop_entry(struct ip_vs_conn *cp)
98777
98778 /* Don't drop the entry if its number of incoming packets is not
98779 located in [0, 8] */
98780- i = atomic_read(&cp->in_pkts);
98781+ i = atomic_read_unchecked(&cp->in_pkts);
98782 if (i > 8 || i < 0) return 0;
98783
98784 if (!todrop_rate[i]) return 0;
98785diff --git a/net/netfilter/ipvs/ip_vs_core.c b/net/netfilter/ipvs/ip_vs_core.c
98786index 3581736..c0453e9 100644
98787--- a/net/netfilter/ipvs/ip_vs_core.c
98788+++ b/net/netfilter/ipvs/ip_vs_core.c
98789@@ -567,7 +567,7 @@ int ip_vs_leave(struct ip_vs_service *svc, struct sk_buff *skb,
98790 ret = cp->packet_xmit(skb, cp, pd->pp, iph);
98791 /* do not touch skb anymore */
98792
98793- atomic_inc(&cp->in_pkts);
98794+ atomic_inc_unchecked(&cp->in_pkts);
98795 ip_vs_conn_put(cp);
98796 return ret;
98797 }
98798@@ -1706,7 +1706,7 @@ ip_vs_in(unsigned int hooknum, struct sk_buff *skb, int af)
98799 if (cp->flags & IP_VS_CONN_F_ONE_PACKET)
98800 pkts = sysctl_sync_threshold(ipvs);
98801 else
98802- pkts = atomic_add_return(1, &cp->in_pkts);
98803+ pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
98804
98805 if (ipvs->sync_state & IP_VS_STATE_MASTER)
98806 ip_vs_sync_conn(net, cp, pkts);
98807diff --git a/net/netfilter/ipvs/ip_vs_ctl.c b/net/netfilter/ipvs/ip_vs_ctl.c
98808index a3df9bd..895ae09 100644
98809--- a/net/netfilter/ipvs/ip_vs_ctl.c
98810+++ b/net/netfilter/ipvs/ip_vs_ctl.c
98811@@ -794,7 +794,7 @@ __ip_vs_update_dest(struct ip_vs_service *svc, struct ip_vs_dest *dest,
98812 */
98813 ip_vs_rs_hash(ipvs, dest);
98814 }
98815- atomic_set(&dest->conn_flags, conn_flags);
98816+ atomic_set_unchecked(&dest->conn_flags, conn_flags);
98817
98818 /* bind the service */
98819 old_svc = rcu_dereference_protected(dest->svc, 1);
98820@@ -1641,7 +1641,7 @@ proc_do_sync_ports(struct ctl_table *table, int write,
98821 * align with netns init in ip_vs_control_net_init()
98822 */
98823
98824-static struct ctl_table vs_vars[] = {
98825+static ctl_table_no_const vs_vars[] __read_only = {
98826 {
98827 .procname = "amemthresh",
98828 .maxlen = sizeof(int),
98829@@ -2062,7 +2062,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
98830 " %-7s %-6d %-10d %-10d\n",
98831 &dest->addr.in6,
98832 ntohs(dest->port),
98833- ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
98834+ ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
98835 atomic_read(&dest->weight),
98836 atomic_read(&dest->activeconns),
98837 atomic_read(&dest->inactconns));
98838@@ -2073,7 +2073,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
98839 "%-7s %-6d %-10d %-10d\n",
98840 ntohl(dest->addr.ip),
98841 ntohs(dest->port),
98842- ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
98843+ ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
98844 atomic_read(&dest->weight),
98845 atomic_read(&dest->activeconns),
98846 atomic_read(&dest->inactconns));
98847@@ -2551,7 +2551,7 @@ __ip_vs_get_dest_entries(struct net *net, const struct ip_vs_get_dests *get,
98848
98849 entry.addr = dest->addr.ip;
98850 entry.port = dest->port;
98851- entry.conn_flags = atomic_read(&dest->conn_flags);
98852+ entry.conn_flags = atomic_read_unchecked(&dest->conn_flags);
98853 entry.weight = atomic_read(&dest->weight);
98854 entry.u_threshold = dest->u_threshold;
98855 entry.l_threshold = dest->l_threshold;
98856@@ -3094,7 +3094,7 @@ static int ip_vs_genl_fill_dest(struct sk_buff *skb, struct ip_vs_dest *dest)
98857 if (nla_put(skb, IPVS_DEST_ATTR_ADDR, sizeof(dest->addr), &dest->addr) ||
98858 nla_put_be16(skb, IPVS_DEST_ATTR_PORT, dest->port) ||
98859 nla_put_u32(skb, IPVS_DEST_ATTR_FWD_METHOD,
98860- (atomic_read(&dest->conn_flags) &
98861+ (atomic_read_unchecked(&dest->conn_flags) &
98862 IP_VS_CONN_F_FWD_MASK)) ||
98863 nla_put_u32(skb, IPVS_DEST_ATTR_WEIGHT,
98864 atomic_read(&dest->weight)) ||
98865@@ -3684,7 +3684,7 @@ static int __net_init ip_vs_control_net_init_sysctl(struct net *net)
98866 {
98867 int idx;
98868 struct netns_ipvs *ipvs = net_ipvs(net);
98869- struct ctl_table *tbl;
98870+ ctl_table_no_const *tbl;
98871
98872 atomic_set(&ipvs->dropentry, 0);
98873 spin_lock_init(&ipvs->dropentry_lock);
98874diff --git a/net/netfilter/ipvs/ip_vs_lblc.c b/net/netfilter/ipvs/ip_vs_lblc.c
98875index eff13c9..c1aab3e 100644
98876--- a/net/netfilter/ipvs/ip_vs_lblc.c
98877+++ b/net/netfilter/ipvs/ip_vs_lblc.c
98878@@ -118,7 +118,7 @@ struct ip_vs_lblc_table {
98879 * IPVS LBLC sysctl table
98880 */
98881 #ifdef CONFIG_SYSCTL
98882-static struct ctl_table vs_vars_table[] = {
98883+static ctl_table_no_const vs_vars_table[] __read_only = {
98884 {
98885 .procname = "lblc_expiration",
98886 .data = NULL,
98887diff --git a/net/netfilter/ipvs/ip_vs_lblcr.c b/net/netfilter/ipvs/ip_vs_lblcr.c
98888index 0b85500..8513fa5 100644
98889--- a/net/netfilter/ipvs/ip_vs_lblcr.c
98890+++ b/net/netfilter/ipvs/ip_vs_lblcr.c
98891@@ -289,7 +289,7 @@ struct ip_vs_lblcr_table {
98892 * IPVS LBLCR sysctl table
98893 */
98894
98895-static struct ctl_table vs_vars_table[] = {
98896+static ctl_table_no_const vs_vars_table[] __read_only = {
98897 {
98898 .procname = "lblcr_expiration",
98899 .data = NULL,
98900diff --git a/net/netfilter/ipvs/ip_vs_sync.c b/net/netfilter/ipvs/ip_vs_sync.c
98901index f448471..995f131 100644
98902--- a/net/netfilter/ipvs/ip_vs_sync.c
98903+++ b/net/netfilter/ipvs/ip_vs_sync.c
98904@@ -609,7 +609,7 @@ static void ip_vs_sync_conn_v0(struct net *net, struct ip_vs_conn *cp,
98905 cp = cp->control;
98906 if (cp) {
98907 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
98908- pkts = atomic_add_return(1, &cp->in_pkts);
98909+ pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
98910 else
98911 pkts = sysctl_sync_threshold(ipvs);
98912 ip_vs_sync_conn(net, cp->control, pkts);
98913@@ -771,7 +771,7 @@ control:
98914 if (!cp)
98915 return;
98916 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
98917- pkts = atomic_add_return(1, &cp->in_pkts);
98918+ pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
98919 else
98920 pkts = sysctl_sync_threshold(ipvs);
98921 goto sloop;
98922@@ -895,7 +895,7 @@ static void ip_vs_proc_conn(struct net *net, struct ip_vs_conn_param *param,
98923
98924 if (opt)
98925 memcpy(&cp->in_seq, opt, sizeof(*opt));
98926- atomic_set(&cp->in_pkts, sysctl_sync_threshold(ipvs));
98927+ atomic_set_unchecked(&cp->in_pkts, sysctl_sync_threshold(ipvs));
98928 cp->state = state;
98929 cp->old_state = cp->state;
98930 /*
98931diff --git a/net/netfilter/ipvs/ip_vs_xmit.c b/net/netfilter/ipvs/ip_vs_xmit.c
98932index c47444e..b0961c6 100644
98933--- a/net/netfilter/ipvs/ip_vs_xmit.c
98934+++ b/net/netfilter/ipvs/ip_vs_xmit.c
98935@@ -1102,7 +1102,7 @@ ip_vs_icmp_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
98936 else
98937 rc = NF_ACCEPT;
98938 /* do not touch skb anymore */
98939- atomic_inc(&cp->in_pkts);
98940+ atomic_inc_unchecked(&cp->in_pkts);
98941 goto out;
98942 }
98943
98944@@ -1194,7 +1194,7 @@ ip_vs_icmp_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
98945 else
98946 rc = NF_ACCEPT;
98947 /* do not touch skb anymore */
98948- atomic_inc(&cp->in_pkts);
98949+ atomic_inc_unchecked(&cp->in_pkts);
98950 goto out;
98951 }
98952
98953diff --git a/net/netfilter/nf_conntrack_acct.c b/net/netfilter/nf_conntrack_acct.c
98954index 2d3030a..7ba1c0a 100644
98955--- a/net/netfilter/nf_conntrack_acct.c
98956+++ b/net/netfilter/nf_conntrack_acct.c
98957@@ -60,7 +60,7 @@ static struct nf_ct_ext_type acct_extend __read_mostly = {
98958 #ifdef CONFIG_SYSCTL
98959 static int nf_conntrack_acct_init_sysctl(struct net *net)
98960 {
98961- struct ctl_table *table;
98962+ ctl_table_no_const *table;
98963
98964 table = kmemdup(acct_sysctl_table, sizeof(acct_sysctl_table),
98965 GFP_KERNEL);
98966diff --git a/net/netfilter/nf_conntrack_core.c b/net/netfilter/nf_conntrack_core.c
98967index 5d892fe..d2fc9d8 100644
98968--- a/net/netfilter/nf_conntrack_core.c
98969+++ b/net/netfilter/nf_conntrack_core.c
98970@@ -1600,6 +1600,10 @@ void nf_conntrack_init_end(void)
98971 #define DYING_NULLS_VAL ((1<<30)+1)
98972 #define TEMPLATE_NULLS_VAL ((1<<30)+2)
98973
98974+#ifdef CONFIG_GRKERNSEC_HIDESYM
98975+static atomic_unchecked_t conntrack_cache_id = ATOMIC_INIT(0);
98976+#endif
98977+
98978 int nf_conntrack_init_net(struct net *net)
98979 {
98980 int ret;
98981@@ -1614,7 +1618,11 @@ int nf_conntrack_init_net(struct net *net)
98982 goto err_stat;
98983 }
98984
98985+#ifdef CONFIG_GRKERNSEC_HIDESYM
98986+ net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%08lx", atomic_inc_return_unchecked(&conntrack_cache_id));
98987+#else
98988 net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%p", net);
98989+#endif
98990 if (!net->ct.slabname) {
98991 ret = -ENOMEM;
98992 goto err_slabname;
98993diff --git a/net/netfilter/nf_conntrack_ecache.c b/net/netfilter/nf_conntrack_ecache.c
98994index 1df1761..ce8b88a 100644
98995--- a/net/netfilter/nf_conntrack_ecache.c
98996+++ b/net/netfilter/nf_conntrack_ecache.c
98997@@ -188,7 +188,7 @@ static struct nf_ct_ext_type event_extend __read_mostly = {
98998 #ifdef CONFIG_SYSCTL
98999 static int nf_conntrack_event_init_sysctl(struct net *net)
99000 {
99001- struct ctl_table *table;
99002+ ctl_table_no_const *table;
99003
99004 table = kmemdup(event_sysctl_table, sizeof(event_sysctl_table),
99005 GFP_KERNEL);
99006diff --git a/net/netfilter/nf_conntrack_helper.c b/net/netfilter/nf_conntrack_helper.c
99007index 974a2a4..52cc6ff 100644
99008--- a/net/netfilter/nf_conntrack_helper.c
99009+++ b/net/netfilter/nf_conntrack_helper.c
99010@@ -57,7 +57,7 @@ static struct ctl_table helper_sysctl_table[] = {
99011
99012 static int nf_conntrack_helper_init_sysctl(struct net *net)
99013 {
99014- struct ctl_table *table;
99015+ ctl_table_no_const *table;
99016
99017 table = kmemdup(helper_sysctl_table, sizeof(helper_sysctl_table),
99018 GFP_KERNEL);
99019diff --git a/net/netfilter/nf_conntrack_proto.c b/net/netfilter/nf_conntrack_proto.c
99020index ce30041..3861b5d 100644
99021--- a/net/netfilter/nf_conntrack_proto.c
99022+++ b/net/netfilter/nf_conntrack_proto.c
99023@@ -52,7 +52,7 @@ nf_ct_register_sysctl(struct net *net,
99024
99025 static void
99026 nf_ct_unregister_sysctl(struct ctl_table_header **header,
99027- struct ctl_table **table,
99028+ ctl_table_no_const **table,
99029 unsigned int users)
99030 {
99031 if (users > 0)
99032diff --git a/net/netfilter/nf_conntrack_proto_dccp.c b/net/netfilter/nf_conntrack_proto_dccp.c
99033index a99b6c3..cb372f9 100644
99034--- a/net/netfilter/nf_conntrack_proto_dccp.c
99035+++ b/net/netfilter/nf_conntrack_proto_dccp.c
99036@@ -428,7 +428,7 @@ static bool dccp_new(struct nf_conn *ct, const struct sk_buff *skb,
99037 const char *msg;
99038 u_int8_t state;
99039
99040- dh = skb_header_pointer(skb, dataoff, sizeof(_dh), &dh);
99041+ dh = skb_header_pointer(skb, dataoff, sizeof(_dh), &_dh);
99042 BUG_ON(dh == NULL);
99043
99044 state = dccp_state_table[CT_DCCP_ROLE_CLIENT][dh->dccph_type][CT_DCCP_NONE];
99045@@ -457,7 +457,7 @@ static bool dccp_new(struct nf_conn *ct, const struct sk_buff *skb,
99046 out_invalid:
99047 if (LOG_INVALID(net, IPPROTO_DCCP))
99048 nf_log_packet(net, nf_ct_l3num(ct), 0, skb, NULL, NULL,
99049- NULL, msg);
99050+ NULL, "%s", msg);
99051 return false;
99052 }
99053
99054@@ -486,7 +486,7 @@ static int dccp_packet(struct nf_conn *ct, const struct sk_buff *skb,
99055 u_int8_t type, old_state, new_state;
99056 enum ct_dccp_roles role;
99057
99058- dh = skb_header_pointer(skb, dataoff, sizeof(_dh), &dh);
99059+ dh = skb_header_pointer(skb, dataoff, sizeof(_dh), &_dh);
99060 BUG_ON(dh == NULL);
99061 type = dh->dccph_type;
99062
99063@@ -577,7 +577,7 @@ static int dccp_error(struct net *net, struct nf_conn *tmpl,
99064 unsigned int cscov;
99065 const char *msg;
99066
99067- dh = skb_header_pointer(skb, dataoff, sizeof(_dh), &dh);
99068+ dh = skb_header_pointer(skb, dataoff, sizeof(_dh), &_dh);
99069 if (dh == NULL) {
99070 msg = "nf_ct_dccp: short packet ";
99071 goto out_invalid;
99072@@ -614,7 +614,7 @@ static int dccp_error(struct net *net, struct nf_conn *tmpl,
99073
99074 out_invalid:
99075 if (LOG_INVALID(net, IPPROTO_DCCP))
99076- nf_log_packet(net, pf, 0, skb, NULL, NULL, NULL, msg);
99077+ nf_log_packet(net, pf, 0, skb, NULL, NULL, NULL, "%s", msg);
99078 return -NF_ACCEPT;
99079 }
99080
99081diff --git a/net/netfilter/nf_conntrack_standalone.c b/net/netfilter/nf_conntrack_standalone.c
99082index f641751..d3c5b51 100644
99083--- a/net/netfilter/nf_conntrack_standalone.c
99084+++ b/net/netfilter/nf_conntrack_standalone.c
99085@@ -471,7 +471,7 @@ static struct ctl_table nf_ct_netfilter_table[] = {
99086
99087 static int nf_conntrack_standalone_init_sysctl(struct net *net)
99088 {
99089- struct ctl_table *table;
99090+ ctl_table_no_const *table;
99091
99092 table = kmemdup(nf_ct_sysctl_table, sizeof(nf_ct_sysctl_table),
99093 GFP_KERNEL);
99094diff --git a/net/netfilter/nf_conntrack_timestamp.c b/net/netfilter/nf_conntrack_timestamp.c
99095index 902fb0a..87f7fdb 100644
99096--- a/net/netfilter/nf_conntrack_timestamp.c
99097+++ b/net/netfilter/nf_conntrack_timestamp.c
99098@@ -42,7 +42,7 @@ static struct nf_ct_ext_type tstamp_extend __read_mostly = {
99099 #ifdef CONFIG_SYSCTL
99100 static int nf_conntrack_tstamp_init_sysctl(struct net *net)
99101 {
99102- struct ctl_table *table;
99103+ ctl_table_no_const *table;
99104
99105 table = kmemdup(tstamp_sysctl_table, sizeof(tstamp_sysctl_table),
99106 GFP_KERNEL);
99107diff --git a/net/netfilter/nf_log.c b/net/netfilter/nf_log.c
99108index 85296d4..8becdec 100644
99109--- a/net/netfilter/nf_log.c
99110+++ b/net/netfilter/nf_log.c
99111@@ -243,7 +243,7 @@ static const struct file_operations nflog_file_ops = {
99112
99113 #ifdef CONFIG_SYSCTL
99114 static char nf_log_sysctl_fnames[NFPROTO_NUMPROTO-NFPROTO_UNSPEC][3];
99115-static struct ctl_table nf_log_sysctl_table[NFPROTO_NUMPROTO+1];
99116+static ctl_table_no_const nf_log_sysctl_table[NFPROTO_NUMPROTO+1] __read_only;
99117
99118 static int nf_log_proc_dostring(struct ctl_table *table, int write,
99119 void __user *buffer, size_t *lenp, loff_t *ppos)
99120@@ -274,14 +274,16 @@ static int nf_log_proc_dostring(struct ctl_table *table, int write,
99121 rcu_assign_pointer(net->nf.nf_loggers[tindex], logger);
99122 mutex_unlock(&nf_log_mutex);
99123 } else {
99124+ ctl_table_no_const nf_log_table = *table;
99125+
99126 mutex_lock(&nf_log_mutex);
99127 logger = rcu_dereference_protected(net->nf.nf_loggers[tindex],
99128 lockdep_is_held(&nf_log_mutex));
99129 if (!logger)
99130- table->data = "NONE";
99131+ nf_log_table.data = "NONE";
99132 else
99133- table->data = logger->name;
99134- r = proc_dostring(table, write, buffer, lenp, ppos);
99135+ nf_log_table.data = logger->name;
99136+ r = proc_dostring(&nf_log_table, write, buffer, lenp, ppos);
99137 mutex_unlock(&nf_log_mutex);
99138 }
99139
99140diff --git a/net/netfilter/nf_sockopt.c b/net/netfilter/nf_sockopt.c
99141index f042ae5..30ea486 100644
99142--- a/net/netfilter/nf_sockopt.c
99143+++ b/net/netfilter/nf_sockopt.c
99144@@ -45,7 +45,7 @@ int nf_register_sockopt(struct nf_sockopt_ops *reg)
99145 }
99146 }
99147
99148- list_add(&reg->list, &nf_sockopts);
99149+ pax_list_add((struct list_head *)&reg->list, &nf_sockopts);
99150 out:
99151 mutex_unlock(&nf_sockopt_mutex);
99152 return ret;
99153@@ -55,7 +55,7 @@ EXPORT_SYMBOL(nf_register_sockopt);
99154 void nf_unregister_sockopt(struct nf_sockopt_ops *reg)
99155 {
99156 mutex_lock(&nf_sockopt_mutex);
99157- list_del(&reg->list);
99158+ pax_list_del((struct list_head *)&reg->list);
99159 mutex_unlock(&nf_sockopt_mutex);
99160 }
99161 EXPORT_SYMBOL(nf_unregister_sockopt);
99162diff --git a/net/netfilter/nfnetlink_log.c b/net/netfilter/nfnetlink_log.c
99163index d92cc31..e46f350 100644
99164--- a/net/netfilter/nfnetlink_log.c
99165+++ b/net/netfilter/nfnetlink_log.c
99166@@ -82,7 +82,7 @@ static int nfnl_log_net_id __read_mostly;
99167 struct nfnl_log_net {
99168 spinlock_t instances_lock;
99169 struct hlist_head instance_table[INSTANCE_BUCKETS];
99170- atomic_t global_seq;
99171+ atomic_unchecked_t global_seq;
99172 };
99173
99174 static struct nfnl_log_net *nfnl_log_pernet(struct net *net)
99175@@ -563,7 +563,7 @@ __build_packet_message(struct nfnl_log_net *log,
99176 /* global sequence number */
99177 if ((inst->flags & NFULNL_CFG_F_SEQ_GLOBAL) &&
99178 nla_put_be32(inst->skb, NFULA_SEQ_GLOBAL,
99179- htonl(atomic_inc_return(&log->global_seq))))
99180+ htonl(atomic_inc_return_unchecked(&log->global_seq))))
99181 goto nla_put_failure;
99182
99183 if (data_len) {
99184diff --git a/net/netfilter/xt_gradm.c b/net/netfilter/xt_gradm.c
99185new file mode 100644
99186index 0000000..c566332
99187--- /dev/null
99188+++ b/net/netfilter/xt_gradm.c
99189@@ -0,0 +1,51 @@
99190+/*
99191+ * gradm match for netfilter
99192